Go to page:

Search:   Help



LyX documentation


Shared groups


LyX /


Categories: Category SyncTeX
<< | Page list | >>

--which version of LyX is described? 1.6 and 2.0 have completely different approach to it. note that lot of info about forward/reverse search in lyx advanced manual --ps

This page describes how to use SyncTeX to get reverse search, that is, the ability to get from a line in a PDF to the same line in the LyX document with a single click.

Forward and Reverse Search Settings for LyX 2.0

NB: forward/reverse search does not seem to work (on OS X at least) if the LyX.app is renamed or not in /Applications. A work-around for this is to put a symlink (symbolic link) in /Applications that points to Lyx.app. Using an OS X alias will not work. To create the symlink, open Terminal.app which is in /Applications/Utilities by double-clicking on it. Then paste a line like the following

ln -s /path/to/LyX.app /Applications

where /path/to/ is the path to the folder containing LyX.app. Hit return and quit Terminal.app. Check /Applications to see if the symlink is there—it should look like the LyX.app icon but with a small arrow added. Note that symlinks are different from aliases in that with an alias, if the target (pointed-to) file is moved, the alias will still point to it but the symlink will not. Finally, there is a free utility that can be used if one prefers to not use Terminal.app; see https://www.macupdate.com/app/mac/10433/symboliclinker.

Setting up LyX

  • In Document > Settings > Output, check Synchronize with output
  • If your viewer needs another output format than \synctex=-1 (which is the default), select it or insert it in "Custom Macro"
  • Modify Output > General > PDF for your PDF viewer (see the viewer-specific notes below)

Viewer-specific notes


As opposed to many other readers, forward and backward search with evince requires some helper scripts to be installed (since evince uses the D-Bus channel to communicate with editors). These scripts can be downloaded here. Installation and setup instructions are included in the ZIP archive (see README file).


In LyX,

  • LyX > Preferences > Output > General > PDF command: /path/to/Skim.app/Contents/SharedSupport/displayline $$n $$o $$t where /path/to/ is the path to Skim.app which is frequently just /Applications/.

In Skim:

  • Skim PDF-TeX Sync setting: Custom
  • command: /Applications/LyX.app/Contents/MacOS/lyxeditor
  • arguments: "%file" %line; /usr/bin/osascript -e 'tell application "LyX" to activate'


In LyX (Forward search):
  • On Windows: Add KDE's bin path (e.g. C:\ProgramData\KDE\bin\) as search path to LyX, separated with semicolon before (at Tools > Preferences > Paths > PATH)
  • Tools > Preferences > Output > General > PDF command: okular --unique "file:$$o#src:$$n $$f" or okular --unique "$$o#src:$$n $$f" (Windows)
  • This only works in LyX version 2.0.5+
In Okular (Inverse search):
  • Click Settings > Configure Okular
  • On Linux:
* Click Editor, and select LyX-client from the drop-down list.
* If it doesn't work, try "Custom editor" and insert lyxeditor %f %l
  • On Windows:
