Purplelink
← All guides

SyncTeX on Mac: jump between LaTeX source and PDF

SyncTeX links your LaTeX source and the PDF in both directions. This guide shows how to switch it on, how to set it up in four Mac editors, and what to check when a click lands nowhere.

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:

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

  1. No .synctex.gz exists. Look next to the PDF. If it is missing, the build ran without the flag. Add -synctex=1 and rebuild.
  2. 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.
  3. 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.
  4. The build output goes to another folder. With latexmk -outdir=build I found the PDF and the .synctex.gz together in build/, and the command line tool worked when I pointed it at build/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.
  5. The project has included files with no root hint. In TeXShop, add the % !TEX root line to each included file.
  6. 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.
  7. 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

For how the editors compare on price and platform, see the best LaTeX editors for Mac and the TeXShop alternatives guide.

Frequently asked questions

How do I turn on SyncTeX on a Mac?
Add the flag to the build: latexmk -pdf -synctex=1 main.tex or pdflatex -synctex=1 main.tex. The build then writes a .synctex.gz file next to the PDF. Most Mac editors add the flag for you, so you only need it for terminal or custom builds.
Why does clicking the PDF not jump to my source?
Usually the build wrote no .synctex.gz, the PDF is older than the source, or the project folder was moved after the last build, because the map stores absolute paths. Rebuild with -synctex=1 and try again.
What is the shortcut for inverse search?
It depends on the program. TeXShop and ModernTex use Command-click in the PDF. Skim uses Shift-Command-click. LaTeX Workshop in VS Code uses Ctrl-click by default, with a setting for double-click.
Does SyncTeX work with an included or multi-file project?
Yes. The map records the source file for every piece of text, and I checked that a line in a file loaded with \input resolves to the right PDF page. In TeXShop, put % !TEX root = ../main.tex at the top of each included file.

From the maker of these tools

Writing LaTeX on a Mac?

ModernTex is a native macOS LaTeX editor with the PDF jump set up from the first build. It also has plain-language compile errors and submission checks. $19.99 once, all updates included.

I make ModernTex. $19.99 once after the trial, macOS 14 or later, no account.