LaTeX Health Check: Self-Healing Build Agent
Compile all LaTeX projects, auto-fix known errors iteratively, and verify cross-project consistency (symlinks, shared bibliographies, Overleaf separation).
When to Use
- Periodically (weekly) to catch build rot before it becomes debugging sessions
- After major infrastructure changes (template updates, symlink reorganisation)
- Before submission season to verify all papers compile cleanly
- When the user says "check my LaTeX", "build health", "compile everything"
Modes
| Mode | Trigger | What it does |
|------|---------|-------------|
| Single project | Path argument | Compile + fix + verify one project |
| All projects | all argument | Discover and compile every LaTeX project |
| Quick | quick argument | Compile only, no fixes, report errors |
Phase 1: Discover LaTeX Projects
Find all directories containing a \documentclass in a .tex file:
Search locations in this order, checking that each exists:
- an explicit path argument;
- the current project;
- project roots declared by the current repository or client guidance;
~/Projects/as a portable fallback forallmode.
For each discovered project, record:
- Project name (directory name)
- Main .tex file path
- Whether it has a
.latexmkrc - Whether it has an
out/directory - Whether it's inside a
paper/subdirectory (Overleaf-linked)
Phase 2: Build Loop (per project)
For each project:
2a. Pre-flight
- Resolve the byte-identical
templates/build-config/.latexmkrcbundle from the installedlatexskill; stop if it is unavailable. - If
.latexmkrcis missing, copy the resolved canonical verbatim. If it exists, compare it byte-for-byte; report divergence and do not overwrite it without explicit migration approval. - Allow
.latexmkrc.localfor project-specific paths, dependencies,$bibtex_use,$clean_ext, or@default_files, but flag any$pdf_modeassignment. - Create
out/directory if missing
2b. Compile
cd <project-dir> && latexmk -interaction=nonstopmode <main.tex> 2>&1
Engine selection: Do NOT hardcode -pdf. The canonical recursively infers pdfLaTeX, XeLaTeX, or LuaLaTeX from the requested driver and local dependencies. Passing -pdf overrides this and breaks Unicode-engine projects. Let latexmk read .latexmkrc.
2c. Parse log
Extract from out/*.log: