LaTeX Compile
Run the four-pass LaTeX build loop and report something a human can act on: the log tail, the page count, and the warnings that actually matter (undefined citations, overfull boxes, missing font shapes).
Boundaries
Do:
- Compile an existing
.texentry file into a PDF. - Report exit code, page count, and extracted warning signals.
- Optionally enforce
--min-pages/--min-refsas pre-compile gates.
Do not:
- Rewrite the user's
.texsource. This skill only reads it. - Inject an author/title line or assemble sibling
abstract.tex/method.texfragments — that was the upstream meta-skill's contract, not a general compiler's job. - Claim a build succeeded without checking that the PDF actually exists.
Preflight
# 1. engine present?
Get-Command xelatex -ErrorAction SilentlyContinue
# 2. document present?
Get-Item .\paper\paper.tex
# 3. bibliography present (only needed for citations)?
Get-ChildItem .\paper\*.bib
If xelatex is missing, stop and give the install command (winget install MiKTeX.MiKTeX or
choco install miktex on Windows; tlmgr/TeX Live elsewhere). Do not fall back to a different
engine silently — pdflatex cannot render CJK without extra packages.
Run
python scripts\compile.py .\paper\paper.tex
python scripts\compile.py .\paper\paper.tex --engine pdflatex --no-bibtex
python scripts\compile.py .\paper\paper.tex --min-pages 10 --min-refs 20
python scripts\compile.py .\paper\paper.tex --bib .\paper\refs.bib --tail-lines 80
| Flag | Default | Meaning |
|---|---|---|
tex_path |
— | .tex entry file (required) |
--engine |
xelatex |
LaTeX engine; use pdflatex for ASCII-only docs |
--bib |
auto | .bib path; otherwise <stem>.bib or references.bib next to the .tex |
--no-bibtex |
off | skip the bibtex pass |
--min-pages |
0 (off) |
fail when the PDF has fewer pages |
--min-refs |
0 (off) |
fail when fewer references are cited |
--tail-lines |
40 |
log tail lines written to stderr |
--timeout |
300 |
per-pass timeout in seconds |
What the script does
- Preflight:
.texexists, engine onPATH,.biblocated. - Optional citation gate: undefined
\citekeys and--min-refsare checked before spending build time. - Build passes:
xelatex→bibtex→xelatex→xelatex.xelatexreturns 0 even on minor issues, so only the final pass is allowed to fail hard. - PDF existence check, page-count parse from the log, warning extraction.
- stdout stays a single clean line (
Compiled: <pdf> (<n> KB, pages=<n>)); the verbose log tail and warnings go to stderr.
Exit codes
| Code | Meaning |
|---|---|
| 0 | success |
| 2 | .tex does not exist |
| 3 | engine not on PATH |
| 4 | no PDF produced |
| 5 | citation contract failed (undefined keys or --min-refs) |
| 6 | page contract failed (--min-pages) |
| 124 | a pass timed out |
| other | exit code of the final engine pass |
Common traps
- Stale
.aux/.bbl: if citations look wrong after a.bibedit, delete*.aux/*.bbland rebuild — the four-pass loop alone cannot always recover a corrupt aux. bibtexfails but PDF exists: reported as a warning, not a hard failure. Check the warning list forbibtex:lines before telling the user citations resolved.- CJK renders as boxes: the engine lacks a CJK font mapping. Add
\usepackage{xeCJK}+\setCJKmainfont{...}(orfontspecwith a CJK TTF) to the preamble; the script does not inject it. - Windows PATH: a freshly installed MiKTeX/TeX Live needs a new shell. If
Get-Command xelatexworks but the script reports exit 3, pass the absolute engine path by putting itsbinonPATHfirst. - Overfull hbox floods the tail: harmless warnings. Do not "fix" them by trimming the user's prose unless asked.
Related skills
../research-paper-writing/SKILL.md— drafting and polishing the manuscript itself.../arxiv/SKILL.md— fetching papers and generating BibTeX entries.