synctex + gedit + evince

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.

External Tools Code

PDFLatex tool
Name: PDFLatex
Shortcut Key: p
Save: Current Document
Input: Nothing
Output: Display in bottom pane

pdflatex -synctex=1 -interaction nonstopmode "$GEDIT_CURRENT_DOCUMENT_NAME"

Name: Bibtex
Shortcut Key: b
Save: Current Document
Input: Nothing
Output: Display in bottom pane


Synctex Forward
Name: Synctex Forward
Shortcut Key: f
Save: Nothing
Input: Nothing
Output: Display in bottom pane


Instructions for getting it all working

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...

Existing Issues

  1. Both evince and gedit must be run on the same desktop in Natty. If not the evince_backward_search script will load gedit once and then hang. Further Ctrl+clicks will produce no action until the previous gedit instance is closed. At this point the script will process the unactioned events.
  2. The evince_backward_search script does not exit. If you want the process killed you must do it manually. I'm not sure what I'd like here. Perhaps that the script exits once the evince process displaying the same file name exits. There must be a way to do this using the dbus, but I'm not (currently) worked up enough about it to care.
  3. The pdflatex external tool does not stop for errors (you can change this by removing -interaction nonstopmode


  1. 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.

  2. 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!

  3. 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 to window.SyncView(tex_file, (line_number,1), int(time.time()), dbus_interface="org.gnome.evince.Window")
  4. . Again this was debugged using dfeet. A great little tool. I just wish that there was a document that presented the evince dbus API!

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.