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:
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!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 triggerpdflatexinstead oflatexmkfor 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:
Open
settings.json. See Opening settings.json below.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, checkSet pdflatex to full path. See Getting path to pdflatex below for obtaining the "Full path to pdflatex".Generate new settings, and save them to the
settings.json.Restart VS Code.
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#
- Windows
- Mac
- Linux
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.
Open the app called Terminal. 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 which pdflatex and press enter. This should give one line, which is the
path to pdflatex.
Open Terminal. 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 which pdflatex and press enter. This should give one line, which is the
path to pdflatex.
Manual compilation#
- Windows
- Mac
- Linux
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.
In VS Code, right-click your document.tex, and select Copy Path.
Open Terminal. Type cd ", and press Command+V to paste the path we just
got in VS Code. Remove the /document.tex and 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 Finder. 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.
In VS Code, right-click your document.tex, and select Copy Path.
Open Terminal. Type cd ", and press Ctrl+Shift+V to paste the path we just
got in VS Code. Remove the /document.tex and 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 Finder. 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.