Disclosure up front: I make ModernTex, one of the editors covered here. The setup steps for the others come from their own documentation, and where I ran a command myself I say so.
SyncTeX is what lets you click a line in your LaTeX source and land on the matching spot in the PDF, and click the PDF to land on the source line. It is a TeX feature, not an editor feature, so the same file drives TeXShop, Skim, TeXstudio, VS Code and ModernTex. When sync does not work, the cause is almost always in the build, not in the editor. The blog post Forward and inverse search aren't mirror images covers why the two directions are different problems.
How it works
When TeX builds a PDF with SyncTeX turned on, it also writes a small map next to it, named like the PDF with .synctex.gz on the end. The map records, for each piece of text on each page, which source file and line produced it. An editor or viewer reads that map in one of two directions:
- Forward search goes from a source position to a place on a PDF page. The editor asks for the page and rectangle that came from line N, then scrolls the PDF there.
- Inverse search (also called backward search) goes from a click on the PDF to a source file and line. The viewer asks which line produced that spot, then tells the editor to open it.
You can see the map work without any editor. I built a two-file test project with TinyTeX and ran the command line tool that ships with TeX Live. Forward, from line 6 of main.tex:
synctex view -i "6:1:main.tex" -o main.pdf
It prints a block that starts with Output:main.pdf and Page:1, followed by x and y coordinates in PDF points and the size of the box. Inverse, from a point on page 1:
synctex edit -o "1:133:140:main.pdf"
It printed Input: with the full path of main.tex and Line:3. A line in the second file, sections/two.tex, resolved to the right page too, which is the multi-file case editors depend on. Notice the full path in Input:. The map stores absolute paths, which matters for the troubleshooting section below.
Step one: turn SyncTeX on in the build
Every setup starts here. I ran latexmk -pdf main.tex on a clean folder with TinyTeX and got a PDF and no .synctex.gz. Adding the flag produced it:
latexmk -pdf -synctex=1 main.tex
Most editors add this flag for you; in my October 11 test TeXShop wrote the SyncTeX file with no setting changed (see the editor tests). If you build from a terminal, a Makefile or a custom command, add it yourself. You can also put \synctex=1 in the preamble, which Skim's documentation lists as an alternative. With pdflatex directly the flag is the same: pdflatex -synctex=1 main.tex.
Setting it up in each editor
TeXShop
TeXShop's PDF preview and its source window are linked by Command-click in both directions. Command-click in the source window jumps to the matching place in the PDF, and Command-click in the PDF jumps to the source line. If TeXShop's sync method preference is set to something older than SyncTeX, set it to SyncTeX. For a project split across files, give each included file a first line that names the main file, so TeXShop knows which document the file belongs to:
% !TEX root = ../main.tex
The path is relative to the included file. Without it, typesetting from a chapter file and forward search from it can fail or act on the wrong document.
Skim as a separate viewer
Skim is a free PDF viewer that many TeX users prefer because it reloads the PDF as it changes. Per Skim's synchronization page, inverse search is Shift-Command-click on the PDF, and the editor to open is chosen in Skim's Sync preferences, either from a preset or as a custom command. Forward search from an editor runs Skim's helper:
/Applications/Skim.app/Contents/SharedSupport/displayline LINE "main.pdf" "main.tex"
The same page says that if forward search does nothing, check System Settings, Privacy and Security, Automation, and make sure your editor is allowed to control Skim. It lists no built-in TeXShop preset; a custom command is needed there.
VS Code with LaTeX Workshop
From the LaTeX Workshop wiki: forward search is the command SyncTeX from cursor, Command-Option-J on a Mac. Inverse search in the built-in PDF viewer is Ctrl-click by default, and the setting latex-workshop.view.pdf.internal.synctex.keybinding changes it to double-click (reload VS Code afterward). The setting latex-workshop.synctex.afterBuild.enabled runs a forward search after every build; it is off by default. The wiki says SyncTeX with an external viewer such as Skim is not officially supported, so use the built-in viewer if sync matters.
ModernTex
ModernTex uses SyncTeX and adds the flag itself, so there is nothing to configure. Per the app's built-in guide: Command-click anywhere in the PDF jumps the editor cursor to that source line, and a double-click does the same when direct PDF editing (the pencil button) is off. Command-Control-J, Sync PDF to Cursor, moves the PDF to wherever the cursor is. With View, Follow Selection Between PDF and Source on, selecting text in either pane highlights the matching region in the other. Whether this works in your project depends on the same things as any other editor, covered next.
When sync does not work
- No
.synctex.gzexists. Look next to the PDF. If it is missing, the build ran without the flag. Add-synctex=1and rebuild. - The PDF is older than the source. The map describes the last build. If you edited and did not rebuild, positions will be wrong or missing. Build, then try again.
- You moved or renamed the project folder. The map holds absolute paths to your source files (the
Input:line above). After a move, rebuild so it records the new ones. - The build output goes to another folder. With
latexmk -outdir=buildI found the PDF and the.synctex.gztogether inbuild/, and the command line tool worked when I pointed it atbuild/main.pdf. An editor that looks for the map next to the source file will not find it; tell it where the build folder is, or build in place. - The project has included files with no root hint. In TeXShop, add the
% !TEX rootline to each included file. - You use an external viewer and an editor from different makers. Each side needs the other's command, as in the Skim section. If an editor integrates its own viewer, use that first.
- The jump lands near the right spot, not on it. SyncTeX maps to the box that TeX built from a line. Long paragraphs, display math, tables and figures are single boxes, so expect to land on a nearby line there.
Which setup to choose
- Free and standard on a Mac: TeXShop with MacTeX. It has sync built in.
- You already work in VS Code: LaTeX Workshop with its built-in viewer.
- You want a PDF viewer that stays out of the way: Skim, with the editor commands above.
- You want it configured already, for manuscripts: ModernTex, $19.99 after a free 7-day trial.
For how the editors compare on price and platform, see the best LaTeX editors for Mac and the TeXShop alternatives guide.