Lyx reverse search in windows

I’m still using this setup in Lyx 2.0.0 as the method they describe in Help/Additional Features doesn’t take into account spaces in file names. I can’t get the reverse search button to do anything of value either.

I’ve had this working for a while. I’ve not noticed anyone posting about how to use it without cygwin. This works with the standard windows version of lyx rather than the cygwin version. Its a bit of a stupid method with some cludges but it does work fine, its not as neat as the cygwin version (which it’s basically a port of). If anyone manages to clean it up a bit and remove some of the dependancies that would be good.

Requirements:

  • Python 2.6 (might work with other versions not tried it)
  • win32api – Python extension (to find the short pathnames)
  • SumatraPDF – This is the only appropriate windows pdf viewer I am aware of. It prints badly though in my experience.
  • ReverseSearch – The scripts defined below

Setup:

  • Set the lyxserver pipe (under paths in the settings) to “\\.\pipe\lyxserver”
  • put “SumatraPDF.bat”, “search.py” and “SumatraPDF.exe” in “../lyx16/bin”
  • Update the paths in “SumatraPDF.bat” to be correct for your setup (mine is 64bit), use pythonw.exe to supress the console
  • Set your in “PDF (pdflatex)” viewer field (in file formats) to: SumatraPDF.bat
  • Set the “Latex (pdflatex) -> PDF (pdflatex)” converter to “pdflatex –synctex=-1 $$i”

Fixes:

  • If it won’t work uncomment the time.sleep(100) line to see python errors and change “pythonw.exe” to “python.exe” in “SumatraPDF.bat”. Also take out start “SumatraPDF.exe”.
  • To turn on debugging in lyx for the pipe use the flag -dbg lyxserver. This will probably say something illuminating, or nothing at all if its not worked.

SumatraPDF.bat

start "SumatraPDF.exe" "SumatraPDF.exe" -inverse-search "C:/Progra~1/Python26/pythonw.exe C:/Progra~2/lyx16/bin/search.py %%l %%f" %1
exit

search.py

# This script (along with sumatra.bat) enables DVI/PDF search in windows using Sumatra
import sys
import time
import os
import win32api

#Debug output to ensure the path name is picked up properly
print(sys.argv[1])
print(sys.argv[2:])
line = sys.argv[1]
filename = ' '.join(sys.argv[2:])
print(filename)

#We have to get the windows short filename to avoid having spaces which upsets the command
filename = win32api.GetShortPathName(filename);

#create the command to be send to the lyx server pipe with an echo to a windows pipe
command = "echo LYXCMD:revdvi:server-goto-file-row:"+filename+" "+line+">> \\\\.\pipe\lyxserver.in"

#print it for debugging and send it to the os
print(command)
os.system(command)

#Uncomment the next line if there are problems, it lets you see  the debugging output (this is still suppressed with pythonw.exe though)
#time.sleep(100)

5 comments

  1. Hi;

    Thank you very much for this guide, if i can get this one work for me, it will be great.

    I did follow all the steps above, but somehow still i couldn’t get it to work. At the end, when i compile the file, it doesn’t give any error or anything but at the same time, when i go to pdf file in sumatra, if i try double click or alt+rightclikc or ctrl+click, it doesn’t take me back to the lyx file.

    I would try to run lyx in debugging mode, but i am newbie and don’t know how to do that.

    Thanks for the help.

    Guven

    • Chris Lingwood

      Double clicking won’t take you back to lyx, but hopefully (if you’ve got it working properly) the cursor in lyx will jump to (very nearly) the right place. Make sure it’s a longish document you test it with otherwise it can be tricky to see if it has worked.

      The lyx debug will probably not tell you the problem. The problem is almost certainly before lyx gets involved. Try the first of the fixes where you can see the output of the python.

      If you double click on the sumatra document and no python window appears then the paths in “SumatraPDF.bat” are probably wrong. Make sure they are old style “short” paths like this “C:/Progra~1/Python26/pythonw.exe” putting long path names (with spaces and things) upsets one or other part of this method. Ensure that both paths are correct.

  2. Thanks a lot for the script, I have modified it a bit to use it with LED editor and it seems to work:
    **** begin ****
    # This script (along with sumatra.bat) enables DVI/PDF search in windows using Sumatra
    import sys
    import time
    import os
    import win32api

    #Debug output to ensure the path name is picked up properly
    print(sys.argv[1])
    print(sys.argv[2:])
    line = sys.argv[1]
    filename = ‘ ‘.join(sys.argv[2:])
    print(‘FILENAME: ‘ + filename)

    #We have to get the windows short filename to avoid having spaces which upsets the command
    #filename = win32api.GetShortPathName(filename);

    #create the command to be send to the lyx server pipe with an echo to a windows pipe
    #command = “echo LYXCMD:revdvi:server-goto-file-row:”+filename+” “+line+”>> \\\\.\pipe\lyxserver.in”
    command = “c:\Util\LEd\LEd.exe ” +'”‘+filename+”:”+line+'”‘

    #print it for debugging and send it to the os
    print(command)
    os.system(command)

    #Uncomment the next line if there are problems, it lets you see the debugging output (this is still suppressed with pythonw.exe though)
    #time.sleep(100)
    ##fileOUT = open(‘out.txt’, ‘w’)
    ##fileOUT.write(command)
    ##fileOUT.close()
    **** end ****

    the line to be added to the options in sumatraPDF is:

    C:/Util/Python27/pythonw.exe C:/Util/LEd/search.py %l %f

    (of course modify the paths accordingly to your system)
    If you add it into the options menu of SumatraPDF there is no need to launch it through the batch file,

    Hope it helps,

    Enjoy

  3. Hi,

    I am also very interested in using LEd with Sumatrapdf. I tried everything that was described above, but unfortunately it didn´t work. For instance, “pdflatex –synctex=-1 $$i” because LEd couldn’t handle $$i.

    What can I try to make it running?

    Thanks,

    batch

Leave a Reply