TeX and LaTeX

LaTeX builds on TeX's macro and typesetting system. A few basics help explain its layout and error messages.

Expansion

TeX reads tokens, expands macros and builds the page. A command's behaviour can depend on when its arguments are read or expanded.

Commands such as \verb cannot be used in ordinary macro arguments. Commands in headings and captions may also need special handling because those arguments are saved and read again.

Boxes and glue

TeX lays out boxes separated by stretchable space. An overfull box usually means content extends beyond the available width; an underfull box means spacing could not be balanced well.

Paragraphs are broken into lines as a whole. Figures use a separate placement system. [htbp] allows more positions, and \clearpage outputs pending floats.

Mathematics

Use amsmath for aligned equations and \text inside maths. In LaTeX documents, use \[...\] or a named display environment rather than $$.

\left and \right size paired delimiters automatically. The \bigl and \bigr family gives manual control.

The toolchain

latexmk handles repeated compilation and bibliography steps. XeLaTeX and LuaLaTeX support Unicode and system fonts through fontspec.

Read the .log file for full error context. The reported line may be where TeX noticed a problem, rather than where it began.

Where the errors come from

  • Missing $ inserted: often an underscore or maths command in text mode.
  • Undefined control sequence: usually a typo or missing package.
  • Runaway argument: often a missing closing brace.

If the source of an error is unclear, reduce the document until it disappears. Package order can matter: load cleveref after hyperref.

Organising supervision work

Use sections for questions and labels for equations or figures you refer to later. Cross-references survive editing better than manually typed numbers. Keep notation consistent across the document.

Separate the statement of a result from its justification. An aligned derivation should make clear which transformation happens on each line. Use words around equations to explain the argument.

References and files

Keep bibliography entries in a .bib file if the document needs citations. Use one bibliography workflow consistently; BibTeX and biber are different tools.

Store figures with meaningful filenames and use paths relative to the project. A document that only builds with files from your home directory is difficult to share.

Finding a broken build

Start with the first error, which often causes the later ones. Check braces, environment names and recently added commands. Remove generated auxiliary files if stale state is causing problems, then rebuild.

Preview the final PDF. Check clipped equations, missing references, page breaks and whether the text is readable at normal size. A successful compilation does not guarantee a good document.

Reading