Document class & preamble

On 1 June 1994, LaTeX split one command into two, and every LaTeX document has begun the same way ever since: a \documentclass line, then a preamble of \usepackage declarations. Before that you wrote \documentstyle[12pt,twoside]{article}, cramming options and add-on styles into the same brackets. Separating the document class from the packages was not tidying up. The class decides what your document is — a paper, a report, a book, a deck of slides — and the preamble decides what it can do. Draw that line correctly and a journal can restyle your whole manuscript by editing one line; draw it wrong and the evening you meant to spend writing goes on Option clash for package geometry instead.

What \documentclass actually decides

\documentclass[options]{class} is the one command that must come first in a document; the only thing allowed before it is a comment beginning with %. The braces hold the class name, the brackets hold the options — and the name in braces points at a real file on disk. Writing article loads article.cls, a few hundred lines of definitions that contain rules and nothing else. A \section heading, for instance, is set in \Large\bfseries with 3.5ex of space above and 2.3ex below; those three values are written out literally in article.cls. Not one character of your text lives there.

That division of labour was not an accident. In the early 1980s Leslie Lamport was starting to write a book, found the macro package then in circulation inadequate, and realised that a little extra effort would turn the macros he needed into something other people could use as well. In a January 2000 interview for the DMV-Mitteilungen he describes that as the origin of LaTeX. A class, then, is the separation of structure from appearance cast as a file. In the body you write \section{Introduction} — meaning, and nothing else — and setting it large and bold, numbering it, and leaving space above is the class's job. This is exactly why societies and publishers ship their own: amsart, IEEEtran, elsarticle, revtex4-2 and acmart are all real classes you may be required to use. Lamport argued for the idea himself in the late 1980s, proposing that the ACM produce standard document styles for TeX/LaTeX, troff and Scribe so that electronic submissions could move faster — an ACM editor turned him down.

latex
% Only the first line changes; the body stays as it is.
\documentclass[11pt,a4paper]{article}  % top level heading is \section
% \documentclass[11pt,a4paper]{book}   % \chapter becomes available

\begin{document}
\section{Introduction}
The source carries the structure; the class supplies the appearance.
\end{document}

article vs report vs book: what actually differs

In practice the difference comes down to two things: whether there are chapters, and whether two-sided printing is assumed. article.cls defines no \chapter at all, so \section is its top level; report.cls and book.cls both define one. The defaults are spelled out on the \ExecuteOptions line of each class file: article uses letterpaper,10pt,oneside,onecolumn,final, report adds openany, and only book switches to twoside and openright. The paper size is the trap — all three default to letterpaper, so if you want A4 you must ask for a4paper yourself. The title differs too: in article it runs on at the top of the first page, while report and book give it a page of its own.

ClassBest forChapters and defaults
articlePapers, notes, general short and medium documentsNo \chapter; oneside, onecolumn, notitlepage
reportTechnical reports, theses, multi-chapter documentsHas \chapter; oneside, openany, own title page
bookFull-length booksHas \chapter; twoside, openright, chapters open on the right
letterLettersNo sectioning; \address, \signature, \opening, \closing

book has one more mechanism worth knowing: \frontmatter / \mainmatter / \backmatter, which implement the conventions of a printed book in roughly a line each. \frontmatter calls \pagenumbering{roman}, so the preface and table of contents get lowercase roman numerals (i, ii, iii…) and chapters go unnumbered. \mainmatter calls \pagenumbering{arabic}, restarting the count at 1 and switching chapter numbering back on. \backmatter keeps arabic page numbers but drops chapter numbers again, so the index does not come out as “Chapter 12 Index”. Every book whose preface is numbered i, ii, iii while the text starts again at 1 is the result of those three lines.

When the four standard classes are not enough, CTAN has one for almost every purpose. For talks, beamer is the default choice: one frame environment becomes one slide, and stepwise reveals (overlays) and themes come with it. If the standard classes' default typography feels dated, KOMA-Script's scrartcl / scrreprt / scrbook map onto article / report / book and offer a far richer interface for adjusting details. For Japanese typesetting the options are jsarticle / jsbook (the jsclasses, maintained by Haruhiko Okumura and the texjporg team) on pLaTeX / upLaTeX, their LuaTeX-ja counterparts ltjsarticle / ltjsbook on LuaLaTeX, and jlreq, which is built on the Requirements for Japanese Text Layout (JLReq), detects the engine automatically, and switches to report-like or book-like behaviour via the report and book options. In every case the first question is the same: does the class match the engine you compile with?

What the \documentclass options mean

Options are comma-separated switches inside the brackets that apply to the whole document, as in \documentclass[11pt,a4paper,twoside]{article}. Order does not matter, and if you give two options from the same family (oneside and twoside, say) the later one wins. The table below lists the ones you will actually reach for, but the defaults are the part worth memorising: body text at 10pt, paper at letterpaper, layout at onecolumn. If you intend to print on A4, a4paper is something you have to write every time.

OptionEffectDefault
10pt / 11pt / 12ptBase body font size; headings and footnotes scale with it10pt
a4paper / letterpaperPaper size; a5paper, b5paper, legalpaper, executivepaper also existletterpaper
twocolumn / onecolumnSet the body in two columns; float placement moves to figure* and friendsonecolumn
twoside / onesideMake margins and running heads asymmetric left/right, for bindingoneside; twoside in book
openright / openanyWhether chapters must begin on an odd (right-hand) pageopenright in book, openany in report
titlepage / notitlepageWhether \maketitle gets a page to itselftitlepage in report/book, notitlepage in article
fleqn / leqnoFlush displayed equations left / put equation numbers on the leftCentred, numbers on the right
draft / finalMark overfull boxes with a black bar in the marginfinal

