Nearly every .tex file today is a LaTeX document, or a part of one. The
structure below is that of LaTeX2e, released in 1994, as found in the LaTeX
Project’s source files and guides and in the LaTeX2e reference manual (see
Sources). Commands are read according to the
character rules of TeX.
Layout of a file
\documentclass[a4paper,11pt]{article} % 1. class
\usepackage[british]{babel} % 2. preamble: packages and settings
\usepackage{amsmath,graphicx,hyperref}
\title{A Short Note}
\author{A. Author}
\begin{document} % 3. body
\maketitle
\section{Introduction}\label{sec:intro}
See section~\ref{sec:intro} and \cite{knuth84}.
\bibliographystyle{plain}
\bibliography{refs}
\end{document} % 4. anything after this is ignored
\documentclass[options]{class}is normally the first command.- The commands between
\documentclassand\begin{document}are the preamble: they load packages and set things up. - The body runs from
\begin{document}to\end{document}; thedocumentenvironment is required. \end{document}finishes with TeX’s own\end, so TeX stops reading there and anything after it is ignored.
A file without \documentclass is usually a part read by a main file.
\input{file} reads it as if its text were in place;
\include{file}, allowed only in the body, puts it on new pages and
keeps its own .aux file, and \includeonly in the preamble
chooses which included files are read.
Document classes
| Class | For |
|---|---|
article | Articles and general use; no chapters. |
report | Documents between an article and a book in length, with chapters. |
book | Books: chapters, front and back matter; two-sided and opening chapters on right-hand pages by default. |
letter | Letters. |
slides | Slide presentations, rarely used now. |
proc | Proceedings, built on article. |
minimal | The smallest working class: a \normalsize font, text width and height, and page numbering, and nothing else. |
Classes from packages on CTAN include memoir, KOMA-Script’s
replacements for the standard three (scrartcl, scrreprt,
scrbook), beamer for presentations and the AMS classes
amsart, amsbook and amsproc.
The options of article, report and book
(classes.dtx): 10pt, 11pt, 12pt;
a4paper, a5paper, b5paper,
letterpaper, legalpaper, executivepaper;
landscape; oneside, twoside;
onecolumn, twocolumn; titlepage,
notitlepage; openright, openany (not in
article); leqno, fleqn;
openbib; draft, final. All three default to
letterpaper, 10pt, onecolumn and
final; article and report are one-sided.
Sectioning
| Command | Level | Classes |
|---|---|---|
\part | −1 (book, report) or 0 (article) | all |
\chapter | 0 | book, report |
\section | 1 | all |
\subsection | 2 | all |
\subsubsection | 3 | all |
\paragraph | 4 | all |
\subparagraph | 5 | all |
A starred form (\section*{…}) is not numbered and not in the contents;
an optional argument (\section[Short]{Long title}) gives a short title
for the contents and running heads. The counters secnumdepth and
tocdepth set how deep numbering and the contents go: 3 in
article, 2 in report and book. All three
classes have \appendix; book also has
\frontmatter, \mainmatter and
\backmatter.
Standard environments
| Environment | Content |
|---|---|
document | The body. |
abstract | The abstract (article, report). |
itemize, enumerate, description | Lists of \items: bulleted, numbered, and with labels (\item[term]). |
quote, quotation, verse | Quotations and poetry. |
center, flushleft, flushright | Alignment. |
verbatim, verbatim* | Text exactly as typed; \verb|…| inline. |
tabular, tabular*, array | Tables: {l c r p{3cm} |} column specification, & between cells, \\ between rows, \hline. |
table, figure | Floats with \caption, placed by LaTeX: an optional [htbp] lists the allowed places (here, top, bottom, a page of floats) and ! relaxes the limits; the default is tbp. |
tabbing, minipage, picture | Tab stops, a box of text, simple line drawings. |
equation, eqnarray, math, displaymath | Maths; equation numbers its formula and displaymath does not. The AMS packages add more, and are recommended for mathematical documents. |
thebibliography | A hand-written bibliography of \bibitems. |
titlepage | A title page. |
filecontents, filecontents* | Text written out to a file when the document is processed; the starred form leaves out the header of comments. An existing file is not overwritten unless the force or overwrite option is given. |
Maths
Inline maths goes between \(…\) (preferred), $…$
(common) or in a math environment; displayed maths between
\[…\], the same as the displaymath environment, or in
equation. In maths mode ^ and _ make
superscripts and subscripts, letters are variables in italic, and commands such as
\frac, \sqrt, \sum, \int and
\alpha build formulas.
Cross references and bibliographies
\label{key}names the current section, equation, figure or table;\ref{key}gives its number and\pageref{key}its page. LaTeX keeps the labels in the.auxfile, so a forward reference needs a second run (“Label(s) may have changed. Rerun to get cross references right.”).\cite{key}cites a work. With BibTeX,\bibliography{refs}names one or more.bibdatabases (comma-separated) and\bibliographystyle{plain}a.bststyle.\tableofcontents,\listoffiguresand\listoftablesare built from the.toc,.lofand.lotfiles of the previous run. Index entries go to a.idxfile, which MakeIndex or xindy turns into the.indfile read by\printindex.
Files around a .tex file
| Extension | Content |
|---|---|
.cls, .sty | Document classes and packages: TeX code with @ names, loaded by \documentclass and \usepackage. |
.bib | The BibTeX bibliography database. |
.bst | BibTeX bibliography styles. |
.aux | Written by LaTeX: cross-reference information for the next run. Each \included file has its own. |
.toc, .lof, .lot | Contents, list of figures, list of tables. |
.idx, .ind | Raw index entries, and the index MakeIndex or xindy makes from them. |
.log | The transcript of the run: loaded packages, warnings and errors. |
.dtx | Documented source, the form of LaTeX’s own kernel and class files (classes.dtx, ltfiles.dtx). |
.pdf, .dvi, .xdv | The output: PDF from pdfLaTeX, LuaLaTeX and XeLaTeX, DVI from latex (and dvilualatex); XeTeX writes a DVI variant, .xdv, internally and turns it into PDF with xdvipdfmx. |
Sources
- classes.dtx – source of
article,reportandbook: options and defaults, sectioning levels,secnumdepthandtocdepth, front and back matter, environments and float defaults - LaTeX kernel sources –
ltsect.dtx(starred and short-title sections),ltfloat.dtx(placement letters),ltfiles.dtx(\includeand its.auxfiles),ltmiscen.dtx(\end{document}),ltlists.dtx,lttab.dtx,ltmath.dtx,ltboxes.dtx,ltpictur.dtx - LaTeX for package and class authors (clsguide) – LaTeX2e released in 1994,
@names in class and package files,procbuilt onarticle, theminimalclass - LaTeX2e unofficial reference manual – document classes, the preamble,
\inputand\include, maths modes, cross references, BibTeX, MakeIndex and xindy,filecontents, output files and TeX engines - CTAN: KOMA-Script, memoir, beamer and amscls – the classes from packages