At the following two subpoints, change LyX's bin path (here as an example C:\Program Files (x86)\LyX\bin\)) accordingly:
* Click Editor, select "Custom Text Editor" and insert "C:\Program Files (x86)\LyX\bin\lyxeditor.cmd" "%f" "%l" (don't delete the quotation marks before "C:" and after "cmd")
* create a batch-file in LyX's bin path named lyxeditor.cmd:

@echo off
SETLOCAL enabledelayedexpansion
set file=%1
set row=%2
REM remove quotes from variables 
set file=!file:"=!
set row=!row:"=!
%comspec% /q /c (@echo LYXCMD:revdvi:server-goto-file-row:%file% %row%)> \\.\pipe\lyxpipe.in&&type \\.\pipe\lyxpipe.out

* Additional Settings for LyX 2.1.x:
* Enter Tools > Preferences > File Handling > Converters
* Click "LaTeX (pdflatex) > PDF (pdflatex)" in the list. In the "Converter" box, it now says pdflatex $$i. Instead, put pdflatex -synctex=-1 $$i there.
* Click Modify to the right of the list, then Apply.
  • Now, holding SHIFT while clicking with your left mouse button somewhere in the PDF should make LyX move to the corresponding position in the source document. Note that this only works in Browse mode - for example, pressing Shift-click will not do anything in Text Selection mode.

Sumatra PDF (on Windows; Updated 2015-10-19)

Tools → Preferences → Path

  • Add the directory, where SumatraPDF.exe resides, to the PATH prefix line.
  • Set the line LyXServer pipe to \\.\pipe\lyxpipe.

Tools → Preferences → File Handling → Converters

  • Select the format LaTeX (pdflatex) -> PDF (pdflatex)
  • Set the entry converter to
      pdflatex -interaction=nonstopmode -synctex=1 $$i
  • Click Modify (otherwise the change will be discarded).
  • This change is needed to make MikTeX produce a FILE.synctex.gz file.

Tools → Preferences → Output → General

  • In the “forward search” section set the entry PDF command to
      SumatraPDF -reuse-instance "$$o" -forward-search "$$t" $$n

Tools → Preferences → File Handling → File Formats

  • Select the format PDF (pdflatex)
  • Set the Viewer field to Custom with a command
    SumatraPDF -reuse-instance -inverse-search "CMD /C (ECHO LYXCMD:revdvi:server-goto-file-row:%f %l) > \\.\pipe\lyxpipe.in"
    (Note: inverse search of .lyx files with spaces or other special characters in the file name does not work with this approach on some Windows systems)
  • You may need to close all SumatraPDF windows and use “Document → View”.
  • Alternatively you can set inverse search command directly in SumatraPDF by going to “Preferences → Options” and set the fields “Command line for the inverse search” to CMD /C (ECHO LYXCMD:revdvi:server-goto-file-row:%f %l) > \\.\pipe\lyxpipe.in. In this case you can reduce the “Viewer” command to SumatraPDF -reuse-instance.


  • Unlike in some plain-LaTeX editors, forward search will not be toggled by the “Document → View” command; It must be explicitly used with “Right Click → Forward Search”.
  • Inverse search (from SumatraPDF to LyX) is effected by double clicking on a line in Sumatra.

Additional Remarks

  • The current version was tested with LyX 2.1.3 and 2.1.4. Also LyX 2.2.2 and SumatraPDF v.3.1.2 (64 bit) on Windows 7.
  • If pasting from the wiki into LyX (e.g. SumatraPDF -reuse-instance) when following these instructions, ensure that you do not also paste a bullet at the start of the entry!
  • Judging from the old text, the “Converters” setting wasn't required before LyX 2.1.x.
  • The old version of this section mentioned an alternative value of \\.\pipe\C:\lyxserver in case that reverse search doesn't work.If you try, you need to change \\.\pipe\lyxpipe.in into \\.\pipe\C:\lyxserver.in.
  • Renaming the pipe to C:\lyxserver shouldn't make any difference, as on Windows named pipes reside in their own namespace, separate from user-accessible files. \\.\pipe\C:\lyxserver should have nothing to do with the file \\.\C:\lyxserver aka C:\lyxserver
  • The old version used a “Viewer” command SumatraPDF -reuse-instance -inverse-search "lyxeditor.cmd \"%f\" \"%l\"" with the script mentioned in the section for Okular.

Forward and Reverse Search Settings for LyX 1.6.*

To get this wonderful feature, you'll have to (1) enable SyncTeX in LyX, and (2) set LyX as the editor in your PDF reader.

Enable SyncTeX in LyX

First you'll have to ensure that LyX writes the SyncTeX file which tells your PDF reader about the correspondences between PDF positions and source document positions.

  1. Enter Tools > Preferences > File Handling > Export programs
  2. Click "LaTeX (pdflatex) > PDF (pdflatex)" in the list. In the "Export program" box, it now says pdflatex $$i. Instead, put pdflatex -synctex=-1 $$i there.
  3. Click Modify to the right of the list, then Apply.

(Some tutorials will tell you to use -synctex=1 instead. This enables compression, in order to save some disk space. However, the PDF readers I've tried have not been able to use the compressed file.)

Set LyX as SyncTeX editor in your PDF reader

If you use Okular

  1. In Okular, click Settings > Set up Okular
  2. Click Editor, and select LyX-client from the drop-down list.

Now, holding SHIFT while clicking with your left mouse button somewhere in the PDF should make LyX move to the corresponding position in the source document.

If you use Skim.app

  1. In Skim, click Preferences > Sync
  2. Select LyX in the menu

Now, holding COMMAND-SHIFT while clicking with your left mouse button somewhere in the PDF should make LyX move to the corresponding position in the source document.

In case LyX does not open Skim.app as your previewer: In LyX, click Preferences > File formats > PDF (pdflatex), enter open -a Skim.app $$i in the viewer setting. Then you need to click the Modify button, and then Save.

If you use Sumatra, yap or xdvi on Cygwin

See http://wiki.lyx.org/LyX/LyXOnCygwin#toc6

Troubleshooting SyncTeX

Make sure that the .lyxpipe.in and .lyxpipe.out files do not exist when LyX is not running. (They are normally deleted when LyX quits, but if LyX crashes, they remain and prevent LyX from communicating with PDFView.) Their location can be found in LyX > Preferences > Paths.

SyncTeX vs pdfsync

Another possible way of getting reverse-search is adding \usepackage{pdfsync} to the LaTeX preamble. However, this method is seen as deprecated now. (SyncTeX was created by the same person as pdfsync, and has the potential for more precise positioning; although LyX is at the moment not able to completely make use of the extra precision.)


Category SyncTeX

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2017-07-20 08:37 CEST