Tx · LaTeX & TikZ

How to Go from a PDF to Its Source in TeXstudio

Published By the 9to5Science editorial team

At a glance

  1. 1. Enable SyncTeX

    Make sure the LaTeX compiler command includes the -synctex=1 option.

  2. 2. Recompile the document

    Build the main .tex file so TeXstudio creates an up-to-date SyncTeX file.

  3. 3. Open the PDF

    View the newly compiled PDF in TeXstudio's internal viewer.

  4. 4. Jump to the source

    Ctrl-click the relevant PDF text, or choose the source-navigation command from the viewer's context menu.

TeXstudio can jump from a position in a compiled PDF to the LaTeX source that produced it. This feature relies on SyncTeX, which records links between positions in the output and locations in the source files.

The usual workflow is to compile with SyncTeX enabled, open the resulting PDF in TeXstudio, and Ctrl-click the text you want to locate. If the jump does not work, check the compiler option, rebuild the document, and confirm that you are using the right PDF viewer.

Enable SyncTeX and compile

Open Options → Configure TeXstudio → Build and check the command used for your compiler. The command should include the option -synctex=1. For example, a pdfLaTeX command may look like this:

pdflatex -synctex=1 -interaction=nonstopmode %.tex

TeXstudio’s default compiler commands commonly include SyncTeX already. If yours does, you do not need to add the option again. Avoid replacing the whole command unless necessary; preserve its other options and change only what is needed.

Compile the document after confirming the setting. Compile the main .tex file—the file that includes the document preamble and calls \begin{document}—rather than compiling an included chapter file by itself. SyncTeX produces a companion file, commonly named something like main.synctex.gz, alongside the PDF. That file provides the mapping used for source navigation.

Jump from the PDF to the source

Open the compiled PDF in TeXstudio’s internal PDF viewer. Move to the text you want to find and Ctrl-click it. TeXstudio should open the corresponding source file and place the cursor near the matching line. Depending on your TeXstudio version or platform, the viewer’s context menu may also offer a source-navigation or synchronization command.

For example, if the PDF contains the sentence “The result follows from the definition,” Ctrl-clicking that sentence should take you to the source line containing it. If the sentence is in a file included with \input or \include, the editor may open that included file rather than the main document. That is expected: SyncTeX can map into source files that are part of the compiled document.

If the jump does not work

Check these items in order:

  1. SyncTeX is enabled. Confirm that the compiler command includes -synctex=1 (or the equivalent option for your compiler).
  2. You rebuilt after changing the command. An existing PDF without a current SyncTeX file may not have usable source mappings.
  3. The PDF and source belong to the same build. If you opened a PDF copied from another folder or produced by another editor, it may not match the source open in TeXstudio.
  4. You are using the internal viewer. Test there first. An external PDF application may need its own inverse-search configuration before it can send a click back to TeXstudio.
  5. The project paths are available. If the document uses included files, make sure those files are present at the paths used during compilation.

If you suspect that an old mapping is being reused, close the PDF, remove the stale generated PDF and SyncTeX file if needed, and compile again. Do not delete your .tex source files. A clean rebuild is often enough to resolve mismatches caused by moving files or switching build directories.

Using an external PDF viewer

The internal viewer is the simplest way to test source navigation because TeXstudio can coordinate the PDF and editor directly. External viewers handle inverse search differently: the viewer must be told how to launch TeXstudio and pass the source location back to it. The exact setup depends on the viewer and operating system, so follow that viewer’s SyncTeX or inverse-search instructions. First verify that navigation works in TeXstudio’s internal viewer; this separates a SyncTeX compilation problem from an external-viewer configuration problem.

Common mistakes

  • Using -synctex=0: This disables SyncTeX recording. Use -synctex=1 for source/PDF synchronization.
  • Expecting the PDF to update automatically: A source-to-PDF mapping cannot be current until the relevant document has been compiled again.
  • Compiling the wrong file: Build the main document, especially when the clicked text comes from an included chapter.
  • Opening a PDF from another build: The PDF and its .synctex.gz file need to correspond to the source and build you are working with.
  • Assuming every external viewer works automatically: External viewers may require a separate inverse-search setup; test with TeXstudio’s internal viewer first.

References

  1. TeXstudio User Manual

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.