Purplelink
← All guides

VS Code and LaTeX Workshop on a Mac: Setup and the latexmk Error

LaTeX Workshop is a free VS Code extension that builds your .tex file with latexmk. It needs a TeX distribution on the PATH of the running VS Code. If the build stops with spawn latexmk ENOENT, VS Code cannot find latexmk. Quit VS Code with Command-Q, open it again, and if the error stays, give the build tool its own PATH in settings.json.

Disclosure: I make ModernTex, a Mac LaTeX editor, and it gets one short mention near the end. This page is about VS Code. I ran the Terminal commands below on a Mac and say what each one printed. I did not install LaTeX Workshop or open VS Code for this page, so the steps inside VS Code come from the extension's own wiki and are marked that way.

1. Install a TeX distribution first

The extension does not include LaTeX. Its install page says the only requirement is a compatible distribution on your PATH (the list of folders a program searches for commands), and it lists TeX Live, TinyTeX and MiKTeX. On a Mac that usually means MacTeX, BasicTeX or TinyTeX. How to install LaTeX on a Mac covers the choice and the steps.

Where the programs end up matters later. MacTeX keeps a link at /Library/TeX/texbin that points to them, and TinyTeX puts them in a folder under ~/Library/TinyTeX/bin. On the Mac I used, which has TinyTeX, that folder is ~/Library/TinyTeX/bin/universal-darwin.

2. Install the LaTeX Workshop extension

Per the extension's wiki, you find it in the Visual Studio Code Marketplace, or you press Command-P in VS Code and run ext install latex-workshop. In the Extensions view, search for LaTeX Workshop and check that the publisher is James Yu. The extension is free and MIT-licensed.

3. Quit VS Code with Command-Q and open it again

The extension never edits your PATH. Its wiki says that if VS Code cannot find the TeX programs, the system's setting is at fault, and that you must restart VS Code after changing the variable. A report on r/LaTeX from October 2026 describes the same thing: a student got spawn latexmk ENOENT although which -a latexmk found the program, and quitting and reopening VS Code fixed it.

On a Mac, closing the window leaves VS Code running. Press Command-Q, or choose Code, then Quit Code, so the whole app stops, then open it again. I did not test whether closing the window alone would leave the old PATH in place, so treat the full quit as the safe habit rather than a proven requirement.

4. Check latexmk from Terminal

Open a new Terminal window and run this. -a lists every match, so you see if two installs compete.

which -a latexmk

With MacTeX you expect a path under /Library/TeX/texbin. On the Mac I tested, the command printed latexmk not found, because TinyTeX is installed there but its folder is not on the PATH. Calling the program by its full path worked:

~/Library/TinyTeX/bin/universal-darwin/latexmk -v

That printed Latexmk, John Collins, 9 March 2026. Version 4.88. So the program exists and only the PATH is wrong, which is the situation behind most reports of this error. If nothing prints on your Mac in either form, latexmk may be missing. It is a TeX Live package, and tlmgr info latexmk shows its status (on my install it reported installed: Yes). The install command for a missing package is sudo tlmgr install latexmk, without sudo on TinyTeX. I did not run that command, because I installed nothing for this page.

The wiki adds that latexmk needs Perl. macOS includes a Perl at /usr/bin/perl, which the settings below keep on the path.

5. Give the build its own PATH in settings.json

If a full quit did not help, the wiki offers a way out: override PATH with the env property of a tool in latex-workshop.latex.tools. It warns that only placeholders such as %DIR% are expanded, and variables such as $PATH are not. So you write the whole PATH out as plain text. To open the file, press Command-Shift-P and run Preferences: Open User Settings (JSON). Add this block for MacTeX or BasicTeX:

{
  "latex-workshop.latex.tools": [
    {
      "name": "latexmk",
      "command": "latexmk",
      "args": [
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-pdf",
        "-outdir=%OUTDIR%",
        "%DOC%"
      ],
      "env": { "PATH": "/Library/TeX/texbin:/usr/bin:/bin:/usr/sbin:/sbin" }
    }
  ]
}

The tool's name, command and arguments are the defaults from the wiki, so the only change is the env line. Replace /Library/TeX/texbin with the TinyTeX folder if that is what you use. Setting latex-workshop.latex.tools replaces the default list, so the other default tools, such as the XeLaTeX and LuaLaTeX variants, are gone until you add them back.

