Skip to main content

VS Code problems troubleshooting

Common errors#

When setting up VS Code with LaTeX, you might encounter some hurdles trying to compile. There are two frequent problems:

  1. LaTeX fatal error: spawn pdflatex ENOENT

    Cause: VS Code cannot locate the compiler (TeXLive, MiKTeX or MacTeX).
    Try closing VS Code and restarting your computer, this might solve the problem!

  2. Perl not found

    Cause: LaTeX Workshop assumes Perl is installed. This is not automatically the case for Windows users when using MiKTeX. Perl is required by latexmk, which compiles the code on each change by default. Have a look at the installation page for instructions on how to install Perl. Alternatively, the next section shows you how to trigger pdflatex instead of latexmk for each compilation. This does not require Perl.

Fixing using the wizard#

For this reason, I have made a Config wizard which fixes the settings for everything to work again. Follow these steps:

  1. Open settings.json. See Opening settings.json below.

  2. Select the desired options.

    Check "Add pdflatex-only recipe". You need it if you have installed MiKTeX as compiler, or if you are getting the error 'Perl not found'. But adding it never hurts.

    If you are experiencing LaTeX fatal error: spawn pdflatex ENOENT, check Set pdflatex to full path. See Getting path to pdflatex below for obtaining the "Full path to pdflatex".

  3. Generate new settings, and save them to the settings.json.

  4. Restart VS Code.

  5. If it is still not working, contact me. If it is working, I would love to hear if it helped!

    E-mail: Not available

Opening settings.json#

Select View > Command Palette, type settings.json and type enter.

Getting path to pdflatex#

Press Start+R, type cmd and hit enter. Type pdflatex -version and press enter. If this gives an error telling the command does not exist, there is a problem which your distribution. You can try uninstalling it and installing a different distribution, or contact me. Else, proceed.

Type where.exe pdflatex and press enter. This should give one line, which is the path to pdflatex.

Manual compilation#

In VS Code, right-click your document.tex, and select Copy Path.

Right-click the Windows Start menu on the bottom-left of the screen and select 'Windows Powershell'. Type cd ", and press Ctrl+V to paste the path we just got in VS Code. Remove the \document.tex at the end, type " to close the quotes, and hit enter.

Now type pdflatex document and hit enter. Right-click your document.tex in VS Code, and select Reveal in File Explorer. You should now see there is a document.pdf alongside the document.tex. If you press 'View' in the TeX menu in VS Code, this should open this pdf.