LaTeX in VS Code (Overleaf-equivalent)
Turn VS Code into an Overleaf replacement and operate it from the CLI. The body
below is the general playbook; machine-specific facts are fenced in the last
section. Prefer checks over assumptions — verify each tool/path on the host
you're actually on.
Mental model
LaTeX Workshop (james-yu.latex-workshop) is an orchestrator, not a compiler.
You need two things:
- A TeX distribution providing
latexmk, pdflatex/lualatex, bibtex
(TeX Live / MacTeX / MiKTeX). Verify: command -v latexmk pdflatex bibtex.
If absent, install one (brew install --cask mactex, apt install texlive-full, or an HPC module) — the extension ships none of these.
- LaTeX Workshop + a few companions (LTeX for grammar, Live Share for
collaboration, Code Spell Checker for spelling).
Configuration
Settings location depends on context:
- Local VS Code:
~/.config/Code/User/settings.json (Linux),
~/Library/Application Support/Code/User/settings.json (macOS).
- Remote-SSH / WSL / container: server-side
~/.vscode-server/data/Machine/settings.json (Machine scope = all folders on
that host). There is no ~/.config/Code on a Remote-SSH host.
- Per-project override:
.vscode/settings.json in the workspace.
Recommended settings (the Overleaf build loop):
{
"latex-workshop.latex.autoBuild.run": "onSave", // recompile on save
"latex-workshop.latex.recipe.default": "latexmk", // one recipe: pdflatex+bibtex+reruns
"latex-workshop.latex.outDir": "%DIR%/build", // isolate aux files -> clean tree
"latex-workshop.view.pdf.viewer": "tab", // PDF in a tab beside source
"latex-workshop.synctex.afterBuild.enabled": true,// source <-> PDF jump
"latex-workshop.message.error.show": true,
"latex-workshop.message.warning.show": false,
"[latex]": {
"editor.formatOnSave": true, // latexindent (ships with TeX Live)
"editor.defaultFormatter": "James-Yu.latex-workshop",
"editor.wordWrap": "on"
},
"ltex.language": "en-US",
"cSpell.language": "en"
}
After editing settings or installing an extension: Developer: Reload Window.
Install an extension headlessly (works over Remote-SSH too):
code --install-extension james-yu.latex-workshop
code --install-extension ltex-plus.vscode-ltex-plus # grammar (maintained LTeX fork)
code --install-extension ms-vsliveshare.vsliveshare # real-time collab
code --install-extension streetsidesoftware.code-spell-checker
On a Remote-SSH host the code CLI lives at
~/.vscode-server/cli/servers/Stable-*/server/bin/remote-cli/code.
Project model
One folder = one "project" (like an Overleaf project), each with a main.tex.
Keep a template with main.tex + refs.bib; new paper = copy the folder.
Compiling from the CLI (what LaTeX Workshop runs)
cd <project>
latexmk -synctex=1 -interaction=nonstopmode -file-line-error -pdf -outdir=build main.tex
- Output:
build/main.pdf; build/main.log (errors); build/main.bbl
(bibliography ran); build/main.synctex.gz (sync data).
lualatex (fontspec/unicode-math): add -lualatex instead of -pdf.
- Clean rebuild:
latexmk -C -outdir=build main.tex, then rebuild.
Diagnosing failures
- Non-zero exit = real error. Locate it:
grep -nE "^.*:[0-9]+:|! |Undefined|Error" build/main.log | head
Citation 'X' undefined → key missing in .bib, or no \bibliography{refs};
latexmk reruns the bibtex pass automatically once those are fixed.
File 'X.sty' not found → package not installed. If the TeX install is
writable, tlmgr install X; if read-only (many HPC/shared installs), vendor
the .sty next to main.tex or switch packages.
- Hang waiting for input → ensure
-interaction=nonstopmode.
Bibliography: bibtex vs biber
natbib + bibtex works on virtually every TeX install. biblatex needs
biber — verify it exists first: command -v biber. If absent, use
natbib/bibtex (latexmk's default recipe handles it).
Editor workflow (Overleaf → VS Code)
| Overleaf |
VS Code here |
| Recompile |
Save (Cmd/Ctrl+S) — auto-rebuilds |
| PDF pane |
Tab beside source (auto, or ▶/PDF icon) |
| Click PDF → source |
Cmd/Ctrl+click in PDF (reverse SyncTeX) |
| Source → PDF |
Cmd/Ctrl+Alt+J (forward SyncTeX) |
| Spell/grammar |
LTeX+ underlines; fix via Cmd/Ctrl+. |
| Collaborate |
Live Share sidebar → Share (session-based, via local VS Code) |
| History |
Git (Source Control panel) |
\cite{/\ref{} complete |
Built into LaTeX Workshop, reads the .bib/labels |
Compute Canada (this machine)
Facts verified on this Remote-SSH host (Fir / gentoo stack) — confirm with the
checks above if the cluster changes:
- LaTeX binaries are already on PATH via the cvmfs gentoo stack — no
module load needed: latexmk, pdflatex, lualatex, bibtex, latexindent.
biber is absent → use natbib/bibtex.
- TeX Live is a shared read-only cvmfs install → no
tlmgr install; vendor
missing .sty files into the project folder.
- Settings live at
~/.vscode-server/data/Machine/settings.json (already
configured per the block above).
- Starter project:
~/papers/example-paper/ (main.tex + refs.bib).
New paper: cp -r ~/papers/example-paper ~/papers/<name>.
- node/npx (for
npx skills …, unrelated to LaTeX) is not on the default
PATH; load it inside one shell call:
bash -lc 'module load nodejs/24.15.0 >/dev/null 2>&1; npx ...'
(module load does not persist across separate Bash tool calls).
Related skills
- Manuscript prose →
scientific-writing.
- Generating/validating BibTeX entries →
citation-management.
- Publication figures →
scientific-visualization.
1---2name: latex-vscode3description: Set up, compile, preview, and troubleshoot LaTeX in VS Code with the LaTeX Workshop extension — an Overleaf-equivalent local/remote workflow (build-on-save, PDF preview, SyncTeX, latexmk, bibtex citations, LTeX grammar, Live Share). Use whenever working with .tex/.bib files, building a PDF, fixing a LaTeX/latexmk compile error, wiring citations/bibliography, or configuring the LaTeX Workshop / LTeX / Live Share setup. Triggers: latex, .tex, latexmk, pdflatex, lualatex, bibtex, \cite, build the pdf, compile my paper, SyncTeX, Overleaf, LaTeX Workshop. NOT for writing prose (use scientific-writing) or generating BibTeX entries (use citation-management).4---56# LaTeX in VS Code (Overleaf-equivalent)78Turn VS Code into an Overleaf replacement and operate it from the CLI. The body9below is the general playbook; machine-specific facts are fenced in the last10section. Prefer **checks over assumptions** — verify each tool/path on the host11you're actually on.1213## Mental model14LaTeX Workshop (`james-yu.latex-workshop`) is an **orchestrator, not a compiler**.15You need two things:161. A **TeX distribution** providing `latexmk`, `pdflatex`/`lualatex`, `bibtex`17 (TeX Live / MacTeX / MiKTeX). Verify: `command -v latexmk pdflatex bibtex`.18 If absent, install one (`brew install --cask mactex`, `apt install19 texlive-full`, or an HPC module) — the extension ships none of these.202. **LaTeX Workshop** + a few companions (LTeX for grammar, Live Share for21 collaboration, Code Spell Checker for spelling).2223## Configuration24Settings location depends on context:25- **Local VS Code**: `~/.config/Code/User/settings.json` (Linux),26 `~/Library/Application Support/Code/User/settings.json` (macOS).27- **Remote-SSH / WSL / container**: server-side28 `~/.vscode-server/data/Machine/settings.json` (Machine scope = all folders on29 that host). There is no `~/.config/Code` on a Remote-SSH host.30- **Per-project override**: `.vscode/settings.json` in the workspace.3132Recommended settings (the Overleaf build loop):33```jsonc34{35 "latex-workshop.latex.autoBuild.run": "onSave", // recompile on save36 "latex-workshop.latex.recipe.default": "latexmk", // one recipe: pdflatex+bibtex+reruns37 "latex-workshop.latex.outDir": "%DIR%/build", // isolate aux files -> clean tree38 "latex-workshop.view.pdf.viewer": "tab", // PDF in a tab beside source39 "latex-workshop.synctex.afterBuild.enabled": true,// source <-> PDF jump40 "latex-workshop.message.error.show": true,41 "latex-workshop.message.warning.show": false,42 "[latex]": {43 "editor.formatOnSave": true, // latexindent (ships with TeX Live)44 "editor.defaultFormatter": "James-Yu.latex-workshop",45 "editor.wordWrap": "on"46 },47 "ltex.language": "en-US",48 "cSpell.language": "en"49}50```51After editing settings or installing an extension: **Developer: Reload Window**.5253Install an extension headlessly (works over Remote-SSH too):54```bash55code --install-extension james-yu.latex-workshop56code --install-extension ltex-plus.vscode-ltex-plus # grammar (maintained LTeX fork)57code --install-extension ms-vsliveshare.vsliveshare # real-time collab58code --install-extension streetsidesoftware.code-spell-checker59```60On a Remote-SSH host the `code` CLI lives at61`~/.vscode-server/cli/servers/Stable-*/server/bin/remote-cli/code`.6263## Project model64One folder = one "project" (like an Overleaf project), each with a `main.tex`.65Keep a template with `main.tex` + `refs.bib`; new paper = copy the folder.6667## Compiling from the CLI (what LaTeX Workshop runs)68```bash69cd <project>70latexmk -synctex=1 -interaction=nonstopmode -file-line-error -pdf -outdir=build main.tex71```72- Output: `build/main.pdf`; `build/main.log` (errors); `build/main.bbl`73 (bibliography ran); `build/main.synctex.gz` (sync data).74- `lualatex` (fontspec/unicode-math): add `-lualatex` instead of `-pdf`.75- Clean rebuild: `latexmk -C -outdir=build main.tex`, then rebuild.7677## Diagnosing failures78- Non-zero exit = real error. Locate it:79 `grep -nE "^.*:[0-9]+:|! |Undefined|Error" build/main.log | head`80- `Citation 'X' undefined` → key missing in `.bib`, or no `\bibliography{refs}`;81 latexmk reruns the bibtex pass automatically once those are fixed.82- `File 'X.sty' not found` → package not installed. If the TeX install is83 writable, `tlmgr install X`; if read-only (many HPC/shared installs), vendor84 the `.sty` next to `main.tex` or switch packages.85- Hang waiting for input → ensure `-interaction=nonstopmode`.8687## Bibliography: bibtex vs biber88`natbib` + `bibtex` works on virtually every TeX install. `biblatex` needs89`biber` — **verify it exists first**: `command -v biber`. If absent, use90natbib/bibtex (latexmk's default recipe handles it).9192## Editor workflow (Overleaf → VS Code)93| Overleaf | VS Code here |94|---|---|95| Recompile | Save (`Cmd/Ctrl+S`) — auto-rebuilds |96| PDF pane | Tab beside source (auto, or ▶/PDF icon) |97| Click PDF → source | `Cmd/Ctrl+click` in PDF (reverse SyncTeX) |98| Source → PDF | `Cmd/Ctrl+Alt+J` (forward SyncTeX) |99| Spell/grammar | LTeX+ underlines; fix via `Cmd/Ctrl+.` |100| Collaborate | Live Share sidebar → Share (session-based, via local VS Code) |101| History | Git (Source Control panel) |102| `\cite{`/`\ref{}` complete | Built into LaTeX Workshop, reads the `.bib`/labels |103104## Compute Canada (this machine)105Facts verified on this Remote-SSH host (Fir / gentoo stack) — confirm with the106checks above if the cluster changes:107- LaTeX binaries are **already on PATH** via the cvmfs gentoo stack — no108 `module load` needed: `latexmk`, `pdflatex`, `lualatex`, `bibtex`, `latexindent`.109- **`biber` is absent** → use natbib/bibtex.110- TeX Live is a **shared read-only** cvmfs install → no `tlmgr install`; vendor111 missing `.sty` files into the project folder.112- Settings live at `~/.vscode-server/data/Machine/settings.json` (already113 configured per the block above).114- Starter project: `~/papers/example-paper/` (`main.tex` + `refs.bib`).115 New paper: `cp -r ~/papers/example-paper ~/papers/<name>`.116- **node/npx** (for `npx skills …`, unrelated to LaTeX) is not on the default117 PATH; load it inside one shell call:118 `bash -lc 'module load nodejs/24.15.0 >/dev/null 2>&1; npx ...'`119 (`module load` does not persist across separate Bash tool calls).120121## Related skills122- Manuscript prose → `scientific-writing`.123- Generating/validating BibTeX entries → `citation-management`.124- Publication figures → `scientific-visualization`.