Writing LaTeX with LaTeX Workshop in VS Code

Steps

  1. Download & Install MacTex: Downloading MacTeX 2024

  2. Install the extension LaTeX Workshop in VS Code

  3. Press Cmd + Shift + P (macOS) in VS Code to show all commands and type in Open User Settings JSON

  4. Copy and paste the snippets into the json file (inside the brackets {}).

    {
    "workbench.colorTheme": "Visual Studio Dark",
    "latex-workshop.latex.path": "/Library/TeX/texbin/pdftex",
    "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": {}
        }
       ],
       "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"
         ]
        }
       ]       
    }
  5. Troubleshooting Recipe terminated with fatal error: spawn pdflatex ENOENT

  6. Compile the file using option + Cmd + B (macOS)

References