Streamlining LaTeX Workflow with VSCode: An Essential Guide

Summary
This guide provides a detailed walkthrough for setting up and using LaTeX within Visual Studio Code. From installing TeX Live to configuring VSCode with essential extensions, readers will learn how to streamline their LaTeX workflow. The article also covers integrating SumatraPDF for efficient PDF viewing and navigation, along with tips for testing, debugging, and formatting LaTeX documents. Whether you're a beginner or an experienced user, this guide will enhance your productivity and proficiency in LaTeX typesetting using VSCode.

1. Installing TeX Live

  1. Download the ISO Image
    Download the latest texlive2025.iso (≈6GB) from a nearby CTAN mirror .

  2. Installation Steps

    • Extract the ISO file and run install-tl-windows.bat as Administrator.
    • Choose a custom installation path (default: C:\, but D:\ is recommended to save space).
    • If needed, it can be further customized by Advanced options.
    • Unnecessary components can be disabled (e.g., TeXworks frontend).
    • Installation may take 30–60 minutes.
  3. Verify Installation
    Open Command Prompt (Win + Rcmd) and run:

    1
    2
    
    latex -v      # Check LaTeX version
    xelatex -v    # Check XeLaTeX version

    Version details confirm a successful installation.

2. Configuring VSCode

  1. Install Extensions
    Search and install these extensions in VSCode:
    • LaTeX Workshop (core plugin for compiling/previewing)
    • The default settings are saved in defaultSettings.json
  2. Set Up Compilation
    Open settings.json in VSCode (Ctrl + Shift + PPreferences: Open User Settings (JSON)) and add:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
{
  "latex-workshop.latex.tools": [
      {
          // XeLaTeX compiler configuration
          "name": "xelatex",
          "command": "xelatex",
          "args": [
              "-synctex=1", // Enable SyncTeX for forward and backward search between PDF and source
              "-interaction=nonstopmode", // Continue compilation even when errors occur
              "-file-line-error", // Show file name and line number in error messages
              "%DOCFILE%" // Placeholder for the document filename
          ]
      },
      {
          // pdfLaTeX compiler configuration
          "name": "pdflatex",
          "command": "pdflatex",
          "args": [
              "-synctex=1",
              "-interaction=nonstopmode",
              "-file-line-error",
              "%DOCFILE%"
          ]
      },
      {
          // BibTeX tool configuration for handling references
          "name": "bibtex",
          "command": "bibtex",
          "args": [
              "%DOCFILE%" // Document filename placeholder, BibTeX only needs filename for processing references
          ]
      },
      {
          // makeglossaries tool configuration for handling glossaries and symbol lists
          "name": "makeglossaries",
          "command": "makeglossaries",
          "args": [
              "%DOCFILE%"
          ]
      }
  ],
  "latex-workshop.latex.recipes": [
      {
          "name": "xelatex",
          "tools": [
              "xelatex"
          ]
      },
      {
          // Compilation sequence explanation:
          // 1. First xelatex run: generates initial aux file with reference information
          // 2. bibtex: processes references, generates bbl file
          // 3. Second xelatex run: incorporates references into document, updates citations
          // 4. Third xelatex run: ensures all cross-references are properly updated
          "name": "xe->bib->xe->xe",
          "tools": [
              "xelatex",
              "bibtex",
              "xelatex",
              "xelatex"
          ]
      },
      {
          "name": "pdflatex",
          "tools": [
              "pdflatex"
          ]
      },
      {
          "name": "pdf->bib->pdf->pdf",
          "tools": [
              "pdflatex",
              "bibtex",
              "pdflatex",
              "pdflatex"
          ]
      },
      {
          // Compilation sequence explanation:
          // 1. First xelatex run: generates .aux file with reference information
          // 2. bibtex: processes references, generates .bbl file
          // 3. xelatex: incorporates references, generates glossary-related files (.glo)
          // 4. makeglossaries: processes glossaries, generates .gls files
          // 5. Final xelatex: integrates all references and glossaries
          "name": "xe->bib->xe->gly->xe",
          "tools": [
              "xelatex",
              "bibtex",
              "xelatex",
              "makeglossaries",
              "xelatex"
          ]
      },
  ],
  "latex-workshop.latex.recipe.default": "first", // Default recipe selection mode
  "latex-workshop.latex.autoBuild.run": "never", // Auto-build trigger options
  "latex-workshop.latex.autoClean.run": "onBuilt", // Clean auxiliary files after PDF generation
  "latex-workshop.latex.clean.fileTypes": [ // File types to clean
      "*.aux",
      "*.bbl",
      "*.blg",
      "*.idx",
      "*.ind",
      "*.lof",
      "*.lot",
      "*.out",
      "*.toc",
      "*.acn",
      "*.acr",
      "*.alg",
      "*.glg",
      "*.glo",
      "*.gls",
      "*.ist",
      "*.fls",
      "*.log",
      "*.fdb_latexmk",
      "*.nav",
      "*.snm",
      "*.synctex.gz"
  ],
  "latex-workshop.view.pdf.viewer": "external", // PDF viewer selection
  "latex-workshop.view.pdf.internal.synctex.keybinding": "ctrl-click",
  "latex-workshop.view.pdf.external.viewer.command": "D:\\Program Files\\SumatraPDF\\SumatraPDF.exe", // Path to SumatraPDF, mind the escape characters
  "latex-workshop.view.pdf.external.synctex.command": "D:\\Program Files\\SumatraPDF\\SumatraPDF.exe", // Same as above
  "latex-workshop.view.pdf.external.synctex.args": [
      "-forward-search",
      "%TEX%",
      "%LINE%",
      "-reuse-instance",
      "-inverse-search",
      "\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"C:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"",
      "%PDF%"
  ],
  
  
  // Bibtex files format
  "latex-workshop.bibtex-format.sort.enabled": true,
  "latex-workshop.bibtex-format.trailingComma": true,

  // Enhanced functionos
  "latex-workshop.check.duplicatedLabels.enabled": true,
  "latex-workshop.message.error.show": true,
  "latex-workshop.showContextMenu": true,
}

