Next: About this document, Up: (dir) [Contents][Index]
This document is an unofficial reference manual for LaTeX, a document preparation system, version as of May 2013. It is intended to cover LaTeX2e, which has been the standard version of LaTeX for many years.
| • About this document: | Bug reporting, etc. | |
| • Overview: | What is LaTeX? | |
| • Starting & ending: | The standard beginning and end of a document. | |
| • Document classes: | Some of the various classes available. | |
| • Typefaces: | And fonts, such as bold, italics etc. | |
| • Layout: | Controlling the page layout. | |
| • Sectioning: | How to section properly. | |
| • Cross references: | Automatic referencing. | |
| • Environments: | Such as enumerate & itemize. | |
| • Line breaking: | Influencing line breaks. | |
| • Page breaking: | Influencing page breaks. | |
| • Footnotes: | How to produce footnotes. | |
| • Definitions: | Define your own commands etc. | |
| • Counters: | Internal counters used by LaTeX. | |
| • Lengths: | The length commands. | |
| • Making paragraphs: | Paragraph commands. | |
| • Math formulas: | How to create mathematical formulas. | |
| • Modes: | Paragraph, Math or LR modes. | |
| • Page styles: | Various styles of page layout. | |
| • Spaces: | Horizontal and vertical space. | |
| • Boxes: | Making boxes. | |
| • Special insertions: | Inserting reserved and special characters. | |
| • Splitting the input: | Dealing with big files by splitting. | |
| • Front/back matter: | Tables of contents, glossaries, indexes. | |
| • Letters: | The letter class. | |
| • Terminal input/output: | User interaction. | |
| • Command line: | System-independent command-line behavior. | |
| • Document templates: | Starter templates for various document classes. | |
| • Concept Index: | General index. | |
| • Command Index: | Alphabetical list of LaTeX commands. |
The LaTeX document preparation system is implemented as a macro package for Donald E. Knuth’s TeX typesetting program. LaTeX was originally created by Leslie Lamport; it is now maintained by a group of volunteers (http://latex-project.org). The official documentation written by the LaTeX project is available from their web site.
The present document is completely unofficial and has not been reviewed by the LaTeX maintainers. Do not send bug reports or anything else about this document to them. Instead, please send all comments to latexrefman-discuss@gna.org.
The home page for this document is http://home.gna.org/latexrefman. That page has links to the current output in various formats, sources, mailing lists, and other infrastructure.
Of course, there are many, many other sources of information about LaTeX. Here are a few:
Two pages of recommended references to LaTeX documentation.
Writing your first document, with a bit of both text and math.
The guide for document authors maintained as part of LaTeX; there are several others.
Introduction to the TeX system, including LaTeX.
Next: Starting & ending, Previous: About this document, Up: Top [Contents][Index]
What is LaTeX?
LaTeX typesets a file of text using the TeX program and the LaTeX “macro package” for TeX. That is, it processes an input file containing the text of a document with interspersed commands that describe how the text should be formatted. LaTeX files are plain text that can be written in any reasonable editor. It produces at least three files as output:
.dviIf invoked as latex, a “Device Independent” (.dvi)
file is produced. This contains commands that can be translated into
commands for virtually any output device. You can view such
.dvi output of LaTeX by using a program such as
xdvi (display directly), dvips (convert to
PostScript), or dvipdfmx (convert to PDF).
.pdfIf invoked as pdflatex, a “Portable Document Format”
(.pdf) file. Typically, this is a self-contained file, with
all fonts and images embedded. This can be very useful, but it does
make the output much larger than the .dvi produced from the
same document.
If invoked as lualatex, a .pdf file is created using
the LuaTeX engine (http://luatex.org).
If invoked as xelatex, a .pdf file is created using
the XeTeX engine (http://tug.org/xetex).
Many other less-common variants of LaTeX (and TeX) exist, which can produce HTML, XML, and other things.
An open-ended list of other files might be created. We won’t try to list them all. Xxx components?
In the LaTeX input file, a command name starts with a \,
followed by either (a) a string of letters or (b) a single
non-letter. Arguments contained in square brackets, [], are
optional while arguments contained in braces, {}, are
required.
LaTeX is case sensitive. Enter all commands in lower case unless explicitly directed to do otherwise.
Next: Document classes, Previous: Overview, Up: Top [Contents][Index]
A minimal input file looks like the following:
\documentclass{class}
\begin{document}
your text
\end{document}
where the class is a valid document class for LaTeX. See Document classes, for details of the various document classes available locally.
You may include other LaTeX commands between the \documentclass
and the \begin{document} commands (this area is called the
preamble).
Next: Typefaces, Previous: Starting & ending, Up: Top [Contents][Index]
The class of a given document is defined with the command:
\documentclass[options]{class}
The \documentclass command must be the first command in a
LaTeX source file.
Built-in LaTeX document class names are (many other document classes are available as add-ons; see Overview):
article report book letter slides
Standard options are described below.
| • Document class options: | Global options. |
Up: Document classes [Contents][Index]
You can specify so-called global options or class options
to the \documentclass command by enclosing them in square
brackets as usual. To specify more than one option, separate
them with a comma:
\documentclass[option1,option2,...]{class}
Here is the list of the standard class options.
All of the standard classes except slides accept the following
options for selecting the typeface size (default is 10pt):
10pt 11pt 12pt
All of the standard classes accept these options for selecting the paper
size (default is letterpaper):
a4paper a5paper b5paper executivepaper legalpaper letterpaper
Miscellaneous other options:
draft, finalmark/do not mark overfull boxes with a big black box; default is final.
fleqnPut displayed formulas flush left; default is centered.
landscapeSelects landscape format; default is portrait.
leqnoPut equation numbers on the left side of equations; default is the right side.
openbibUse “open” bibliography format.
titlepage, notitlepageSpecifies whether the title page is separate; default depends on the class.
These options are not available with the slides class:
onecolumntwocolumnTypeset in one or two columns; default is onecolumn.
onesidetwosideSelects one- or two-sided layout; default is oneside, except
for the book class.
The \evensidemargin (\oddsidemargin parameter determines
the distance on even (odd) numbered pages between the left side of the
page and the text’s left margin. The defaults vary with the paper
size and whether one- or two-side layout is selected. For one-sided
printing the text is centered, for two-sided, \oddsidemargin is
40% of the difference between \paperwidth and \textwidth,
with \evensidemargin the remainder.
openrightopenanyDetermines if a chapter should start on a
right-hand page; default is openright for book.
The slides class offers the option clock for printing
the time at the bottom of each note.
Additional packages are loaded like this:
\usepackage[options]{pkg}
To specify more than one pkg, you can separate them with a
comma, or use multiple \usepackage commands.
Any options given in the \documentclass command that are unknown
by the selected document class are passed on to the packages loaded with
\usepackage.
Next: Layout, Previous: Document classes, Up: Top [Contents][Index]
Two important aspects of selecting a font are specifying a size and a style. The LaTeX commands for doing this are described here.
| • Font styles: | Select roman, italics etc. | |
| • Font sizes: | Select point size. | |
| • Low-level font commands: | Select encoding, family, series, shape. |
Next: Font sizes, Up: Typefaces [Contents][Index]
The following type style commands are supported by LaTeX.
This first group of commands is typically used like
\textit{italic text}. The corresponding command in
parenthesis is the “declaration form”, which takes no arguments. The
scope of the declaration form lasts until the next type style command
or the end of the current group.
The declaration forms are cumulative; i.e., you can say either
\sffamily\bfseries or \bfseries\sffamily to get bold
sans serif.
You can alternatively use an environment form of the declarations; for
instance, \begin{ttfamily}...\end{ttfamily}.
These commands automatically supply an italic correction if the
\textrm (\rmfamily)Roman.
\textit (\itshape)Italics.
\emphEmphasis (switches between \textit and \textrm).
\textmd (\mdseries)Medium weight (default).
\textbf (\bfseries)Boldface.
\textup (\upshape)Upright (default). The opposite of slanted.
\textsl (\slshape)Slanted.
\textsf (\sffamily)Sans serif.
\textsc (\scshape)Small caps.
\texttt (\ttfamily)Typewriter.
\textnormal (\normalfont)Main document font.
\mathrmRoman, for use in math mode.
\mathbfBoldface, for use in math mode.
\mathsfSans serif, for use in math mode.
\mathttTypewriter, for use in math mode.
\mathit(\mit)Italics, for use in math mode.
\mathnormalFor use in math mode, e.g. inside another type style declaration.
\mathcal‘Calligraphic’ letters, for use in math mode.
In addition, the command \mathversion{bold} can be used for
switching to bold letters and symbols in
formulas. \mathversion{normal} restores the default.
Finally, the command \oldstylenums{numerals} will
typeset so-called “old-style” numerals, which have differing heights
and depths (and sometimes widths) from the standard “lining”
numerals. LaTeX’s default fonts support this, and will respect
\textbf (but not other styles; there are no italic old-style
numerals in Computer Modern). Many other fonts have old-style
numerals also; sometimes the textcomp package must be loaded,
and sometimes package options are provided to make them the default.
FAQ entry: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=osf.
LaTeX also provides these commands, which unconditionally switch to
the given style, that is, are not cumulative. They are used
differently than the above commands, too: {\cmd ...}
instead of \cmd{...}. These are two very different
things.
\bf
Switch to bold face.
\cal
Switch to calligraphic letters for math.
\em
Emphasis (italics within roman, roman within italics).
\it
Italics.
\rm
Roman.
\sc
Small caps.
\sf
Sans serif.
\sl
Slanted (oblique).
\tt
Typewriter (monospace, fixed-width).
Next: Low-level font commands, Previous: Font styles, Up: Typefaces [Contents][Index]
The following standard type size commands are supported by LaTeX. The table shows the command name and the corresponding actual font size used (in points) with the ‘10pt’, ‘11pt’, and ‘12pt’ document size options, respectively (see Document class options).
| Command | 10pt | 11pt | 12pt |
|---|---|---|---|
\tiny | 5 | 6 | 6 |
\scriptsize | 7 | 8 | 8 |
\footnotesize | 8 | 9 | 10 |
\small | 9 | 10 | 10.95 |
\normalsize (default) | 10 | 10.95 | 12 |
\large | 12 | 12 | 14.4 |
\Large | 14.4 | 14.4 | 17.28 |
\LARGE | 17.28 | 17.28 | 20.74 |
\huge | 20.74 | 20.74 | 24.88 |
\Huge | 24.88 | 24.88 | 24.88 |
The commands as listed here are “declaration forms”. The scope of
the declaration form lasts until the next type style command or the
end of the current group. You can also use the environment form of
these commands; for instance, \begin{tiny}...\end{tiny}.
Previous: Font sizes, Up: Typefaces [Contents][Index]
These commands are primarily intended for writers of macros and packages. The commands listed here are only a subset of the available ones.
\fontencoding{enc}Select font encoding. Valid encodings include OT1 and T1.
\fontfamily{family}Select font family. Valid families include:
cmr for Computer Modern Roman
cmss for Computer Modern Sans Serif
cmtt for Computer Modern Typewriter
and numerous others.
\fontseries{series}Select font series. Valid series include:
m Medium (normal)
b Bold
c Condensed
bc Bold condensed
bx Bold extended
and various other combinations.
\fontshape{shape}Select font shape. Valid shapes are:
n Upright (normal)
it Italic
sl Slanted (oblique)
sc Small caps
ui Upright italics
ol Outline
The two last shapes are not available for most font families.
\fontsize{size}{skip}Set font size. The first parameter is the font size to switch to and
the second is the line spacing to use; this is stored in a parameter
named \baselineskip. The unit of both parameters defaults to
pt. The default \baselineskip for the Computer Modern typeface
is 1.2 times the \fontsize.
The line spacing is also multiplied by the value of the
\baselinestretch parameter when the type size changes; the
default is 1. However, the best way to “double space” a document,
if you should be unlucky enough to have to produce such, is to use the
setspace package; see
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=linespace.
\linespread{factor}Equivalent to
\renewcommand{\baselinestretch}{factor}, and
therefore must be followed by \selectfont to have any effect.
Best specified in the preamble, or use the setspace package, as
described just above.
The changes made by calling the font commands described above do
not come into effect until \selectfont is called.
\usefont{enc}{family}{series}{shape}The same as invoking \fontencoding, \fontfamily,
\fontseries and \fontshape with the given parameters,
followed by \selectfont.
Next: Sectioning, Previous: Typefaces, Up: Top [Contents][Index]
Miscellaneous commands for controlling the general layout of the page.
| • \onecolumn: | Use one-column layout. | |
| • \twocolumn: | Use two-column layout. | |
| • \flushbottom: | Make all text pages the same height. | |
| • \raggedbottom: | Allow text pages of differing height. | |
| • Page layout parameters: | \headheight \footskip. |
Next: \twocolumn, Up: Layout [Contents][Index]
\onecolumnThe \onecolumn declaration starts a new page and produces
single-column output. This is the default.
Next: \flushbottom, Previous: \onecolumn, Up: Layout [Contents][Index]
\twocolumnSynopsis:
\twocolumn[text1col]
The \twocolumn declaration starts a new page and produces
two-column output. If the optional text1col argument is present,
it is typeset in one-column mode before the two-column typesetting
starts.
These parameters control typesetting in two-column output:
\columnsep
The distance between columns (35pt by default).
\columnseprule
The width of the rule between columns; the default is 0pt, so there is no rule.
\columnwidth
The width of the current column; this is equal to \textwidth in
single-column text.
These parameters control float behavior in two-column output:
\dbltopfraction
Maximum fraction at the top of a two-column page that may be occupied by floats. Default ‘.7’, can be usefully redefined to (say) ‘.9’ to avoid going to float pages so soon.
\dblfloatpagefraction
The minimum fraction of a float page that must be occupied by floats, for a two-column float page. Default ‘.5’.
\dblfloatsep
Distance between floats at the top or bottom of a two-column float page. Default ‘12pt plus2pt minus2pt’ for ‘10pt’ and ‘11pt’ documents, ‘14pt plus2pt minus4pt’ for ‘12pt’.
\dbltextfloatsep
Distance between a multi-column float at the top or bottom of a page and the main text. Default ‘20pt plus2pt minus4pt’.
Next: \raggedbottom, Previous: \twocolumn, Up: Layout [Contents][Index]
\flushbottomThe \flushbottom declaration makes all text pages the same
height, adding extra vertical space where necessary to fill out the
page.
This is the default if twocolumn mode is selected
(see Document class options).
Next: Page layout parameters, Previous: \flushbottom, Up: Layout [Contents][Index]
\raggedbottomThe \raggedbottom declaration makes all pages the natural
height of the material on that page. No rubber lengths will be
stretched.
Previous: \raggedbottom, Up: Layout [Contents][Index]
\headheight
Height of the box that contains the running head. Default is
‘30pt’, except in the book class, where it varies with the
type size.
\headsep
Vertical distance between the bottom of the header line and the top of
the main text. Default is ‘25pt’, except in the book
class, where it varies with the type size.
\footskip
Distance from the baseline of the last line of text to the baseline of
the page footer. Default is ‘30pt’, except in the book
class, where it varies with the type size.
\linewidth
Width of the current line, decreased for each nested list
(see list). Specifically, it is smaller than \textwidth by
the sum of \leftmargin and \rightmargin
(see itemize). The default varies with the font size, paper
width, two-column mode, etc. For an article document in
‘10pt’, it’s set to ‘345pt’; in two-column mode, that
becomes ‘229.5pt’.
\textheight
The normal vertical height of the page body; the default varies with
the font size, document class, etc. For an article or
report document in ‘10pt’, it’s set to
‘43\baselineskip’; for book, it’s ‘41\baselineskip’.
For ‘11pt’, it’s ‘38\baselineskip’ and for ‘12pt’,
‘36\baselineskip’.
\textwidth
The full horizontal width of the entire page body; the default varies
as usual. For an article or report document, it’s
‘345pt’ at ‘10pt’, ‘360pt’ at ‘11pt’, and
‘390pt’ at ‘12pt’. For a book document, it’s
‘4.5in’ at ‘10pt’, and ‘5in’ at ‘11pt’ or
‘12pt’.
In multi-column output, \textwidth remains the width of the
entire page body, while \columnwidth is the width of one column
(see \twocolumn).
In lists (see list), \textwidth remains the width of the
entire page body (and \columnwidth the width of the entire
column), while \linewidth may decrease for nested lists.
Inside a minipage (see minipage) or \parbox
(see \parbox), all the width-related parameters are set to the
specified width, and revert to their normal values at the end of the
minipage or \parbox.
For completeness: \hsize is the TeX primitive parameter used
when text is broken into lines. It should not be used in normal
LaTeX documents.
\topmargin
Space between the top of the TeX page (one inch from the top of the
paper, by default) and the top of the header. The default is computed
based on many other parameters: \paperheight - 2in -
\headheight - \headsep - \textheight - \footskip, and
then divided by two.
\topskip
Minimum distance between the top of the page body and the baseline of the first line of text. For the standard clases, the default is the same as the font size, e.g., ‘10pt’ at ‘10pt’.
Next: Cross references, Previous: Layout, Up: Top [Contents][Index]
Sectioning commands provide the means to structure your text into units:
\part
\chapter
(report and book class only)
\section
\subsection
\subsubsection
\paragraph
\subparagraph
All sectioning commands take the same general form, e.g.,
\chapter[toctitle]{title}
In addition to providing the heading title in the main text, the section title can appear in two other places:
You may not want the same text in these places as in the main text. To handle this, the sectioning commands have an optional argument toctitle that, when given, specifies the text for these other places.
Also, all sectioning commands have *-forms that print
title as usual, but do not include a number and do not make an
entry in the table of contents. For instance:
\section*{Preamble}
The \appendix command changes the way following sectional units
are numbered. The \appendix command itself generates no text
and does not affect the numbering of parts. The normal use of this
command is something like
\chapter{A Chapter}
…
\appendix
\chapter{The First Appendix}
The secnumdepth counter controls printing of section numbers.
The setting
\setcounter{secnumdepth}{level}
suppresses heading numbers at any depth > level, where
chapter is level zero. (See \setcounter.)
Next: Environments, Previous: Sectioning, Up: Top [Contents][Index]
One reason for numbering things like figures and equations is to refer the reader to them, as in “See Figure 3 for more details.”
| • \label: | Assign a symbolic name to a piece of text. | |
| • \pageref: | Refer to a page number. | |
| • \ref: | Refer to a section, figure or similar. |
Next: \pageref, Up: Cross references [Contents][Index]
\labelSynopsis:
\label{key}
A \label command appearing in ordinary text assigns to
key the number of the current sectional unit; one appearing
inside a numbered environment assigns that number to key.
A key name can consist of any sequence of letters, digits, or punctuation characters. Upper and lowercase letters are distinguished.
To avoid accidentally creating two labels with the same name, it is common to use labels consisting of a prefix and a suffix separated by a colon or period. Some conventionally-used prefixes:
chfor chapters
secfor lower-level sectioning commands
figfor figures
tabfor tables
eqfor equations
Thus, a label for a figure would look like fig:snark or
fig.snark.
Next: \ref, Previous: \label, Up: Cross references [Contents][Index]
\pageref{key}Synopsis:
\pageref{key}
The \pageref{key} command produces the page number of
the place in the text where the corresponding
\label{key} command appears.
Previous: \pageref, Up: Cross references [Contents][Index]
\ref{key}Synopsis:
\ref{key}
The \ref command produces the number of the sectional unit,
equation, footnote, figure, …, of the corresponding
\label command (see \label). It does not produce any text,
such as the word ‘Section’ or ‘Figure’, just the bare number itself.
Next: Line breaking, Previous: Cross references, Up: Top [Contents][Index]
LaTeX provides many environments for marking off certain text. Each environment begins and ends in the same manner:
\begin{envname}
...
\end{envname}
| • abstract: | Produce an abstract. | |
| • array: | Math arrays. | |
| • center: | Centered lines. | |
| • description: | Labelled lists. | |
| • displaymath: | Formulas that appear on their own line. | |
| • document: | Enclose the whole document. | |
| • enumerate: | Numbered lists. | |
| • eqnarray: | Sequences of aligned equations. | |
| • equation: | Displayed equation. | |
| • figure: | Floating figures. | |
| • flushleft: | Flushed left lines. | |
| • flushright: | Flushed right lines. | |
| • itemize: | Bulleted lists. | |
| • letter: | Letters. | |
| • list: | Generic list environment. | |
| • math: | In-line math. | |
| • minipage: | Miniature page. | |
| • picture: | Picture with text, arrows, lines and circles. | |
| • quotation: | Indented environment with paragraph indentation. | |
| • quote: | Indented environment with no paragraph indentation. | |
| • tabbing: | Align text arbitrarily. | |
| • table: | Floating tables. | |
| • tabular: | Align text in columns. | |
| • thebibliography: | Bibliography or reference list. | |
| • theorem: | Theorems, lemmas, etc. | |
| • titlepage: | For hand crafted title pages. | |
| • verbatim: | Simulating typed input. | |
| • verse: | For poetry and other things. |
Next: array, Up: Environments [Contents][Index]
abstractSynopsis:
\begin{abstract}
...
\end{abstract}
Environment for producing an abstract, possibly of multiple paragraphs.
Next: center, Previous: abstract, Up: Environments [Contents][Index]
arraySynopsis:
\begin{array}{template}
col1 text&col1 text&coln}\\
...
\end{array}
Math arrays are produced with the array environment, normally
within an equation environment (see equation). It has a
single mandatory template argument describing the number of
columns and the alignment within them. Each column col is
specified by a single letter that tells how items in that row should
be formatted, as follows:
ccentered
lflush left
rflush right
Column entries are separated by &. Column entries may include
other LaTeX commands. Each row of the array is terminated with
\\.
In the template, the construct @{text} puts text
between columns in each row.
Here’s an example:
\begin{equation}
\begin{array}{lrc}
left1 & right1 & centered1 \\
left2 & right2 & centered2 \\
\end{array}
\end{equation}
The \arraycolsep parameter defines half the width of the space
separating columns; the default is ‘5pt’. See tabular, for other
parameters which affect formatting in array environments,
namely \arrayrulewidth and \arraystretch.
The array environment can only be used in math mode.
Next: description, Previous: array, Up: Environments [Contents][Index]
centerSynopsis:
\begin{center}
line1 \\
line2 \\
\end{center}
The center environment allows you to create a paragraph
consisting of lines that are centered within the left and right
margins on the current page. Each line is terminated with the
string \\.
| • \centering: | Declaration form of the center environment.
|
\centeringThe \centering declaration corresponds to the center
environment. This declaration can be used inside an environment such
as quote or in a parbox. Thus, the text of a figure or
table can be centered on the page by putting a \centering
command at the beginning of the figure or table environment.
Unlike the center environment, the \centering command
does not start a new paragraph; it simply changes how LaTeX formats
paragraph units. To affect a paragraph unit’s format, the scope of
the declaration must contain the blank line or \end command (of
an environment such as quote) that ends the paragraph unit.
Here’s an example:
\begin{quote}
\centering
first line \\
second line \\
\end{quote}
Next: displaymath