LaTeX Documents skill for Codex
One-command LaTeX builds with zero undefined refs. Codex sets up LaTeX projects that build from a clean checkout with a single latexmk call, picks pdfLaTeX, LuaLaTeX or XeLaTeX deliberately, and keeps package order and bibliography tooling consistent. When a build fails it reads the log from the first error using a cause table, and before hand-over it checks for undefined references, overfull boxes and unembedded fonts.
curl -fsSL codexskills.dev/install.sh \ | sh -s -- latex-documents Installs to ~/.agents/skills/latex-documents/ for every project on this machine.
curl -fsSL codexskills.dev/cli.mjs -o codex-skills.mjsnode codex-skills.mjs install latex-documents The CLI also searches, updates and removes skills. Run it with no arguments to pick from a list. Needs Node 20.12+.
curl -fsSL codexskills.dev/install.sh \ | sh -s -- --project latex-documents Installs to .agents/skills/latex-documents/ in the current repository. Commit it and everyone who runs Codex there gets it.
curl -fsSLO codexskills.dev/downloads/latex-documents.zipunzip -o latex-documents.zip -d ~/.agents/skills/ The archive holds the skill folder with its generated agents/openai.yaml. Unzip into .agents/skills/ to scope it to a repo.
& ([scriptblock]::Create((irm codexskills.dev/install.ps1))) latex-documents PowerShell 5.1 or 7. Installs to %USERPROFILE%\.agents\skills\. Add -Project for the current repo.
104-line POSIX script. No sudo, no telemetry. Read install.sh
Use it in Codex
Start a prompt with $latex-documents, or pick it from /skills.
You can also just describe the task: Codex reads the description below and loads the playbook when your request matches.
What Codex reads before loading it
Writes, structures and builds LaTeX documents - papers, theses, reports and journal templates - with latexmk, the right engine (pdfLaTeX, LuaLaTeX, XeLaTeX), biblatex/biber or BibTeX bibliographies, booktabs tables, cleveref cross-references, and fast diagnosis of build errors from the log. Use when the user asks to set up or fix a LaTeX project, add citations, get a failing build to compile, prepare an arXiv or journal submission, or build LaTeX in CI.
Use it when
- Starting or restructuring a LaTeX paper, thesis or report
- A LaTeX build fails or shows undefined references or citations
- Preparing an arXiv or journal submission
- Building LaTeX documents in CI
Use something else when
- You want a faster, simpler typesetting system for a new document: use typst-documents
- You only need to convert Markdown to PDF once: use document-conversion
How to check the result
Run latexmk -C then latexmk, grep the log for undefined references and citations, review each overfull box, and confirm all fonts are embedded with pdffonts.
The mistake it prevents
Placing \label before \caption in a figure, so every reference to it prints the section number instead of the figure number.
Done well means: the document builds from a clean checkout with one command, produces no undefined references or citations, no unexplained overfull boxes, and its source is split so collaborators can edit chapters without merge pain.
Before changing anything
- Find the root file (the one with
\documentclass) and the build entry point: a.latexmkrc,Makefile, CI workflow, orAGENTS.mdnote. Use it rather than inventing one. - Identify the engine and bibliography toolchain from the preamble:
fontspecmeans LuaLaTeX/XeLaTeX;biblatexusually means biber;\bibliographystyleplus\bibliography{}means BibTeX. - Check TeX is installed:
latexmk -v,lualatex --version. Installing TeX Live or missing packages (tlmgr install <pkg>) needs network and a lot of disk; in a sandbox, ask for approval or use the project’s Docker image (texlive/texlive). - If a journal or university template is involved, use their class file unmodified and put your additions in the preamble of your own file.
Engine choice
| Need | Engine |
|---|---|
| Journal/arXiv submission, classic templates, fastest builds | pdfLaTeX |
| System/OpenType fonts, Unicode text, modern default for new documents | LuaLaTeX |
| Existing XeLaTeX project, or specific CJK setups | XeLaTeX |
arXiv compiles with pdfLaTeX by default; check its current TeX Live year before relying on very new packages.
Project layout
paper/
├── main.tex # preamble + \input of sections, nothing else
├── .latexmkrc
├── sections/ # intro.tex, method.tex, results.tex ...
├── figures/ # PDF/PNG figures; vector PDF for plots
├── tables/ # generated .tex tables (from scripts)
└── refs.bib
# .latexmkrc
$pdf_mode = 4; # 1 pdflatex, 4 lualatex, 5 xelatex
$out_dir = 'build';
@default_files = ('main.tex');
$bibtex_use = 2; # run biber/bibtex when needed, clean .bbl with -c
set_tex_cmds('-interaction=nonstopmode -halt-on-error -file-line-error -synctex=1 %O %S');
latexmk # builds main.tex into build/ per .latexmkrc
latexmk -pvc # rebuild on save
latexmk -c # remove auxiliary files (keep the PDF)
A preamble that avoids common conflicts
\documentclass[11pt,a4paper]{article}
\usepackage{fontspec} % LuaLaTeX/XeLaTeX; for pdfLaTeX use \usepackage[T1]{fontenc} + lmodern
\setmainfont{Libertinus Serif}
\usepackage{microtype}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[style=authoryear,backend=biber]{biblatex}
\addbibresource{refs.bib}
\usepackage[hidelinks]{hyperref} % load late
\usepackage[capitalise,noabbrev]{cleveref} % after hyperref
\graphicspath{{figures/}}
Order matters: hyperref near the end, cleveref after it. Do not load both natbib
and biblatex, or subfigure with subcaption.
Content patterns
\begin{figure}[tbp]
\centering
\includegraphics[width=\linewidth]{latency-p95.pdf}
\caption{p95 latency by region after the cache change.}
\label{fig:latency} % label after caption, or references point to the section
\end{figure}
\begin{table}[tbp]
\centering
\caption{Throughput per configuration.}
\label{tab:throughput}
\begin{tabular}{l S[table-format=4.1] S[table-format=2.2]}
\toprule
Config & {Req/s} & {Error \%} \\
\midrule
Baseline & 1204.5 & 0.41 \\
Cached & 1890.2 & 0.12 \\
\bottomrule
\end{tabular}
\end{table}
As \cref{fig:latency} shows, the change halves tail latency \parencite{dean2013tail}.
- Tables generated from data: write them from code into
tables/*.tex(pandasDataFrame.to_latexor a small template) and\inputthem; never retype numbers. - Use
booktabsrules, no vertical lines; align numbers on the decimal point withsiunitx. - Plots: export vector PDF (matplotlib
savefig("x.pdf")), sized to the final width so fonts are not scaled down.
Bibliography
@article{dean2013tail,
author = {Dean, Jeffrey and Barroso, Luiz Andr{\'e}},
title = {The Tail at Scale},
journal = {Communications of the ACM},
volume = {56},
number = {2},
pages = {74--80},
year = {2013},
doi = {10.1145/2408776.2408794},
}
- Protect capitalisation that must survive styles:
title = {Scaling {BERT} on {GPUs}}. - One key format (
authorYYYYword), no duplicates:biber --tool --validate-datamodel refs.bibreports problems. - biblatex needs biber; BibTeX styles (
.bst) needbibtex. A mismatch shows as “Citation undefined” on every key. - For arXiv with biblatex, upload the generated
.bbl; it must come from a biber version matching arXiv’s biblatex, otherwise switch that submission to BibTeX.
Reading a failed build
Read the log from the first error, not the last line. With -file-line-error, errors look
like ./sections/method.tex:42: Undefined control sequence.
| Message | Usual cause | Fix |
|---|---|---|
Undefined control sequence | Typo or missing package | Check the macro on that line; add the package |
Missing $ inserted | _, ^ or math outside math mode | Escape \_, wrap math in $...$ |
File 'x.sty' not found | Package not installed | tlmgr install x (network) or use the TeX Live Docker image |
Citation 'k' undefined | Key missing in .bib, or bib tool not run | Check key spelling; run full latexmk |
Reference 'fig:x' undefined | Label typo or label before caption | Fix label; rebuild |
Overfull \hbox (12.3pt too wide) | Long word/URL, wide table or image | \url{}, \linewidth, rephrase, \sloppy locally as last resort |
Option clash for package x | Package loaded twice with different options | Load once; pass options via \PassOptionsToPackage before the class loads it |
Dimension too large | Plot coordinates huge (pgfplots) | Rescale data or use fpu |
Stuck after edits that should work: latexmk -C (removes stale aux files), then rebuild.
CI
# .github/workflows/latex.yml
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
container: texlive/texlive:latest
steps:
- uses: actions/checkout@v4
- run: latexmk
- run: "! grep -E 'undefined|Rerun to get' build/main.log"
- uses: actions/upload-artifact@v4
with: { name: paper, path: build/main.pdf }
Pin the image tag (e.g. a TeX Live year tag) when a submission must be reproducible.
Verification
latexmk -C && latexmk # clean build succeeds
grep -nE "LaTeX Warning: (Reference|Citation).*undefined" build/main.log # expect nothing
grep -c "Overfull" build/main.log # review each one
pdffonts build/main.pdf # all fonts embedded (journals require it)
Open the PDF and check: every \cref resolves to the right number, the bibliography
lists only cited works, figures appear near their first mention.
Hand-over
**Build:** `latexmk` (LuaLaTeX via .latexmkrc, output build/main.pdf, 14 pages)
**Fixed:** cleveref loaded before hyperref; 3 labels placed before captions; missing siunitx
**Bibliography:** biblatex + biber, 42 entries, 0 undefined citations
**Remaining:** 1 overfull box in tables/ablation.tex (2.1pt) - acceptable or shorten header What the zip contains
SKILL.md plus the interface file below. Nothing runs on install.
agents/openai.yaml
Gives the Codex app a display name, a one-line description and a starter prompt for this skill.
interface:
display_name: "LaTeX Documents"
short_description: "One-command LaTeX builds with zero undefined refs"
default_prompt: "$latex-documents My thesis stopped compiling after I added cleveref - fix it" About this skill
Written and maintained by the Codex Skills editors to the same editorial standard as every skill here: a selective description, a real workflow, known pitfalls and a way to verify the work. First published , last updated . MIT licensed. Something wrong or out of date? Tell us.