3. Integrating Sumatra PDF

  1. Install SumatraPDF
    • Download the portable version from SumatraPDF (≈10MB).
  2. Configure Inverse Search (optional) In SumatraPDF, Settings –> Options –> Set inverse search command-line, fill in
    1
    
     "C:\Users\seekz\AppData\Local\Programs\Trae\Trae.exe" "C:\Users\seekz\AppData\Local\Programs\Trae\resources\app\out\cli.js" -r -g "%f:%l"
  3. Alternatively, specify inverse search parameters directly in Advanced options, i.e., SumaraPDF-settings.txt
    1
    
      InverseSearchCmdLine = "C:\Users\seekz\AppData\Local\Programs\Trae\Trae.exe" "C:\Users\seekz\AppData\Local\Programs\Trae\resources\app\out\cli.js" -r -g "%f:%l"

​3. Verify Bidirectional Navigation

  • Forward Search: Press Ctrl + Alt + J in VSCode to jump to the corresponding line in the PDF.
  • Inverse Search: Double-click text in SumatraPDF to navigate to the LaTeX source code in VSCode.

4. Testing and Debugging

  1. Create a Test Document
    Create test.tex with:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    \documentclass{article}
    \usepackage{amsmath}  % For mathematical equations
    \usepackage{graphicx} % For image handling
    
    \title{LaTeX Test Document}
    \author{Author Name}
    \date{\today}
    
    \begin{document}
    \maketitle
    
    \section{Text Test}
    This is a sample text for testing purposes. LaTeX is a high-quality typesetting system.
    
    \section{Mathematical Equations}
    Inline equation: $E=mc^2$
    
    Display equation:
    \[
    \sum_{i=1}^{n} i = \frac{n(n+1)}{2}
    \]
    
    \section{List Example}
    \begin{itemize}
      \item First item
      \item Second item
      \item Third item
    \end{itemize}
    
    \section{Table Example}
    \begin{tabular}{|l|c|r|}
      \hline
      Left & Center & Right \\
      \hline
      1 & 2 & 3 \\
      4 & 5 & 6 \\
      \hline
    \end{tabular}
    
    \end{document}
  2. Compile and Preview
    • Save the file (Ctrl + S), compile and generate the PDF.
    • View the output in the VSCode preview panel or SumatraPDF.

5. Formatting

  1. Download latexindent.exe from the GitHub repository

  2. Add the folder containing the executable to your system’s PATH environment variable

  3. Configure VSCode by adding the following settings to settings.json:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
     // LaTeX files format
     // Define the program to format the LaTeX document.
     //  - none: Do not use any formatter.
     //  - latexindent: Use `latexindent` to format the LaTeX document.
     //  - tex-fmt: Use `tex-fmt` to format the LaTeX document.
     "latex-workshop.formatting.latex": "latexindent",
    
       // Define the location of the latexindent executable file.
     "latex-workshop.formatting.latexindent.path": "latexindent",
  4. Format your LaTeX files using the shortcut Shift + Alt + F

6. Keyboard Shortcuts

  1. Default LaTeX Workshop Shortcuts VSCode’s LaTeX Workshop extension comes with built-in shortcuts for common operations:
  • Build Document: Ctrl + Alt + B (Windows/Linux)
  • Preview PDF: Ctrl + Alt + V (Windows/Linux)
  • Forward Search (PDF ↔ Source): Ctrl + Alt + J (Windows/Linux)
  • Kill Compilation: Ctrl + Alt + C (Windows/Linux)
  1. Customizing LaTeX Shortcuts

    Step 1: Access Keyboard Shortcuts Configuration

    • Press Ctrl + KCtrl + S (Windows/Linux) to open the Keyboard Shortcuts interface
    • Click the “Open Keyboard Shortcuts (JSON)” icon in the top-right corner to access keybindings.json

    Step 2: Add Custom Shortcuts

    Add the following examples to keybindings.json (modify as needed):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[
  {
    "key": "alt+s",
    "command": "latex-workshop.synctex", // Trigger synctex between source and PDF
    "when": "editorTextFocus && !isMac"
  },
  {
    "key": "alt+b",
    "command": "latex-workshop.build", // Build LaTeX document
    "when": "editorTextFocus && !isMac"
  },
  {
    "key": "alt+t",
    "command": "latex-workshop.kill", // Kill the current compilation process
    "when": "editorTextFocus && !isMac"
  },
  {
    "key": "alt+e",
    "command": "latex-workshop.recipes" // Show available build recipes
  },
  {
    "key": "ctrl+b",
    "command": "editor.action.insertSnippet", // Insert bold text snippet
    "args": {
      "snippet": "\\textbf{${TM_SELECTED_TEXT}}"
    },
    "when": "editorTextFocus && editorLangId == latex"
  },
  {
    "key": "ctrl+i", // Windows/Linux
    "command": "editor.action.insertSnippet", // Insert italic text snippet
    "args": {
      "snippet": "\\textit{${TM_SELECTED_TEXT}}"
    },
    "when": "editorTextFocus && editorLangId == latex"
  }
]