latex
LaTeX Document Compilation
Critical Rules
- Build artifacts go to
out/, but the PDF stays in the source directory. Before compiling, check for.latexmkrc— if missing, create one with the standard config (see Output Directory section). The.latexmkrcuses a PerlEND {}block to copy the PDF back to the source directory after each build. - NEVER write BibTeX entries from memory. Always verify against web sources (CrossRef, Google Scholar, DOI lookup) before writing. See the
literatureskill. - Check document class before adding packages. Some classes load packages internally (e.g.,
elsarticleloadsnatbib— adding\usepackage{natbib}causes errors).
Overleaf-Synced Projects
When a project is synced to Overleaf (via Dropbox or Git):
- The
out/directory will sync to Overleaf but Overleaf ignores it — this is fine - Always use
.latexmkrcto enforceout/— Overleaf ignores this file too - Overleaf compiles independently on its server; local compilation is for verification only
- The
.bstfile (e.g.,elsarticle-harv.bst) lives in the source directory, notout/
When NOT to Use
- Markdown documents — use plain markdown, not LaTeX
- Quick notes or drafts — LaTeX overhead not worth it
- Documents that don't need citations, equations, or precise formatting
Local-Only Projects (No Overleaf)
Not all projects sync to Overleaf. For local-only projects:
- The same
out/and.latexmkrcconventions apply — this keeps the working directory clean regardless of sync method - There is no
paper/symlink —.texfiles live directly in the project root or a subdirectory - Use
/latex-autofixfor compilation — it handles.latexmkrccreation if missing
Templates
Working Paper Template
When creating a new working paper, use the template. The canonical location is the Overleaf copy, with a local fallback:
~/Library/CloudStorage/YOUR-CLOUD/Apps/Overleaf/Template/(Overleaf source)~/Library/CloudStorage/YOUR-CLOUD/Task Management/templates/latex-wp/(local copy)
The template contains:
| File | Purpose |
|---|---|
main.tex |
Document entry point with structure |
your-template.sty |
Packages, layout, formatting, math environments |
your-bib-template.sty |
Bibliography config (biblatex, source cleanup, Harvard style) |
references.bib |
Bibliography file (initially empty) |
out/ |
Compilation output directory |
To create a new working paper:
- Copy the template files to your new project folder
- Rename as needed
- Update
main.texwith your title, author, abstract - Add references to
references.bib - Compile with
latexmk main.tex
Citation Style Toggle
The template uses biblatex/biber with a toggle for Harvard vs generic authoryear style.
In main.tex, control the style via package option:
\usepackage[harvard]{your-bib-template} % Harvard style (default)
\usepackage[noharvard]{your-bib-template} % Generic authoryear style
Harvard style features:
- Author names: Family, G.
- Volume in bold, issue in parentheses
- DOI/URL shown as "Available at: ..."
- No dashes for repeated authors
Bibliography File Naming
Always name the bibliography file references.bib — for any paper, whether using the working paper template or not. This is the standard naming convention across all projects.
Bibliography Commands
The template uses biblatex. In main.tex:
\printbibliography % (not \bibliography{references})
If you need natbib instead, do not load your-bib-template and use:
\bibliographystyle{agsm}
\bibliography{references}
Note: This template is for working papers only. Other document types (presentations, theses, etc.) may require different templates.
Output Directory
All LaTeX build artifacts (.aux, .log, .bbl, .fls, etc.) go to an out/ subfolder relative to the source file. The PDF is copied back to the source directory after each successful build, so it lives alongside the .tex file for easy access. This keeps the working directory clean while keeping the deliverable visible.
Configuration
The PDF-copy convention is enforced in two places — keep them in sync when making changes:
.latexmkrc(per-project) — PerlEND {}block copies PDF after terminal/Claude Code builds- VS Code
.vscode/settings.json(per-workspace) — explicit latexmk args in LaTeX Workshop tool definition
Place a .latexmkrc in the project root to enforce output directory automatically.
VS Code integration, engine auto-detection (pdfLaTeX/XeLaTeX/LuaLaTeX), manual override configs, reference checking scripts, and manual compilation commands:
LaTeX Skill Hierarchy
Three compilation skills exist for different scopes. Use this decision tree:
Need to compile LaTeX?
├── Single project, want auto error resolution?
│ └── /latex-autofix (default — 5 iterations, citation audit, quality score)
├── Single project, need manual control or config reference?
│ └── /latex (this skill — .latexmkrc setup, engine selection, VS Code config)
└── Multiple projects / fleet-wide health check?
└── /latex-health-check (project discovery, 3 iterations per project, cross-project checks)
| Skill | Scope | Iterations | Extra features |
|---|---|---|---|
/latex |
Single project | Manual | Config reference, engine auto-detection, VS Code integration |
/latex-autofix |
Single project | Up to 5 | Auto error fix, citation audit, quality score |
/latex-health-check |
All projects | Up to 3 each | Project discovery, symlink integrity, Overleaf separation, template drift |
Rule of thumb: Use /latex-autofix by default. Use /latex when you need to understand or configure the build system. Use /latex-health-check for periodic maintenance.