One mechanism here catches everyone at least once. Options written in \documentclass do not belong to the class alone: they are handed to every package loaded afterwards as global options. In the terminology of clsguide, anything given directly to \usepackage[...] is a local option, anything given to \documentclass[...] is a global option, and a package picks up the option names it recognises from both. So \documentclass[twocolumn]{article} quietly puts every two-column-aware package into two-column mode. The same mechanism is also the cure for ! LaTeX Error: Option clash for package geometry., which appears when one package is loaded twice with different options — usually because a class or template already loaded it. LaTeX's own advice in the log is to move the option up into the \documentclass declaration, because a global option cannot clash with a second load.

What goes in the preamble, and what goes in the body

The preamble runs from the line after \documentclass to just before \begin{document}, and it may contain declarations only — not one character of body text. Put an ordinary sentence there and compilation stops with ! LaTeX Error: Missing \begin{document}. The name is misleading; what it means is “something printable arrived before the body started”. The same line appears when a % comment in the preamble is left unterminated, or when a stray non-breaking or full-width space slips in. The mirror image is calling \usepackage inside the body, which gives ! LaTeX Error: Can be used only in preamble. — every package has to be present before the first page is composed.

  • Package loading\usepackage[options]{package}. You can group them as \usepackage{amsmath,amssymb}, but that form cannot carry options.
  • Title metadata\title{...}, \author{...}, \date{...}. What actually typesets them is \maketitle in the body; by convention the three declarations live in the preamble.
  • Your own commands and environments\newcommand, \renewcommand, \newenvironment, for constructs used across the whole document.
  • Lengths and counters\setlength{\parindent}{0pt}, \setcounter{tocdepth}{2} and other document-wide values.
  • Page style and package configuration\pagestyle{headings}, \hypersetup{...}, \graphicspath{{figures/}}: adjustments made after loading.
  • What must not go there — headings, paragraphs, figures, tables; anything that appears in the output belongs after \begin{document}.

In what order should packages be loaded?

Most packages do not care about order, but the exceptions are worth committing to memory. The famous one is hyperref, whose manual states plainly that it should come last of the packages you load. The reason is blunt: hyperref's job is to redefine a great many LaTeX commands, so loading it early lets a later package overwrite those redefinitions and quietly break your links and PDF bookmarks. The manual attaches a footnote to that advice, noting that work has begun to cut down the number of redefinitions and with it the dependency on load order — so this is a current workaround rather than a permanent law.

And “last” has a famous exception: cleveref must be loaded after hyperref. cleveref builds its reference commands by detecting what hyperref has defined, so the reverse order simply does not work. If you also use varioref, the order its manual prescribes is varioref → hyperref → cleveref. What makes this pitfall nasty is that it fails quietly — the cleveref manual warns that with the wrong order, cross-references will point at completely the wrong thing with no warning in the output or the log. If reference numbers have ever come out mysteriously off by one, check the order of those three lines in your preamble first.

latex
\documentclass[11pt,a4paper]{article}

% 1. encoding and fonts
\usepackage[T1]{fontenc}
% 2. language
\usepackage[english]{babel}
% 3. page geometry
\usepackage[margin=25mm]{geometry}
% 4. mathematics
\usepackage{amsmath,amssymb}
% 5. graphics and colour
\usepackage{graphicx}
\usepackage{xcolor}
% 6. hyperref near the end: it redefines many commands
\usepackage{hyperref}
% 7. cleveref is the exception, it must come after hyperref
\usepackage{cleveref}

% document-wide settings and definitions
\newcommand{\R}{\mathbb{R}}
\setlength{\parindent}{0pt}
\title{A Short Note}
\author{Ada Lovelace}
\date{\today}

\begin{document}
\maketitle

\section{Setup}\label{sec:setup}
For all $x \in \R$ we have $x^2 \ge 0$.

\section{Result}
The argument of \cref{sec:setup} applies unchanged.
\end{document}

Keeping the preamble smaller than the document

In that same interview, Lamport was asked to name three LaTeX mistakes people should stop making. All three of his answers were the same one: worrying too much about formatting and not enough about content. The repetition was the point. The preamble is exactly where that trap is set — one-off visual tweaks, packages tried once and never removed, abbreviations used twice, all accumulating. The cost is not ugliness; it is that when an error finally appears, the culprit is hiding somewhere in those dozens of lines. Keep only what applies to the whole document: class, language and fonts, mathematics, figures and tables, links. Give \newcommand only to constructs that genuinely repeated while you were writing. And when a submission template is involved, respect its preamble first — swapping out a package the class assumes usually comes back as an Option clash, or as something considerably harder to read.

  • A new report — start with article. Touching the page design can wait until the text is roughly written.
  • A thesis — use the class the university distributes as-is and save margin or heading adjustments for the end; not touching the template preamble is the shortest path.
  • A journal submission — put the publisher's class (elsarticle, IEEEtran, revtex4-2…) in first, then add only the minimum of your own preamble on top.
  • Printing on A4 — the standard classes default to letterpaper, so state \documentclass[a4paper]{...} explicitly; geometry can set it too if you load that.
  • When an error appears — suspect the \usepackage or \newcommand you added last; if that fails, cut the preamble in half and bisect.