LaTeX for Research Papers: An Intermediate Course
This course is for someone who already knows Markdown well and wants to get genuinely comfortable with LaTeX. That means being able to:
- open any arXiv / NeurIPS / ICML paper and have a good idea how each part of it was written,
- write your own paper from a conference template without fighting the tooling,
- know where LaTeX fits next to Overleaf, local toolchains, Typst, Pandoc, and so on.
Read the chapters in order. Each one builds on the one before. Code blocks marked latex are real, compilable snippets. Paste them into Overleaf or a local file and play with them.
Chapters
| # | File | What you’ll learn |
|---|---|---|
| 1 | 01-history-and-ecosystem.md | TeX → LaTeX → today. Why academia (and arXiv) runs on it. Overleaf, Typst, and the other options. |
| 2 | 02-setup-and-workflow.md | Overleaf vs local. Installing TeX on macOS. latexmk, VS Code, the compile pipeline, reading errors. |
| 3 | 03-document-structure.md | Preamble, classes, packages, sections, environments, lists, macros, cross-references. “Markdown → LaTeX” mapping. |
| 4 | 04-math.md | Inline/display math, align, matrices, operators, theorems, ML notation, typography habits. |
| 5 | 05-figures-tables-algorithms-code.md | Floats, images, subfigures, professional tables (booktabs), pseudocode, code listings. |
| 6 | 06-diagrams-chemistry-science.md | TikZ, pgfplots, chemistry (mhchem, chemfig), units (siunitx), physics, circuits, finding any symbol. |
| 7 | 07-bibliography-and-references.md | BibTeX vs BibLaTeX, natbib, \citep vs \citet, getting clean .bib entries, hyperref + cleveref. |
| 8 | 08-writing-ml-papers-arxiv-neurips-icml.md | Conference style files, anonymization, page limits, appendices, checklists, and submitting to arXiv. |
| 9 | 09-reading-papers-and-cheatsheet.md | Working backwards from a paper you see to the LaTeX that made it, common pitfalls, and a one-page cheat sheet. |
There’s also a complete, minimal, compilable paper project in example-paper/ that uses nearly everything from the course. Once you’ve finished chapter 2, compile it, then break it and fix it.
How to study this
- Read chapters 1–2 to get the lay of the land, and get a working setup (an Overleaf account takes 2 minutes).
- Chapters 3–7 are hands-on. Keep a scratch
.texfile open and type the examples in yourself. Typing beats copy-pasting. - Chapter 8 is about the real world: conference templates, arXiv. Read it before your first submission.
- Chapter 9 is the capstone. Download the LaTeX source of a paper you like from arXiv and read it next to the PDF.
Mental model in one paragraph
Markdown says “this is a heading, this is a list” and leaves the looks to a renderer. LaTeX is the same idea, taken much further: you describe structure and meaning (\section, \begin{theorem}, \cite{}, \label/\ref), and a decades-old, very carefully tuned typesetting engine handles line breaking, hyphenation, math spacing, numbering, cross-references, and bibliography formatting. The price is a programming-language-like syntax and a compile step. The payoff is output that looks professionally typeset and is accepted by every journal, conference, and preprint server in the quantitative sciences.
Chapter 1: History and Ecosystem
1.1 A short history
TeX (1978): Donald Knuth gets annoyed
In 1976 Donald Knuth got the galley proofs for the second edition of The Art of Computer Programming, Volume 2. The publisher had moved from hot-metal typesetting to early phototypesetting, and the math looked terrible. Knuth decided to write his own typesetting system. He expected it to take a few months. It took about ten years.
What came out was TeX (pronounced “tech”. The letters are the Greek τεχ, as in technē, “art/craft”). Its key ideas are still what make LaTeX output look good:
- Boxes and glue. Every character, word and line is a box. The space between boxes is “glue” that can stretch and shrink.
- Knuth–Plass line breaking. Instead of filling lines one at a time like a word processor, TeX looks at the whole paragraph and chooses the breaks that minimize a global “badness” score. That’s why LaTeX paragraphs look even and avoid “rivers” of white space.
- A real math typesetting model. It has classes of symbols (ordinary, operator, binary, relation, punctuation…) with spacing rules between them that were based on centuries of printers’ practice.
- Stability. Knuth froze TeX. Its version number converges to π (currently 3.141592653), and on his death it is to be fixed at exactly π. A
.texfile from 1990 usually still compiles today.
TeX itself is a low-level macro language. Writing raw TeX (“plain TeX”) is like writing assembly.
LaTeX (1984): Leslie Lamport adds structure
Leslie Lamport (later a Turing Award winner for distributed systems: Paxos, logical clocks) wrote LaTeX, a big set of TeX macros that let you describe logical structure instead of formatting:
\section{Introduction} % not "18pt bold, 2em space above"
\begin{itemize} ... \end{itemize}
\cite{knuth1984}
That separation of content and presentation is the same idea that HTML/CSS and Markdown made popular later. A journal can switch your paper’s entire look by swapping the document class, and you don’t have to change your text.
Milestones:
| Year | Event |
|---|---|
| 1978 | TeX first released |
| 1984 | LaTeX 2.09 (Lamport) |
| 1985 | BibTeX (Oren Patashnik): bibliography databases |
| 1994 | LaTeX2ε, the version everyone uses today (the “LaTeX3” project kept improving it from inside) |
| 1990s–2000s | pdfTeX: produce PDF directly, microtypography |
| 2000s | XeTeX and LuaTeX: Unicode and system fonts (LuaTeX also embeds a Lua scripting engine) |
| 2012 | Overleaf (originally WriteLaTeX) launches. ShareLaTeX launched in 2011 and merged with it in 2017 |
| 2020s | LaTeX kernel gets modern features (expl3 built in, tagged/accessible PDF work), plus new competitors like Typst |
Pronunciation
“LAH-tek” or “LAY-tek”. Never “latex” like the rubber. You’ll hear both of the first two at every conference.
1.2 Why research runs on LaTeX
- Math. This is still the main reason. Nothing else produces publication-quality equations as reliably, and LaTeX math syntax (
\frac{a}{b},\sum_{i=1}^n) has become the lingua franca. It’s what MathJax/KaTeX render on the web, what Markdown math blocks use, what Jupyter, Notion and Obsidian accept, and what ChatGPT-style models print. - Templates from publishers and conferences. NeurIPS, ICML, ICLR, ACL, CVPR, IEEE, ACM, Springer, Elsevier, APS (physics) and AMS (math) all ship official LaTeX style files. Some (NeurIPS, ICML, ICLR) only provide LaTeX templates.
- arXiv. arXiv strongly prefers LaTeX source to PDFs. When you upload
.tex, arXiv compiles it itself and keeps the source, which anyone can download (see chapter 9; that’s a great way to learn). In some fields, a PDF that was clearly made from LaTeX gets rejected and you’re asked for the source. - Automatic numbering and cross-referencing. Equations, figures, tables, sections, theorems and citations are all numbered and linked automatically. Reorder sections and every “Figure 3” updates.
- Bibliographies. Keep one
.bibfile for your whole career. Every paper pulls from it and formats references in whatever style the venue requires. - Plain text. Works with git, diff, grep, scripts and LLMs. You can review a co-author’s change line by line.
- Long-term stability and it’s free. Open source, runs everywhere, and decades-old documents still build.
- Culture and network effects. Your advisor uses it, your co-authors use it, the template is in LaTeX. That alone is self-reinforcing.
Where it’s weaker: error messages are cryptic, compiles are slow on large documents, precise layout control is painful, and accessibility/HTML output have historically been poor (arXiv now generates HTML versions of papers from LaTeX source, and the LaTeX project is actively working on tagged PDF).
1.3 How people actually write papers today
A typical 2020s ML/physics/math research workflow:
- Overleaf for collaborative papers (the default in most labs), or a local editor + git for people who prefer their own tools, often syncing with Overleaf through its Git integration or GitHub sync.
- A conference template as the starting point. You never start from a blank file.
- A shared
.bibfile, with entries exported from Google Scholar, DBLP, Semantic Scholar, Zotero or Paperpile. - Figures made in matplotlib/seaborn (exported as PDF), TikZ, draw.io, Figma, Keynote or Inkscape, and included as PDF/PNG.
- Macros for notation (
\newcommand{\loss}{\mathcal{L}}) so it stays consistent. - Comment macros for collaboration (
\todo{}, or colored\alice{...},\bob{...}notes). - LLM assistants for drafting tables, fixing errors, converting equations from screenshots, and so on. This works well because LaTeX is plain text and the models have seen a huge amount of it.
1.4 Why Overleaf is so popular
Overleaf is a browser-based LaTeX editor and compiler. It’s popular because:
- Zero install. A full TeX Live distribution (several GB) lives on their servers. Students don’t need to fight installers.
- Real-time collaboration, like Google Docs: several cursors, track changes, comments, history.
- Template gallery. Thousands of templates, including official ones for most conferences and journals. Many conferences link straight to Overleaf.
- Rich text / visual editor for co-authors who are scared of the syntax.
- Error panel that turns TeX log noise into readable messages with links to docs.
- Integrations: Git, GitHub, Dropbox, Zotero/Mendeley (premium), and direct submission to some journals.
- Institutional licenses. Many universities pay for premium accounts, which removes compile-timeout limits and adds more collaborators and full history.
- Network effect. Once your advisor shares an Overleaf link, you’re on Overleaf.
Downsides: needs internet (there’s no real offline mode), the free tier has collaborator and compile-time limits, big projects can be slow to compile, and you’re editing in a browser rather than your own editor. Overleaf’s core is open source (Overleaf Community Edition) and can be self-hosted.
Some alternatives in the same space: Prism (OpenAI’s LaTeX workspace with AI built in), Papeeria, CoCalc, and Typst’s web app (for Typst rather than LaTeX).
1.5 Running LaTeX locally
You install a TeX distribution: the engines (pdfTeX, XeTeX, LuaTeX), the LaTeX format, thousands of packages, and fonts.
| Distribution | Platform | Notes |
|---|---|---|
| TeX Live | Linux, macOS, Windows | The reference distribution, updated yearly. Overleaf runs TeX Live. |
| MacTeX | macOS | TeX Live plus Mac GUI apps (TeXShop, BibDesk). About 5–6 GB. |
| BasicTeX | macOS | A small (~100 MB) MacTeX subset. You add packages with tlmgr. |
| MiKTeX | Windows (also others) | Installs missing packages on the fly. |
| TinyTeX | All | Small, R/Quarto-friendly TeX Live. |
| Tectonic | All | A modern, self-contained engine (based on XeTeX) that downloads what it needs and reruns automatically. |
Then you pick an editor: VS Code + LaTeX Workshop (very popular), TeXstudio, TeXShop, Vim + VimTeX, Emacs + AUCTeX, Zed, Sublime + LaTeXTools. Chapter 2 walks through a concrete setup.
1.6 The engines: pdfLaTeX vs XeLaTeX vs LuaLaTeX
You’ll see these names in Overleaf’s settings and in templates.
| Engine | Input | Fonts | When to use |
|---|---|---|---|
| pdfLaTeX | 8-bit (UTF-8 is fine for Latin scripts) | TeX fonts | Default. What arXiv and most conference templates expect. Fastest. |
| XeLaTeX | Full Unicode | Any system font (OTF/TTF) via fontspec | Non-Latin scripts (Chinese, Arabic, Devanagari), custom fonts |
| LuaLaTeX | Full Unicode | System fonts, and Lua scripting | Modern successor. Good for complex documents. Slower. |
Rule of thumb for ML/physics papers: use pdfLaTeX unless the template says otherwise. If you need Hindi, Chinese and so on in your paper, use XeLaTeX or LuaLaTeX.
1.7 Typst: the new kid
Typst (2023, from two Berlin students, written in Rust) is a modern typesetting system designed as a successor to LaTeX:
#set page(paper: "us-letter")
#set heading(numbering: "1.")
= Introduction
We minimize the loss $cal(L)(theta) = sum_(i=1)^n ell(f_theta (x_i), y_i)$.
$ nabla_theta cal(L) = 1/n sum_i nabla_theta ell_i $ <eq:grad>
See @eq:grad and @smith2020.
#bibliography("refs.bib")
Strengths
- Markdown-like syntax (
= Heading,*bold*,_italic_,- list). You’ll feel at home. - Instant, incremental compilation (milliseconds vs seconds), so live preview is real.
- Readable, actual error messages.
- A proper scripting language built in (variables, functions, loops) instead of TeX’s macro expansion.
- One small binary. No multi-GB distribution.
- Reads
.bibfiles, has packages (“Typst Universe”), and has a collaborative web app.
Weaknesses (as of 2026)
- Conferences and arXiv still want LaTeX. arXiv does not accept Typst source. You can upload the PDF, but you lose the “source on arXiv” benefits. NeurIPS/ICML/ICLR official templates are LaTeX. Community Typst templates exist for some venues but aren’t official.
- Smaller ecosystem. There’s nothing as mature as TikZ,
chemfig, or the long tail of 6000+ CTAN packages. - Co-authors probably don’t know it.
- Different math syntax (
frac(a, b)ora/b,sum_(i=1)^n), so your LaTeX-math muscle memory transfers only partially.
Verdict: Learn LaTeX first, because it’s the requirement for publishing. Typst is great for personal notes, CVs, homework, theses (if your university allows it), and internal reports. Knowing LaTeX makes Typst trivial to pick up later; the reverse isn’t true.
1.8 Other tools you’ll hear about
- Pandoc: universal document converter. It can turn Markdown (including LaTeX math) into LaTeX/PDF. Good for drafts. Papers usually end up as pure LaTeX anyway.
- Quarto / R Markdown: Markdown + executable code (Python/R) → PDF via LaTeX. Popular in statistics.
- LyX: a WYSIWYM GUI on top of LaTeX.
- ConTeXt: another TeX-based macro system, focused on design control. Niche.
- MathJax / KaTeX: render LaTeX math in browsers (Markdown math on GitHub, blogs, Jupyter). Math only, no documents.
- Beamer: the LaTeX class for slides. You’ll see Beamer talks at every conference.
- CTAN (ctan.org): the Comprehensive TeX Archive Network, where every package lives together with its documentation.
texdoc <package>opens the local docs. - TeX StackExchange (tex.stackexchange.com): the best Q&A site. Almost every problem has already been answered there.
1.9 Key takeaways
- TeX = engine (Knuth). LaTeX = structure layer on top (Lamport). You write LaTeX.
- Research uses LaTeX because of math quality, templates, arXiv, automatic numbering/citations, and network effects.
- Overleaf = LaTeX in the browser + collaboration. Local = TeX Live/MacTeX + editor +
latexmk. - Use pdfLaTeX for papers unless told otherwise.
- Typst is the promising modern alternative, but for conference/arXiv papers, LaTeX is still what you need.
Chapter 2: Setup and Workflow
2.1 Option A: Overleaf (start here)
- Create an account at overleaf.com.
- New Project → Blank Project. You get a
main.tex. - Left pane: files. Middle: source editor (toggle Code Editor / Visual Editor). Right: PDF.
- Recompile with
Ctrl/Cmd + Enter. Turn on Auto compile in the menu. - Menu (top-left) → Compiler (pdfLaTeX / XeLaTeX / LuaLaTeX), TeX Live version, Main document.
- Useful features:
- Synctex: double-click in the PDF to jump to the source, and vice versa with the arrow button.
- Logs and output files button: shows errors/warnings, and lets you download the
.bblfile (you need it for arXiv, see chapter 8). - History: labeled versions and diff view.
- Review: track changes and comments.
- Share: invite by email or link.
- Menu → Sync → Git/GitHub: clone the project with git and work locally.
- New Project → Upload Project (zip) or Templates → search “NeurIPS”, “ICML”, “ICLR”, and so on.
That’s all you need to start. Everything in chapters 3–7 works in Overleaf.
2.2 Option B: Local setup on macOS
Install a distribution
# Full (recommended if you have ~6 GB of space): everything just works
brew install --cask mactex-no-gui # TeX Live without the GUI apps
# or the full MacTeX with TeXShop, BibDesk, etc.:
# brew install --cask mactex
# Minimal alternative (~100 MB): install packages as needed
# brew install --cask basictex
# sudo tlmgr update --self
# sudo tlmgr install latexmk booktabs siunitx cleveref ...
Open a new terminal (so PATH includes /Library/TeX/texbin) and check:
pdflatex --version
latexmk --version
tlmgr --version
Keep it updated:
sudo tlmgr update --self --all
TeX Live is released yearly (around April). To upgrade between years, install the new MacTeX.
Editor: VS Code + LaTeX Workshop
- Install the LaTeX Workshop extension (James Yu).
- Open a folder with a
.texfile. Save, and it builds automatically withlatexmk. The PDF opens in a VS Code tab with SyncTeX (Cmd+Clickin the PDF jumps to the source;Cmd+Option+Jjumps from the source to the PDF). - Recommended
settings.jsonadditions:
{
"latex-workshop.latex.autoBuild.run": "onSave",
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.latex.outDir": "%DIR%/build"
}
Optional extras: LTeX+ (grammar/spell checking that understands LaTeX), Code Spell Checker, and chktex linting (built into LaTeX Workshop).
Other good editors: TeXstudio (all-in-one, beginner-friendly), Skim as an external PDF viewer on macOS (auto-reloads, SyncTeX), Vim + VimTeX, Emacs + AUCTeX.
Tectonic (alternative, no big install)
brew install tectonic
tectonic main.tex # downloads only the packages it needs, reruns automatically
Great for quick builds and CI. Some edge cases differ from TeX Live, and arXiv uses TeX Live, so check your final build with TeX Live.
2.3 What actually happens when you “compile”
Files in a typical project:
paper/
├── main.tex # your source
├── refs.bib # bibliography database
├── figures/ # PDFs/PNGs
├── neurips_2026.sty # conference style file
└── (generated)
├── main.aux # labels, citations, page numbers recorded by LaTeX
├── main.bbl # formatted bibliography (generated by BibTeX/Biber)
├── main.blg # BibTeX log
├── main.log # full compile log (errors + warnings)
├── main.out # hyperref bookmarks
├── main.toc # table of contents
├── main.synctex.gz
└── main.pdf # 🎉
Why does LaTeX need several passes? LaTeX reads the file once, top to bottom. When it sees \ref{fig:arch} on page 2, it doesn’t know yet that the figure will be number 3. So:
- pdflatex (pass 1): writes all
\labels and\citekeys tomain.aux. References show as ??. - bibtex (or biber): reads the citation keys from
.aux, looks them up inrefs.bib, writes formatted entries tomain.bbl. - pdflatex (pass 2): reads
.auxand.bbl. Citations appear, but their numbers can shift the layout. - pdflatex (pass 3): everything settles.
You never need to remember this. latexmk does it for you, rerunning exactly as many times as needed:
latexmk -pdf main.tex # pdfLaTeX
latexmk -pdf -pvc main.tex # keep watching files and rebuild on save (preview continuous)
latexmk -xelatex main.tex # XeLaTeX
latexmk -lualatex main.tex # LuaLaTeX
latexmk -c # clean aux files (keep PDF)
latexmk -C # clean everything including PDF
A .latexmkrc in the project folder can set defaults:
$pdf_mode = 1; # use pdflatex
$out_dir = 'build';
$bibtex_use = 2; # run bibtex/biber when needed, delete .bbl on clean
Overleaf runs latexmk behind the scenes too.
If using latex-workshop extension in vscode, also set this in.vscode/settings.json:
{
"latex-workshop.latex.outDir": "%DIR%/build"
}
2.4 Reading errors (the most important survival skill)
A LaTeX error looks like this:
! Undefined control sequence.
l.42 We use the \softmx
function to normalize.
!starts the error message.l.42is the line number, and the break in the quoted line shows exactly where TeX stopped.- Here:
\softmxis a typo (or you forgot to define it).
The ten errors you’ll hit 95% of the time:
| Message | Usual cause | Fix |
|---|---|---|
Undefined control sequence | Typo in a command, or missing package | Fix the spelling / \usepackage{...} |
Missing $ inserted | Math-only command (_, ^, \alpha) used outside math | Wrap in $...$ or escape \_ |
Missing } inserted / Extra } | Unbalanced braces | Count your { } |
File 'xyz.sty' not found | Package not installed | tlmgr install xyz, or check spelling |
File 'fig.png' not found | Wrong path / extension | Check figures/ path and case (Linux and arXiv are case-sensitive) |
Environment xyz undefined | Missing package (align needs amsmath) | Add the package |
\begin{x} ended by \end{y} | Mismatched environments | Fix nesting |
Misplaced alignment tab character & | & outside a table/align | Escape as \& |
Too many }'s | Extra closing brace | Remove it |
Citation 'xyz' undefined / Reference 'fig:x' undefined (warnings) | Key typo, or haven’t rerun BibTeX | Check keys, rerun latexmk |
Warnings worth noticing:
Overfull \hbox (12.3pt too wide): a line sticks into the margin. Usually a long URL, a long math expression or an unbreakable word. Look at the PDF: if you can see it, fix it (reword,\allowbreak,\url{}, break the equation).Underfull \hbox: a line is too loose. Usually harmless.Label(s) may have changed. Rerun:latexmkhandles it.There were multiply-defined labels: two\label{x}with the same name. Fix it.
Debugging strategy when you’re stuck:
- Look at the first error. Later ones are often cascades.
- Comment out half the document (
%or put\end{document}early) and bisect. - Delete aux files (
latexmk -C, or in Overleaf: Logs → Clear cached files). A corrupted.auxcan cause weird errors. - Search the exact message on TeX StackExchange.
In the terminal, pdflatex stops at an error and waits for input (? prompt). Type x + Enter to quit, or run with -interaction=nonstopmode (latexmk does a sensible version of this; add -halt-on-error to stop at the first error).
2.5 Project organization for a real paper
my-paper/
├── main.tex
├── macros.tex # \newcommand definitions (notation)
├── sections/
│ ├── 1-intro.tex
│ ├── 2-related.tex
│ ├── 3-method.tex
│ ├── 4-experiments.tex
│ ├── 5-conclusion.tex
│ └── appendix.tex
├── figures/
│ ├── architecture.pdf
│ └── results.pdf
├── tables/
│ └── main_results.tex # often auto-generated by your Python scripts
├── refs.bib
├── neurips_2026.sty
└── .latexmkrc
In main.tex:
\input{macros}
...
\input{sections/1-intro}
\input{sections/2-related}
\input{file}pastes the file’s content in place (you can leave off.tex). Use this.\include{file}also forces a page break and works with\includeonly{}for faster partial builds of long documents like theses. Not great for papers.
Put the project in git. Add a .gitignore:
*.aux
*.bbl
*.blg
*.log
*.out
*.toc
*.fls
*.fdb_latexmk
*.synctex.gz
build/
Tip: one sentence per line. LaTeX treats a single newline as a space, so you can put each sentence on its own line. Git diffs become sentence-level, and merges conflict much less. A blank line still means “new paragraph”.
2.6 Key takeaways
- Overleaf is the fastest way to start. Local = MacTeX + VS Code + LaTeX Workshop.
latexmk -pdf main.texhandles multi-pass compilation and BibTeX.- Read the first error, use the line number, and know the top ten errors.
- Split big papers with
\input, keep figures infigures/, use git, write one sentence per line.
Chapter 3: Document Structure, Syntax and Text
3.1 The smallest complete document
\documentclass{article} % 1. what kind of document
\usepackage{amsmath} % 2. preamble: load packages, define things
\title{My First Paper}
\author{Ada Lovelace}
\date{\today}
\begin{document} % 3. body: the actual content
\maketitle
\section{Introduction}
Hello, \LaTeX{}! This is a paragraph.
This is another paragraph, because there was a blank line.
\end{document}
Everything before \begin{document} is the preamble: configuration only, no visible output. Everything between \begin{document} and \end{document} is content. Anything after \end{document} is ignored.
3.2 The syntax in five rules
- Commands start with a backslash:
\section,\textbf,\alpha.- Mandatory arguments go in braces:
\textbf{bold} - Optional arguments go in square brackets, before the braces:
\section[Short]{A Very Long Title},\documentclass[11pt,twocolumn]{article} - Starred versions:
\section*{Acknowledgments}= unnumbered. - A command name made of letters eats the spaces after it:
\LaTeX is→ “LaTeXis”. Use\LaTeX{} isor\LaTeX\ is.
- Mandatory arguments go in braces:
- Environments wrap a region:
\begin{name} ... \end{name}. - Groups: braces
{ }limit scope:{\small this is small} this is not. - Comments:
%to the end of the line. There’s no block comment by default. Use\iffalse ... \fior thecommentpackage. - Special characters you must escape:
| Char | Meaning in LaTeX | To print it |
|---|---|---|
% | comment | \% |
$ | math mode | \$ |
& | alignment tab | \& |
# | macro parameter | \# |
_ | subscript (math) | \_ |
^ | superscript (math) | \^{} or \textasciicircum |
{ } | grouping | \{ \} |
~ | non-breaking space | \textasciitilde or $\sim$ |
\ | command | \textbackslash |
The one that bites ML people constantly: underscores in model names and file names. Write \texttt{train\_model.py}, or use \verb|train_model.py| or \path{}/\url{}.
3.3 Whitespace and paragraphs
- Multiple spaces = one space. A single newline = a space.
- A blank line = a new paragraph. (
\pardoes the same thing.) \\forces a line break without a new paragraph. Avoid it in body text. It’s for tables, addresses, poetry.~is a non-breaking space. Use it before references so the number never ends up alone at the start of a line:Figure~\ref{fig:a},Section~3,Dr.~Smith.- After an abbreviation ending in a period, LaTeX assumes the sentence ended and adds extra space. Fix:
e.g.\ this,et al.\ show, ori.e.,(a following comma avoids the issue). - Explicit spacing:
\,thin,\quadand\qquadwide,\hspace{1cm},\vspace{2mm}. Avoid using these as a habit; let the class do layout. \newpage,\clearpage(also flushes pending floats).
3.4 Document classes
\documentclass[options]{class}
| Class | Use |
|---|---|
article | Papers, short reports. The base for most conference templates. |
report, book | Theses and books (have \chapter) |
beamer | Slides |
memoir, scrartcl/scrreprt (KOMA-Script) | Flexible, typographically refined alternatives |
revtex4-2 | APS physics journals |
amsart | AMS math journals |
IEEEtran, acmart, llncs (Springer), elsarticle | Publisher classes |
Common options: 10pt|11pt|12pt, a4paper|letterpaper, twocolumn, draft (shows overfull boxes as black bars, skips images: fast), final.
Conference templates for ML (NeurIPS, ICML, ICLR) use article and add their own style package (\usepackage{neurips_2026}). See chapter 8.
3.5 Packages
\usepackage[options]{package}
A solid default preamble for a research paper:
\usepackage[utf8]{inputenc} % harmless; UTF-8 is the default since 2018
\usepackage[T1]{fontenc} % proper font encoding (hyphenation of accented words, copy-paste)
\usepackage{lmodern} % or: times, mathptmx, newtxtext/newtxmath, libertine, ...
\usepackage{microtype} % subtle spacing improvements: always use it
\usepackage{amsmath,amssymb,amsthm,mathtools} % math (chapter 4)
\usepackage{graphicx} % \includegraphics
\usepackage{booktabs} % good tables
\usepackage{xcolor} % colors
\usepackage{hyperref} % clickable links (load late)
\usepackage[capitalize,noabbrev]{cleveref} % smart references (load after hyperref)
Package load order matters a bit. Rule of thumb: hyperref goes near the end, and cleveref comes after hyperref. Conference style files often load some of these already. Loading a package twice with the same options is harmless; with different options it gives an “option clash” error.
Find package docs: texdoc booktabs in the terminal, or ctan.org/pkg/booktabs.
3.6 Title, authors, abstract
\title{Attention Is All You Need (Again)}
\author{
Ada Lovelace\thanks{Equal contribution.} \\
Analytical Engine Lab\\
\texttt{ada@example.org}
\And % \And / \AND are NeurIPS-style separators; plain article uses \and
Alan Turing\footnotemark[1] \\
Bletchley Institute
}
\begin{document}
\maketitle
\begin{abstract}
We propose ...
\end{abstract}
Author formatting is the most template-specific thing in LaTeX. ICML uses \icmlauthor{}, IEEE uses \IEEEauthorblockN, acmart uses \author{}\affiliation{} blocks. Always copy the pattern from the template’s example file.
3.7 Sectioning
\part{...} % rarely used in papers
\chapter{...} % report/book only
\section{Introduction}
\subsection{Motivation}
\subsubsection{A detail}
\paragraph{Bold run-in heading.} Text continues on the same line.
\subparagraph{...}
\section*{Acknowledgments} % unnumbered, not in table of contents
\appendix % from here on, sections are lettered A, B, C...
\section{Proofs}
\paragraph{} is heavily used in ML papers for the bold inline mini-headings (“Datasets. We evaluate on…”).
Table of contents: \tableofcontents (rare in papers, common in theses and long appendices).
3.8 Text formatting
| Markdown | LaTeX | Notes |
|---|---|---|
**bold** | \textbf{bold} | |
*italic* | \emph{italic} | \emph is semantic (toggles inside italic text). \textit forces italic. |
`code` | \texttt{code} | Escape _ inside it. Or `\verb |
\textsc{Small Caps} | Common for method names: \textsc{BERT} | |
\underline{x} | Rarely used in papers, except for marking “second best” in tables | |
\textsf{sans} | ||
\sout{x} (package ulem) | ||
[link](url) | \href{https://x.org}{link}, \url{https://x.org} | needs hyperref / url |
Old-style {\bf ...} and {\it ...} are deprecated, but you’ll still see them in old papers.
Font sizes (as switches): \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge. Example: {\small text}.
Quotes: use ``double'' and `single'. Never type " for quotes in pdfLaTeX: you get a straight or closing-style quote on both sides instead of proper opening quotes. Or use the csquotes package with \enquote{...}.
Dashes:
-hyphen: state-of-the-art--en dash: ranges pages 10–20, 2019–2024, encoder–decoder---em dash: a break in thought—like this
Ellipsis: \ldots (text) or \dots. Not three periods.
Colors: \textcolor{red}{text}, {\color{blue} text} (package xcolor). Define your own: \definecolor{mygreen}{RGB}{0,150,80}.
3.9 Lists
\begin{itemize} % bullets (Markdown: - item)
\item First
\item Second
\begin{itemize}
\item Nested
\end{itemize}
\end{itemize}
\begin{enumerate} % numbered (Markdown: 1. item)
\item First
\item[(a)] Custom label
\end{enumerate}
\begin{description} % term–definition
\item[Encoder] maps inputs to latents.
\item[Decoder] maps latents to outputs.
\end{description}
The enumitem package lets you control spacing and labels. Use it to save space in papers:
\usepackage{enumitem}
\begin{itemize}[leftmargin=*, nosep]
\item Compact list, no extra vertical space.
\end{itemize}
\begin{enumerate}[label=(\roman*)] % (i), (ii), (iii)
\item ...
\end{enumerate}
The classic “our contributions are:” list in ML papers is an itemize with nosep or itemsep=0pt.
3.10 Footnotes, quotes, verbatim
Transformers\footnote{Introduced by \citet{vaswani2017}.} are everywhere.
\begin{quote}
A short block quote.
\end{quote}
\begin{verbatim}
Text exactly as typed, including _ % $ & characters.
\end{verbatim}
3.11 Labels and cross-references
This is one of LaTeX’s superpowers.
\section{Method}\label{sec:method}
\begin{equation}
y = Wx + b \label{eq:linear}
\end{equation}
\begin{figure}
...
\caption{Our architecture.}\label{fig:arch} % \label AFTER \caption!
\end{figure}
As shown in Section~\ref{sec:method}, Eq.~\eqref{eq:linear}, and Figure~\ref{fig:arch}...
On page~\pageref{fig:arch}...
Conventions for label prefixes: sec:, subsec:, eq:, fig:, tab:, alg:, thm:, lem:, app:. They’re just text, but they keep you sane.
cleveref writes the word for you:
\cref{fig:arch} % → "Figure 3" (with [capitalize,noabbrev] options)
\Cref{eq:linear} % → "Equation (2)", capitalized for start of sentence
\cref{fig:a,fig:b,fig:c} % → "Figures 1 to 3"
Most modern ML papers use \cref. (Chapter 7 covers hyperref + cleveref setup.)
Gotcha: \label refers to the most recent numbered thing. In figures, it must come after \caption, or you get the section number instead.
3.12 Defining your own commands (macros)
This is where LaTeX beats Markdown: you can define your own vocabulary.
% In the preamble (or macros.tex)
\newcommand{\method}{\textsc{FastNet}} % no arguments
\newcommand{\R}{\mathbb{R}}
\newcommand{\norm}[1]{\left\lVert #1 \right\rVert} % one argument: #1
\newcommand{\inner}[2]{\langle #1, #2 \rangle} % two arguments
\newcommand{\vect}[1][x]{\mathbf{#1}} % optional arg with default "x"
\renewcommand{\vec}[1]{\boldsymbol{#1}} % redefine an existing command
% xspace: adds a space after a macro unless followed by punctuation
\usepackage{xspace}
\newcommand{\ours}{\textsc{FastNet}\xspace}
Usage:
\method outperforms baselines. % careful: eats the space → "FastNetoutperforms"
\method{} outperforms baselines. % OK
\ours outperforms baselines. % OK with \xspace
Let $x \in \R^d$ and $\norm{x} \le 1$, with $\inner{u}{v} = 0$.
Changing \method in one place renames your method across the whole paper. That’s invaluable when reviewers or co-authors want a different name.
Collaboration/TODO macros (very common)
\newcommand{\todo}[1]{\textcolor{red}{[TODO: #1]}}
\newcommand{\ada}[1]{\textcolor{blue}{[Ada: #1]}}
\newcommand{\alan}[1]{\textcolor{orange}{[Alan: #1]}}
% to hide all notes for the final version:
% \renewcommand{\todo}[1]{}
Or use the todonotes package for margin notes: \todo{fix this}.
Environments of your own
\newenvironment{keyidea}
{\begin{quote}\itshape\textbf{Key idea.}~}
{\end{quote}}
3.13 Boxes, minipages and columns
\begin{minipage}{0.48\textwidth}
Left content
\end{minipage}\hfill
\begin{minipage}{0.48\textwidth}
Right content
\end{minipage}
\fbox{framed text}
\parbox{5cm}{a paragraph in a fixed-width box}
Useful length units: \textwidth (text block width), \linewidth (current line width, use this inside columns/minipages), \columnwidth, pt, mm, cm, in, em (width of an “M” in the current font).
For fancy colored boxes (like “takeaway” boxes in papers), use tcolorbox:
\usepackage{tcolorbox}
\begin{tcolorbox}[colback=blue!5, colframe=blue!60!black, title=Takeaway]
Scaling data matters more than scaling parameters.
\end{tcolorbox}
(blue!5 means 5% blue mixed with white. That xcolor syntax shows up everywhere.)
3.14 Markdown → LaTeX quick map
| Markdown | LaTeX |
|---|---|
# H1 / ## H2 / ### H3 | \section{} / \subsection{} / \subsubsection{} |
| blank line | blank line (same!) |
**b**, *i* | \textbf{b}, \emph{i} |
`c` | \texttt{c} |
- item | \begin{itemize} \item ... \end{itemize} |
1. item | \begin{enumerate} \item ... \end{enumerate} |
[t](u) | \href{u}{t} |
 | \begin{figure}...\includegraphics{img}...\end{figure} |
> quote | \begin{quote}...\end{quote} |
```code``` | verbatim / lstlisting / minted |
$x$, $$x$$ | $x$, \[ x \] (never $$ in LaTeX) |
| table with pipes | tabular (chapter 5) |
footnote [^1] | \footnote{...} |
--- horizontal rule | \noindent\rule{\linewidth}{0.4pt} (rare in papers) |
3.15 Key takeaways
- Preamble = setup; body = content. Commands
\x{}, optional args[ ], environments\begin{}...\end{}. - Escape
% $ & # _ { } ~ ^ \. Underscores in code names are the usual trap. - Blank line = paragraph. Use
~before refs. Avoid\\in prose. \label+\ref/\creffor everything. Label after caption.- Define macros for your method name, notation and TODOs.
Chapter 4: Mathematics
You probably already write $x^2$ in Markdown. This chapter takes you from “I can write inline math” to “I can typeset a theory-heavy appendix properly”.
Required preamble for everything below:
\usepackage{amsmath} % align, equation*, \text, \eqref, cases, matrices ...
\usepackage{amssymb} % \mathbb, \leqslant, extra symbols
\usepackage{amsthm} % theorem/proof environments
\usepackage{mathtools} % amsmath fixes/extensions: \coloneqq, dcases, \DeclarePairedDelimiter
\usepackage{bm} % \bm{} bold math
4.1 Inline vs display math
Inline: the loss $\mathcal{L}(\theta)$ is convex. % also \( ... \)
Display, unnumbered:
\[
\mathcal{L}(\theta) = \frac{1}{n}\sum_{i=1}^{n} \ell\bigl(f_\theta(x_i), y_i\bigr)
\]
Display, numbered:
\begin{equation}
\theta_{t+1} = \theta_t - \eta \nabla_\theta \mathcal{L}(\theta_t)
\label{eq:sgd}
\end{equation}
Numbered environment, suppressed: \begin{equation*} ... \end{equation*}
- Never use
$$ ... $$in LaTeX. It’s plain-TeX syntax: it messes up vertical spacing and ignores thefleqnoption. Use\[ ... \]orequation*. - Refer to equations with
\eqref{eq:sgd}→ “(1)”, or\cref{eq:sgd}→ “Equation (1)”. - Punctuation: equations are part of sentences. Put the comma/period inside the display:
... \mathcal{L}(\theta_t). \end{equation} - Don’t leave a blank line before
\begin{equation}unless you really mean to start a new paragraph. Blank lines inside math environments are errors.
4.2 The basics
x^2, \quad x_i, \quad x_i^2, \quad x^{2n}, \quad x_{i,j}, \quad e^{-\frac{x^2}{2}}
Braces matter: x^10 gives x¹0. You need x^{10}.
| What | Code | Notes |
|---|---|---|
| Fraction | \frac{a}{b} | \tfrac (small), \dfrac (display-size), a/b inline is often nicer |
| Root | \sqrt{x}, \sqrt[3]{x} | |
| Sum / product | \sum_{i=1}^{n}, \prod_{i} | limits go under/over in display mode, to the side inline |
| Integral | \int_0^\infty f(x)\,\mathrm{d}x | note the thin space \, before dx |
| Limits | \lim_{n \to \infty} | |
| Derivatives | \frac{\partial \mathcal{L}}{\partial \theta}, \nabla, f'(x), \dot{x} | |
| Binomial | \binom{n}{k} | |
| Overline etc. | \bar{x}, \hat{y}, \tilde{x}, \vec{v}, \overline{AB}, \widehat{xyz} | |
| Under/overbrace | \underbrace{a+b}_{\text{sum}} | |
| Text in math | \text{if } x > 0 | Uses the surrounding text font. Keep the spaces inside \text{} |
| Upright subscripts | x_{\text{train}}, \mathcal{L}_{\mathrm{CE}} | words as subscripts must be upright, not italic |
Greek letters
\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \vartheta \iota \kappa \lambda \mu \nu \xi \pi \rho \sigma \tau \phi \varphi \chi \psi \omega
Uppercase: \Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Phi \Psi \Omega (uppercase A, B, E… are just Latin letters).
Relations and operators
| Code | Symbol | Code | Symbol |
|---|---|---|---|
\le, \ge | ≤ ≥ | \neq | ≠ |
\approx | ≈ | \sim | ∼ |
\equiv | ≡ | \propto | ∝ |
\ll, \gg | ≪ ≫ | \coloneqq (mathtools) | ≔ |
\in, \notin | ∈ ∉ | \subset, \subseteq | ⊂ ⊆ |
\cup, \cap | ∪ ∩ | \setminus | ∖ |
\forall, \exists | ∀ ∃ | \emptyset, \varnothing | ∅ |
\to, \mapsto | → ↦ | \Rightarrow, \iff | ⇒ ⇔ |
\times, \cdot | × · | \otimes, \oplus | ⊗ ⊕ |
\odot | ⊙ (Hadamard) | \circ | ∘ |
\pm, \mp | ± ∓ | \infty | ∞ |
\partial | ∂ | \nabla | ∇ |
\top (transpose: x^\top) | ⊤ | \perp | ⊥ |
\ldots, \cdots | … ⋯ | \vdots, \ddots | ⋮ ⋱ |
Use \cdots between operators (a_1 + \cdots + a_n) and \ldots between commas (x_1, \ldots, x_n). Or just use \dots, which amsmath usually guesses correctly.
Math fonts (alphabets)
\mathbb{R}, \mathbb{E}, \mathbb{N} % blackboard bold: number sets, expectation
\mathcal{L}, \mathcal{D}, \mathcal{N} % calligraphic: loss, dataset, Gaussian
\mathbf{x}, \mathbf{W} % bold upright: vectors/matrices (Latin only)
\bm{\theta}, \bm{x} % bold italic incl. Greek (package bm)
\boldsymbol{\mu} % amsmath version of bold
\mathrm{d}x, \mathrm{softmax} % upright roman
\mathsf{T} % sans-serif
\mathfrak{g} % fraktur (Lie algebras etc.)
\mathscr{L} % script (package mathrsfs)
ML convention: lowercase bold = vector (x), uppercase bold = matrix (W), calligraphic = sets/distributions/losses, blackboard = ℝ and 𝔼. Pick one and stay consistent. Macros help (§4.9).
4.3 Delimiters that size themselves
\left( \frac{a}{b} \right) % grows to fit
\left[ ... \right], \left\{ ... \right\}, \left| x \right|, \left\langle u, v \right\rangle
\left. \frac{df}{dx} \right|_{x=0} % invisible left delimiter
% Manual sizing (often looks better than \left/\right):
\bigl( \Bigl( \biggl( \Biggl( ... \Bigr) ...
\left(...\right) can make delimiters too big around sums and gives odd spacing. Professionals often use \bigl(/\bigr) manually.
With mathtools, define paired delimiters once:
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
$\norm{x}$ % normal size
$\norm*{\frac{a}{b}}$ % auto-sized (\left \right)
$\norm[\big]{x}$ % manual size
4.4 Multi-line equations
| Environment | Use |
|---|---|
align / align* | Several equations aligned at & (usually at =). Each line numbered (or not with *). |
gather | Several centered equations, no alignment |
multline | One long equation split over lines (first left, last right) |
split (inside equation) | One equation, several aligned lines, one number |
cases | Piecewise definitions |
aligned / gathered | Sub-blocks inside another math environment |
\begin{align}
\mathcal{L}(\theta)
&= \mathbb{E}_{(x,y)\sim\mathcal{D}} \left[ -\log p_\theta(y \mid x) \right] \label{eq:nll}\\
&\approx -\frac{1}{n} \sum_{i=1}^{n} \log p_\theta(y_i \mid x_i) \nonumber \\
&= \mathcal{L}_{\text{emp}}(\theta). \label{eq:emp}
\end{align}
&marks the alignment point;\\ends a line (but not after the last line).\nonumber(or\notag) removes the number from one line.\labelper line.
One number for a multi-line derivation:
\begin{equation}
\begin{split}
(a+b)^2 &= (a+b)(a+b) \\
&= a^2 + 2ab + b^2.
\end{split}
\label{eq:square}
\end{equation}
Several equation columns in one align: a &= b & c &= d \\ (every other & separates columns).
Piecewise:
\mathrm{ReLU}(x) =
\begin{cases}
x & \text{if } x > 0, \\
0 & \text{otherwise.}
\end{cases}
(dcases from mathtools gives display-style fractions inside.)
Text between aligned lines:
\begin{align*}
f(x) &= x^2 + 2x + 1 \\
\intertext{and therefore} % or \shortintertext{} from mathtools
f(x) &= (x+1)^2.
\end{align*}
Subequations (1a, 1b, 1c):
\begin{subequations}\label{eq:system}
\begin{align}
\dot{x} &= \sigma (y - x) \label{eq:lorenz-x}\\
\dot{y} &= x(\rho - z) - y \\
\dot{z} &= xy - \beta z
\end{align}
\end{subequations}
4.5 Matrices and arrays
\begin{pmatrix} a & b \\ c & d \end{pmatrix} % ( )
\begin{bmatrix} a & b \\ c & d \end{bmatrix} % [ ]
\begin{vmatrix} a & b \\ c & d \end{vmatrix} % | | determinant
\begin{Bmatrix} ... \end{Bmatrix} % { }
\begin{matrix} ... \end{matrix} % no delimiters
% General n×m matrix
\mathbf{A} =
\begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1m} \\
a_{21} & a_{22} & \cdots & a_{2m} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nm}
\end{bmatrix}
% Inline small matrix
$\left(\begin{smallmatrix} 1 & 0 \\ 0 & 1 \end{smallmatrix}\right)$
% array: custom column alignment, vertical rules for augmented matrices
\left[\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6
\end{array}\right]
4.6 Operators: argmax, softmax, KL…
Functions like \sin \cos \log \exp \max \min \sup \inf \lim \det \dim \ker \Pr \arg are predefined and print upright. For anything else, declare an operator rather than writing argmax (which would print as italic a·r·g·m·a·x, i.e. a product of variables):
% preamble
\DeclareMathOperator*{\argmax}{arg\,max} % * = limits go underneath in display
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator{\softmax}{softmax}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\KL}{KL}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\DeclareMathOperator{\rank}{rank}
% body
\[
\theta^\star = \argmin_{\theta \in \Theta} \mathcal{L}(\theta), \qquad
\mathrm{Attn}(Q,K,V) = \softmax\!\left(\frac{QK^\top}{\sqrt{d_k}}\right)V
\]
\[
D_{\KL}(p \,\|\, q) = \sum_x p(x) \log \frac{p(x)}{q(x)}
\]
(\! is a negative thin space, used here to pull the parenthesis closer.)
4.7 Spacing in math
LaTeX ignores spaces you type in math mode: $a b$ = $ab$. Spacing comes from symbol classes. Manual spacing:
| Code | Width |
|---|---|
\! | −3/18 em (negative) |
\, | 3/18 em |
\: | 4/18 em |
\; | 5/18 em |
\quad | 1 em |
\qquad | 2 em |
Common uses: \int f(x)\,\mathrm{d}x, x \,\|\, y, separating conditions: \quad \text{for all } i.
\mid vs |: use p(y \mid x) for “given”. It has the right spacing for a relation; p(y|x) is cramped.
\colon for function signatures: f \colon \mathbb{R}^d \to \mathbb{R}.
4.8 Theorems, lemmas, proofs (amsthm)
% preamble
\theoremstyle{plain} % italic body
\newtheorem{theorem}{Theorem}[section] % numbered within sections: Theorem 3.1
\newtheorem{lemma}[theorem]{Lemma} % shares counter with theorem
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition} % upright body
\newtheorem{definition}[theorem]{Definition}
\newtheorem{assumption}{Assumption}
\theoremstyle{remark}
\newtheorem*{remark}{Remark} % * = unnumbered
\begin{assumption}[Smoothness]\label{asm:smooth}
$\mathcal{L}$ is $\beta$-smooth: $\norm{\nabla\mathcal{L}(x) - \nabla\mathcal{L}(y)} \le \beta\norm{x-y}$.
\end{assumption}
\begin{theorem}[Convergence of SGD]\label{thm:conv}
Under \cref{asm:smooth}, with step size $\eta \le 1/\beta$,
\[
\min_{t \le T} \mathbb{E}\norm{\nabla \mathcal{L}(\theta_t)}^2 \le \frac{2(\mathcal{L}(\theta_0) - \mathcal{L}^\star)}{\eta T} + \eta\beta\sigma^2 .
\]
\end{theorem}
\begin{proof}
By $\beta$-smoothness, ... which completes the proof.
\end{proof} % prints ∎ (QED box) automatically
\begin{proof}[Proof of \cref{thm:conv}]
... (custom proof title, common in appendices)
\end{proof}
If a proof ends with a display equation, put \qedhere inside the equation so the ∎ doesn’t sit on its own line.
With cleveref, \cref{thm:conv} prints “Theorem 3.1” automatically.
Common ML-paper pattern: state the theorem in the main text, then restate it in the appendix with the proof. The thmtools / thm-restate packages give you \begin{restatable}{theorem}{convthm} ... \end{restatable} and then \convthm* reprints it in the appendix with the same number.
4.9 A notation macro file for ML papers
Many ML papers literally \input the ICLR math_commands.tex file (from the Deep Learning book) to get consistent notation (\vx, \mW, \E, \R, …). A trimmed personal version:
% macros.tex
\newcommand{\R}{\mathbb{R}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\N}{\mathcal{N}}
\newcommand{\D}{\mathcal{D}}
\newcommand{\loss}{\mathcal{L}}
\newcommand{\vx}{\bm{x}}
\newcommand{\vy}{\bm{y}}
\newcommand{\vtheta}{\bm{\theta}}
\newcommand{\mW}{\mathbf{W}}
\newcommand{\tran}{^{\top}}
\newcommand{\given}{\mid}
\newcommand{\iid}{\stackrel{\text{i.i.d.}}{\sim}}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}
Then $\vx \in \R^d$, $\mW\tran\vx$, $\E_{\vx \sim \D}[\loss(\vtheta; \vx)]$ stays short and consistent.
4.10 Typography habits that separate pros from beginners
- Upright text subscripts:
x_{\text{max}}notx_{max}(italic “max” reads as m·a·x). - Upright operators:
\log,\exp,\softmaxvia\DeclareMathOperator, never plainlog. - Differential d:
\mathrm{d}xwith\,before it (physics/European) ordx(common in US). Be consistent. \midfor conditioning,\colonfor maps,\coloneqqfor definitions (:=has bad spacing).\ldotsvs\cdots(§4.2).- Don’t use math for emphasis or for non-math words.
$Adam$is wrong; writeAdam. - Numbers in text:
$10^{-3}$in math;0.5as plain text is fine. For units, usesiunitx(chapter 6):\SI{3}{\giga\byte},\num{1e-4}. - Punctuate displays as part of the sentence.
- Number only equations you reference. Use
align*/\nonumberfor the rest (or themathtoolsoptionshowonlyrefs). - Long equations: break before binary operators (
\\ &\quad + ...) and align the continuation lines.
4.11 Finding a symbol you don’t know
- Detexify (detexify.kirelabs.org): draw the symbol and it tells you the command and package.
- The Comprehensive LaTeX Symbol List (
texdoc symbols-a4): 200+ pages of every symbol. - Overleaf docs → “List of Greek letters and math symbols”.
- Mathpix / LLMs: screenshot an equation from a PDF → LaTeX. Always proofread the output.
4.12 Exercise
Typeset the following without looking (answers in the example paper’s sections/method.tex):
- The softmax: σ(z)ᵢ = exp(zᵢ) / Σⱼ exp(zⱼ), numbered, labeled
eq:softmax. - Scaled dot-product attention with
\softmaxas an operator. - A 3-line
alignderivation of the gradient of MSE, numbering only the last line. - A theorem plus proof using
\qedhere.
Chapter 5: Figures, Tables, Algorithms and Code
5.1 Floats: the concept that confuses everyone
Figures and tables are floats: LaTeX moves them to where they fit best (top of a page, bottom, or a page of floats), not necessarily where you wrote them in the source. That’s how professionally typeset books behave, and why you always refer to them by number (“see Figure 3”) instead of “the figure below”.
\begin{figure}[t] % placement specifier
...
\end{figure}
| Specifier | Meaning |
|---|---|
h | here, approximately |
t | top of a page |
b | bottom of a page |
p | on a separate float page |
! | try harder (ignore some aesthetic limits) |
H | exactly HERE, no floating (package float). Use sparingly |
Recommendation for papers: [t] for most figures/tables (ML templates look best with floats at the tops of pages), [!t] if one keeps drifting, [h!] only in special cases. Avoid [H] in conference papers: it creates big gaps.
If floats pile up and drift to the end: write fewer large floats, put them in the source near (slightly before) where they’re first mentioned, or use \clearpage to flush them.
5.2 Including images
\usepackage{graphicx}
\graphicspath{{figures/}} % optional: where to look
\begin{figure}[t]
\centering % not \begin{center}: adds extra space
\includegraphics[width=0.8\linewidth]{architecture} % extension optional
\caption{Overview of our architecture. The encoder maps ...}
\label{fig:arch}
\end{figure}
\includegraphics options: width=, height=, scale=0.5, angle=90, keepaspectratio, trim=l b r t, clip (crop), page=2 (for multi-page PDFs).
File formats:
| Format | Use |
|---|---|
Best for plots and diagrams (vector: crisp at any zoom, small). Export matplotlib with plt.savefig("fig.pdf", bbox_inches="tight"). | |
| PNG | Screenshots, raster images, heatmaps with huge numbers of points |
| JPG | Photos |
| EPS | Old; only with latex+dvips (pdfLaTeX converts via epstopdf) |
| SVG | Not directly. Convert to PDF (Inkscape), or use the svg package (needs Inkscape and shell-escape) |
Matplotlib tips for papers:
import matplotlib.pyplot as plt
plt.rcParams.update({
"font.family": "serif", # match the paper's font
"font.size": 9, # paper body is ~10pt; figure text should be similar
"pdf.fonttype": 42, # embed TrueType: some venues reject Type 3 fonts
"ps.fonttype": 42,
# "text.usetex": True, # render labels with real LaTeX (slow, needs TeX installed)
})
fig, ax = plt.subplots(figsize=(3.25, 2.2)) # single-column width ≈ 3.25in (two-column formats)
...
fig.savefig("figures/results.pdf", bbox_inches="tight")
Make the figure at its final size (e.g. figsize = column width) and include it with width=\linewidth. Then fonts in the figure match the text instead of becoming tiny or huge after scaling.
Useful widths: in NeurIPS/ICLR (single column) \textwidth ≈ 5.5in. In ICML/CVPR/IEEE (two-column) \columnwidth ≈ 3.25in, and figure* spans both columns.
5.3 Captions
- Figure captions go below the figure; table captions go above the table (convention, and most templates’ style).
- The first sentence of a caption should work alone; ML papers often bold it:
\caption{\textbf{Scaling curves.} Loss vs. compute ...}. \caption[Short]{Long ...}: the short version appears in the list of figures.- Customize with the
captionpackage:\usepackage[font=small,labelfont=bf]{caption}. (Many templates already set this. Check the rules before changing caption styling, since some venues forbid it.)
5.4 Subfigures and side-by-side
\usepackage{subcaption} % modern; do NOT use the old subfig/subfigure packages with it
\begin{figure}[t]
\centering
\begin{subfigure}[b]{0.48\linewidth}
\centering
\includegraphics[width=\linewidth]{loss_curve}
\caption{Training loss.}
\label{fig:loss}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\linewidth}
\centering
\includegraphics[width=\linewidth]{accuracy}
\caption{Test accuracy.}
\label{fig:acc}
\end{subfigure}
\caption{Training dynamics on ImageNet.}
\label{fig:dynamics}
\end{figure}
\cref{fig:loss} → “Figure 2a”. \subref{fig:loss} → “(a)”.
Simpler alternative (no sub-captions, just images side by side): put several \includegraphics in one figure separated by \hfill.
Figure beside text (wrapfig) saves space in page-limited papers:
\usepackage{wrapfig}
\begin{wrapfigure}{r}{0.4\textwidth} % r = right side
\centering
\includegraphics[width=\linewidth]{small_plot}
\caption{A small plot.}
\label{fig:small}
\end{wrapfigure}
Paragraph text flows around the figure...
wrapfig is fragile: don’t put it near section headings, lists or page breaks.
Two-column templates: \begin{figure*}[t] ... \end{figure*} spans the full width (only t or p placement).
5.5 Tables
Anatomy of tabular
\begin{tabular}{l c r p{4cm}} % column spec: left, center, right, paragraph of fixed width
Name & Value & Count & Description \\ % & separates cells, \\ ends row
\hline
A & 1.0 & 10 & long text that wraps ... \\
\end{tabular}
Column types: l, c, r, p{width} (top-aligned paragraph), | (vertical line, don’t use in papers), @{} (remove the inter-column padding), *{5}{c} (repeat c 5 times).
Professional tables with booktabs
The house style of nearly every good ML paper: no vertical lines, three horizontal rules.
\usepackage{booktabs}
\usepackage{multirow}
\begin{table}[t]
\centering
\caption{Test accuracy (\%) on standard benchmarks. Best in \textbf{bold}, second \underline{underlined}.}
\label{tab:main}
\begin{tabular}{@{}lcccc@{}}
\toprule
\multirow{2}{*}{Method} & \multicolumn{2}{c}{CIFAR-10} & \multicolumn{2}{c}{ImageNet} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& Top-1 & Params & Top-1 & Params \\
\midrule
ResNet-50 & 93.0 & 25M & 76.1 & 25M \\
ViT-B/16 & \underline{98.1} & 86M & \underline{81.8} & 86M \\
\method (ours) & \textbf{98.6} & 40M & \textbf{82.9} & 40M \\
\bottomrule
\end{tabular}
\end{table}
\toprule,\midrule,\bottomrule: rules with proper weights and spacing.\cmidrule(lr){2-3}: a partial rule under columns 2–3, trimmed at left/right.\multicolumn{2}{c}{text}: span 2 columns, centered.\multirow{2}{*}{text}: span 2 rows (packagemultirow).\addlinespace: a little extra space between groups of rows.
Making tables fit
\small % or \footnotesize, inside the table environment, before tabular
\setlength{\tabcolsep}{4pt} % default 6pt; reduces column padding
\resizebox{\linewidth}{!}{ \begin{tabular}...\end{tabular} } % scale to width
\resizebox is common in ML papers but makes font sizes inconsistent. Prefer \small plus fewer columns when possible.
Fixed total width with stretchy columns:
\usepackage{tabularx}
\begin{tabularx}{\linewidth}{@{}lX@{}} % X columns share the remaining width
\toprule
Term & Definition that will wrap as needed to fill the line \\
\bottomrule
\end{tabularx}
Numbers in tables
-
Align decimals with
siunitx’sScolumn type:\usepackage{siunitx} \begin{tabular}{l S[table-format=2.1] S[table-format=1.3]} \toprule Model & {Acc} & {Loss} \\ % non-numeric headers in braces \midrule A & 93.1 & 0.231 \\ B & 8.4 & 1.020 \\ \bottomrule \end{tabular} -
Mean ± std:
93.1{\scriptsize$\pm$0.2}or$93.1_{\pm 0.2}$, both common. -
Colored cells:
\usepackage[table]{xcolor}then\cellcolor{gray!15},\rowcolor{blue!5}.
Don’t hand-write big tables
Generate them from your results: pandas.DataFrame.to_latex(), or write a tiny Python script that emits \toprule ... \bottomrule into tables/main.tex, then \input{tables/main}. This avoids copy-paste errors in your numbers.
Online generators like Tables Generator (tablesgenerator.com) help for one-off complex layouts.
Long tables
longtable (or xltabular) for tables that break across pages, common in appendices (hyperparameter listings, per-task results).
5.6 Algorithms / pseudocode
There are two main families. Templates and lab culture decide which you use.
algorithm + algpseudocode (algorithmicx): what ICML’s and many other templates use:
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{algorithm}[t]
\caption{Mini-batch SGD}
\label{alg:sgd}
\begin{algorithmic}[1] % [1] = number every line
\Require dataset $\mathcal{D}$, learning rate $\eta$, epochs $T$
\Ensure parameters $\theta$
\State initialize $\theta_0$
\For{$t = 1$ \textbf{to} $T$}
\For{each minibatch $B \subset \mathcal{D}$}
\State $g \gets \frac{1}{|B|}\sum_{(x,y)\in B} \nabla_\theta \ell(f_\theta(x), y)$
\State $\theta \gets \theta - \eta\, g$ \Comment{gradient step}
\EndFor
\If{converged}
\State \textbf{break}
\EndIf
\EndFor
\State \Return $\theta$
\end{algorithmic}
\end{algorithm}
algorithm2e: a different syntax (semicolons, \eIf, \KwIn) that you’ll often see:
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\begin{algorithm}[t]
\caption{Mini-batch SGD}\label{alg:sgd2}
\KwIn{dataset $\mathcal{D}$, learning rate $\eta$}
\KwOut{parameters $\theta$}
initialize $\theta$\;
\For{$t \gets 1$ \KwTo $T$}{
sample minibatch $B$\;
$\theta \gets \theta - \eta \nabla \ell_B(\theta)$\;
}
\Return{$\theta$}\;
\end{algorithm}
Don’t load both families in one document: they both define an algorithm environment and will clash.
5.7 Code listings
listings: pure LaTeX, works everywhere (including arXiv):
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\small,
keywordstyle=\color{blue},
commentstyle=\color{gray},
stringstyle=\color{teal},
numbers=left, numberstyle=\tiny, frame=single,
breaklines=true, showstringspaces=false,
}
\begin{lstlisting}[language=Python, caption={Training loop}, label={lst:train}]
for x, y in loader:
loss = criterion(model(x), y) # forward
loss.backward()
optimizer.step(); optimizer.zero_grad()
\end{lstlisting}
Inline: \lstinline|model.train()|
Whole file: \lstinputlisting[language=Python]{code/train.py}
minted: much prettier syntax highlighting with Pygments, but it needs Python plus -shell-escape. Works on Overleaf. Causes problems on arXiv (it needs either shell-escape or the frozencache option with cached files). Use listings for arXiv-bound papers unless you know the workaround.
\usepackage{minted}
\begin{minted}[fontsize=\small, linenos]{python}
def f(x): return x ** 2
\end{minted}
5.8 A full “teaser figure” pattern (very common in ML papers)
A full-width figure at the top of page 1, right under the abstract (or above it):
% two-column (ICML/CVPR) style: figure* right after \maketitle area
\begin{figure*}[t]
\centering
\includegraphics[width=\textwidth]{teaser}
\caption{\textbf{\method in action.} ...}
\label{fig:teaser}
\end{figure*}
% CVPR-style teaser *above* the abstract is done with a template-specific trick:
% \twocolumn[{\maketitle \begin{center} \includegraphics... \captionof{figure}{...} \end{center}}]
% (\captionof needs the caption package; lets you caption outside a float)
5.9 Key takeaways
- Figures and tables float. Use
[t]and refer to them by\cref, never “below”. - Vector PDFs for plots, generated at final size with matching fonts.
subcaptionfor subfigures.figure*for full width in two-column templates.booktabstables: no vertical lines,\toprule/\midrule/\bottomrule. Generate big tables from code.algorithm+algpseudocode(oralgorithm2e), but never both.listingsfor code if you’re going to arXiv.
Chapter 6: Diagrams, Plots, Chemistry and Other Scientific Notation
LaTeX can draw too. This chapter covers the drawing and domain-specific packages you’re most likely to meet in papers.
6.1 TikZ: drawing with code
TikZ (“TikZ ist kein Zeichenprogramm”, German for “TikZ is not a drawing program”) is the standard LaTeX graphics package. Many diagrams in papers (neural nets, graphs, commutative diagrams, flowcharts) are TikZ.
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, shapes, calc, fit, backgrounds}
Basics
\begin{tikzpicture}
\draw (0,0) -- (2,0) -- (2,1) -- cycle; % lines (coordinates in cm)
\draw[thick, red, ->] (0,0) -- (1,1); % styled arrow
\draw[fill=blue!20] (3,0) rectangle (4,1); % filled rectangle
\draw (5,0.5) circle (0.5); % circle
\draw[dashed] (6,0) to[bend left] (7,1); % curve
\node at (1,-0.5) {label}; % text at a point
\fill (0,0) circle (2pt); % dot
\end{tikzpicture}
Every command ends with ;. Coordinates are (x,y) in cm by default. Options in [...]: colors, thick/very thick/line width=1pt, ->/<->/-{Stealth} arrow heads, dashed/dotted, fill=, draw=, rounded corners.
Nodes and edges: the part you’ll actually use
\begin{tikzpicture}[
node distance=1.2cm and 1.5cm,
box/.style={draw, rounded corners, minimum width=2.2cm, minimum height=0.8cm, align=center, fill=#1},
box/.default=white,
arrow/.style={-{Stealth[length=2mm]}, thick},
]
\node[box=gray!10] (input) {Input\\$x$};
\node[box=blue!15, right=of input] (enc) {Encoder};
\node[box=orange!20, right=of enc] (lat) {Latent $z$};
\node[box=blue!15, right=of lat] (dec) {Decoder};
\node[box=gray!10, right=of dec] (out) {Output\\$\hat{x}$};
\draw[arrow] (input) -- (enc);
\draw[arrow] (enc) -- (lat);
\draw[arrow] (lat) -- (dec);
\draw[arrow] (dec) -- (out);
\draw[arrow, dashed, red] (out.south) -- ++(0,-0.8) -| node[pos=0.25, below] {reconstruction loss} (input.south);
\end{tikzpicture}
Key ideas:
\node[options] (name) {text};creates a named node.(name.north),.south,.east,.west,.north eastare anchors.right=of enc,below=of x(librarypositioning) for relative layout./.style={...}defines reusable styles (like CSS classes).#1is a style parameter.-|and|-draw orthogonal (elbow) connections.++(0,-0.8)is a relative move.node[pos=..., above]on a path labels an edge.
Loops: drawing a neural network
\begin{tikzpicture}[neuron/.style={circle, draw, minimum size=6mm}, x=1.8cm, y=0.9cm]
\foreach \i in {1,...,3} \node[neuron, fill=green!20] (I\i) at (0,-\i) {};
\foreach \j in {1,...,4} \node[neuron, fill=blue!20] (H\j) at (1,-\j+0.5) {};
\foreach \k in {1,2} \node[neuron, fill=red!20] (O\k) at (2,-\k-0.5) {};
\foreach \i in {1,...,3} \foreach \j in {1,...,4} \draw[->] (I\i) -- (H\j);
\foreach \j in {1,...,4} \foreach \k in {1,2} \draw[->] (H\j) -- (O\k);
\node[above] at (0,-0.5) {Input};
\node[above] at (1,0) {Hidden};
\node[above] at (2,-1) {Output};
\end{tikzpicture}
Practical TikZ advice
-
TikZ is slow to learn and to compile. For complex figures, many researchers draw in draw.io / Figma / Keynote / Inkscape / Illustrator and export PDF. That’s completely acceptable.
-
TikZ wins when you want fonts and math that exactly match the paper, precise diagrams (graphs, commutative diagrams, geometry), or programmatic figures.
-
Steal from texample.net and TeX StackExchange. Read
texdoc tikz(a 1300-page manual, but its tutorials at the start are excellent). -
TikZ via external file: keep big diagrams in
figures/arch.texand\inputthem, or compile them separately withstandaloneand include the PDF:% figures/arch.tex \documentclass[tikz,border=2pt]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture} ... \end{tikzpicture} \end{document} -
Other diagram packages:
tikz-cd(commutative diagrams),forest(trees: parse trees, decision trees),tikz-network,smartdiagram,quiver(q.uiver.app, draw commutative diagrams in the browser and exporttikz-cdcode).
\usepackage{tikz-cd}
\begin{tikzcd}
A \arrow[r, "f"] \arrow[d, "g"'] & B \arrow[d, "h"] \\
C \arrow[r, "k"'] & D
\end{tikzcd}
6.2 pgfplots: plots in native LaTeX
pgfplots (built on TikZ) plots data or functions with paper-matching fonts:
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{tikzpicture}
\begin{axis}[
width=\linewidth, height=5cm,
xlabel={Training steps}, ylabel={Loss},
xmode=log, grid=major, legend pos=north east,
]
\addplot[blue, thick] table[x=step, y=loss, col sep=comma] {data/baseline.csv};
\addlegendentry{Baseline}
\addplot[red, thick, domain=10:1e5, samples=100] {2 + 50/x^0.3};
\addlegendentry{Ours (fit)}
\end{axis}
\end{tikzpicture}
Most ML people use matplotlib instead (chapter 5). pgfplots is great for clean, simple plots, and you’ll see it in theory papers. Bridge: the tikzplotlib Python package (now unmaintained) converted matplotlib figures to pgfplots code.
6.3 Chemistry
mhchem: formulas and reactions (most common)
\usepackage[version=4]{mhchem}
\ce{H2O}, \ce{H2SO4}, \ce{CO2}, \ce{Fe^{3+}}, \ce{SO4^{2-}}, \ce{^{14}_{6}C}
\ce{CuSO4 * 5H2O} % hydrate dot
\ce{2H2 + O2 -> 2H2O} % reaction
\ce{N2 + 3H2 <=> 2NH3} % equilibrium
\ce{A ->[catalyst][\Delta] B} % text above/below arrow
\ce{CaCO3 ->[\Delta] CaO + CO2 ^} % gas evolution (up arrow)
\ce{Ag+ + Cl- -> AgCl v} % precipitate (down arrow)
\ce{[Cu(NH3)4]^{2+}} % complex ion
$K = \frac{[\ce{NH3}]^2}{[\ce{N2}][\ce{H2}]^3}$ % inside math
\ce{} handles subscripts, charges and arrows automatically: no _ or ^ fiddling. It also works in MathJax, so the same syntax works on the web.
chemfig: structural formulas
\usepackage{chemfig}
\chemfig{H-C(-[2]H)(-[6]H)-H} % methane; [n] = angle n×45°
\chemfig{*6(=-=-=-)} % benzene ring
\chemfig{*6(-=-=(-OH)-=)} % phenol
\chemfig{H_3C-C(=[1]O)-[7]OH} % acetic acid
\chemfig{C(-[:150]H_3C)(-[:30]OH)=[6]O} % absolute angles in degrees with [:deg]
% reaction schemes
\schemestart
\chemfig{*6(=-=-=-)} \arrow{->[\ce{HNO3}][\ce{H2SO4}]} \chemfig{*6(=-=(-NO_2)-=-)}
\schemestop
Bonds: - single, = double, ~ triple, >/< wedges (stereo). *6(...) = 6-membered ring. Branches in parentheses.
Also: chemmacros (a full chemistry suite: oxidation states, IUPAC names, thermodynamics), chemformula (an alternative to mhchem), modiagram (molecular orbital diagrams). For complex molecules, many chemists draw in ChemDraw and include the PDF.
6.4 Units and numbers: siunitx
Essential for physics, engineering, chemistry, and ML hardware/compute reporting:
\usepackage{siunitx}
\sisetup{group-digits=integer, group-minimum-digits=4}
\num{123456789} % 123 456 789 (digit grouping)
\num{1.5e-4} % 1.5 × 10⁻⁴
\num{3+-0.2} % 3 ± 0.2
\qty{9.81}{\metre\per\second\squared} % 9.81 m/s² (\SI{}{} in older versions)
\qty{300}{\kelvin}, \qty{1.2}{\giga\hertz}, \qty{80}{\giga\byte}
\qty{2.5}{\micro\metre}
\unit{\kilo\gram\metre\per\second} % unit alone (\si{} in older versions)
\qtyrange{10}{20}{\celsius} % 10 °C to 20 °C
\ang{45} % 45°
\qty{95}{\percent} % 95 %
Benefits: correct spacing between number and unit, upright units, consistent formatting, locale settings, and the S table column (chapter 5).
For compute: \qty{1e24}{FLOPs} (unit strings that aren’t predefined can be plain text), or declare your own with \DeclareSIUnit{\flop}{FLOP}.
6.5 Physics
\usepackage{physics} % convenient shortcuts (some people dislike it; it redefines things)
\bra{\psi}, \ket{\phi}, \braket{\psi}{\phi}, \ketbra{0}{1} % Dirac notation
\expval{H}, \mel{n}{H}{m} % ⟨H⟩, ⟨n|H|m⟩
\dv{f}{x}, \dv[2]{f}{x}, \pdv{f}{x}{y} % derivatives
\grad, \div, \curl, \laplacian % vector calculus
\abs{x}, \norm{v}, \qty(\frac{a}{b}) % auto-sized delimiters
\tr, \Tr, \rank % operators
\vb{F}, \vu{x} % bold vector, unit vector
Alternatives: braket (just Dirac notation, lighter), qcircuit / quantikz (quantum circuits in TikZ), tensor (index notation), feynmp/tikz-feynman (Feynman diagrams).
\usepackage{tikz}\usetikzlibrary{quantikz2} % library name depends on version: quantikz or quantikz2
\begin{quantikz}
\lstick{$\ket{0}$} & \gate{H} & \ctrl{1} & \meter{} \\
\lstick{$\ket{0}$} & \qw & \targ{} & \meter{}
\end{quantikz}
6.6 Electrical circuits: circuitikz
\usepackage{circuitikz}
\begin{circuitikz}
\draw (0,0) to[battery1, l=$V$] (0,2)
to[R, l=$R_1$] (3,2)
to[C, l=$C$] (3,0)
to[L, l=$L$] (0,0);
\end{circuitikz}
6.7 Other domain packages you may meet
| Domain | Package(s) |
|---|---|
| Logic / proof trees | bussproofs, ebproof |
| Linguistics | forest (syntax trees), gb4e/expex (glossed examples), tipa (IPA phonetics) |
| Graphs/networks | tikz graph library, tikz-network |
| Timing diagrams | tikz-timing |
| Music | lilypond (external), musixtex |
| Astronomy | aastex class (AAS journals) |
| Biology (sequences) | texshade, textopo |
| Game trees/econ | istgame, sgame |
| Statistics | pgfplots stat libraries; or just matplotlib/ggplot2 |
| Neural-net architecture figures | PlotNeuralNet (GitHub, generates TikZ for CNN diagrams) |
| Icons | fontawesome5 (\faGithub), handy for “code available at” lines |
| Emoji | \usepackage{emoji} (LuaLaTeX only), or include an image |
6.8 Symbols in text mode
\usepackage{textcomp} % mostly built into the kernel now
\textdegree, \texttrademark, \textregistered, \copyright, \textmu, \texteuro
\checkmark (amssymb, math or text), \ding{51} \ding{55} (package pifont: ✓ ✗ in tables)
$\dagger$, $\ddagger$, \S (section sign), \P (pilcrow)
The ✓/✗ in “feature comparison” tables of ML papers are usually \cmark/\xmark defined via pifont:
\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
6.9 Key takeaways
- TikZ: nodes + edges + styles +
\foreach. Use it for precise diagrams; external tools are fine for complex art. - pgfplots for native plots; most ML people use matplotlib PDFs.
- Chemistry:
\ce{}(mhchem) for formulas/reactions,chemfigfor structures. siunitxfor every number with a unit.- For any odd symbol: Detexify, then the Comprehensive Symbol List.
Chapter 7: Bibliographies, Citations and Links
7.1 The model
- You keep references in a
.bibfile: a database of entries, each with a citation key. - In the text you write
\cite{key}. - A tool (BibTeX or Biber) pulls out only the cited entries, formats them in the required style, and writes
main.bbl. - LaTeX prints the bibliography where you write
\bibliography{refs}(or\printbibliography).
You never format a reference by hand. The venue’s style decides “Smith et al. (2020)” vs “[12]”, the order, abbreviations, and so on.
7.2 A .bib file
@inproceedings{vaswani2017attention,
title = {Attention Is All You Need},
author = {Vaswani, Ashish and Shazeer, Noam and Parmar, Niki and Uszkoreit, Jakob
and Jones, Llion and Gomez, Aidan N. and Kaiser, {\L}ukasz and Polosukhin, Illia},
booktitle = {Advances in Neural Information Processing Systems},
volume = {30},
year = {2017}
}
@article{lecun2015deep,
title = {Deep Learning},
author = {LeCun, Yann and Bengio, Yoshua and Hinton, Geoffrey},
journal = {Nature},
volume = {521},
number = {7553},
pages = {436--444},
year = {2015},
doi = {10.1038/nature14539}
}
@misc{touvron2023llama,
title = {{LLaMA}: Open and Efficient Foundation Language Models},
author = {Touvron, Hugo and others},
year = {2023},
eprint = {2302.13971},
archivePrefix = {arXiv},
primaryClass = {cs.CL}
}
@book{goodfellow2016deep,
title = {Deep Learning},
author = {Goodfellow, Ian and Bengio, Yoshua and Courville, Aaron},
publisher = {MIT Press},
year = {2016},
url = {https://www.deeplearningbook.org}
}
Entry types you’ll use: @inproceedings (conference papers, which most ML papers are), @article (journals), @misc (arXiv preprints, websites, software), @book, @phdthesis, @techreport, @incollection.
Gotchas:
- Authors: separate with
and(never commas between people).Last, Firstis safest.and others→ “et al.”. - Capitalization: many styles lowercase titles (“Bert: pre-training…”). Protect capitals with braces:
{BERT},{ImageNet},{G}aussian. - Special characters:
{\"o}for ö,{\L}for Ł,{\'e}for é. UTF-8 works with Biber; with BibTeX it mostly works but braces are safest. - Keys: pick a scheme like
authorYEARfirstword(vaswani2017attention, which is Google Scholar’s scheme). Keys are case-sensitive. - Duplicates: the same paper under two keys gives a duplicate reference. Keep one
.bibper paper, or a carefully curated master file.
7.3 Getting good entries (don’t type them)
| Source | Notes |
|---|---|
| Google Scholar | “Cite” → BibTeX. Fast but often incomplete or wrong (arXiv version cited instead of the published one, missing venues). |
| DBLP (dblp.org) | Best for CS/ML. Clean, consistent, correct venue. |
| Semantic Scholar, ACL Anthology | Good for ML/NLP |
| arXiv | “Export BibTeX citation” on each abstract page |
doi2bib.org, or curl -LH "Accept: application/x-bibtex" https://doi.org/<DOI> | From a DOI |
| Zotero (+ Better BibTeX plugin), Paperpile, Mendeley, JabRef | Reference managers that export/sync .bib; Zotero+BBT can auto-export a live .bib |
Cite the published version when a paper appeared at a venue (NeurIPS, ICLR, …), not the arXiv preprint. Reviewers notice. Tools like rebiber (GitHub) automatically replace arXiv entries with their published versions.
7.4 Two systems: BibTeX + natbib vs BibLaTeX + Biber
| BibTeX (+ natbib) | BibLaTeX + Biber | |
|---|---|---|
| Age | 1985, classic | Modern (2006+) |
| Styles | .bst files | Configured with LaTeX options |
| Unicode | Limited | Full |
| Customization | Hard (.bst is a stack language) | Easy |
| Conference templates | NeurIPS, ICML, ICLR, ACL, CVPR, IEEE, arXiv-friendly | Rare |
| arXiv | ✅ | ✅ only if you upload a .bbl that matches arXiv’s Biber version, so fragile |
For ML papers: use BibTeX + natbib, because that’s what the templates use. Use BibLaTeX for theses, books, or when you control the format.
BibTeX + natbib setup
\usepackage[numbers]{natbib} % or [authoryear] (NeurIPS/ICML templates set this up)
...
\bibliographystyle{plainnat} % style: plainnat, abbrvnat, unsrtnat, or the venue's .bst
\bibliography{refs} % refs.bib (no extension); place where the list should appear
Common .bst styles: plain (sorted, numeric), unsrt (order of citation), alpha ([Knu84]), abbrv; the *nat versions work with natbib. Venues ship their own (icml2026.bst, iclr2026_conference.bst, IEEEtran.bst, ACM-Reference-Format.bst).
BibLaTeX setup (for reference)
\usepackage[backend=biber, style=authoryear, maxcitenames=2]{biblatex}
\addbibresource{refs.bib} % WITH extension
...
\printbibliography
Styles: numeric, authoryear, alphabetic, ieee, apa, nature, chem-acs, phys, and more. Commands: \textcite{} ≈ \citet{}, \parencite{} ≈ \citep{}, \autocite{}.
7.5 Citation commands (natbib)
This is the part you’ll type a thousand times.
| Command | Author-year output | Numeric output | Use when |
|---|---|---|---|
\citet{key} | Vaswani et al. (2017) | Vaswani et al. [12] | Author is part of the sentence |
\citep{key} | (Vaswani et al., 2017) | [12] | Parenthetical |
\citep[see][p.~3]{key} | (see Vaswani et al., 2017, p. 3) | Pre/post notes | |
\citep{a,b,c} | (A, 2019; B, 2020; C, 2021) | [3, 7, 9] | Several at once |
\citeauthor{key} | Vaswani et al. | ||
\citeyear{key} | 2017 | ||
\citealp{key} | Vaswani et al., 2017 | No parentheses (inside your own parens) | |
\cite{key} | ≈ \citet in author-year mode | [12] | Generic |
\nocite{key} / \nocite{*} | (nothing) | Put in bibliography without citing / include all entries |
Style rule: a citation is not a noun. Write “Transformers \citep{vaswani2017attention} use attention” or “\citet{vaswani2017attention} introduced…”, and never “In \citep{x}, they show…”.
Use ~ to avoid a line break before numeric citations: Transformers~\cite{x}.
7.6 hyperref: clickable everything
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue, % internal links (sections, equations, figures)
citecolor=blue, % citations
urlcolor=magenta, % URLs
pdftitle={My Paper},
pdfauthor={Ada Lovelace},
}
- Makes
\ref,\cite, footnotes and table-of-contents entries clickable, and adds PDF bookmarks. \url{https://github.com/me/repo}(breaks nicely across lines),\href{https://...}{text}.- Load
hyperreflate, after most other packages. Exceptions that go after it:cleveref,algorithm-related fixes, and a few others. - Some templates already load it (ICML does). Don’t load it again with conflicting options. Use
\hypersetupinstead. - For anonymous submissions, check that
pdfauthormetadata doesn’t contain your name.
7.7 cleveref: the last piece
\usepackage[capitalize,noabbrev]{cleveref} % after hyperref
\cref{fig:arch} % Figure 1
\cref{tab:main} % Table 2
\cref{eq:loss} % Equation (3) (Eq. (3) without noabbrev)
\cref{sec:method} % Section 3
\cref{app:proofs} % Appendix A
\cref{thm:main,lem:aux} % Theorem 1 and Lemma 2
\Cref{...} % capitalized at the start of a sentence
% customize names
\crefname{assumption}{Assumption}{Assumptions}
\crefname{algorithm}{Algorithm}{Algorithms}
\crefname{equation}{Eq.}{Eqs.} % if you prefer "Eq. (3)"
The [capitalize] option makes \cref always capitalized, which is common style in ML papers.
7.8 A complete minimal example
\documentclass{article}
\usepackage[numbers]{natbib}
\usepackage{hyperref}
\usepackage[capitalize,noabbrev]{cleveref}
\begin{document}
\section{Introduction}\label{sec:intro}
\citet{vaswani2017attention} proposed the Transformer.
Deep learning has many applications~\citep{lecun2015deep,goodfellow2016deep}.
We revisit this in \cref{sec:intro}.
\bibliographystyle{plainnat}
\bibliography{refs}
\end{document}
Build: latexmk -pdf main.tex (or Overleaf, which runs BibTeX automatically).
7.9 Troubleshooting citations
| Symptom | Fix |
|---|---|
[?] or (?) in the PDF | Key typo, entry missing from .bib, or BibTeX hasn’t run. Check main.blg. |
| “I found no \bibdata command” | \bibliography{...} missing |
| “I couldn’t open database file refs.bib” | Wrong file name/path. \bibliography{refs} without .bib |
| BibTeX error on one entry | Missing comma, unbalanced braces, or @ typo in .bib. .blg shows the line |
| Author-year citation shows numbers (or vice versa) | natbib option or .bst style mismatch |
| Bibliography is in the wrong place | It goes where \bibliography{} is written |
| “Bibliography not compatible with author-year citations” | Using \citet with a non-natbib .bst like plain. Use plainnat |
| Stale results | Delete .aux/.bbl (latexmk -C) and rebuild |
7.10 Key takeaways
- One
.bibfile, entries from DBLP/Scholar/Zotero, published versions preferred,{Braces}for capitals. - ML templates: BibTeX + natbib + the venue’s
.bst. Know\citetvs\citep. hyperreflate,cleverefafter it,\crefeverywhere.
Chapter 8: Writing Real Papers for NeurIPS, ICML, ICLR and arXiv
This chapter is about the practical side: templates, rules, anonymity, page limits, camera-ready, and getting a clean arXiv submission.
⚠️ Page limits, file names and options change every year. Always download the current year’s style files from the official call for papers (CFP) and read its instructions. The numbers below are typical, not authoritative.
8.1 Anatomy of an ML paper
Title, authors (anonymous at submission), abstract
1 Introduction ← problem, gap, idea, contributions list, (teaser figure)
2 Related Work ← sometimes after experiments
3 Background / Preliminaries ← notation, problem setup
4 Method ← equations, algorithm box, architecture figure
5 Experiments ← setup (\paragraph{Datasets.} ...), main table, ablations, plots
6 Discussion / Limitations
7 Conclusion
Acknowledgments ← only in camera-ready
References
(NeurIPS: Paper checklist)
Appendix A, B, C ... ← proofs, extra experiments, hyperparameters, more figures
8.2 The big three ML templates
| NeurIPS | ICML | ICLR | |
|---|---|---|---|
| Layout | single column | two column | single column |
| Base | article + neurips_20XX.sty | article + icml20XX.sty | article + iclr20XX_conference.sty |
| Main text limit (submission, typical) | 9 pages | 8 pages | 9–10 pages |
| Camera-ready | +1 page usually | +1 page | varies |
| References & appendix | don’t count | don’t count | don’t count |
| Citation style | natbib (author-year or numeric allowed) | natbib author-year, icml20XX.bst | natbib author-year, iclr20XX_conference.bst |
| Anonymous by default? | Yes. [final] or [preprint] option turns it off | Yes. [accepted] turns it off | Yes. \iclrfinalcopy turns it off |
| Extra | Mandatory paper checklist at the end | Impact statement section | math_commands.tex notation file included |
Other venues you’ll see: CVPR/ICCV/ECCV (two-column, cvpr.sty, numbered citations), ACL/EMNLP (acl.sty, two-column), AAAI (very strict: no hyperref, no \vspace tricks), IEEE (IEEEtran), ACM (acmart), JMLR (jmlr2e), TMLR (tmlr.sty).
NeurIPS skeleton
\documentclass{article}
% Submission (anonymous, line numbers):
\usepackage{neurips_2026}
% Preprint for arXiv (non-anonymous, no "submitted to" footer):
% \usepackage[preprint]{neurips_2026}
% Camera-ready:
% \usepackage[final]{neurips_2026}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{url}
\usepackage{booktabs}
\usepackage{amsfonts}
\usepackage{nicefrac}
\usepackage{microtype}
\usepackage{xcolor}
% + your own: amsmath, amsthm, graphicx, subcaption, cleveref, algorithm, ...
\title{Your Title}
\author{%
Ada Lovelace \\
Analytical Engine Lab \\
\texttt{ada@example.org} \\
\And
Alan Turing \\
Bletchley Institute \\
}
\begin{document}
\maketitle
\begin{abstract}
...
\end{abstract}
\section{Introduction}
...
\begin{ack} % NeurIPS-specific: hidden automatically in the anonymous version
We thank ...
\end{ack}
\bibliographystyle{plainnat}
\bibliography{refs}
\newpage
\appendix
\section{Proofs}
...
\input{checklist} % NeurIPS checklist (template provides it)
\end{document}
ICML skeleton (two-column, special title block)
\documentclass{article}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{icml2026} % [accepted] for camera-ready
\usepackage{amsmath,amssymb,mathtools,amsthm}
\usepackage[capitalize,noabbrev]{cleveref}
\icmltitlerunning{Short Title for Header}
\begin{document}
\twocolumn[
\icmltitle{Your Full Title}
\begin{icmlauthorlist}
\icmlauthor{Ada Lovelace}{lab}
\icmlauthor{Alan Turing}{inst}
\end{icmlauthorlist}
\icmlaffiliation{lab}{Analytical Engine Lab}
\icmlaffiliation{inst}{Bletchley Institute}
\icmlcorrespondingauthor{Ada Lovelace}{ada@example.org}
\icmlkeywords{Machine Learning, ICML}
\vskip 0.3in
]
\printAffiliationsAndNotice{} % footnote with affiliations
\begin{abstract} ... \end{abstract}
\section{Introduction} ...
\bibliography{refs}
\bibliographystyle{icml2026}
\newpage
\appendix
\onecolumn % appendix is often single-column
\section{Proofs} ...
\end{document}
Two-column habits for ICML: figure = one column (width=\columnwidth), figure*/table* = full width. Wide tables are the biggest pain, so plan for them.
ICLR
\documentclass{article}
\usepackage{iclr2026_conference,times}
\input{math_commands.tex}
\usepackage{hyperref}
\usepackage{url}
% \iclrfinalcopy % uncomment for camera-ready
...
\bibliography{iclr2026_conference}
\bibliographystyle{iclr2026_conference}
ICLR reviews are public on OpenReview, and the PDF can be revised during the discussion period.
8.3 Rules that get papers desk-rejected
- Changing the template’s layout: margins, font size,
\linespread, thegeometrypackage, or squeezing caption/section spacing. Program chairs check. Don’t loadgeometry,fullpage, ortimes(unless the template does). - Going over the page limit. The main text must end by page N. References and appendix can follow.
- Breaking anonymity:
- No author names, affiliations or acknowledgments (the template hides
\authorin anonymous mode, but you must handle the rest). - Cite your own previous work in the third person: “\citet{lovelace2024} showed…”, not “In our previous work [3]…”.
- Code links: use an anonymized repo (e.g. anonymous.4open.science) or put code in the supplementary material.
- No identifying GitHub URLs, lab names or project pages in the paper or the figures.
- Check PDF metadata (
pdfinfo paper.pdf) for the author field. Don’t setpdfauthorin\hypersetupat submission. %comments (like% TODO: ask Ada) never appear in the PDF, so they’re safe at submission. But anyone can read them in your arXiv source (§8.6), so clean them before posting there.
- No author names, affiliations or acknowledgments (the template hides
- Missing required sections: the NeurIPS checklist, the ICML impact statement. Read the CFP.
- Type 3 fonts (some venues/IEEE PDF eXpress reject them): usually from matplotlib. Fix with
pdf.fonttype: 42(chapter 5). Check withpdffonts paper.pdf.
8.4 Space-saving techniques (the legitimate ones)
When you’re half a page over:
- Tighten the prose. Delete weak sentences, especially at the ends of paragraphs (single words alone on the last line of a paragraph waste a whole line).
\paragraph{Title.}instead of\subsection.- Lists with
enumitem’s[nosep, leftmargin=*]. - Put figures side by side (
subcaption,minipage) or usewrapfigure. - Make tables
\smalland reduce\tabcolsep. Combine tables. - Move proofs, extra ablations and hyperparameter details to the appendix, and reference them: “(proof in \cref{app:proofs})”.
- Inline short equations instead of displaying them.
\vspace{-2mm}after figures, a classic gray-area hack. Small amounts are common, but heavy use is noticed and some venues (AAAI) forbid it. Use it as a last resort.
8.5 Submission vs camera-ready checklist
Before submitting (anonymous):
- Correct year’s style file, anonymous mode
- Page limit respected (main text)
- No
??in the PDF (undefined refs/citations). Search the PDF for “??” - No overfull boxes sticking into the margins
- All figures readable when printed; fonts not tiny; colorblind-friendly colors
- Self-citations in the third person; no identifying links
- Required checklists/statements included
- Supplementary/appendix compiled (same PDF or separate, per the rules)
- TODO/comment macros disabled (
\renewcommand{\todo}[1]{})
Camera-ready:
-
[final]/[accepted]/\iclrfinalcopy - Authors, affiliations, emails, equal-contribution footnotes (
\thanks{}or the template’s mechanism) - Acknowledgments and funding
- De-anonymized code links
- Reviewer requests addressed, using the extra page
- References cleaned (published versions, consistent venue names, protected capitals)
8.6 Submitting to arXiv
Why upload the source and not the PDF
arXiv compiles your source with TeX Live, stores the source permanently, and offers it to anyone (“TeX Source” link). It also now generates an HTML version from your source. Submitting only a PDF made from LaTeX is often rejected with a request for the source.
Steps
-
Make it compile cleanly with pdfLaTeX. arXiv uses a specific (possibly year-old) TeX Live version and auto-detects the compiler. Overleaf has an “arXiv-ready” check; compiling with pdfLaTeX locally is the real test.
-
Use non-anonymous mode (e.g.
[preprint]for NeurIPS). Venue policies generally allow arXiv preprints, but check whether the venue has a rule about posting/advertising during review. -
Clean the source. Your comments become public. Use Google’s
arxiv_latex_cleaner:pip install arxiv-latex-cleaner arxiv_latex_cleaner ./my-paper --resize_images --im_size 1500 # creates ./my-paper_arXiv with comments removed, unused files deleted, images resized -
Include the
.bblfile. arXiv uses the.bblyou upload, and BibTeX version mismatches are a classic failure. Uploadmain.bbl(same base name as the main.tex). In Overleaf: Logs and output files → Other logs and files → main.bbl (or Submit → arXiv, which packages it for you). Uploading.bibalone is risky; uploading the.bblalways works for BibTeX. With BibLaTeX the.bblmust match arXiv’s Biber version, which is one more reason to use BibTeX for papers. -
Check file names: arXiv’s filesystem is case-sensitive (
Figure1.PDF≠figure1.pdf). Avoid spaces and special characters. Use relative paths only. -
Remove things arXiv can’t run:
minted/-shell-escape,\write18,svgpackage,\usepackage{epstopdf}conversions at build time. Pre-render them to PDF. -
Package it: zip or tar.gz the folder (main
.texat the top level, or specify it). Size limit is about 50 MB; resize huge PNGs. -
Upload at arxiv.org/submit: choose license (CC BY 4.0 is common), primary category (
cs.LG,cs.CL,cs.CV,cs.AI,stat.ML, …), title and abstract (plain text/limited TeX: no\cite, no custom macros), and comments like “Accepted at NeurIPS 2026. Code: https://…”. -
Check the compiled preview carefully. arXiv shows the PDF it built. Look for
??, missing figures, broken fonts. -
First-time submitters in a category may need an endorsement from an established author.
Timing: submissions before the daily cutoff (14:00 US Eastern, Monday–Friday) are announced that evening (~20:00 ET). Updated versions are v2, v3, …, and old versions stay public forever. You can’t delete a paper, only withdraw it (the earlier versions stay visible).
Typical arXiv errors
| Error | Cause |
|---|---|
| Missing figure | Case mismatch, or file not uploaded |
File 'xyz.sty' not found | Custom/venue .sty not uploaded (upload it with the source) |
Citations [?] | .bbl not uploaded or doesn’t match the main file name |
| Fonts/encoding issues | Using XeLaTeX features without telling arXiv; non-UTF-8 files |
| “Processed with errors” but a PDF exists | Look at the log anyway. Often an overfull box or warning arXiv treats strictly |
You can control the build with a 00README.json (or the older 00README.XXX) in the archive, specifying the main file and compiler. See arXiv’s help pages.
8.7 Supplementary code and reproducibility
- Link code with
\url{}in a footnote on page 1 (camera-ready) or the abstract. - Add hyperparameter tables in the appendix (
booktabs,\small). - Generate result tables and numbers from scripts so the paper matches the logs (chapter 5).
- Some people even use macros for numbers: a script writes
\newcommand{\mainacc}{82.9}toresults.tex, and the text says “our model reaches \mainacc%”. When the result changes, every mention updates.
8.8 Collaboration in practice
- One Overleaf project, or a git repo + Overleaf sync. Agree on one sentence per line.
- Each co-author gets a comment macro (
\ada{...}), plus a switch to hide all comments before submission. - Split sections into files to reduce edit conflicts.
- Freeze notation in
macros.texearly. - Keep a
READMElisting which section each person owns and the deadline schedule. - Use
latexdiff old.tex new.tex > diff.texto produce a PDF with changes marked, useful for rebuttals, journal revisions and advisor reviews.
8.9 Key takeaways
- Start from the official template for the current year and never modify its layout.
- Anonymity is your job, not just the template’s.
- arXiv: compile with pdfLaTeX, clean the comments, upload the
.bbl, mind case-sensitive file names, check the preview.
Chapter 9: Reading Papers Like Source Code, and a Cheat Sheet
The fastest way to get from intermediate to fluent: read the LaTeX source of papers you admire, next to their PDFs. arXiv makes this possible for most papers.
9.1 Getting the source of any arXiv paper
- Open the abstract page, e.g.
https://arxiv.org/abs/1706.03762. - Under Access Paper, click “TeX Source” (or Other formats → Download source). The direct URL pattern is
https://arxiv.org/src/1706.03762(older pattern:/e-print/). - You get a gzipped tarball (sometimes a single gzipped
.tex):
mkdir attention && cd attention
curl -L -o src.tar.gz https://arxiv.org/src/1706.03762
tar -xzf src.tar.gz || (gunzip -c src.tar.gz > main.tex)
ls
- Find the main file:
grep -l '\\documentclass' *.tex. - Compile it locally (
latexmk -pdf main.tex) or upload the folder to Overleaf as a zip. Then change things and watch what happens.
Authors’ comments are often still in there. It’s a fascinating look at how papers get written, and sometimes at what got cut.
9.2 Working backwards: “how did they make that?”
| You see in the PDF | It’s probably |
|---|---|
| Bold run-in heading: “Datasets. We use…” | \paragraph{Datasets.} |
| Equation numbers like (3) on the right | equation / align; referenced via \eqref or \cref |
| “(Vaswani et al., 2017)” | \citep{} with natbib author-year |
| “Vaswani et al. (2017) show” | \citet{} |
| “[12]” or “[3, 7–9]” | numeric natbib/cite package, \cite{} |
| Blue/colored clickable links | hyperref with colorlinks |
| “Figure 3” auto-linked | \cref{fig:...} or Figure~\ref{} |
| Table with three thick/thin horizontal rules, no vertical lines | booktabs |
| Table entries “82.9±0.3” small std | $82.9_{\pm0.3}$ or {\scriptsize$\pm$0.3} |
| Gray-shaded rows in a table | \rowcolor{gray!10} (xcolor with table option) |
| ✓ / ✗ in a comparison table | \cmark/\xmark via pifont |
| Numbered “Algorithm 1” box with line numbers | algorithm + algpseudocode (\State, \For) or algorithm2e (\;, \KwIn) |
| Colored rounded box with a title (“Takeaway”, “Finding 1”) | tcolorbox (or mdframed) |
| Figure with (a) (b) sub-panels, each with its own caption | subcaption |
| Figure that text wraps around | wrapfig |
| Full-width figure in a two-column paper | figure* |
| Big figure above the abstract (CVPR “teaser”) | \twocolumn[{...}] trick + \captionof |
| “Theorem 3.1 (Convergence).” italic body, ∎ at the end of the proof | amsthm \newtheorem + proof |
| Same theorem repeated in the appendix with the same number | thm-restate’s restatable |
| Bold vectors x, calligraphic 𝓛, blackboard ℝ | \bm/\mathbf, \mathcal, \mathbb |
| “arg min” with θ underneath | \DeclareMathOperator*{\argmin}{arg\,min} |
| Tiny line numbers in the left margin | the submission/anonymous mode of the template (or lineno) |
| GitHub logo next to a link | fontawesome5’s \faGithub |
Small-caps method names (MᴇᴛʜᴏᴅNᴀᴍᴇ) | \textsc{} in a macro |
| Hyperlinked “Appendix B” | \appendix then \section{}, referenced with \cref |
| Neat diagram with LaTeX-font labels | TikZ (look for \begin{tikzpicture} or figures/*.tex) |
| Plot with paper-matching fonts | pgfplots, or matplotlib with text.usetex |
| “Contributions” bullet list with no extra spacing | itemize + enumitem [nosep] |
| Colored inline author comments in drafts | custom macros like \newcommand{\ada}[1]{\textcolor{blue}{#1}} |
9.3 A reading exercise
Pick three papers from arXiv’s cs.LG listing:
- A theory paper: look at their
\newtheoremsetup, macros, how proofs are split into lemmas,restatableusage. - An empirical / benchmark paper: look at the table code, how they generate tables,
\resizeboxusage, colors. - A systems / architecture paper: look at the TikZ or PDF figures,
algorithmboxes,wrapfigurelayout.
For each paper, write down:
- Preamble packages you haven’t seen → look them up with
texdoc <pkg>. - Their macro file: steal good ideas for your own
macros.tex. - One trick you didn’t know.
Then rewrite one page of each paper from the PDF alone, without looking at the source, and compare.
9.4 Common pitfalls (and fixes)
| Pitfall | Fix |
|---|---|
$$...$$ | \[...\] or equation* |
x_{max} italic | x_{\max} (operator) or x_{\text{max}} |
"quotes" | ``quotes'' or \enquote{} |
Figure \ref{x} broken across lines | Figure~\ref{x} or \cref{x} |
\label before \caption | label after caption |
e.g. this (wide space) | e.g.\ this or e.g., this |
\\ for paragraph breaks | blank line |
\begin{center} around figure content | \centering |
| Raster plots (blurry PNG) | vector PDF |
| Manual numbering “Eq. 3” | \label + \cref |
\bf, \it (old) | \textbf{}, \emph{} |
log(x) | \log(x) |
| `p(y | x)` |
| Overfull boxes from URLs | \url{} (with hyperref/url), xurl package for very long URLs |
| Floats drifting to the end | [t], smaller floats, place source earlier, \clearpage |
Loading subfig and subcaption together | Only subcaption |
algorithm2e + algorithmic together | Pick one |
| Hand-typed table numbers | Generate from code |
| Editing the template’s spacing/margins | Don’t. Desk-reject risk |
9.5 Typst equivalents (for when you try it)
| LaTeX | Typst |
|---|---|
\section{Intro} | = Intro |
\textbf{b} \emph{i} | *b* _i_ |
$\frac{a}{b}$ | $a/b$ or $frac(a, b)$ |
$\sum_{i=1}^n x_i$ | $sum_(i=1)^n x_i$ |
$\mathbb{R}$, $\mathcal{L}$ | $RR$, $cal(L)$ |
\label{eq:a} + \cref{eq:a} | <eq:a> + @eq:a |
\citep{key} | @key or #cite(<key>) |
\newcommand{\R}{\mathbb{R}} | #let R = $RR$ |
\begin{figure}...\end{figure} | #figure(image("a.pdf"), caption: [...]) |
9.6 One-page cheat sheet
%================= PREAMBLE =================
\documentclass[11pt]{article} % or the venue template
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{amsmath,amssymb,amsthm,mathtools,bm}
\usepackage{graphicx} \graphicspath{{figures/}}
\usepackage{subcaption,booktabs,multirow,siunitx}
\usepackage{xcolor}
\usepackage{enumitem} \setlist{nosep} % compact lists everywhere
\usepackage{algorithm,algpseudocode}
\usepackage[numbers]{natbib} % templates usually set this
\usepackage{hyperref} % late
\usepackage[capitalize,noabbrev]{cleveref} % after hyperref
\input{macros}
%================= STRUCTURE =================
\title{} \author{} \maketitle
\begin{abstract} \end{abstract}
\section{} \subsection{} \paragraph{Bold.} \section*{No number}
\appendix
\input{sections/intro}
%================= TEXT =================
\textbf{} \emph{} \texttt{} \textsc{} \url{} \href{url}{text}
\footnote{} ~ (nbsp) -- (range) --- (dash) ``quotes''
\% \$ \& \# \_ \{ \}
\begin{itemize} \item \end{itemize} \begin{enumerate} \item \end{enumerate}
%================= MATH =================
$inline$ \[ display \] \begin{equation} \label{eq:x} \end{equation}
\begin{align} a &= b \\ &= c \nonumber \end{align}
\frac{}{} \sqrt{} \sum_{i}^{n} \int_a^b \prod \lim_{x\to0}
\mathbb{R} \mathcal{L} \bm{x} \mathbf{W} \mathrm{d}x \text{if}
\left( \right) \bigl( \bigr) \mid \top \odot \coloneqq
\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{cases} \end{cases}
\DeclareMathOperator*{\argmin}{arg\,min}
\begin{theorem} \end{theorem} \begin{proof} \end{proof}
%================= FLOATS =================
\begin{figure}[t] \centering \includegraphics[width=\linewidth]{f}
\caption{} \label{fig:f} \end{figure}
\begin{table}[t] \centering \caption{} \label{tab:t}
\begin{tabular}{@{}lcc@{}} \toprule A & B & C \\ \midrule ... \\ \bottomrule \end{tabular}
\end{table}
%================= REFERENCES =================
\cref{fig:f} \Cref{eq:x} \eqref{eq:x} \citet{k} \citep{k}
\bibliographystyle{plainnat} \bibliography{refs}
%================= BUILD =================
% latexmk -pdf main.tex | latexmk -pdf -pvc main.tex | latexmk -C
9.7 Where to go next
- Overleaf’s “Learn LaTeX in 30 minutes” and its documentation pages, which are excellent per-topic references.
- “The Not So Short Introduction to LaTeX2ε” (
texdoc lshort): the classic free book. - “LaTeX for Beginners” / learnlatex.org: interactive lessons that run in the browser.
- Package manuals via
texdoc:amsmath(texdoc amsldoc),booktabs,siunitx,cleveref,tikz,biblatex. - TeX StackExchange for every “how do I…” question.
- The LaTeX Companion, 3rd ed. (Mittelbach & Fischer, 2023): the definitive reference book.
- Read arXiv sources of 10 papers in your field. This beats every tutorial.
9.8 Final project
Take example-paper/ and turn it into a 4-page mock paper on a topic you know:
- Swap in the current NeurIPS or ICML style file (download it from the CFP) and adapt the author block.
- Write your own
macros.texnotation. - Add a matplotlib-generated PDF figure at the correct width.
- Generate one results table from a Python script.
- Add a theorem with a proof in the appendix using
restatable. - Run
arxiv_latex_cleanerand check that the cleaned version compiles with justlatexmk -pdf.
If you can do all six without searching more than a couple of times, you’re past intermediate.