[Tex/LaTex] LyX + SyncTeX + Document Viewer Evince


I am running LyX 2.0.2 in Ubuntu 12.04 and using the default PDF viewer Evince.

I want to setup SyncTeX to go back and forth between the document and the source, at the right position in the text.

I found this in the LyX website, but it doesn't give the Evince viewer.

Does anybody know how to set it up?

Best Answer

It seems there's no easy way to do this, yet.

Modifying Scripts

  • Download files. (They are from Benjamin Kellermann, originally posted to Ubuntuusers on March 2011, based on an older version of the Gedit Synctex Plugin by Jose Aliste.)
  • Extract them, e.g. to your desktop.
  • Rename the file evince to evince-synctex. (To be sure that this file will be started because /usr/bin/evince will be found first in PATH.)
  • Open this file (evince-synctex) and replace the second line (starting with EDITORCMD) to

    EDITORCMD="lyxclient -g %f %l"
  • In file evince_backward_search, replace the line

    cmd = re.sub("%f",input_file,self.editor) with

    cmd = re.sub("%f",input_file.split("file://")[1],self.editor)

    Be sure that this text aligns with the text of the lines afterwards. (That change is needed because it seems that LyX can't handle filenames starting with "file://".)

  • Move all three files (evince-synctex, evince_backward_search, evince_forward_search) to /usr/local/bin (needs root rights). (That's the place where user scripts should be stored.)

Extra for Evince 3.4.0 (= Ubuntu 12.04)

In file evince_forward_search, replace the last line (starting with window.SyncView() with

window.SyncView(tex_file, (line_number,1), int (time.time ()), dbus_interface="org.gnome.evince.Window")

Setting up LyX

  • In Document > Settings > Output, check Synchronize with output
  • In Tools > Preferences > Output > General > PDF command, write evince_forward_search $$o $$n $$t
  • Change PDF Viewer (Tools > Preferences > File Handling > File Formats > PDF (pdflatex)) to evince-synctex.

Backward Search (Evince -> LyX)

  • Open file in LyX, view "PDF (pdflatex)".
  • Hold Ctrl key and (left-)click on the line you want to edit. It should be shown in LyX now.

Forward Search (LyX -> Evince)

  • Open file in LyX, view "PDF (pdflatex)".
  • Right-click on one line (in LyX), choose "forward search".