Wednesday, August 5, 2009

Setting up TeXlipse and Sumatra PDF


Update (24-03-2012)
Instead of going through the hassle of configuring SumatraPDF (steps 4-8 below), it's way easier to use the Eclipse PDF viewer PDF4Eclipse. It's specifically written for TeXlipse, and has forward- and inverse-search out-of-the-box.


After raving about how brilliant TeXlipse is, it's perhaps time to describe my actual LaTeX setup on Windows. The key ingredients are:
  • LaTeX distribution: MikTeX. I currently have version 2.7 installed, which has SyncTeX support (important for forward- and inverse-searching in PDF files). I haven't tried TeX Live, but that should in principle also work (it also has SyncTex support).
  • Editor: Eclipse + TeXlipse.
  • Previewer: Sumatra PDF. Yes, that's right, no DVI files for me!
Installation is a bit difficult, but worth the while. Here's how you do it:
  1. Download and install MikTeX 2.7 (or newer if you're up for it). Shouldn't be too difficult.
  2. Get a good version of Eclipse. A bit more difficult, since there are gazillion versions floating on the internet. The standard ones come with support for either C++ or Java, which we don't want. The cleanest distribution I could find is the Platform Runtime Binary. Download it and extract the zip file in C:\Program Files\ or the likes. Also put a shortcut to eclipse.exe on the desktop if you're lazy like me.
  3. Fire up Eclipse and follow the instructions on the TeXlipse website in order to install TeXlipse.
  4. Download and install Sumatra PDF. Also easy.
  5. And now the going gets though: it's time to configure TeXlipse. Luckily the TeXlipse folks also have a page for that. The extra ingredient from me is to add the switch "-synctex=1" to the pdflatex command, which enables PDF syncing. The pdflatex config should look something like this:
  6. Add a new viewer configuration for SumatraPDF, and make it the top of the list so it's the default viewer. Here's how its config should look:
  7. We're almost done. We still need to configure the inverse search for Sumatra PDF. Create a .BAT file in the Eclipse directory (or somewhere else convenient), with the following line:
    java -classpath "%ECLIPSEDIR%\plugins\net.sourceforge.texlipse_1.3.0\texlipse.jar" net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f %1 -l %2
    There are no hard line breaks here, it's just one single line. Also add a environment variable via Control Panel -> System -> Advanced -> Environment variables -> System variables -> New. The variable name should be "ECLIPSEDIR", its value "c:\program files\eclipse" or wherever you installed Eclipse (both without the quotes).
  8. Configure Sumatra PDF for inverse search by running the command
    SumatraPDF.exe -inverse-search "\"C:\Program Files\eclipse\inverse_search.bat\" \"%f\" %l"
    where you should take care to properly point to the .BAT file you created in the previous step.
And that's it. Now you should be ready to experience all the wonders of the TeXlipse + Sumatra PDF combination. Enjoy!

35 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thanks for working this out! Unfortunately, for me forward search is hit and miss (and mostly miss!) - sometimes it works and the correct line is highlighted, sometimes nothing happens and SumatraPDF does not even obtain focus. Any ideas? (My suspicion is that there is a problem with the DDE communication, but I'm not sure how to check that.)

    ReplyDelete
  3. Sorry, I also don't have a clue. You might try to ask for support at the TeXlipse or SumatraPDF forums.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. There is not need to create a file inverse_search.bat. Just run the following command (all in one line):

    SumatraPDF.exe -inverse-search "java -classpath \"%ECLIPSEDIR%\plugins\net.sourceforge.texlipse_1.3.0\texlipse.jar\" net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f \"%f\" -l %l"

    Don't forget to define %ECLIPSEDIR% as described in the blog post or replace it with actual path to the Eclipse installation.

    ReplyDelete
  7. Yup, that should work too. Thanks for the contribution!

    ReplyDelete
  8. it doesn't work......forwards works ok but inverse don't...i just get a flash command windows that appears and disappear

    ReplyDelete
  9. You should double check the path:

    \plugins\net.sourceforge.texlipse_1.3.0\texlipse.jar

    My path was actually:

    \plugins\net.sourceforge.texlipse_1.4.0\texlipse.jar

    ReplyDelete
  10. All was OK, but the next day, I didn't change anything but it didn't work....

    I start sumatraPDF with this command :
    SumatraPDF.exe -inverse-search "\"C:\Program Files\eclipse\inverse_search.bat\" \"%f\" %l"

    When I want to use inverse search, SumatraPDF try to execute this command :
    "C:\Program Files\eclipse\inverse_search.bat" "%f\" %l

    I don't understand why the \" after %f is not replaced by ".

    If anybody has the same problem, the soluce is to replace the file SumtraPDF.exe by this version : http://william.famille-blum.org/software/sumatra, and to configure inverse-search in Preferences/Options instead of -inverse-search command

    ReplyDelete
  11. I tried the instructions above but failed. The first time I launched the preview it actually appeared. Subsequent attempts didn't show the PDF but added a launch configuration with a consecutive number. I've no clue what went wrong. Any ideas anyone??

    Rryk said that the two commands can be executed at once. How often do I have to execute it and when? Only once to configure SumataraPDF or each time I'd like to see a preview (wouldn't make sense to me)?

    I have no experience with inverse search and don't care (for now). I just wanted the use the auto-refresh feature so that I don't have to open and close the PDF over and over again.

    ReplyDelete
  12. It could be that the path to the TeXlipse plugin in step 7 is wrong, as the newest version is 1.4.0, and not 1.3.0. Try changing that, and see if it works.

    ReplyDelete
  13. This is what I prompted:
    C:\Programme\SumatraPDF>SumatraPDF.exe -inverse-search "java -classpath \"C:\programme\eclipse\eclipse3.5\plugins\net.sour
    ceforge.texlipse_1.4.0\texlipse.jar\" net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f \"%f\" -l %l"

    Nothing happened. Except for adding a run configuration each time I hit the preview button.

    When compiling the document:
    pdflatex.exe> SyncTeX written on document.synctex.gz
    pdflatex.exe> Transcript written on document.log.

    The document.synctex.gz file is nonreadable and the document.log file doesn't contain a word about Sumatra.

    Any suggestions?

    ReplyDelete
  14. If you get document.synctex.gz the you should change "-synctex=1" to "-synctex=-1" in order to get the correct file type.

    ReplyDelete
  15. Try downloading PDF (modified for TEX) from this site (the site also contains some directions on integrating Texlipse and Sumatra)

    http://william.famille-blum.org/blog/static.php?page=static081010-000413

    It worked for me. ;)
    Cheers!

    ReplyDelete
  16. WARNING:
    I was using
    pdflatex Version 3.1415926-1.40.8-alpha-20080323 (MiKTeX 2.7)
    it does not support paramter -synctex !
    So compilation was aborted and the old pdf file was used. sumatrapdf just told me "no synchronization file found". Solution: Use miktex 2.8.

    ReplyDelete
  17. After a little work I got it to work. Thanks.
    For those of you also doing this make sure you include the correct version number/ file location for texlipse in the .bat file. I had to change it to 1.4.1

    ReplyDelete
  18. Thanks for the post, I got everything working except inverse search. The inverse search command in SummatraPDF is

    java -classpath "C:\Eclipse\plugins\net.sourceforge.texlipse_1.4.1\texlipse.jar" net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f "%f" -l %l

    and if I double-click in the document, I get the error "Empty lineNumber" in a shell window. I tried substituting concrete values in the inverse search command, e.g.

    java -classpath "C:\Eclipse\plugins\net.sourceforge.texlipse_1.4.1\texlipse.jar" net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f "C:\document.tex" -l 40

    This works perfectly, when I run it from the command line. However, running it from within SumatraPDF results in the "Empty lineNumber" error. Any ideas?

    ReplyDelete
  19. Nevermind: Wrapping everything in a BAT file solves the problem for some reason.

    ReplyDelete
  20. Thanks for the very helpful description. I was struggling with the location of the texlipse.jar file. I found mine in my user directory. My command in the .bat file looks like this:
    javaw -classpath C:\Users\myname\.eclipse\org.eclipse.platform_3.6.1_1709980481\plugins\net.sourceforge.texlipse_1.4.1\texlipse.jar net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f %1 -l %2

    ReplyDelete
  21. Thanks for the detailed directions! When I click in SUMATRA, instead of returning control to ECLIPSE my *.tex file appears in notepad. Any ideas? Thanks in advance.

    Alan-

    ReplyDelete
  22. Hi
    I am having the same problem as Alan,
    has anybody any ideas?

    ReplyDelete
  23. Thanks for the detailed info Teake!
    On Win7 64bit I ran into an issue with inverse search. Clicking in Sumatra did nothing. However, manually entering the command in a prompt window worked. Turns out that for some mysterious reason it could not find the java executable, I had to give the full path to java.exe

    Alan, try this: In your .bat file add PAUSE in another line. This keeps the prompt window open, such that you can examine the actual command that is executed...

    ReplyDelete
  24. Thank you very much for this helpful blog entry!

    ReplyDelete
  25. Hi, I get the following error message:

    C:\Program Files (x86)\SumatraPDF>"C:\Program Files\Java\jdk1.6.0_21\bin\java.ex
    e" -classpath ""D:\eclipse\"\plugins\net.sourceforge.texlipse_1.4.1\texlipse.jar
    " net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f "l -l
    Unrecognized option: -l
    Could not create the Java virtual machine.

    ReplyDelete
  26. I following step very important for me


    To use the first one you just need to load the 'pdfsync' package in your latex document as follows:
    \usepackage{pdfsync}

    ReplyDelete
  27. thx.. it was very helpful ;)

    ReplyDelete
  28. Thanks very much for this - it works perfectly. I had to install the pdfsync package (didn't have it by default), and the closest thing I could find to a texlipse.jar file was net.sourceforge.texlipse_10401.7.0.b201106190930E36sw.jar, which was located in the plugins folder. I guess this was what was needed, as it works...

    ReplyDelete
  29. Hi, I have problem with "inverse search" in win7 64-bitar. Nothing happens when I run the following command in the cmd:

    java -classpath "C:\Program\Eclipse SDK\plugins\net.sourceforge.texlipse_1.4.2\texlipse.jar" net.sourceforge.texlipse.viewer.util.FileLocationClient -p 55000 -f "C:\Thesis\chap6.tex" -l 87

    but if I change the port, i.e., -p 55005 I get the following results in the cmd:

    Couldn't get I/O for the connection to: localhost

    thus, something is wrong with Eclipse since the program does recognize the port
    but no ''marked lines'' are showed on the screen.

    ReplyDelete
  30. Does not work. Eclipse opens pdf files always with Adobe Reader and ignores the TeXlipse' viewer settings (I have put SumatraPDF to the top of the list, of course). I want to use Adobe Reader as system default PDF viewer and Sumatra as TeXlipse default only. This seems to be impossible...

    ReplyDelete
  31. Hi,

    thx Teake for the tutorial.

    Got it working right now with a bat-file. That works out for the moment.

    But I would prefer to run the command directly from sumatraPDF (no cmd-window flashing).
    As someone said earlier it does not find the java.exe, so I gave it the full path.
    Now it says something like
    "Error. The main class net.sourceforge.texlipse.viewer.util.FileLocationClient cannot be found or loaded"

    Seems it runs in some kind of sandbox...I tried to run sumatra with admin rights, but it's still the same error.

    Does anybody know a solution here?

    Greez
    Alex

    PS: Im running Win7x64

    ReplyDelete
  32. Try javaw instead of java in the command line set up for inverse search.

    Best

    Egon

    ReplyDelete
  33. Thanks for the PDF4Eclipse tip!
    Why don't you move it towards the top of the post?
    Cheers,

    ReplyDelete