Introduction
Visual Studio Code (VS Code) is a free, powerful, cross-platform code editor. With the LaTeX Workshop extension, it becomes an excellent LaTeX editing environment with live preview, autocomplete, and integrated PDF viewing.
VS Code + LaTeX Workshop is the recommended editor for LaTeX. You also need to install a backend compiler to use LaTex. See LaTeX for installation of the TeX backend (TexLive).
Installation
In the following shortcuts,
Cmddenotes theCommandkey in MacOS and should be replaced by theControlkey in Windows.
VS Code
-
Download from https://code.visualstudio.com/
-
Install the application
-
(Optional but recommended) Install the command-line tool to open files from terminal with
code:There are two ways to install the
codecommand:Option 1: During installation
- Ensure the checkbox “Add to PATH (requires shell restart)” is selected during the VS Code installation wizard
Option 2: From within VS Code (if already installed)
- Launch VS Code
- Open the Command Palette: Press
Cmd + Shift + P - Type “shell command”
- Select Shell Command: Install ‘code’ command in PATH from the list
- Restart Terminal: Close any open terminal windows and reopen them for the changes to take effect
- Verify: Type
code --versionin your terminal to confirm the installation
Extensions
- Open VS Code
- Go to Extensions view:
- Location: Click the Extensions icon in the Activity Bar (the leftmost vertical sidebar)
- Icon appearance: The icon looks like four squares connected in a 2×2 grid pattern (like a puzzle piece).
- Keyboard shortcut: Press
Cmd+Shift+X(orCtrl+Shift+Xon Windows/Linux)
- Search for the name of extensions such as
- “LaTeX Workshop” (by James Yu)
- “Markdown All in One (by Yu Zhang)”
- “Github Copilot Chat”
- Click Install
Configuration
After installation, LaTeX Workshop should work with sensible defaults. For customization:
- Open Settings (
Cmd+,or click the setting icon at the bottom of the activity bar) - Search for “latex workshop”
- You could find many settings there.
You could change the settings of other extensions similarly.
LaTeX Usage
Compile and Preview
- Open your existing
.texfile or create a new one - Compile it: click the
Build(a triangle) button on the top right of the tex file - Preview the
.pdffile: click theView Latex PDFbutton next to theBuildbutton
AutoCompile (Recommended)
LaTeX Workshop can automatically compile it when you save the tex file:
- Go to Settings (the button at the bottom left corner of VS Code) → search “latex workshop auto build run”
- Select the option
onSave
When you use
Cmd+SorFile->Saveto save the tex file, it will compile the pdf file automatically.
AutoCompile is convenient for iterative editing but may cause brief lag on large documents.
Forward/Backward SyncTeX
- Forward: Right-click in tex file→ “SyncTeX from cursor” → jumps to corresponding PDF
- Backward:
Cmd+Clickon text in PDF → jumps to Tex location.You could change it from
Cmd+ClicktoDouble Clickin Settings (searchlatexworkshop pdf synctex keybindingin settings).
Common Commands (Command Palette Cmd+Shift+P or Click the TeX icon in activity bar)
LaTeX Workshop: Build— Compile manuallyLaTeX Workshop: Clean— Delete auxiliary filesLaTeX Workshop: View PDF— Open PDF without buildingLaTeX Workshop: SyncTex from PDF— Start reverse search
Markdown Usage
Preview
- Open an existing
.mdfile or create a new one (check Markdown for the basic syntax) - Preview: click the button
Open Preview to the Sideon the top right corner of the.mdfile
Export
Cmd+Shift+P→ “Print current document to HTML” to export an.htmlfile