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.