Latex Guide
Latex Guide
109
Subject: LATEX Tutorial
Date: April 1997
Table of Contents
1. LATEX Basics 1
1.1 What is TEX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 What is LATEX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 How LATEX Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.4 The LATEX Input File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4.1 Entering LATEX Commands . . . . . . . . . . . . . . . . . . . . . . 2
1.4.2 Entering Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4.3 Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4.4 Structure of the Input File . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Some LATEX Vocabulary . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2. Creating A LATEX Document 6
2.1 Document Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Class Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Making a Title Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 Making a Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Behind the Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6.1 Auxiliary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6.2 How a Page is Built . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.7 Example: Report Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.8 Example: Letter Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3. Document Layout 12
3.1 Line Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Text Justification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.5 Headers, Footers, and Page Numbering . . . . . . . . . . . . . . . . . . . 14
• TEX is portable. It is available for most computers and is used all over the world.
TEX documents can be moved easily from one system to another, as long as the
required fonts are on both systems.
• TEX comes with its own set of fonts, called “Computer Modern.” These fonts exist
in a variety of styles, including serif, sans serif, and typewriter (fixed pitch).
• Most LATEX commands are “high-level” (such as chapter and section) and specify
the logical structure of a document. The author rarely needs to be concerned with
the details of document layout. Most plain TEX commands also work with LATEX.
• The document class determines how the document will be formatted. LATEX pro-
vides several standard document classes from which to choose.
1
This memo describes the LATEX language. To learn how to run, preview, and print on Rensselaer’s
unix systems, see Quick Study#20, Using TEX and LATEX on RCS.
RPI.109
2
1.4 The LATEX Input File
LATEX input files normally have names that end with the extension .tex: for example,
an acceptable filename might be myfile.tex. The input file contains both the text of
your document and the LATEX commands needed to format it.
• control symbols consist of the backslash followed by exactly one non-letter. They
are most often used to put a special symbol in the text. For example \$ prints a
$ (which cannot be entered directly because LATEX uses it to begin math mode).
Control symbols do not have to be followed by a space.
LATEX commands are case-sensitive. Most are all lowercase. A few commands use the
first letter in uppercase such as \Delta → ∆. Fewer still use all uppercase.
Some commands take an “argument,” placed within curly braces { } after the command
name. For example, \textbf{this text is bold} prints the text inside the braces in
boldface type: this text is bold
LATEX uses grouping to limit the effect of certain commands. Braces ({ and }) are used
to begin and end groups. For example, the \large command is usually used inside a
group: {\large this is bigger than normal} produces:
this is bigger than normal
A command such as \large is called a “declaration” because, unless it is given within
a group, its effect will continue until another declaration (in this case \normalsize)
counteracts it. Note the difference between a declaration used inside a group and a
command like \textbf{...}, which will not work unless an argument is specified.
The symbol % can be used to put a comment in your input file. When LATEX sees a %, it
ignores the rest of the line.
When you use commands that specify a length, such as a command to set the size of a
margin or a command to leave a certain amount of space, you will need to specify the
units of measurement. LATEX recognizes the following units:
cm centimeter pt printer’s point, ≈ 72 per inch
mm millimeter em font-dependent width of “m”
in inch ex font-dependent height of “x”
April 1997
RPI.109
3
1.4.2 Entering Text
In the input file, words are separated by leaving one blank space. Paragraphs are
separated by leaving one blank line. (You can also use the command \par to indicate a
new paragraph.) LATEX ignores multiple blank spaces and multiple blank lines in input
files.
Type single quotation marks by using the left (‘) and right (’) single quote marks on
your keyboard. Type left double quotation marks by using using two single left quotes
(‘‘), and type right double quotation marks by using either two single right quotes (’’)
or the double quote key (").
There are three kinds of dashes in typeset documents: the hyphen (for compound words),
the endash (for such things as page number ranges), and the emdash (used as a punc-
tuation mark in English prose). Since there is only one dash on the keyboard, type -,
--, and --- to get -, –, and — .
To prevent two words from being split at a line break, tie them together with the tilde
character: for example Mr.~Smith will never appear with “Mr.” at the end of one line
and “Smith” at the start of the next.
Note that some characters have special meaning to LATEX and must be entered in a
special way, as described in the next section.
\documentclass[options]{class}
Preamble
\begin{document}
Document text
\end{document}
In the first command above, class specifies the type of document you intend to create.
You can choose from one of the LATEX classes described in the next chapter. If you wish,
you can also include one or more options to modify the behavior of the document class.
The preamble is the section of the file between the \documentclass{...} command and
the \begin{document} command. This is the place to put commands that will influence
the style of your entire document and macro definitions that you will use later. You may
also load packages that add new features to LATEX. Text is not allowed in the preamble.
The \begin{document} command indicates the end of the preamble and the beginning
of your text. A corresponding \end{document} command always ends your files. A
really short LATEX input file might look like:
\documentclass{article}
\begin{document}
This LaTeX file is short and sweet. It uses the article class,
a good all-purpose layout. There is nothing in the preamble, which
is perfectly acceptable.
April 1997
RPI.109
5
1.5 Some LATEX Vocabulary
Commands produce text or space. For example, \hspace{2in} and \vspace{2in} are
commands that create 2 inches of horizontal and vertical space, respectively, and
\textit{some italic words} puts the contents of its argument in italic type.
Declarations produce neither text nor space, but either affect the way LATEX prints
the following text or provide information for later use. Font size changes are an
example of declarations. \large will cause any text that follows to appear in a
larger type size. Declarations are often used within a group to limit their scope.
For example: {\large Only the text inside these braces is large.}
Optional arguments follow a command name and are inclosed in square brackets: [ ].
For example, the size of type to be used for your main text is an optional argument
in the {\documentclass} command. To use the article class in 11-point type, you
would type \documentclass[11pt]{article}. Without this optional argument,
you would get the default 10-point type.
April 1997
RPI.109
7
Multiple options are separated by commas. The standard class options include:
10pt, 11pt, 12pt Selects the point size of main font for the document. If no option is
specified, 10pt is assumed. This memo uses 12-point type.
titlepage Causes the \maketitle command to generate the title page on a separate
page for the article class. This option is not necessary for the book and report
classes, as they print separate title pages by default.
leqno Puts equation numbers on left side. (They are on the right by default.)
twoside Formats for printing on both sides of paper. (Whether the document is actually
printed two-sided depends on the printer.) Twoside is the default for the book class,
but not for any of the other classes.
openright If the twoside option is in effect, chapters will begin on right hand pages.
This is the default for the book class. It does not apply to the article class,
which does not contain chapters. (The opposite of openright is openany.)
2.3 Packages
There are a large number of LATEX packages available that provide many additional
features. Some packages are distributed with LATEX; others are provided by expert users
worldwide. If you sometimes find that the features of standard LATEX do not provide the
special formatting you want, chances are good that you can find a package to meet your
needs. A package generally consists of one or more files that contain extra definitions
and macros. Some packages are simple; others are complex and can contain options.
The file names usually have the extension .sty.
You load a package with the \usepackage command, which should come immediately
after the \documentclass command in your input file. The command has the form:
\usepackage[options ]{package }
Each package may be included with its own \usepackage command, or you may use
one command to load several packages by separating their names with commas. For
example, if you are inserting PostScript graphics in your document (see section 7.4), the
package graphicx will make this easier for you. The beginning of your input file might
look like:
\documentclass[11pt]{article}
\usepackage{graphicx}
The \usepackage command above instructs LATEX to read the file graphicx.sty.
April 1997
RPI.109
9
2.6 Behind the Scenes
2.6.1 Auxiliary Files
Part of the convenience of LATEX is its ability to do forward references (see section 4.11)
and to create a table of contents, a list of tables, and a list of figures.
Forward reference numbers, as well as page numbers for sections, figures and tables, are
unknown when LATEX is first processing the input file. LATEX stores this information
in auxiliary files as it processes the job. A second run allows LATEX to extract the
information from its auxiliary files and complete the table of contents, etc. Therefore all
information used by LATEX for tables of contents, etc. is from the previous run. The only
way to be sure that all this material is correct is to format the file twice after making
any changes. Usually for drafts, the difference between runs is not enough to matter,
but for final versions you should remember to run LATEX twice before printing.
The auxiliary files have the same “root” name as the LATEX input file, but different
extensions. For example, all documents need an AUX file. If the input file is named
myfile.tex, the AUX file will be named myfile.aux. Other auxiliary files (see the list
below) are needed only if you are producing a table of contents, etc. Most computer
systems automatically create the auxiliary files as they are needed.
filename.aux always needed
filename.toc for table of contents
filename.lot for list of tables
filename.lof for list of figures
April 1997
RPI.109
11
2.8 Example: Letter Class
\documentclass[12pt]{letter} % letter class, 12 points
3.2 Paragraphs
To start a new paragraph, either leave a blank line or use the control sequence \par.
By default, paragraphs are indented by 1.5em, which means 1.5 times the point size of
the document. No extra blank space is inserted between paragraphs. The commands
\parindent and \parskip control paragraph indentation and paragraph separation. To
get block paragraphs, for example, include in the preamble the commands:
\parindent=0in
\parskip=10pt
2
the section between the \documentclass command and the \begin{document} command
April 1997
RPI.109
13
3.3 Text Justification
By default, LATEX justifies your text horizontally so that both left and right margins are
smooth. If you prefer “ragged right” text, you can use the declaration:
\raggedright
Note that this has the side-effect of wiping out the paragraph indentation. (It assumes
you want everything flush left.) If you want indented paragraphs, you must specifically
request it (i.e., \parindent=1.5em) after the \raggedright declaration.
Vertical justification is controlled by using either \flushbottom or \raggedbottom.
\flushbottom makes all text pages the same height, adding extra vertical space if nec-
essary. \raggedbottom allows the height to vary a bit from page to page. \flushbottom
is the default for the book class and for the twoside option in the article and report
classes; otherwise \raggedbottom is the default.
3.4 Margins
Top and left margins are set in reference to a value of one inch (which means that
setting these margins equal to 0 produces one-inch margins). Therefore, setting a top
margin of .5in will actually make a top margin of 1.5 inches, and setting a top margin
of -.5in produces a top margin of .5 inches. The opposite margins (bottom and right)
are determined indirectly by setting the height and width of the text area.
to set margin use the command
top margin \topmargin
bottom margin \textheight
left margin (for odd pages or single sided) \oddsidemargin
left margin (for even pages, if using twoside) \evensidemargin
right margin \textwidth
The command names controlling the margins are called lengths, and the “official” way to
set lengths in LATEX is with a command such as: \setlength{\oddsidemargin}{.5in}.
However, it is easier to borrow from plain TEX and use commands like those below:
\topmargin=-.5in % topmargin is 1/2 inch (note negative value)
\oddsidemargin=0in % left margin is 1 inch on right-hand pages
\evensidemargin=0in % same for left-hand pages in a 2-sided document
\textwidth=6.5in % leaves 1 inch for the right margin
\textheight=9in % 9 inches reserved for the text
LATEX also leaves .5 inch at the top of the page for a header and about .6 inch at the
bottom of the page for a footer. You must take this into account when choosing a value
for textheight. The values in the examples above leave one inch between the paper
edge and the text on all four sides. (The spaces for the header and footer are controlled
by the lengths headheight, headsep, and footskip. You can change these values too
if you wish, but it is not usually necessary.) For a quick and easy way to set one-inch
margins all around, you can use the package fullpage.
Academic Computing Services, RPI
RPI.109
14
3.5 Headers, Footers, and Page Numbering
The output page consists of the head, the body and the foot. Header and footer material,
such as page numbers and/or section titles, appear in the head or the foot. All the
classes (except letter) print at least the page number by default.
If you don’t like the default action of the document class, you can determine what infor-
mation goes into the head and foot by using the pagestyle command. This command
is often placed just after a \chapter or a similar command. There are four standard
page styles:
\pagestyle{plain}: The page number is in the foot and the head is empty. This is
the default page style for the article and report document classes.
\pagestyle{headings}: The page number and current section heading (the level of
the heading is determined by the document class) is put in the head; the foot is
empty. This is the default for the book class.
\pagestyle{myheadings}: Similar to the headings page style, except you specify the
information (other than the page number) that goes in the head by using the
markboth and markright commands. markboth is used for two-sided docu-
ments, and markright is used for one-sided:
\markboth{leftheader }{rightheader }
\markright{rightheader }
\thispagestyle{style}: Changes the page style for the current page only. For example,
to have nothing in the head and foot for the current page without affecting the
style for the rest of the pages, use \thispagestyle{empty}.
You can also specify arabic (the default) or roman page numbering either in the preamble
or in the text. It is common to put \pagenumbering{roman} before the text begins and
\pagenumbering{arabic} after the first \chapter command. These commands also
set the page number to 1. You can change the page number counter yourself with a
command such as \setcounter{page}{2}.
If the above pagestyle commands don’t do what you want, there is a package called
fancyhdr that allows you to customize your headers and footers in an easy way. With
this package you can define three-part headers and footers (left, right, and center), multi-
line headers and footers, separate headers and footers for even and odd pages, and more.
To use it, include the following commands in the preamble:
\usepackage{fancyhdr}
\pagestyle{fancy}
For simple use, you need only to include the following 6 commands in your preamble, sup-
plying your text inside the {} in each case: \lhead{}, \chead{}, \rhead{}, \lfoot{},
cfoot{}, \rfoot{}. For more information, see the documentation for fancyhdr in the
RCS directory /campus/doc/text/Latex2e/Packages/Contrib.
April 1997
RPI.109
15
Chapter 4. Within the Text
Within the text, there will always be certain sections that require special treatment—
such as a different size of type, indentation, or special placement on the page. Some
specialized areas of text (particularly those that require indentation) are formatted with
the help of LATEX environments.
April 1997
RPI.109
17
4.3 Starting New Lines and New Pages
Normally LATEX decides where to start a new line and a new page, always trying to pick
the most aesthetically pleasing break points. But sometimes you want to force the start
of a new line or page. The command \\ will force a new line. For example,
This will be on one line\\ this will be on the next line
If you want extra space between two lines, do not use two \\ commands in a row.
Instead use an optional parameter (given inside square brackets) to specify the amount
of blank space. For example, the following command will leave an extra space of 10
points between the lines:
This will be on one line\\[10pt] this will be on the next line
To force a new page, the simplest command is \newpage, which starts a new page
immediately. There is also the command \clearpage, which acts like \newpage except
that it also forces any leftover figures or tables to print before starting the new page.
With the twoside style option, the command \cleardoublepage produces a blank page,
if necessary, to ensure that the new page starts on a new sheet of paper.
4.7 Centering
If you have only one line to center, it’s easiest to use the plain TEX command
\centerline:
\centerline{This line is centered}
If you have several lines to be centered horizontally, the center environment is conve-
nient. The example below produces three lines, each horizontally centered.
\begin{center}
This is line one. \\
This is line two. \\
This is line three.
\end{center}
4.8 Quotations
The quote environment begins a new line and indents text from both sides. It
is delimited with \begin{quote} and \end{quote}. Any special effects (such
as changes to the type size or style) started within the quote environment
are terminated by \end{quote}.
New paragraphs are block style: that is, no indent and a blank line as sepa-
ration. This section is inside a quote environment.
There is also a very similar environment called quotation. The only difference is that
paragraphs in the quotation environment are indented with no blank line between.
3
This is the note text. Here it is at the bottom of the page.
April 1997
RPI.109
19
4.9 Reproducing Text As-Is
To reproduce new lines and spaces exactly as they are in your input file, you have a
choice of several methods.
The verbatim environment prints its text in typewriter-style type and sets it off from
the rest of the document with blank lines before and after. (It does not indent.) To use
it, surround the text with the commands \begin{verbatim} and \end{verbatim}. The
only LATEX command obeyed inside this environment is \end{verbatim}. For example,
the following input
\begin{verbatim}
All spacing is displayed in verbatim as entered.
So are special characters ! @ # & * ( ) _ } ] \ | > <
Verbatim is used to display LaTeX commands in this document.
\end{verbatim}
produces:
Example of Itemize
\begin{itemize} • This is the first item.
\item This is the first item.
\item This is the second item. • This is the second item.
\item This is the third item.
\end{itemize} • This is the third item.
Example of Description
\begin{description} enumerate Puts numbers in front
\item[enumerate] Puts numbers of the items
in front of the items
\item[itemize] Puts bullets itemize Puts bullets in front of the
in front of the items items
\item[description] Puts words
in front of the items description Puts words in front of
\end{description} the items
Below is an example of nesting list environments to achieve a different format.
Here are some useful environments: Here are some useful environments:
\begin{itemize} • center environment
\item center environment
\item quote environment • quote environment
\item the three list environments:
• the three list environments:
\begin{enumerate}
\item enumerate (uses numbers) 1. enumerate (uses numbers)
\item itemize (uses bullets) 2. itemize (uses bullets)
\item description (uses words) 3. description (uses words)
\end{enumerate}
\end{itemize}
April 1997
RPI.109
21
4.11 Cross References
In longer documents, there are often cross references to sections, figures, tables, or
equations. LATEX provides the following commands for cross referencing:
\label{marker } set a marker for future reference
\ref{marker } include the number of the section, figure, etc. of the cor-
responding \label command
\pageref{marker } include the page number of the corresponding \label com-
mand
marker is an identifier that you choose—it may contain letters, numbers, or other
characters (except for LATEX’s special list of characters). It can be helpful (but not
necessary) to start the marker name with a tag that identifies what is being marked:
for example, sec: for sections, eqn: for equations, fig: for figures, etc. (See the
example below.) The \label command should be placed immediately after a sectioning
command, within an equation environment, or inside a figure or table environment
immediately following the caption command.
\label{sec:xrefs}
For information on cross references, see
For information on cross references,
section 4.11 on page 21.
see section~\ref{sec:xrefs} on
page~\pageref{sec:xrefs}.
Note that LATEX uses the numbers from the .aux file produced by the previous run, so
it will take two runs (sometimes more) to get the cross references correct.
4.12.2 Example
The example below produces a figure, which LATEX places “here” because there happens
to be room for it. Note that you can put anything inside the figure environment: it can
be blank space created with the \vspace command, or it can be an imported PostScript
April 1997
RPI.109
23
graphic (see section 7.4). Likewise, a table environment can contain any LATEX com-
mands or text, but usually contains tabular material inside the tabular environment
(see section 5.2).
\begin{figure}[htp]
\begin{center}
\fbox{\parbox[t][2in][c]{4in} %top, 2in deep, v-centered, 4in wide
{\centerline{This space intentionally left blank}}}
\end{center}
\caption{What an Interesting Picture!}
\label{fig:space}
\end{figure}
5.1 Tabbing
Tabbing uses the following commands:
\= Set a tab stop
\\ Terminate a line
Tabs are usually set in the first line but may also be added in later lines. A special line
ending with the command \kill may be used to set tabs but not print the line. Below
are two examples of tabbing. Note that the last entry does not require a \\ to end the
line.
April 1997
RPI.109
25
Example 2: A Little More Complex
\begin{tabbing}
\hspace{2in} \= \hspace{2in} \= \kill
First column \> Second column \> Third column \\
\> Second \> Third \\
\hspace{1in} \\ % make a blank line
This Text extends past tab 1 \>\> Third column \\
\> Text spans columns two and three \\
xxxxxxxx \= xxxxxxxx \= xxxxxxxx \= \kill % set up new tab stops
Col 1 \> Col 2 \> Col 3 \> Col 4
\end{tabbing}
Produces:
First column Second column Third column
Second Third
5.2 Tabular
The tabular environment requires an additional argument that specifies the alignment
of each column (centered, left justified, etc.):
\begin{tabular}{align}
You may substitute any combination of the following symbols for the align argument:
l Left-justified column entry
\begin{center}
\begin{tabular}{|l|c|r|} % 3 cols (left, ctr, right); vert. lines
\hline % draw horizontal line
Name & Oblateness & Diameter \\
\hline
Mercury & 0 & 3,100 \\
Venus & 0 & 7,700 \\
Earth & 1/297 & 7,927 \\
Mars & 1/192 & 4,200 \\
Jupiter & 1/15 & 88,700 \\
Saturn & 1/9.5 & 75,100 \\
Uranus & 1/14 & 32,100 \\
Neptune & 1/40 & 27,700 \\
Pluto & ? & 3,600\\
\hline
\end{tabular}
\end{center}
Produces:
April 1997
RPI.109
27
5.2.2 Using Paragraph Columns, Spanning Columns
The following example illustrates making paragraphs within a table and placing text
across multiple columns using the \multicolumn command. This command has the
form:
\multicolumn{n}{pos}{item}
where n is the number of columns to be spanned, pos specifies the alignment of the item,
and item is the text.
This example is inside the table environment, which ensures that the table will be
“floated” rather than broken across a page (see section 4.12) and also provides the
opportunity to supply a caption. In this example, the optional parameter [hb] specifies
that the table should appear “here” or at the bottom of the page.
To center tabular material inside the table environment, you can use the declaration
\centering, which has the same effect as the center environment. (The centering
action will be confined to inside the table environment.)
\begin{tabular}{@{} l @{}}
\hline
no leading or trailing space\\ no leading or trailing space
\hline
\end{tabular}
\begin{tabular}{l}
\hline
leading space left and right\\ leading space left and right
\hline
\end{tabular}
4
For an another method, see the dcolumn package, provided as part of the LATEX “tools” bundle.
April 1997
RPI.109
29
Chapter 6. Mathematics
One of the greatest strengths of LATEX is its ability to typeset formulas and equations. To
make it easier to enter mathematical text, LATEX has defined several hundred Greek sym-
bols, mathematical symbols, delimiters, and operators. These are listed in Appendix A
of this memo.
LATEX has several modes for setting math text, which are described below. When in
math mode, LATEX sets type differently than when in text mode. For example, all letters
are set in the math italic typeface, and spaces in the input are ignored because LATEX
uses its own “mathematically correct” spacing. Therefore, if you want to use normal
text or retain spaces while in math mode, you must enclose this text with an “mbox”:
\mbox{this is normal text}. Also, new paragraphs are not allowed within math
mode, so be sure not to leave any blank lines.
If your mathematical expressions are particularly complex or sophisticated, you may
want to look at AMS-LATEX, a collection of packages that provides extensions to LATEX’s
mathematical capabilities.5
produces:
The derivative of the function f(x) at the point x0 is
f(x) − f(x0 )
f 0 (x0 ) = x→x
lim (1)
0 x − x0
April 1997
RPI.109
31
6.4 Eqnarray Environment (for multiline equations)
The eqnarray environment builds a three-column array of numbered equations, with
the first column right-justified, the second centered, and the third left-justified. It is
used mainly for displaying multi-line formulas. It numbers each line by default, but you
can include the command \nonumber on any line to suppress the equation number. (Or
you can use the alternative environment eqnarray*, which does not number any lines.)
The following example illustrates this environment. Note that you can use the \label
and \ref commands to refer to equation numbers in the text.
These three products can be expanded and simplified to
produce these equations:
\begin{eqnarray}
(a + b)(a + b) & = & a^2 + ab + ba + b^2 \nonumber \\
& = & a^2 + 2ab + b^2 \label{eq:simp1} \\
(a + b)(a - b) & = & a^2 - ab + ba - b^2 \nonumber \\
& = & a^2 - b^2 \label{eq:simp2} \\
(a + b)^3 & = & a^3 + 3a^2b + 3ab^2 + b^3 \label{eq:simp3}
\end{eqnarray}
The results after simplification are shown in equations
\ref{eq:simp1}, \ref{eq:simp2}, and \ref{eq:simp3}.
produces:
These three products can be expanded and simplified to produce these equations:
(a + b)(a + b) = a2 + ab + ba + b2
= a2 + 2ab + b2 (1)
(a + b)(a − b) = a2 − ab + ba − b2
= a 2 − b2 (2)
3
(a + b) = a3 + 3a2 b + 3ab2 + b3 (3)
April 1997
RPI.109
33
6.6 Building Mathematical Expressions
6.6.1 Superscripts and Subscripts
In math mode, the symbols ‘ˆ’ and ‘ ’ are used to make superscripts and subscripts. If
more than one character is to be used as a superscript or subscript, enclose the characters
in braces. For example:
$$ 2^{2^2} = 2^4 = 4^2 $$
$$ a^2_{i_1} = b^2_{i,j} $$
$$ _2F^1_3 $$
$${}_2^1P{}^3_4 $$
produces:
2
22 = 24 = 42
a2i1 = b2i,j
1
2 F3
1 3
2P 4
k·x = x
|
+ x +{z. . . + x}
k terms
Integral signs are produced with the \int command, and summation signs are produced
with the \sum command. These symbols are often used with superscripts and subscripts:
$$\sum^{\infty}_{n=1} \qquad \int^b_a e^{x^2}\,dx $$
$$\sqrt{\sum_{i=1}^{n}i} \qquad \sum_{\stackrel{i=1}{j=2}}^{\infty}$$
$$\sum \Delta V=\int\!\!\!\int\!\!\!\int_V dv $$
produces:
∞
X Z b 2
ex dx
n=1 a
v
u n ∞
uX X
t i
i=1 i=1
j=2
X ZZZ
∆V = dv
V
April 1997
RPI.109
35
6.6.6 Large Delimiters
The commands \left and \right are used to put large delimiters (such as ( ) [ ]) in
displayed formulas. (For braces, use \{ and \}). See Appendix A for a complete list
of delimiters. There must be a \right for every \left and vice versa for each output
line, although the left and right delimiters need not be the same type. You can even
use a period to create an invisible delimiter—very useful if you need an odd number of
delimiters. Large delimiters are often used with the array environment. Below are two
examples of large delimiters. (For another example, see Section 6.5 on page 32.)
$$
\mbox{det} = \left|
\begin{array}{lllll}
c_0 & c_1 & c_2 & \ldots & c_n \\
c_1 & c_2 & c_3 & \ldots & c_{n+1} \\
c_2 & c_3 & c_4 & \ldots & c_{n+2} \\
\vdots & \vdots & \vdots && \vdots \\
c_n & c_{n+1} & c_{n+2} & \ldots & c_{2n}
\end{array}
\right| > 0.
$$
produces:
c0 c1 c2 . . . cn
c1 c2 c3 . . . cn+1
det = c2 c3 c4 . . . cn+2 > 0.
.. .. .. ..
. . . .
cn cn+1 cn+2 . . . c2n
$$
\mbox{signum}(x)=\left\{
\begin{array}{rl}
1 & \mbox{if $x>0$} \\
0 & \mbox{if $x=0$} \\
-1 & \mbox{otherwise}
\end{array} \right.
$$
produces:
1 if x > 0
signum(x) = 0 if x = 0
−1 otherwise
April 1997
RPI.109
37
Below is an example of a thebibliography environment, followed by the output it
produces. On the \begin{thebibliography} line, the width of the item in the second
pair of braces determines the indent of the entries. This item is usually a dummy number
with as many digits as the highest-numbered entry. In this case, the number 9 indicates
there are fewer than 10 entries. If there are 10 or more entries but less than 100, use
the number 99.
Within this environment, each entry starts with the \bibitem command. The argument
for this command is the same keyword used in the corresponding \cite command in
the text. The \bibitem commands automatically generate a number in square brackets
before each entry. The first entry in the list will be numbered 1.
Note that in the book and report classes, Bibliography is used as the chapter title;
in the article class, References is used as the section heading.
\begin{thebibliography}{9}
\bibitem{lamport} Leslie Lamport. \textit{\LaTeX\ -- A Document
Preparation System}. Addison-Wesley, Reading, MA, 2nd edition, 1994.
\bibitem{kopka} Helmut Kopka and Patrick W.~Daly. \textit{A Guide
to \LaTeXe}. Addison-Wesley, Reading, MA, 1995.
\bibitem{goossens} Michel Goossens, Frank Mittelbach
\& Alexander Samarin. \textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, MA, 1994.
\end{thebibliography}
References
[1] Leslie Lamport. LATEX – A Document Preparation System. Addison-Wesley, Reading, MA,
second edition, 1994.
[2] Helmut Kopka and Patrick W. Daly. A Guide to LATEX 2ε . Addison-Wesley, Reading, MA,
1995.
[3] Michel Goossens, Frank Mittelbach & Alexander Samarin. The LATEX Companion. Addison-
Wesley, Reading, MA, 1994.
If you prefer, you can choose a label to identify the work in both the text and in the
bibliography, instead of the number assigned by LATEX. You do this by including an
optional label on the \bibitem command. (The \cite command doesn’t change.) For
example, to refer to the third book as “companion,” its entry in the thebibliography
environment would be:
\bibitem[companion]{goossens} Michel Goossens, Frank Mittelbach
\& Alexander Samarin. \textit{The \LaTeX\ Companion}.
Addison-Wesley, Reading, MA, 1994.
For more information, including how to use the BibTEX program to generate a bibliog-
raphy from a database, see any of the above three references.
April 1997
RPI.109
39
7.4 Including and Manipulating PostScript Graphics6
The easiest way to put graphics into your LATEX document is to first create the graphic
using a software package (such as xfig, Gnuplot, MATLAB, CorelDraw, etc.) and save
the graphic in EPS (Encapsulated PostScript) format.
You can then include the graphic in your document by using the LATEX graphicx package
(part of the LATEX graphics bundle) and the PostScript printer driver dvips. To include
EPS graphics, first put in your preamble the command:
\usepackage{graphicx}
The graphicx package provides the command \includegraphics, which allows you
to specify the name of the PostScript file as well as optional arguments for scaling or
rotating the graphic. The command (which you will normally put inside the figure
environment, described in section 4.12) will look something like:
\includegraphics[width=4in]{myfigure.eps}
Inside the [...], you can specify a number of optional arguments, separated by commas.
In this case, width=4in will scale the width of graphic to four inches. Since no height is
specified, the height will be scaled so that the figure remains in proportion. The most
commonly used arguments are:
width scale graphic to the specified width
height scale graphic to the specified height
scale scale graphic by scale factor. (scale=2 makes the graphic twice as large
as its natural size; scale=.5 makes it half as large.)
angle rotate graphic by specified number of degrees. A positive number in-
dicates the counter-clockwise direction. (angle=90 rotates 90 degrees
counter-clockwise.)
Note that in the following example, the graphic is first rotated counter-clockwise by 90
degrees and then scaled to a width of 8 inches:
\includegraphics[angle=90,width=8in]{myfigure.eps}
Complete documentation for the graphics bundle is in the file
/campus/doc/text/Latex2e/Packages/Graphics/grfguide.dvi
You can view it with xdvi; information on the graphicx package is in section 4.4.
To print an entire figure, including the caption, in landscape orientation, use the
rotating package in addition to graphicx. Load it as usual with the \usepackage
command:
6
This section assumes you are using the PostScript driver dvips and have a PostScript printer
available. Alternatively, if you have a PC with a non-PostScript printer, you can still include EPS
graphics if you have both dvips and Ghostview installed.
April 1997
RPI.109
41
7.5 Accents and Special Characters
LATEX provides commands that allow you to print accents required by many European
languages. The table below shows how to apply a variety of accents to the letter o. Of
course, any other letter can be used in place of o.
If you want to place an accent on top of an i or a j, however, you need to print them
without their dots. You can print a dotless i or j by typing \i and \j. For example, ı̆ is
formed by typing \u{\i}.
ò \‘{o} ó \’{o} ô \^{o} õ \~{o}
ō \={o} ȯ \.{o} ö \"{o} o̊ \r{o}
ŏ \u{o} ǒ \v{o} ő \H{o} o̧ \c{o}
o. \d{o} o \b{o} oo \t{oo}
¯
Note that the accent commands that are control symbols (i.e., they consist of just one
non-letter) can also be used without braces. For example \^o and \^{o} both produce
ô.
The special letters that are part of European languages can be generated with the
following commands:
œ {\oe} Œ {\OE} æ {\ae} Æ {\AE}
å {\aa} Å {\AA} ø {\o} Ø {\O}
ß {\ss} SS {\SS} l {\l} L {\L}
¡ !‘ ¿ ?‘
For example:
na\"{\i}ve, r\’esum\’e, {\AA}ngstr{\o}m, se\~norita, stra{\ss}e
produces:
naı̈ve, résumé, Ångstrøm, señorita, straße
Greek Alphabet
α \alpha ι \iota % \varrho
β \beta κ \kappa σ \sigma
γ \gamma λ \lambda ς \varsigma
δ \delta µ \mu τ \tau
\epsilon ν \nu υ \upsilon
ε \varepsilon ξ \xi φ \phi
ζ \zeta o o1 ϕ \varphi
η \eta π \pi χ \chi
θ \theta $ \varpi ψ \psi
ϑ \vartheta ρ \rho ω \omega
Γ \Gamma Ξ \Xi Φ \Phi
∆ \Delta Π \Pi Ψ \Psi
Θ \Theta Σ \Sigma Ω \Omega
Λ \Lambda Υ \Upsilon
Capitals not shown are produced with English capital letters.
1
An ordinary “o” looks Greek when used in a math environment: $o$ → o.
Miscellaneous Symbols
ℵ \aleph 0 \prime ∀ \forall
h̄ \hbar ∅ \emptyset ∃ \exists
ı \imath ∇
√ \nabla ¬ \neg
\jmath \surd [ \flat
` \ell > \top \ \natural
℘ \wp ⊥ \bot ] \sharp
< \Re k \Vert or \| ♣ \clubsuit
= \Im 6 \angle ♦ \diamondsuit
∂ \partial 4 \triangle ♥ \heartsuit
∞ \infty 3 \Diamond ♠ \spadesuit
0P \mho 2Q \Box \
`
\backslash
R \sum H \prod \coprod
\int \oint 1 \Join
The symbols whose names are underlined require latexsym, a standard LATEX package.
Load it with the command: \usepackage{latexsym}.
April 1997
RPI.109
43
Non-Mathematical Symbols
These symbols can be used in either text mode or math mode:
† \dag ‡ \ddag § \S ¶ \P c \copyright £ \pounds
Function Names
When using function names in a math environment, you can prefix them with a \ so
that they will print as normal text rather than in italics:
\arccos \arcsin \arctan \arg \cos \cosh
\cot \coth \csc \deg \det \dim
\exp \gcd \hom \inf \ker \lg
\lim \liminf \limsup \ln \log \max
\min \Pr \sec \sin \sinh \sup
\tan \tanh
Delimiters
The following symbols can expand in size to “fit around” the expressions they delimit. To
make a delimiter the right size, use it with the \left ... \right commands described
in section 6.6.6.
( ( ) ) b \lfloor c \rfloor
[ [ ] ] d \lceil e \rceil
{ \{ } \} h \langle i \rangle
| | k \| ↑ \uparrow ⇑ \Uparrow
/ / \ \backslash ↓ \downarrow ⇓ \Downarrow
l \updownarrow m \Updownarrow
Relational Operators
≤ \le or \leq ≥ \geq ≡ \equiv
≺ \prec \succ ∼ \sim
\preceq \succeq ' \simeq
\ll \gg \asymp
⊂ \subset ⊃ \supset ≈ \approx
⊆ \subseteq ⊇ \supseteq ∼
= \cong
< \sqsubset = \sqsupset ⊥ \perp
v \sqsubseteq w \sqsupseteq ./ \bowtie
∈ \in 3 \ni ∝ \propto
` \vdash a \dashv |= \models
.
^ \smile | \mid = \doteq
_ \frown k \parallel
6 < \not< 6 > \not> 6= \not=
Note that \not before a relation will negate it.
The symbols whose names are underlined require the latexsym package.
The symbols whose names are underlined require the latexsym package.
Math Accents
â \hat{a} ǎ \check{a} ă \breve{a}
á \acute{a} à \grave{a} ã \tilde{a}
ā \bar{a} ~a \vec{a} ȧ \dot{a}
ä \ddot{a} xd −y \widehat{x-y} g
xyz \widetilde{xyz}
Arrows
← \leftarrow ←− \longleftarrow ↑ \uparrow
⇐ \Leftarrow ⇐= \Longleftarrow ⇑ \Uparrow
→ \rightarrow −→ \longrightarrow ↓ \downarrow
⇒ \Rightarrow =⇒ \Longrightarrow ⇓ \Downarrow
↔ \leftrightarrow ←→\longleftrightarrow l \updownarrow
⇔ \Leftrightarrow ⇐⇒\Longleftrightarrow m \Updownarrow
7 → \mapsto 7−→ \longmapsto % \nearrow
←- \hookleftarrow ,→ \hookrightarrow & \searrow
( \leftharpoonup * \rightharpoonup . \swarrow
) \leftharpoondown + \rightharpoondown - \nwarrow
*
) \rightleftharpoons ; \leadsto
The symbols whose names are underlined require the latexsym package.
April 1997
RPI.109
45
Appendix B
Error Messages
Most files need some debugging before they print properly. This section describes some
common errors and shows how to correct them.
• You failed to match delimiters. For example, you have a $ with no matching $.
• You used a special or math character in ordinary text. The most common
problem character is &. Others are $, #, and %.
• You inserted too many tabs on the line before the \\.
• Whatever you \begin{...}, you must \end{...}. This includes braces: { ... }.
• A command wasn’t given all its arguments and is trying to use the rest of the file
for an argument.
April 1997