Generated from
folio-assistant-sci/skills/content/folio-paper-adapter/latex-validation.md— do not edit here.
LaTeX Validation Skill
Purpose
Validate LaTeX source files for syntactic correctness, structural
consistency, and adherence to project conventions defined in the
repository’s AGENTS.md / contributor instructions.
Checks
1. Syntax Correctness
- Every
\begin{env}has a matching\end{env}. - Braces
{}, brackets[], and parentheses()are balanced. - No undefined control sequences (commands must be provided by a declared package or defined in the preamble).
- Math mode delimiters (
$...$,\(...\),\[...\]) are properly paired.
2. Environment Usage
- Theorem-like environments (
theorem,lemma,proposition,corollary,definition,example,remark,conjecture) are used only as declared inmain.texand are never redeclared in chapter files. - Display math uses
equationoralignenvironments — never$$...$$.
3. Label Conventions
- Every labeled item uses the correct prefix as specified in the
project labeling convention:
chap:for chapterssec:/ssec:for sections / subsectionsdef:/thm:/lem:/prop:/cor:/ex:/rem:/conj:for theorem-like environmentseq:for equations,fig:for figures,tab:for tables
- Every theorem-like environment and every numbered equation carries a
\label{...}.
4. Cross-References
\refand\eqreftargets correspond to existing\labelcommands within the changeset or the broader document.- Non-breaking spaces (
~) precede\refand\eqref.
5. Bibliography
- Every
\cite{key}key must resolve to an entry incontent/schema/references.ts(the CSL-JSON source of truth;references.bibis auto-generated viabun run export-bibtex). - Citation keys follow the
<firstauthorlastname><year>convention. - Validate with
bun run validate-refs. - Every new reference: add a
ref()call incontent/schema/references.tswith at minimumauthor,title,issued, and eitherDOIorURL.
6. Commutative Diagrams (Herrlich–Strecker style)
- Use
tikzcdenvironments, notCD(amscd). Both packages are loaded, buttikzcdis the project standard. - Every definition must include commutative diagrams alongside equations. Diagrams come first; the equation they express follows.
- Standard spacings:
row sep=2.5em, column sep=3em(or3.5emfor wider labels). - Arrow styles:
\ar[r, "label"]for horizontal,\ar[d, "label"']for downward (label below),two headsfor epimorphisms,dashedfor induced/factored morphisms,equalfor identity/equality arrows. - Definitions of algebraic structures (Hopf, Frobenius, monoidal) must display the structure morphisms as a diagram before listing axioms.
7. Deformation / Parameter Convention
- If the paper introduces a deformation or specialization parameter, it must not appear in definitions, examples, lemmas, or theorems before the section that introduces it.
- Quantities that have an undeformed and a deformed form are written in the undeformed form in the pre-parameter material; the deformed form appears only after the parameter is introduced.
- This convention is project-specific — consult the project’s
AGENTS.mdfor the exact parameter, its introducing section, and the undeformed/deformed notation pairs.
8. LeanBlueprint Macros
\lean{<Paper>.Namespace.decl}must reference a fully qualified Lean declaration that exists (or will exist after stub generation) in the paper’s Lean source tree (lean/<Paper>/).\leanokmay only appear when the corresponding Lean proof contains nosorry. Never add\leanokspeculatively.\uses{label1, label2}must reference labels that exist in the same document or inblueprint/src/content.tex. Every dependency edge must be bidirectionally consistent: if B\uses{A}, then A must carry a\label{}.\proves{thm:label}links a proof block to its statement; the label must match an existing theorem-like\label{}.- Place blueprint macros inside the environment, immediately after
\label{}:\begin{theorem}\label{thm:my-result} \lean{Paper.Chapter.my_result} \uses{def:prerequisite} Statement... \end{theorem} blueprint/src/content.texis the single source of truth for the formalization dependency graph. Every\lean{}macro inchapters/*.texmust have a corresponding entry there.
9. Blueprint-Bibliography Cross-References
- Every
-- Ref: [key]annotation in Lean files must have a matching citation key incontent/schema/references.ts(exact case-sensitive match). - When adding a
sorryto a Lean file, precede it with a-- Ref: [key] urlcomment linking to the foundational reference. \cite{key}keys inblueprint/src/content.texmust resolve againstreferences.bib(auto-generated fromcontent/schema/references.ts).- Validate all citation keys with
bun run validate-refs.
Mechanical enforcement — the preflight linter (run this FIRST)
The “No undefined control sequences” / balanced-braces aspirations in
§1 are now mechanically enforced by a fast static gate that needs no
TeX install. The content pipeline’s validateLatexAst
(render-latex.ts) uses unified-latex, which never resolves macros,
so three whole classes of fatal-pdflatex bug pass it silently and used
to land on main needing a manual fix(latex) commit each time.
Always run before declaring LaTeX clean:
cd content
bun run pipeline/build.ts <paper>.ts --generate-main --main-out ../main.tex \
--preamble ../latex/preamble.tex # regenerate the compile unit
bun run latex-preflight # gate: exits 1 on any issue
It scans the generated compile unit (main.tex + every \input‘d
chapters/*.tex) and catches:
| Check | Fatal pdflatex error it pre-empts | Fix |
|——-|———————————–|—–|
| A duplicate-newcommand | Command \X already defined | Define the macro once — in latex/preamble.tex or the paper manifest macros: block, never both. Use \providecommand/\renewcommand for an intentional override. |
| B undefined-macro | ! Undefined control sequence | Define it in the preamble/manifest, or use an existing command (e.g. \mathrm{tr}, not \tr). If it is a genuine standard/package command (and its package is loaded in the preamble), add it via re-seed: bun run latex-preflight:seed. |
| C fragile-accent-script | ! Missing { inserted at a math accent | Never use a math accent (\check,\hat,\tilde,…) as a bare sub/superscript. Brace it: X^{\check{q}}, not X^\check{q}. |
| D missing-input | File \…’ not found | Make sure an unconditional \input/\include target exists; guard optional includes with \IfFileExists. |
| **E** math-delimiter-imbalance | ! Missing $ inserted | Balance $…$ within each file; use $ for a literal dollar. |
| **F** environment-mismatch | \begin{X} … ended by \end{Y} | Match every \begin{env} with its \end{env}; check nesting. |
| **H** unmapped-unicode | Unicode character … not set up for use with LaTeX | Add a \newunicodechar{X}{…} to latex/preamble.tex`, use a LaTeX command, or re-seed if inputenc handles it. |
(Re-seed with bun run latex-preflight:seed after legitimately adding a
new standard command or inputenc-native glyph; commit the updated
latex-known-macros.json.)
build.ts also runs the preflight automatically after --generate-main,
and the always-run content-pipeline CI job gates on it — so a
PR fails fast on A/B/C even when the heavy paper-pdf job no-ops (Actions
billing block / [skip-ci]). When reviewing a content PR, reproduce
the preflight locally before APPROVE.
Output Format
- **Summary**: One-paragraph assessment of LaTeX correctness.
- **Issues Found**: Numbered list (severity: critical / major / minor).
- **Suggestions**: Numbered list of improvements.
- **Verdict**: APPROVE, REQUEST_CHANGES, or NEEDS_DISCUSSION.