Forward and backwards search for latex source and their compiled images is a must have feature for me. I also very much like Ubuntu (and Linux in general). Wherever possible I prefer to avoid installing new software. I also like using programs that do what I want but nothing more.
For these reasons I've been trying to get forwards and backwards search with gedit and synctex working for some time. I'm told that both the gedit synctex and gedit latex plugins work well in gnome 3. Unfortunately Ubuntu Natty does not currently play well with gnome 3. It is more unfortunate then that neither the gedit synctex plugin nor the gedit latex plugin work on my machine. Don't ask me why, all I get are series of python exceptions. I've tried just about everything, including cloning the gedit-plugin repository checking out branch gnome-2.32, manually install the plugin code and applying all relevant plugins: I still get python exceptions relating to the gedit/plugin interaction.
Believe me, I've wanted to fix this problem for sometime. Indeed I was so motivated that I stated learning how the dbus works so that I could write my own script to solve the problem. That was when I stumbled across this page. The files that can be downloaded via a link on the first post are written by the same fellow who wrote the evince synctex plugin. The difference here is that they only interact with the dbus. Since the python exceptions I was getting were to do with the why the gedit plugins were implemented and not to do with the dbus interaction these files have solved my problem (but see below for existing problem).
So using the external tools plugin with the following settings I now have forward and backward search working. Note that my system hangs if I attempt to change the applicability settings, thus I won't list them below.
PDFLatex tool
Name: PDFLatex
Shortcut Key: p
Save: Current Document
Input: Nothing
Output: Display in bottom pane
Code:
#!/bin/bash
pdflatex -synctex=1 -interaction nonstopmode "$GEDIT_CURRENT_DOCUMENT_NAME"
Bibtex
Name: Bibtex
Shortcut Key: b
Save: Current Document
Input: Nothing
Output: Display in bottom pane
Code:
#!/bin/sh
bibtex ${GEDIT_CURRENT_DOCUMENT_NAME%.tex}.aux
Synctex Forward
Name: Synctex Forward
Shortcut Key: f
Save: Nothing
Input: Nothing
Output: Display in bottom pane
Code:
#!/bin/sh
evince_forward_search "${GEDIT_CURRENT_DOCUMENT_PATH%.tex}.pdf" "${GEDIT_CURRENT_LINE_NUMBER}" "${GEDIT_CURRENT_DOCUMENT_PATH}"
The external tools above will allow for compilation of the latex code and for forward search. Backward search must be set up by hand. Use the following command or variations there of;
evince_backward_search myfile.pdf "gedit +%l %f"
It goes without saying that evince_backward_search
must be placed in a folder that is in the $PATH
environment. If I could be bothered one could write a nice script to load evince with the appropriate pdf, load evince_backward_search, and then kill it on exit of evince...
-interaction nonstopmode
I have discovered a problem with files whose absolute path contains spaces. The issue arises on line 75 as the url returned by the dbus is format with special characters while self.url is not. This can be fixed by replacing the string 'file://'+pdf_file
with 'file://'+urllib.quote(pdf_file,safe="%/:=&?~#+!$,;'@()*[]")
on line 158. Remember to import the package urllib. This solution came from the nice people of stackoverflow.
20th October 2011
The update to Ubuntu 11.10 breaks the file evince_backward_search
. Change line 124 to def on_sync_source(self, input_file, source_link,timestamp):
. For some reason (I assume an update to the dbus) Ubuntu hands over 3 rather than 2 variables. The extra variable seems to be a time stamp. For those that are interested I used dfeet to have a look at this. Enjoy!
6th September 2012
This time evince_forward_search broke. Looks like an additional argument was added into the evince dbus API for the SyncView method. Just change line 50 towindow.SyncView(tex_file, (line_number,1), int(time.time()), dbus_interface="org.gnome.evince.Window")
Lastly: Yes I can see that the <code> tag isn't formatted correctly in the lists... I will have to talk to the maker of this theme.