Using TeXstudio with SumatraPDF

SumatraPDF is my favourite pdf reader and TeXstudio is my favourite LaTeX editor. Here’s how to get them to work nicely together.

Go to Options/Configure TeXstudio and click on “Commands”. Beside Pdf Viewer, untick “Internal viewer” and add the following command:

"c:/Program Files/SumatraPDF/SumatraPDF.exe" -reuse-instance %.pdf

(If you have SumatraPDF stored somewhere other than the specified paths, you will need to edit this accordingly.)

Then you need to tell SumatraPDF how to jump to the correct line in TeXstudio. From within SumatraPDF, go to Settings/Options and set the inverse search command to

"C:\Program Files\TeXstudio\texstudio.exe" "%f" -line %l

Change the path to TeXstudio if necessary.

In order to go from the tex file to the corresponding location in the pdf, you can add a ForwardSearch command within TeXstudio. Select “User” from the main menu, then “User commands” and “Edit User commands”. Then add a command with the following definition:

dde://"C:/Program Files/SumatraPDF/SumatraPDF.exe":SUMATRA/control/

(That should all be on one line with no space before [ForwardSearch. Again, edit the path for SumatraPDF as necessary. Give the command a name such as “ForwardSearch” and click “OK”. Now you should be able to jump to the corresponding part of the pdf file using “Alt-Shift-F1” (or whatever key-combination is associated with your new command).

Being lazy, I prefer a simple function key. To map F2 to your new command, select “Options/Configure TeXstudio” and choose “Shortcuts”. Find your new command under the User menu, double click to the right of it and select “F2” from the drop-down box. Previously F2 was mapped to LaTeX, but I never use LaTeX directly, so losing this function is no problem.

Now you can double click on any part of the pdf from within SumatraPDF and it should take you to the corresponding place in your tex file in TeXstudio. And then F2 will take you back again.

Related Posts:

  • Desalegn 1Delu

    Thank you so much. it was helpful

  • Dellu

    Great guide. I also love the two applications. thanks

  • Aline Menezes

    Thank you very much indeed!

  • This information was very useful! Thank you.

  • ziv ran

    This is great. Just one little thing: how do you make sumatra automatically in focus
    when you forward search. Thanks.

  • Alex

    Many thanks from the most beautiful country in the world (Italy ;-))

  • In the newest version of TeXStudio (2.5.2), the setting for external pdf viewer doesn’t work any more… I appreciate it if you can check and update the settings.

  • Charles

    Thank you very much. I’ve been looking for these TexStudio and Sumatra commands a lot, and then all of them are neatly described here. Cheers.

  • Pingback: LaTeX unter Windows mit TeXstudio und Sumatra PDF « geloest()

  • Bianca

    This would be very helpful but it seems my SumatraPDF viewer, in the “options” menu, has no way to input the inverse search com­mand, just has “view” and “advanced” tabs. Any help wpuld be appreciated

  • Big T

    Thank you very much. It was pretty difficult to find these commands after the path by myself.

  • Guest

    Great guide, containing exactly the information I needed. Thank you!

  • Slamet

    it seems outdated tutorial, Sir. and I haven’t found another similar post like this from google yet

    • Yes, this is out of date. But the inbuilt pdf viewer in texstudio is now very good and so I’m using that rather than sumatrapdf.

      • Slamet

        but anyway, thanks for the tutorial. I got some hidden features of SumatraPDF instead

  • Oskar

    Thank you very much, this works really perfect! I got all the things above working. Just needed to add an extra / in the dde call i.e. dde:///

  • Bruce

    Thanks for sharing.

  • Majid Rafiee

    your very helpful guide.
    however, some issues may be noted:
    1. the first command line must be replaced by: “c:Program FilesSumatraPDFSumatraPDF.exe” -reuse-instance %.pdf
    (the back-slashes must be used)
    2. dde:// at the third command should have three slashes so that it must be replaced by: dde:///
    3. I couldn’t find the user menu under shortcuts in the texstudio configuration.
    finally, I’m so gratful for your invaluable guide for how to sync texstudio and sumatrapdf.