Skip to main content

FIXING VS CODE

Common errors#

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

  1. LaTeX fatal error: spawn pdflatex ENOENT

    Cause: VS Code can't 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 an installation with TeXLive or MacTeX. This installs Perl by default, while MiKTeX doesn't. Perl is required by latexmk, which compiles the code on each change by default. Instead we can trigger pdflatex for each compilation, which I prefer over automatic compilation.

Fixing using the wizard#

For this reason, I've 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've installed MiKTeX as compiler, or if you're getting the error 'Perl not found'. But adding it never hurts.

    If you're 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's 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 doesn't 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.