1
  • I am running macOS
  • VS Code is installed and working
  • I have installed LaTeX Workshop
  • I have installed MacTeX
  • I get a 'Recipe terminated with fatal error: spawn latexmk ENOENT.' error when trying to compile a LaTeX document in VS Code

Based on the documentation I understand that I need to set the PATH environment variable. However I do not understand (1) what this means, and (2) how to do. I have followed the links in the documentation but I have not been able to resolve my issue.

Can anyone assist with a simplified explanation of the steps required to set the PATH?

6135105654
  • 202
  • 2
  • 5
  • 13

2 Answers2

2

I had the same error: Recipe terminated with fatal error: spawn latexmk ENOENT.

The steps I took to solve my problem on macOS (Ventura 13.3.1), with MacTeX-2023 was:

  1. Within VSCode:
    a. cmd+shift+P, select Preferences: Open User Settings (JSON).
  2. Then within the json, paste the following within the {}:
"latex-workshop.latex.path": "/Library/TeX/texbin",
    "latex-workshop.latex.tools": [
        {
         "name": "latexmk",
         "command": "latexmk",
         "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "-pdf",
          "-outdir=%OUTDIR%",
          "%DOC%"
         ],
         "env": {}
        },
        {
         "name": "xelatex",
         "command": "xelatex",
         "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "%DOC%"
         ],
         "env": {}
        },
        {
         "name": "pdflatex",
         "command": "pdflatex",
         "args": [
          "-synctex=1",
          "-interaction=nonstopmode",
          "-file-line-error",
          "%DOC%"
         ],
         "env": {}
        },
        {
         "name": "bibtex",
         "command": "bibtex",
         "args": [
          "%DOCFILE%"
         ],
         "env": {}
        }
       ],
       "latex-workshop.latex.recipes": [
        {
         "name": "pdfLaTeX",
         "tools": [
          "pdflatex"
         ]
        },
        {
         "name": "latexmk ",
         "tools": [
          "latexmk"
         ]
        },
        {
         "name": "xelatex",
         "tools": [
          "xelatex"
         ]
        },
        {
         "name": "pdflatex ➞ bibtex ➞ pdflatex`×2",
         "tools": [
          "pdflatex",
          "bibtex",
          "pdflatex",
          "pdflatex"
         ]
        },
        {
        "name": "xelatex ➞ bibtex ➞ xelatex`×2",
        "tools": [
          "xelatex",
          "bibtex",
          "xelatex",
          "xelatex"
         ]
        }
       ]        
  1. Ensure "latex-workshop.latex.path": "/Library/TeX/texbin" reflects your MacTeX installation. If you followed the default prompts when installing the .pkg of MacTeX, then the path I specified should be the same.

  2. Restart Visual Studio Code.
    a. I found that reloading the window with the Developer: Reload Window command was not enough, I needed to quit Visual Studio Code and open again.

  3. Try out the following in a test file, within a new .tex file (File > New File > test.tex):
    (I took this MWE from Overleaf)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Welcome to Overleaf --- just edit your LaTeX on the left,
% and we'll compile it for you on the right. If you open the
% 'Share' menu, you can invite other users to edit at the same
% time. See www.overleaf.com/learn for more info. Enjoy!
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[acronym]{glossaries}

\makeglossaries

\newglossaryentry{latex}
{
        name=latex,
        description={Is a mark up language specially suited for 
scientific documents}
}

\newglossaryentry{maths}
{
        name=mathematics,
        description={Mathematics is what mathematicians do}
}

\newglossaryentry{formula}
{
        name=formula,
        description={A mathematical expression}
}

\newacronym{gcd}{GCD}{Greatest Common Divisor}

\newacronym{lcm}{LCM}{Least Common Multiple}

\begin{document}
\printglossary[type=\acronymtype]
The \Gls{latex} typesetting markup language is specially suitable 
for documents that include \gls{maths}. \Glspl{formula} are 
rendered properly an easily once one gets used to the commands.

Given a set of numbers, there are elementary methods to compute 
its \acrlong{gcd}, which is abbreviated \acrshort{gcd}. This 
process is similar to that used for the \acrfull{lcm}.

\clearpage



%\printglossary

\end{document}

  1. Finally, within VSCode:
    1. Select the TeX Workshop Extension in the left sidebar
    2. Select the drop-down arrow to the left of Build LaTeX project
    3. Click the recipe: Recipe: pdfLaTeX
starball
  • 20,030
  • 7
  • 43
  • 238
Matt Payne
  • 99
  • 1
  • 8
0

What you should try is the following.

  1. Use win + x shortcut or go to Windows settings and select System.
  2. From there, select advanced system settings.
  3. Now you should select Environment variables.
  4. You'll see two parts of the windows, the top part with user-based environment variables and the bottom part with system ones. You're gonna find PATH in both of them and do the following :
  5. Select PATH and clic Modify.
  6. Clic New and add the path to your LaTeX distribution, for example : C:\texlive\2021

If you do that, it should work, it worked at installation in my case cause I already added these entries to the PATH.

EDIT: I must be tired, I just realized you are using Mac OS. I will let my Windows answer for other people, but the steps must look alike.