(MacTex/MiKTeX + VSCode + LaTeX Workshop)
All you need are MacTeX/MiKTeX and LaTex Workshop Extension.
Installation
1. Install local LaTeX environment
macOS
Install MacTeX, you can refer to this link, or if you are a homebrew (highly recommended) user, you can simply use
brew install mactexto finish this.Windows / Linux
Refer to miktex.
2. Install LaTeX Workshop VS Code extension.
- Configure the LaTeX Workshop. In fact this extension is out-of-box, but if you want better experience, you can add following code in
settings.json( press command / ctrl + shift + P then type “open” to search for “Preference: Open User Settings (JSON)”
Configuration
JSON Configuration for LaTeX Workshop
"latex-workshop.latex.tools": [ { "name": "latexmk", "command": "latexmk", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "-shell-escape", "-outdir=%OUTDIR%", "%DOC%" ], "env": {} }, { "name": "xelatex", "command": "xelatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-shell-escape", "%DOC%" ], "env": {} }, { "name": "pdflatex", "command": "pdflatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-shell-escape", "%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`x2", "tools": [ "pdflatex", "bibtex", "pdflatex", "pdflatex" ] }, { "name": "xelatex ➞ bibtex ➞ xelatex`x2", "tools": [ "xelatex", "bibtex", "xelatex", "xelatex" ] } ], "latex-workshop.latex.recipe.default": "xelatex",Remark:
- Remember to add “,” if you want to add other contents in the json file.
"-shell-escape"flag is prepared for the use of minted package.- To modify the default recipe, please use
latex-workshop.latex.recipe.default.
Usage
Now you can open a “.tex” file then build and preview it.
If you want to use external pdf viewer, search for “viewer” in extension settings, then choose “external”.
Some useful shortcut:
option + command + B: Build the tex file
option + command + J: Jump from the code to corresponding PDF part
command + mouse press: Jump from the PDF to corresponding code part
Reference Link
Troubleshooting
Manually add texlive path if needed
echo 'export PATH="/usr/local/texlive/2024/bin/universal-darwin:$PATH"' >> ~/.zshrc source ~/.zshrcYou don’t need to manually add path in config file.
Reboot your mac if your LaTex Workshop still not work properly.