I tested the same idea in a plain shell, with a clean environment, since I did not open VS Code. I ran the extension's default latexmk arguments on a small file, with the TinyTeX folder where the block above has /Library/TeX/texbin. The results:

I also reproduced the error text itself. A small Node script that starts latexmk with no TeX folder on the PATH reports spawn latexmk ENOENT, and with the TinyTeX folder added it starts normally. VS Code extensions run on Node, so I read the VS Code error as the same failure. I have not seen it inside VS Code myself.

6. First build and SyncTeX

These keys are from the extension's wiki, not from my own run. Open a .tex file and look at the TeX icon in the sidebar. The command Build LaTeX project is bound to Ctrl-Option-B, and the first recipe in the list, latexmk, is the default. To view the PDF, press Ctrl-Option-V or click the preview icon at the top right of the editor. Forward search, from source to PDF, is Command-Option-J on a Mac. Inverse search, from PDF to source, is Ctrl-click in the built-in viewer by default. SyncTeX on Mac has the settings, and what to check when the jump fails.

If a build fails, the wiki says the raw compiler logs are in the Output pane under LaTeX Compiler. Read that panel first, because it holds the real error.

7. Errors and what they mean

Messages seen when a LaTeX Workshop build does not start, with the cause and the fix
Message Cause Fix
spawn latexmk ENOENT VS Code cannot find latexmk on the PATH it started with. Quit with Command-Q and reopen. If it stays, use the env block in section 5.
Recipe terminated with fatal error A program in the recipe stopped with an error. The message does not say which. Open Output, then LaTeX Compiler, and read the lines above it. This one is the wiki's description of where the log lives, and I did not trigger the message.
zsh: command not found: latexmk in Terminal Terminal cannot find it either, so the program is missing or its folder is not on the PATH. I saw this on the Mac I tested. Open a new Terminal window. Check /Library/TeX/texbin or the TinyTeX folder as in section 4. Add the package with tlmgr if it is missing.
sh: pdflatex: command not found in the build log latexmk started, but the TeX programs are not on the PATH it passes on. I reproduced this. Set the PATH in env, with the TeX folder included, as in section 5.
/Library/TeX/texbin is a link to a missing folder The link points at a folder that is gone, which fits a MacTeX that was removed. On the Mac I tested, ls /Library/TeX/texbin/ printed No such file or directory although the PATH names that folder. Reinstall MacTeX or BasicTeX, or use TinyTeX and put its folder on the PATH.

8. If you would rather not configure an editor

TeXShop is free and comes with MacTeX, so it needs no setup. ModernTex, my own app, is $19.99 once after a 7-day free trial. On first launch it looks for MacTeX or TinyTeX, and if it finds neither it offers to install TinyTeX. See ModernTex. For a wider comparison, read the best LaTeX editors for Mac.

What I ran and what I did not

October 22, 2026. Run on a Mac with TinyTeX installed and without MacTeX, VS Code or LaTeX Workshop: which -a latexmk, latexmk -v by full path, tlmgr info latexmk, ls -la /Library/TeX/texbin, a Node spawn of latexmk with and without the TeX folder on the PATH, and latexmk with the default extension arguments on a one-page file in a clean environment. The build and SyncTeX file were written as expected. Not run: installing the extension, opening VS Code, the Command-Q test, the keys in section 6, and any MacTeX or BasicTeX step. Those come from the sources below.

If something here is out of date or wrong, write to ben@purplelink.llc and I will fix it.

Frequently asked questions

Why does VS Code not find latexmk when Terminal does?
The two can have different PATHs. Terminal builds its PATH when a window opens, and macOS adds /Library/TeX/texbin for MacTeX then. A VS Code that was already running during the TeX install can still have the older PATH. Quit VS Code with Command-Q and open it again. If the error stays, give the latexmk tool its own PATH in settings.json, as shown above.
Do I need MacTeX, or is BasicTeX enough?
The LaTeX Workshop install page says the only requirement is a compatible distribution on the PATH, and lists TinyTeX as a lighter option. Its default build runs latexmk, so the distribution must include that program. latexmk is a TeX Live package, so tlmgr can add it to a small install. TUG recommends the full MacTeX for most people because nothing is missing.
Does LaTeX Workshop work offline?
Building does. The build runs latexmk and the TeX programs on your own Mac, and the extension's built-in PDF viewer opens the result in a VS Code tab. Installing the extension and the TeX distribution needs a connection. On TinyTeX the hover that shows a package's documentation does not work, because TinyTeX ships no offline documentation, according to the extension's install page.