The preamble
10.2 The preamble
You were introduced to the preamble of a document in Section 4.1. Recall that the preamble contains the crucial \documentclass line, specifying the document class and the options that modify its behavior. For instance,
\documentclass[draft,reqno]{amsart} loads the document class amsart with the draft option, which paints a slug in the
margin indicating lines that are too wide (see Section 5.7.1), and the reqno option, which places the equation numbers on the right (see Section 11.5).
article is the most popular legacy document class (see Section 12.1). The com- mand
\documentclass[titlepage,twoside]{article} loads the document class article with the titlepage option, which creates a sep-
arate title page and places the abstract on a separate page, and the twoside option, which formats the typeset article for printing on both sides of the paper.
The \documentclass command is usually followed by the \usepackage com- mands, which load L A TEX enhancements called packages. For instance,
\usepackage{latexsym} loads a package that defines some additional L A TEX symbol names (see Section 12.3),
whereas
250 Chapter 10 L A TEX documents \usepackage[demo]{graphicx}
loads the graphicx package (see Section 10.4.3) with the demo option that inserts rectangles in place of the illustrations. Document class options are also passed on to
the packages as possible options, so \documentclass[demo]{amsart}
\usepackage{graphicx} would also load the graphicx package with the demo option unless it is invoked with \usepackage[final]{graphicx} Any document class options that are not relevant for a package are ignored.
\usepackage commands can also be combined: \usepackage{amssymb,latexsym} is the same as \usepackage{amssymb}
\usepackage{latexsym} Document class files have a cls extension, whereas package files are designated
by the sty extension. The document class amsart is defined in the amsart.cls file, the graphicx package is defined in the graphicx.sty file. You may define your own packages, such as the newlattice package described in Section 15.3.
The preamble normally contains any user-defined commands (see Chapter 15) and the proclamation definitions (see Section 6.4). Some commands can only be in the preamble. \DeclareMathOperator is such a command (see Section 7.6.2) and so is \numberwithin (see Section 7.3). If you put such a command in the body, for example, \DeclareMathOperator, you get an error message:
! LaTeX Error: Can be used only in preamble. l.103 \DeclareMathOperator
There is one command that may only be placed before the \documentclass{...} line: \NeedsTeXFormat{LaTeX2e}[2005/12/01]
This command checks the version of L A TEX being used to typeset the document and issues a warning if it is older than December 1, 2005 or whatever date you specified. Use this optional date argument if your document contains a feature that was introduced on or after the date specified or if an earlier version had a bug that would materially affect the typesetting of your document.
10.3 Top matter 251
For instance, if you use the \textsubscript command, introduced in the De- cember 1, 2005 release (see page 311), then you may use the \NeedsTeXFormat line shown above. L A TEX now hardly changes from year to year, so this command is rarely used except in document class files or package files. See, however, the discussion on page 311.