| name | latex-paper-formatting |
| description | LaTeX formatting and compilation for academic papers. Use when the user asks about LaTeX templates, compilation errors, package conflicts, figure/table formatting, algorithm environments, math typesetting, or any "how do I do X in LaTeX" question in the context of a paper. Also use when setting up a new paper project, switching venue templates, debugging "undefined control sequence" or "missing $ inserted" errors, or when the user's paper has formatting issues visible in the PDF. Covers major ML/AI/NLP venues (NeurIPS, ICML, ICLR, ACL, EMNLP, CVPR, ICCV, ECCV, AAAI, IJCAI) and general LaTeX best practices.
|
LaTeX Paper Formatting
Get a paper compiling cleanly, looking professional, and meeting venue requirements.
This skill handles the LaTeX mechanics — the actual writing is handled by other skills
in the pipeline.
Default to pdfLaTeX — most venue templates are tested and validated with pdfLaTeX,
and switching engines can introduce subtle breakage. Consider LuaLaTeX when you
specifically need Unicode support beyond inputenc, OpenType fonts, or advanced font
features. If switching, verify the venue template compiles cleanly with LuaLaTeX before
committing to it.
Project Setup
Starting a New Paper
When the user is starting fresh:
-
Get the venue template — Most ML/AI venues provide official LaTeX templates.
Download from the venue's author instructions page. Common sources:
- NeurIPS:
neurips_20XX.sty from the official site
- ICML:
icml20XX.sty with icml20XX.bst
- ICLR: typically uses a modified
iclr20XX_conference.sty
- ACL/EMNLP:
acl.sty from the ACL Rolling Review template
- CVPR/ICCV/ECCV: IEEE two-column format with venue-specific styling
- AAAI:
aaai.sty with specific formatting requirements
-
Set up the file structure — A clean structure prevents confusion later:
paper/
├── main.tex # Master file with \input{} for sections
├── abstract.tex
├── introduction.tex
├── related_work.tex
├── method.tex
├── experiments.tex
├── conclusion.tex
├── appendix.tex # Supplementary material
├── references.bib # Bibliography
├── figures/ # All figures
├── tables/ # Complex table files (optional)
└── style/ # Venue .sty, .cls, .bst files
-
Set up the preamble — Include standard packages in a sensible order.
Essential Packages
These cover 90% of what ML/AI papers need:
% Math
\usepackage{amsmath,amssymb,amsthm}
\usepackage{mathtools} % extends amsmath
% Figures and tables
\usepackage{graphicx}
\usepackage{booktabs} % professional tables (\toprule, \midrule, \bottomrule)
\usepackage{subcaption} % subfigures: \begin{subfigure}
% Algorithms
\usepackage{algorithm}
\usepackage{algorithmic} % or algpseudocode for more modern syntax
% Numbers and units
\usepackage{siunitx} % \num{12345} → "12,345"; \SI{10}{\giga\byte} → "10 GB"
% Text and formatting
\usepackage{microtype} % better text rendering (fewer overfull hboxes)
\usepackage{xcolor} % colored text (useful for TODO notes)
\usepackage{hyperref} % clickable references (load last or near-last)
\usepackage{cleveref} % smart references: \cref{fig:x} → "Figure 1"
% Utility
\usepackage{enumitem} % customize lists
\usepackage{xspace} % smart spacing after macros
Load order matters. hyperref should be loaded near the end. cleveref must
come after hyperref. Venue templates may conflict with some packages — check the
template's documentation.
Common Formatting Tasks
Figures
\begin{figure}[t] % [t] = top of page, preferred for conference papers
\centering
\includegraphics[width=\linewidth]{figures/overview.pdf}
\caption{Overview of our approach. Given input $x$, we first...}
\label{fig:overview}
\end{figure}
Best practices:
- Use vector formats (PDF, EPS) for diagrams and plots. PNG/JPG only for photos
or screenshots.
width=\linewidth or width=\columnwidth — don't hardcode dimensions in cm/inches.
- Place
\label after \caption — placing it before can produce wrong numbering.
- Top placement
[t] for conference papers. Avoid [h] (here) — it often
produces bad layouts. Use [!t] or [!b] if [t] doesn't work.
Subfigures
\begin{figure}[t]
\centering
\begin{subfigure}[b]{0.48\linewidth}
\includegraphics[width=\linewidth]{figures/result_a.pdf}
\caption{Method A}
\label{fig:result-a}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\linewidth}
\includegraphics[width=\linewidth]{figures/result_b.pdf}
\caption{Method B}
\label{fig:result-b}
\end{subfigure}
\caption{Comparison of results. (a) Method A achieves... (b) Method B shows...}
\label{fig:results}
\end{figure}
Tables
\begin{table}[t]
\centering
\caption{Main results on the XYZ benchmark. Best results in \textbf{bold},
second best \underline{underlined}.}
\label{tab:main-results}
\begin{tabular}{lcccc}
\toprule
Method & Precision & Recall & F1 & Accuracy \\
\midrule
Baseline A & 78.2 & 81.5 & 79.8 & 80.1 \\
Baseline B & 80.1 & 79.3 & 79.7 & 80.5 \\
\midrule
Ours & \textbf{85.3} & \textbf{84.7} & \textbf{85.0} & \textbf{85.2} \\
\bottomrule
\end{tabular}
\end{table}
Best practices:
- Use
booktabs — \toprule, \midrule, \bottomrule instead of \hline.
Never use vertical lines in academic tables.
- Caption above the table (convention differs from figures, which have captions below).
- Align numbers by decimal point for easy comparison.
- Bold the best results, underline second-best. Be consistent.
Algorithms
\begin{algorithm}[t]
\caption{Our Training Procedure}
\label{alg:training}
\begin{algorithmic}[1] % [1] = line numbers
\REQUIRE Training data $\mathcal{D}$, learning rate $\eta$
\ENSURE Trained model $f_\theta$
\STATE Initialize $\theta$ randomly
\FOR{epoch $= 1$ \TO $T$}
\FOR{batch $(x, y) \in \mathcal{D}$}
\STATE $\hat{y} \leftarrow f_\theta(x)$
\STATE $\mathcal{L} \leftarrow \text{loss}(\hat{y}, y)$
\STATE $\theta \leftarrow \theta - \eta \nabla_\theta \mathcal{L}$
\ENDFOR
\ENDFOR
\end{algorithmic}
\end{algorithm}
Math Typesetting
Italic vs. Roman Type (ISO 31 Rules)
Getting typefaces right in math is a mark of professional typesetting. The rules come
from ISO 31 (see NIST typeface guide):
- Italic for variables, quantities, and running indices: $x$, $t$, $T$, $i$, $f(x)$
- Roman (upright) for:
- Units: m, kg, s, K
- Descriptive subscripts/superscripts: $t_\text{max}$, $E_\text{k}$ (kinetic), $V_\text{m}$ (molar)
- Mathematical constants: e (Euler's number), i (imaginary unit), $\pi$
- Standard functions and operators: sin, cos, exp, log, div, grad
- Chemical elements: Ar, C, Fe
The most common mistake in ML papers: writing $t_{max}$ which renders as
$t_{max}$ (italic "max", implying three multiplied variables) instead of
$t_{\max}$ or $t_\text{max}$ which renders correctly as a descriptive subscript.
More examples:
| Wrong | Right | Why |
|---|
$L_{train}$ | $L_\text{train}$ or $\mathcal{L}_\text{train}$ | "train" is a descriptor, not a variable |
$x_{input}$ | $x_\text{input}$ | same — descriptive subscript |
$c_p$ | $c_p$ | correct as-is — $p$ is the variable "pressure" |
$E_k$ | $E_\text{k}$ | "k" means "kinetic", not a variable |
Custom commands save time and ensure consistency:
% Define once in preamble
\newcommand{\R}{\mathbb{R}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\loss}{\mathcal{L}}
\newcommand{\model}{f_\theta}
\DeclareMathOperator{\softmax}{softmax}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}
Best practices:
- Use
\DeclareMathOperator for function names, not \text{softmax} or \mathrm{softmax}
- Use
\left( ... \right) only when the content is tall — otherwise use \bigl( and
\bigr) for explicit sizing
- Multi-line equations: use
align or aligned, not eqnarray (which has spacing bugs)
- Number only equations you reference. Use
\nonumber or align* for the rest.
Numbers and Units
Do not manually format large numbers or add thousands separators. Use siunitx:
\num{12345} % → 12,345
\num{1.23e4} % → 1.23 × 10⁴
\SI{10}{\giga\byte} % → 10 GB (with proper spacing)
\SI{3.5}{\percent} % → 3.5%
This ensures consistent formatting throughout the paper and correct non-breaking
spaces between numbers and units.
Cross-References
Do not manually type "Figure", "Table", "Theorem", etc. Use automatic reference
commands so the labels stay correct if you reorder floats:
% Option 1: \autoref (from hyperref) — simple and reliable
\autoref{fig:overview} % → "Figure 1"
\autoref{tab:results} % → "Table 2"
\autoref{thm:main} % → "Theorem 1"
% Option 2: \cref (from cleveref) — more configurable
\cref{fig:overview} % → "Figure 1" (or "Fig. 1" if configured)
\Cref{fig:overview} % → "Figure 1" (capitalized, for sentence start)
\cref{fig:a,fig:b} % → "Figures 1 and 2" (handles ranges)
Pick one system (\autoref or \cref) and use it consistently. Both are better
than Figure~\ref{fig:overview} because they automatically produce the right label
name and keep a non-breaking space.
Compilation Troubleshooting
Common Errors
"Undefined control sequence"
- A command is misspelled or its package isn't loaded.
- Read the line number in the error. The offending command is usually obvious.
- Common:
\bm without bm package, \toprule without booktabs.
"Missing $ inserted"
- An underscore
_ or caret ^ outside math mode. Either wrap in $...$ or
escape with \_.
- Also caused by unescaped
%, &, # in text.
"Overfull \hbox"
- A line is too wide. Usually in tables, long URLs, or inline math.
- Fix:
\usepackage{microtype} helps a lot. For URLs, use \url{} from the
url package. For tables, reduce font size with \small or adjust column widths.
"Float(s) lost"
- Too many floats on one page. Add
\clearpage before the problem area, or use
\usepackage[section]{placeins} to constrain floats to their sections.
Package conflicts
- Load packages in the right order. When two packages redefine the same command,
the one loaded last wins. Common conflict:
hyperref with many packages —
load it near the end.
Debugging Strategy
- Read the actual error message — LaTeX errors say which file and line number.
Go there first.
- Binary search — If the error is cryptic, comment out half the document and
see if it compiles. Narrow down which section causes the error.
- Check the .log file — Warnings are often more informative than the terminal
output. Search for "Warning" and "Error".
- Clean build — Delete
.aux, .bbl, .blg, .out, .toc, and other
intermediate files, then recompile from scratch. Stale aux files cause phantom
errors.
Venue-Specific Notes
NeurIPS/ICML/ICLR — Single-column format, usually 8–10 pages excluding references.
Supplementary material in appendices. Use the official .sty file without modification.
ACL/EMNLP — Two-column format with strict page limits. References count toward the
limit in some tracks. Use the ACL Rolling Review template.
CVPR/ICCV/ECCV — IEEE two-column format. Strict 8-page limit excluding references.
Supplementary material is separate.
AAAI — Two-column format with specific margin and font requirements. Their template
is prescriptive — don't override it.
For all venues: read the author instructions carefully. Formatting violations can
lead to desk rejection.
References
Automated Tools
chktex — Lints .tex files for common issues (spacing, quotes, delimiters,
deprecated commands). Run chktex main.tex before manual review.
lacheck — Catches a different set of issues than chktex (unmatched
environments, missing ~ before \cite). Worth running both.
What This Skill Does NOT Do
- Does not write or improve paper content (use
research-paper-writing)
- Does not check references for correctness (use
reference-checking)
- Does not proofread for typos (use
paper-proofreading)
- Does not handle Draw.io to SVG conversion (use
svg-LaTeX-formula)