Ensure you have a LaTeX distribution installed on your system, such as MiKTeX
or TeX Live
To set up LaTeX in VSCode for compiling LaTeX files into PDFs
- Open VSCode
- Go to the Extensions view by clicking on the Extensions icon in the Activity Bar (or press
Ctrl+Shift+X
orCmd+Shift+X
) - Search for "LaTeX Workshop" in the Extensions Marketplace and install it
Ensure you have a LaTeX distribution installed on your system. Popular distributions include TeX Live
(recommended for most users) or MiKTeX
(for Windows)
- Open one of the LaTeX documents (e.g.,
beginner.tex
) - Set the LaTeX Workshop as the default builder:
- Open the VSCode Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
) - Type "LaTeX Workshop: Build LaTeX project" and select it. This sets LaTeX Workshop as the default builder for LaTeX files
- Open the VSCode Command Palette (
- You can configure LaTeX Workshop settings based on your preferences:
- Go to VSCode Settings (
Ctrl+,
orCmd+,
) - Search for "LaTeX Workshop" settings
- Adjust settings like LaTeX distribution, build commands, PDF viewer, etc...
- Go to VSCode Settings (
- With LaTeX Workshop installed and configured, you can now compile your LaTeX files to PDF:
- Open a
.tex
file - Press
Ctrl+Alt+B
orCmd+Alt+B
to compile the LaTeX document - View the output in the LaTeX Workshop panel at the bottom of the VSCode window
- Open a
- To utilize Pygments within a LaTeX document, you typically use the minted package, which interfaces with Pygments to highlight code within your LaTeX document
pip install Pygments
- When compiling your LaTeX document that uses the minted package, you'll need to use the
--shell-escape
flag. For example, if you're usingpdflatex
:
pdflatex -shell-escape yourfile.tex
- This flag allows LaTeX to execute external programs (in this case, Pygments) to generate the highlighted code!
- Ensure your LaTeX distribution (e.g., MiKTeX or TeX Live) is correctly installed and its binaries are added to the system PATH
- Test by running
pdflatex
orlatexmk
commands in Git Bash to verify if the LaTeX distribution is accessible
- Check if the PATH environment variable includes the path to your LaTeX distribution's binaries.
- Open Git Bash and type
echo $PATH
to view the PATH environment variable. Verify if the LaTeX binaries directory is included
- If the LaTeX distribution's binaries are not in the PATH
- Locate the directory containing
pdflatex
orlatexmk
(e.g.,C:\texlive\2021\bin\win32
for TeX Live) - Add the LaTeX distribution's bin directory to the PATH
Replace
export PATH="/path/to/latex/bin:$PATH"
/path/to/latex/bin
with the actual path to the LaTeX binaries - Test LaTeX commands again in Git Bash
- Locate the directory containing
- Ensure that you have appropriate permissions to access and modify files in the LaTeX project directory
- Use
ls -l
command in Git Bash to check file permissions