A Fast Guide on Writing LaTeX with LaTeX Workshop in VS Code

Series - Editors

There are dozens of TeX editors so far, such as Texpad and WinEdt.

After encountered some wired bugs on Texpad, I decided to use native TeX Live / MacTex. However, TexShop (on macOS) does not have a pretty highlight system. It seems that the Visual Studio Code is one of the beast choice.

Windows users: download texlive.iso here.

Mac users: download MacTeX.pkg here.

Here are some references for the installation:

For Windows users, after installation, you should add TeX Live executables to your system PATH.

You can download it here. The installation is easy.

Follows the screenshot below to install the extension LaTeX Workshop.

install-extension
install-extension

After doing that, you may press Shift + Ctrl + P (Windows) or Shift + Cmd + P (macOS) to show all commands. Then type Open User Settings JSON and open the first item (as shown below).

open-json
open-json

Now copy and paste the following two snippets into your json file (inside the brackets {} of your file).

json

"latex-workshop.latex.tools": [
 {
  "name": "latexmk",
  "command": "latexmk",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "-pdf",
   "-outdir=%OUTDIR%",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "xelatex",
  "command": "xelatex",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "pdflatex",
  "command": "pdflatex",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "bibtex",
  "command": "bibtex",
  "args": [
   "%DOCFILE%"
  ],
  "env": {}
 }
],

json

"latex-workshop.latex.recipes": [
 {
  "name": "pdfLaTeX",
  "tools": [
   "pdflatex"
  ]
 },
 {
  "name": "latexmk 🔃",
  "tools": [
   "latexmk"
  ]
 },
 {
  "name": "xelatex",
  "tools": [
   "xelatex"
  ]
 },
 {
  "name": "pdflatex ➞ bibtex ➞ pdflatex`×2",
  "tools": [
   "pdflatex",
   "bibtex",
   "pdflatex",
   "pdflatex"
  ]
 },
 {
 "name": "xelatex ➞ bibtex ➞ xelatex`×2",
 "tools": [
   "xelatex",
   "bibtex",
   "xelatex",
   "xelatex"
  ]
 }
]

Now you may open a tex file or create a new one. If you want to compile the file, press Ctrl + Alt + B (Windows) or option + Cmd + B (macOS). Moreover, you may choose another recipes from the sidebar. There is a button in the right top corner to preview PDF file.

tex-recipes
tex-recipes

Related Content