Latex Guide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

0.

Producing a LaTeX Input File


The first line of the input file should normally consist of an appropriate \documentclass
command. If an article (or similar document) is to be produced on A4 paper, and if the main body of
the text is to be set with a font whose natural size is `12 point', then the appropriate
\documentclass command is
\documentclass[a4paper,12pt]{article}

Other forms of the \documentclass command can be used for letters, reports or books. If 12pt is
omitted from the \documentclass command (with the preceding comma), then the document will
be set in a `10 point' size. One may also replace 12pt with 11pt.
The documentstyle command may be followed by certain other optional commands, such as the
\pagestyle command. It is not necessary to find out about these commands when first learning to
use LaTeX.
After the \documentclass command and these other optional commands, we place the command
\begin{document}

This command is then followed by the main body of the text, in the format prescribed by the rules of
LaTeX.
Finally, we end the input file with a line containing the command
\end{document}

Required Components of a LaTeX Document


Every LaTeX document must contain the following three components. Everything else is optional
(even text).
1. \documentclass{article}
2. \begin{document}
3. \end{document}
The first statement tells LaTeX what kind of document it is to process, as there are different style rules
for different kinds of documents. We will use the article document class exclusively in this tutorial.
Other possible classes include report, book, and letter.
The default font size for each class is 10 point. You can use 11 point or 12 point fonts by including this
information in the \documentclass command as \documentclass[11pt]{article} or
\documentclass[12pt]{article}. You could also use \documentclass[10pt]
{article}, but since this is the default you don't need to type the [10pt] part.
In general, required information is included in LaTeX commands in braces {}, while optional
information is included in square brackets [].
The \documentclass command must appear at the very beginning of your LaTeX document,
before any other LaTeX commands, or you will get an error message.
If you have commands for LaTeX that will affect the whole document, you should include them in the
preamble, which is what the space between the \documentclass and \begin{document}
commands is called. The body of the document, where you include all of your text, must occur between
the \begin{document} and \end{document} commands. Any text that comes after the
\end{document} command will be ignored.

Error Messages
Since LaTeX will stop after any \end{document} command, a good strategy for finding errors is to
insert \end{document} temporarily earlier in the file to see if the error is above its location.

Page Numbering and Headings


The command \pagestyle controls page numbering and headings. It should always go between the
\documentclass{article} and the \begin{document} commands. It can take the
following forms:
1. \pagestyle{plain} is the default, which puts the page number at the center of the bottom
of the page and provides no headings.
2. \pagestyle{empty} provides neither page numbers nor headings.
3. \pagestyle{headings} will provide page numbers and headings from any \section's
that you are using.
4. \pagestyle{myheadings} will provide page numbers and custom headings.
These commands can also be applied to a single page using \thispagestyle instead of
\pagestyle.

Creating a Title Page


The title, author, and date of your document are information that various LaTeX commands can make
use of, if you provide it. It is a good habit to get into to provide this information in the preamble of your
document. (Remember that the preamble refers to any commands between the \documentclass
command and the \begin{document} command.) The commands are:
1. \title{yourtitlehere}
2. \author{yournamehere}
3. \date{currentdate}
Given that you have provided this information in the preamble, you may or may not want a title
heading. If you do, place a \maketitle command immediately after the \begin{document}
command.
The \documentclass command can take a titlepage option:
\documentclass[titlepage]{article}.

Sections
LaTeX is a language for creating structured documents. One of the most important ways of creating
structure in a document is to split it into logical sections. If your document deals with more than one
concept or theme, then each concept should go into its own section.
There are two related commands for creating sections: \section{sectiontitle} and
\section*{sectiontitle}. The first one numbers the sections, while the starred form does not.
Both create separate sections with titles in a larger font size; they also provide information to LaTeX in
case you want to create a Table of Contents.

Section Headings in LaTeX


Section headings of various sizes are produced (in the article document style) using the commands
\section,\subsection and \subsubsection commands. LaTeX will number the sections
and subsections automatically. The title of the section should be surrounded by braces and placed
immediately after the relevant command. Thus if we type
\section{Section Headings}

We explain in this section how to obtain headings


for the various sections and subsections of our
document.

\subsection{Headings in the `article' Document Style}

In the `article' style, the document may be divided up


into sections, subsections and subsubsections, and each
can be given a title, printed in a boldface font,
simply by issuing the appropriate command.

then the title of the section and that of the subsection will be printed in a large boldface font, and will
be numbered accordingly.
Other document styles (such as the book and letter styles) have other `sectioning' commands available
(for example, the book style has a \chapter command for beginning a new chapter).
Sometimes one wishes to suppress the automatic numbering provided by LaTeX. This can be done by
placing an asterisk before the title of the section or subsection. Thus, for example, the section numbers
in the above example could be suppressed by typing
\section*{Section Headings}

We explain in this section how to obtain headings


for the various sections and subsections of our
document.

\subsection*{Headings in the `article' Document Style}

In the `article' style, the document may be divided up


into sections, subsections and subsubsections, and each
can be given a title, printed in a boldface font,
simply by issuing the appropriate command.

Cross-References
If you wish to have cross-references in a document with numbered sections, use \label{name} to
label the point in your document with some mnemonic, and Section \ref{name} to refer to that
point. \ref{name} will be replaced by the number of the section containing the corresponding
\label command. As with your bibliography citations, you will need to run LaTeX twice to generate
these references.

Table of Contents
For a large document, it is a kindness to your reader to provide a Table of Contents. If you have been
using \section commands throughout your document, then LaTeX has all the information that it
needs to construct one for you. Place the command \tableofcontents after your
\begin{document} command.
It may be necessary to run LaTeX twice on a document with a Table of Contents: the first time, LaTeX
stores the page numbers for the sections in a separate file, and then the second time LaTeX writes this
information into the Table of Contents. If you have question marks instead of page numbers in your
Table of Contents, run LaTeX again.

Abstracts
To create an abstract, place your text in an abstract environment, i.e., between \begin{abstract}
and \end{abstract} commands. The abstract should come immediately after your \maketitle
command, but before any \tableofcontents command.

Quotation Marks and Dashes


Single quotation marks are produced in LaTeX using ` and '. Double quotation marks are produced by
typing `` and ''. (The `undirected double quote character " produces double right quotation marks: it
should never be used where left quotation marks are required.)
LaTeX allows you to produce dashes of various length, known as `hyphens', `en-dashes' and `em-
dashes'. Hyphens are obtained in LaTeX by typing -, en-dashes by typing -- and em-dashes by typing
---.
One normally uses en-dashes when specifying a range of numbers. Thus for example, to specify a
range of page numbers, one would type
on pages 155--219.

Dashes used for punctuating are often typeset as em-dashes, especially in older books. These are
obtained by typing ---.
The dialogue
(taken from Alice through the Looking Glass, by Lewis Carroll) illustrates the use of quotation marks
and dashes. It is obtained in LaTeX from the following input:
``You \emph{were} a little grave,'' said Alice.

``Well just then I was inventing a new way of


getting over a gate---would you like to hear it?''

``Very much indeed,'' Alice said politely.

``I'll tell you how I came to think of it,'' said


the Knight. ``You see, I said to myself `The only
difficulty is with the feet: the \emph{head} is
high enough already.' Now, first I put my head on
the top of the gate---then the head's high
enough---then I stand on my head---then the feet
are high enough, you see---then I'm over, you see.''

Sometimes you need single quotes immediately following double quotes, or vica versa, as in

The way to typeset this correctly in LaTeX is to use the control sequence \, between the quotation
marks, so as to obtain the necessary amount of separation. The above example is thus produced with
the input
``I regard computer typesetting as being reasonably
`straightforward'\,'' he said.

Changing Fonts in Text Mode


LaTeX has numerous commands for changing the typestyle. The most useful of these is \emph{text}
which emphasizes some piece of text, setting it usually in an italic font (unless the surrounding text is
already italicized). Thus for example, the text
is obtained by typing
The basic results and techniques of \emph{Calculus}
were discovered and developed by \emph{Newton}
and \emph{Leibniz}, though many of the basic ideas
can be traced to earlier work of \emph{Cavalieri},
\emph{Fermat}, \emph{Barrow} and others.

Another useful font-changing command is \textbf{text}, which typesets the specified portion of
text in boldface.
A font family or typeface in LaTeX consists of a collection of related fonts characterized by size, shape
and series. The font families available in LaTeX include roman, sans serif and typewriter:

The sizes of fonts used in LaTeX are can be determined and changed by means of the control
sequences \tiny, \scriptsize, \footnotesize, \small, \normalsize, \large,
\Large, \LARGE, \huge and \HUGE:

The shape of a font can be upright, italic, slanted or small caps:


The series of a font can be medium (the default) or boldface:

If the necessary fonts are available, one can combine changes to the size, shape and series of a font, for
example producing boldface slanted text by typing \textbf{\textsl{boldface slanted
text}}.
There are in LaTeX font declarations corresponding to the the font-changing commands described
above. When included in the LaTeX input such declarations determine the type-style of the subsequent
text (till the next font declaration or the end of the current `group' delimited by braces or by appropriate
\begin and \end commands). Here is a list of font-changing commands and declarations in text
mode:
Command Declaration

\textrm \rmfamily Roman family


\textsf \sffamily Sans serif family
\texttt \ttfamily Typewriter family

\textup \upshape Upright shape


\textit \itshape Italic shape
\textsl \slshape Slanted shape
\textsc \scshape Small caps shape

\textmd \mdseries Medium series


\textbf \bfseries Boldface series
Accents used in Text
There are a variety of control sequences for producing accents. For example, the control sequence
\'{o} produces an acute accent on the letter o. Thus typing
Se\'{a}n \'{O} Cinn\'{e}ide.

produces

Similarly we use the control sequence \` to produce the grave accent in `algèbre' and we use \" to
produce the umlaut in `Universität'. The accents provided by LaTeX include the following:

These accents are for use in ordinary text. They cannot be used within mathematical formulae, since
different control sequences are used to produce accents within mathematics.
The control sequences \i and \j produce dotless i and j. These are required when placing an accent
on the letter. Thus í is produced by typing \'{\i}.

\usepackage[T1]{fontenc}=>for french accents, with this command, latex is going to


accept directly the typed words.
To display ±, \pm
\ne is for ≠

Alignments
In these environments \\ starts a new line.
\begin{flushleft}
Some people like to stay firmly\\ on the left whereas others
\end{flushleft}
\begin{flushright}
feel more at home on the right.\\
\end{flushright}
\begin{center}
but most of us prefer to stay dead in the center.
\end{center}
Some people like to stay firmly
on the left whereas others
feel much more at home
on the right.
but most of us prefer to stay dead in the center.

Active Characters and Special Symbols in Text


The `active characters'
# $ % & \ ^ _ { } ~

have special purposes within LaTeX. Thus they cannot be produced in the final document simply by
typing them directly. On the rare occasions when one needs to use the special characters
#$%&_{}

in the final document, they can be produced by typing the control sequences
\# \$ \% \& \_ \{ \}

respectively. However the characters \, ^ and ~ cannot be produced simply by preceding them with a
backslash. They can however be produced using \char92 (in the \texttt font only), \char94
and \char126 respectively. (The decimal numbers 92, 94 and 126 are the ASCII codes of these
characters.)
Other special symbols can be introduced into text using the appropriate control sequences:
Mathematical Typesetting

Mathematics Mode
In order to obtain a mathematical formula using LaTeX, one must enter mathematics mode before the
formula and leave it afterwards. Mathematical formulae can occur either embedded in text or else
displayed between lines of text. When a formula occurs within the text of a paragraph one should place
a $ sign before and after the formula, in order to enter and leave mathematics mode. Thus to obtain a
sentence like

one should type


Let $f$ be the function defined by $f(x) = 3x + 7$, and
let $a$ be a positive real number.

In particular, note that even mathematical expressions consisting of a single character, like f and a in
the example above, are placed within $ signs. This is to ensure that they are set in italic type, as is
customary in mathematical typesetting.
LaTeX also allows you to use \( and \) to mark the beginning and the end respectively of a
mathematical formula embedded in text. Thus
may be produced by typing
Let \( f \) be the function defined by \( f(x) = 3x + 7 \).

However this use of \( ... \) is only permitted in LaTeX: other dialects of TeX such as Plain TeX and
AmSTeX use $ ... $.
In order to obtain an mathematical formula or equation which is displayed on a line by itself, one
places \[ before and \] after the formula. Thus to obtain

one would type


If $f(x) = 3x + 7$ and $g(x) = x + 4$ then
\[ f(x) + g(x) = 4x + 11 \]
and
\[ f(x)g(x) = 3x^2 + 19x +28. \]

(Here the character ^ is used to obtain a superscript.)


LaTeX provides facilities for the automatic numbering of displayed equations. If you want an
numbered equation then you use \begin{equation} and \end{equation} instead of using \
[ and \] . Thus
If $f(x) = 3x + 7$ and $g(x) = x + 4$ then
\begin{equation}
f(x) + g(x) = 4x + 11
\end{equation}
and
\begin{equation}
f(x)g(x) = 3x^2 + 19x +28.
\end{equation}

produces

Mathematical Formulas
There are two ways to insert mathematical formulas into your document with LaTeX. One is to have it
appear in a paragraph with text. In doing so, the formulas will be compressed vertically: limits for
integrals and summations will appear to the side instead of on the top and bottom, etc. The other way is
to have them appear in a separate paragraph, where there will be more room.
For formulas that appear in a paragraph, surround them with $'s. For example,
$\alpha$ is the first letter of the Greek alphabet.

becomes
is the first letter of the Greek alphabet.
To have formulas appear in their own paragraph, use matching $$'s to surround them. For example,
$$
\frac{x^n-1}{x-1} = \sum_{k=0}^{n-1}x^k
$$

becomes

Mathematics Mode
In order to obtain a mathematical formula using LaTeX, one must enter mathematics mode before the
formula and leave it afterwards. Mathematical formulae can occur either embedded in text or else dis-
played between lines of text. When a formula occurs within the text of a paragraph one should place a $
sign before and after the formula, in order to enter and leave mathematics mode. Thus to obtain a sen-
tence like

one should type


Let $f$ be the function defined by $f(x) = 3x + 7$, and
let $a$ be a positive real number.
In particular, note that even mathematical expressions consisting of a single character, like f and a in
the example above, are placed within $ signs. This is to ensure that they are set in italic type, as is
customary in mathematical typesetting.
LaTeX also allows you to use \( and \) to mark the beginning and the end respectively of a mathemat-
ical formula embedded in text. Thus

may be produced by typing


Let \( f \) be the function defined by \( f(x) = 3x + 7 \).
However this use of \( ... \) is only permitted in LaTeX: other dialects of TeX such as Plain TeX and
AmSTeX use $ ... $.
In order to obtain an mathematical formula or equation which is displayed on a line by itself, one
places \[ before and \] after the formula. Thus to obtain
one would type
If $f(x) = 3x + 7$ and $g(x) = x + 4$ then
\[ f(x) + g(x) = 4x + 11 \]
and
\[ f(x)g(x) = 3x^2 + 19x +28. \]
(Here the character ^ is used to obtain a superscript.)
LaTeX provides facilities for the automatic numbering of displayed equations. If you want an num-
bered equation then you use \begin{equation} and \end{equation} instead of using \[ and \] .
Thus
If $f(x) = 3x + 7$ and $g(x) = x + 4$ then
\begin{equation}
f(x) + g(x) = 4x + 11
\end{equation}
and
\begin{equation}
f(x)g(x) = 3x^2 + 19x +28.
\end{equation}
produces

Superscripts and Subscripts


Subscripts and superscripts are obtained using the special characters _ and ^ respectively. Thus the
identity

is obtained by typing
.
\[ ds^2 = dx_1^2 + dx_2^2 + dx_3^2 - c^2 dt^2 \]

It can also be obtained by typing

\[ ds^2 = dx^2_1 + dx^2_2 + dx^2_3 - c^2 dt^2 \]

since, when a superscript is to appear above a subscript, it is immaterial whether the superscript or
subscript is the first to be specified.
Where more than one character occurs in a superscript or subscript, the characters involved should be
enclosed in braces. For example, the polynomial is obtained by typing $x^{17} - 1$.

One may not type expressions such as $s^n^j$ since this is ambiguous and could be interpreted either
as or as . The first of these alternatives is obtained by typing $s^{n j}$, the second by typing
$s^{n^j}$. A similar remark applies to subscripts. Note that one can obtain in this way double super-
scripts (where a superscript is placed on a superscript) and double subscripts.
It is sometimes necessary to obtain expressions in which the horizontal ordering of the subscripts is sig-
nificant. One can use an `empty group' {} to separate superscripts and subscripts that must follow one
another. For example, the identity

can be obtained by typing


\[ R_i{}^j{}_{kl} = g^{jm} R_{imkl}
= - g^{jm} R_{mikl} = - R^j{}_{ikl} \]

Exponents and Subscripts


Use the ^ character (shift-6), known as a caret, to create exponents:
$x^2$
produces

If you have an exponent containing more than one char-


acter, group the exponent characters inside braces.
$x^21 \ne x^{21}$
produces

Similarly, subscripts are created using the _ (underscore character).


Again, for subscripts of more than one character, use braces to indicate
where the subscript starts and stops.
$x_21 \ne x_{21}$
produces
Characters in Mathematics Mode
All the characters on the keyboard have their standard meaning in mathematics mode, with the excep-
tion of the characters
# $ % & ~ _ ^ \ { } '
Letters are set in italic type. In mathematics mode the character ' has a special meaning: typing $u' +
v''$ produces . Spaces and single carriage returns in the input file between letters and other
symbols do not have any effect on the typesetting of mathematical formulae, since LaTeX determines
spacing within formulae by its own internal rules. Thus $u v + w = x$ and $uv+w=x$ both produce
.
The characters
# $ % & _ { }
are obtained in mathematics mode by typing
\# \$ \% \& \_ \{ \} .
A backslash \ can be obtained in mathematics mode by typing \backslash.

Greek Letters
1. is \alpha

2. is \beta

3. is \gamma

4. is \delta

5. is \epsilon

6. is \varepsilon

7. is \zeta

8. is \eta

9. is \theta

10. is \vartheta

11. is \iota

12. is \kappa

13. is \lambda
14. is \mu

15. is \nu

16. is \xi

17. is o

18. is \pi

19. is \varpi

20. is \rho

21. is \varrho

22. is \sigma

23. is \varsigma

24. is \tau

25. is \upsilon

26. is \phi

27. is \varphi

28. is \chi

29. is \psi

30. is \omega

31. is \Gamma

32. is \Delta

33. is \Theta

34. is \Lambda

35. is \Xi

36. is \Pi

37. is \Sigma
38. is \Upsilon

39. is \Phi

40. is \Psi

41. is \Omega

Mathematical Symbols
There are numerous mathematical symbols that can be used in mathematics mode. These are obtained
by typing an appropriate control sequence.
Miscellaneous Symbols:

``Large'' Operators:

Binary Operations:
Relations:

Negated Relations:

Arrows:
Openings:

Closings:

Alternative Names:
Above and Below
It is useful to be able to draw horizontal lines and braces
above and below parts of a formula. We can combine the
\overline, \overbrace, \underline, and \underbrace com-
mands to our heart's content.
$$
\left(
\begin{array}{c}
m+n\\
m
\end{array}
\right)
= \frac{(m+n)!}{m!n!}
= \frac
{\overbrace{(m+n)(m+n-1)\cdots(n+1)}^\mbox{$m$
factors}
{\underbrace{m(m-1)\cdots 1}_\mbox{$m$ factors}}
$$
produces

while
$\overline{x+\overline{y}} = \overline{x}+y$
produces

Delimiters
these are made by these and these are made by these
( ( ) )

[ [ ] ]

\{ \}

\lfloor \rfloor
\lceil \rceil

\langle \rangle

/ / \backslash

| | \|

\uparrow \Uparrow

\downarrow \Downarrow

\updownarrow \Updownarrow

This table shows the standard sizes. To get bigger sizes, use these prefices
(for left delimiters) (for right delimiters) magnification
\bigl \bigr a bit bigger, but won't overlap lines
\Bigl \Bigr 150% times big
\biggl \biggr 200% times big
\Biggl \Biggr 250% times big

For example,
$\Biggl\{2\Bigl(x(3+y)\Bigr)\Biggr\}$

gives . If you're not using the default text size these commands might not
work correctly. In that case try the exscale package.
It's preferable to let LATEX choose the delimiter size for you by using \left and \right. These will
produce delimiters just big enough for the formulae inbetween.
$\left( \frac{(x+iy)}{\{\int x\}} \right)$

gives
The left and right delimiters needn't be the same type. It's sometimes useful to make one of them invisi-
ble
\[ z = \left\{
\begin{array}{ll}
1 & (x>0)\\
0 & (x<0)
\end{array}
\right.
\]
produces
Over- and underbracing works too.
$\overbrace{\alpha \ldots \omega}^{\mbox{greek}}
\underbrace{a \ldots z}_{\mbox{english}}$

produces . The use of \mbox stops the text appearing in math


italic.

Changing Fonts in Mathematics Mode


(The following applies to LaTeX2e, a recent version of LaTeX. It does not apply to older versions of
LaTeX.)
The `math italic' font is automatically used in mathematics mode unless you explicitly change the font.
The rules for changing the font in mathematics mode are rather different to those applying when type-
setting ordinary text. In mathematics mode any change only applies to the single character or symbol
that follows (or to any text enclosed within braces immediately following the control sequence). Also,
to change a character to the roman or boldface font, the control sequences \mathrm and \mathbf must
be used (rather than \textrm and \textbf).

The following example illustrates the use of boldface in mathematical formulae. To obtain

one could type


Let $\mathbf{u}$,$\mathbf{v}$ and $\mathbf{w}$ be three
vectors in ${\mathbf R}^3$. The volume~$V$ of the
parallelepiped with corners at the points
$\mathbf{0}$, $\mathbf{u}$, $\mathbf{v}$,
$\mathbf{w}$, $\mathbf{u}+\mathbf{v}$,
$\mathbf{u}+\mathbf{w}$, $\mathbf{v}+\mathbf{w}$
and $\mathbf{u}+\mathbf{v}+\mathbf{w}$
is given by the formula
\[ V = (\mathbf{u} \times \mathbf{v}) \cdot \mathbf{w}.\]
There is also a `calligraphic' font available in mathematics mode. This is obtained using the control se-
quence \mathcal. This font can only be used for uppercase letters. These calligraphic letters have the
form
Standard Functions (sin, cos etc.)
The names of certain standard functions and abbreviations are obtained by typing a backlash \ before
the name. For example, one obtains

by typing
\[ \cos(\theta + \phi) = \cos \theta \cos \phi
- \sin \theta \sin \phi \]
The following standard functions are represented by control sequences defined in LaTeX:

Names of functions and other abbreviations not in this list can be obtained by converting to the roman
font. Thus one obtains by typing $\mathrm{cosec} A$. Note that if one were to type simply
$cosec A$ one would obtain because LaTeX has treated cosec A as the product of six quanti-
ties c, o, s, e, c and A and typeset the formula accordingly.

Functions
LaTeX uses italics in math mode for variables to make them stand out,
but Roman (non-italic) for function names. How is LaTeX to know the dif-
ference between ``sin'' as function name and ``sin'' as the product of
the variables s, i, and n? Use a backslash in front of ``sin'' and other
function names to let LaTeX know that you want the function, not the
product of variables.

Here is a list of function names:


\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

Text Embedded in Displayed Equations


Text can be embedded in displayed equations (in LaTeX) by using \mbox{embedded text}. For exam-
ple, one obtains
by typing
\[ M^\bot = \{ f \in V' : f(m) = 0 \mbox{ for all } m \in M \}.\]
Note the blank spaces before and after the words `for all' in the above example. Had we typed
\[ M^\bot = \{ f \in V' : f(m) = 0 \mbox{for all} m \in M \}.\]
we would have obtained

Fractions and Roots


Fractions of the form

are obtained in LaTeX using the construction


\frac{numerator}{denominator}.
For example, to obtain

one would type


The function $f$ is given by
\[ f(x) = 2x + \frac{x - 7}{x^2 + 4}\]
for all real numbers $x$.
To obtain square roots one uses the control sequence
\sqrt{expression}.
For example, to obtain

one would type


The roots of a quadratic polynomial $a x^2 + bx + c$ with
$a \neq 0$ are given by the formula
\[ \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]
In LaTeX, an nth root is produced using
\sqrt[n]{expression}.
For example, to obtain
in LaTeX, one would type
The roots of a cubic polynomial of the form $x^3 - 3px - 2q$
are given by the formula
\[ \sqrt[3]{q + \sqrt{ q^2 - p^3 }}
+ \sqrt[3]{q - \sqrt{ q^2 - p^3 }} \]
where the values of the two cube roots must are chosen
so as to ensure that their product is equal to $p$.

Fractions
Fractions can be written in two ways: with a diagonal fraction bar or a
horizontal one. Diagonal fraction bars work best in tight places, such as
in a text paragraph or when in a larger fraction.
$a/b$
becomes

The horizontal bar is clearer when you have more room, such as in a for-
mula paragraph. The command is a little more complicated, because
the numerator and denominator are often complicated themselves. A
horizontal bar fraction is written as \frac{numerator}{denominator}.
$$
\frac{a/b-c/d}{e/f-g/h}
$$
becomes

Roots
Use the \sqrt{} command to produce square roots:
$\sqrt{\frac{a}{b}}$
produces
If you need an nth root, use \sqrt[n]{} instead.
$\sqrt[10]{\frac{a}{b}}$
produces

Ellipsis (i.e., `three dots')


Ellipsis (three dots) is produced in mathematics mode using the control sequences \ldots (for dots
aligned with the baseline of text), and \cdots (for dots aligned with the centreline of mathematical for-
mulae). Thus the formula

is obtained by typing
\[ f(x_1, x_2,\ldots, x_n) = x_1^2 + x_2^2 + \cdots + x_n^2 \]
Similarly the formula

is produced using \cdots, by typing


\[ \frac{1 - x^{n+1}}{1 - x} = 1 + x + x^2 + \cdots + x^n \]

Accents in Mathematics Mode


There are various control sequences for producing underlining, overlining and various accents in math-
ematics mode. The following table lists these control sequences, applying them to the letter a:
It should be borne in mind that when a character is underlined in a mathematical manuscript then it is
normally typeset in bold face without any underlining. Underlining is used very rarely in print.
The control sequences such as \' and \", used to produce accents in ordinary text, may not be used in
mathematics mode.

Brackets and Norms


The frequently used left delimiters include (, [ and {, which are obtained by typing (, [ and \{ respec-
tively. The corresponding right delimiters are of course obtained by typing ), ] and \}. In addition |
and || are used as both left and right delimiters, and are obtained by typing | and \| respectively. For
example, we obtain

by typing
Let $X$ be a Banach space and let $f \colon B \to \textbf{R}$
be a bounded linear functional on $X$. The \textit{norm} of
$f$, denoted by $\|f\|$, is defined by
\[ \|f\| = \inf \{ K \in [0,+\infty) :
|f(x)| \leq K \|x\| \mbox{ for all } x \in X \}.\]
Larger delimiters are sometimes required which have the appropriate height to match the size of the
subformula which they enclose. Consider, for instance, the problem of typesetting the following formu-
la:

The way to type the large parentheses is to type \left( for the left parenthesis and \right) for the
right parenthesis, and let LaTeX do the rest of the work for you. Thus the above formula was obtained
by typing
\[ f(x,y,z) = 3y^2 z \left( 3 + \frac{7x+5}{1 + y^2} \right).\]
If you type a delimiter which is preceded by \left then LaTeX will search for a corresponding
delimiter preceded by \right and calculate the size of the delimiters required to enclose the
intervening subformula. One is allowed to balance a \left( with a \right] (say) if one desires: there
is no reason why the enclosing delimiters have to have the same shape. One may also nest pairs of
delimiters within one another: by typing
\[ \left| 4 x^3 + \left( x + \frac{42}{1+x^4} \right) \right|.\]
we obtain

By typing \left. and \right. one obtains null delimiters which are completely invisible. Consider,
for example, the problem of typesetting
We wish to make the vertical bar big enough to match the derivative preceding it. To do this, we
suppose that the derivative is enclosed by delimiters, where the left delimiter is invisible and the right
delimiter is the vertical line. The invisible delimiter is produced using \left. and thus the whole
formula is produced by typing
\[ \left. \frac{du}{dx} \right|_{x=0}.\]

Multiline Formulae in LaTeX


Consider the problem of typesetting the formula

It is necessary to ensure that the = signs are aligned with one another. In LaTeX, such a formula is
typeset using the eqnarray* environment. The above example was obtained by typing the lines
\begin{eqnarray*}
\cos 2\theta & = & \cos^2 \theta - \sin^2 \theta \\
& = & 2 \cos^2 \theta - 1.
\end{eqnarray*}
Note the use of the special character & as an alignment tab. When the formula is typeset, the part of the
second line of the formula beginning with an occurrence of & will be placed immediately beneath that
part of the first line of the formula which begins with the corresponding occurrence of &. Also \\ is
used to separate the lines of the formula.
Although we have placed corresponding occurrences of & beneath one another in the above example, it
is not necessary to do this in the input file. It was done in the above example merely to improve the ap-
pearance (and readability) of the input file.
The more complicated example

was obtained by typing


If $h \leq \frac{1}{2} |\zeta - z|$ then
\[ |\zeta - z - h| \geq \frac{1}{2} |\zeta - z|\]
and hence
\begin{eqnarray*}
\left| \frac{1}{\zeta - z - h} - \frac{1}{\zeta - z} \right|
& = & \left|
\frac{(\zeta - z) - (\zeta - z - h)}{(\zeta - z - h)(\zeta - z)}
\right| \\ & = &
\left| \frac{h}{(\zeta - z - h)(\zeta - z)} \right| \\
& \leq & \frac{2 |h|}{|\zeta - z|^2}.
\end{eqnarray*}
The asterisk in eqnarray* is put there to suppress the automatic equation numbering produced by La-
TeX. If you wish for an automatically numbered multiline formula, you should use \begin{eqnarray}
and \end{eqnarray}.

Sums, Integrals, and Limits


Summations and integrals both have lower and upper
limits, and the commands are similar. Limits usually
have text with an arrow placed below them.
$$
\sum_{k=0}^\infty\frac{(-1)^k}{k+1} = \int_0^1\frac{dx}
{1+x}
$$
produces

$$
\lim_{x\rightarrow 0} \frac{\sin x}{x} = 1
$$
produces

Operators
You will probably not need most of the binary operators
listed here, but it should be a handy reference:
Operato Operato
Command Command
r r
\pm \times

\mp \div
\cdot \ast

\star \dagger

\ddagger \amalg

\cap \cup
\uplus \sqcap
\sqcup \vee

\wedge \oplus

\ominus \otimes

\circ \bullet

\diamond \oslash

\odot \bigcirc

\bigtriangleup \bigtriangledown

\triangleleft \triangleright

\setminus \wr

Relations
Again, here are more relations than you will ever need.
You may want to print this for reference.
Relatio Relatio
Command Command
n n
\le \ge

\ne \sim

\ll \gg

\doteq \simeq

\subset \supset

\approx \asymp

\subseteq \supseteq
\cong \smile

\equiv \frown

\sqsubseteq \sqsupseteq

\propto \bowtie

\in \ni

\prec \succ

\vdash \dashv

\preceq \succeq

\models \perp

\parallel \mid

Negated Symbols
Operato Operato
Command Command
r r
\not< \not>

\not\le \not\ge

\not= \not\equiv

\not\prec \not\succ

\not\preceq \not\succeq

\not\sim \not\simeq

\not\subset \not\supset

\not\subseteq \not\supseteq

\not\approx \not\cong

\not\sqsubseteq \not\sqsupseteq

\not\asymp \notin
More Symbols
Here are some more symbols:
Symbo
Command
l
\aleph

\emptyset

\nabla
\partial
\forall
\exists
\neg
\angle
\therefore
\mathbb{N}

\mathbb{Q}

\mathbb{R}
\mathbb{Z}

Spacing Between Words


LaTeX controls the spacing of your document, trying hard
to break lines in places that are pleasing to the eye. As a
consequence,

1. One blank space is the same as a million blank


spaces.

2. Tabs are treated like blank spaces.

3. Blanks at the end of a line are ignored.

4. A single ``Enter'' is treated like a blank space.


5. More than one ``Enter'' marks the beginning of a
new paragraph.

Fine-Tuning Spacing in Math-Mode


It is possible to adjust the spacing that LaTeX uses in
math mode. (I usually add a little space with \, before
the differential when I write an integral.)

1. \, produces a small space

2. \: produces a medium space

3. \; produces a large space

4. \! produces a small negative space

Double Spacing
There will be times when you will need to submit a draft
that is double-spaced, to permit a grader or editor to
make comments. LaTeX does not explicitly support doing
this, because, well, it looks ugly.

Still: to double-space a paper, put \renewcommand{\base-


linestretch}{2} in your paper's preamble. Give it a try.

Sloppy Line Breaks


LaTeX works very hard to find an optimal line break for
each line of your document. It you are not happy with its
result, surround the offending paragraph with
\begin{sloppypar} and \end{sloppypar} commands. Then
LaTeX will not break words up but rather will allow more
spacing between words in the given paragraph.

Enlarging Pages
LaTeX works very hard to find the best place to break be-
tween pages. If you are unhappy with the result, you can
change it with the following two commands:

1. \newpage will force the start of a new page.

2. \enlargethispage{size} will increase the number of


lines added to a page, where size is a
measurement with units, such as 1in or 2cm.

Hyphenation
There are four different variations on hyphens in LaTeX:
-, --, ---, and $-$.

1. - (a single dash) is for hyphenating words.

2. -- (two dashes) is for ranges of numbers.

3. --- (three dashes) is for an honest-to-goodness


dash between words.

4. $-$ is a minus sign in math mode.


My cousin-in-law lived in Germany in 1995--6;
he speaks French---really, he does. His favorite number
is $-2$.
produces

My cousin-in-law lived in Germany in 1995-6.

He speaks French--really, he does.

His favorite number is .

Notice the difference in appearance of the four varia-


tions.

The LATEX Logo


You can typeset the LATEX logo with the \LaTeX command.
As with most commands, it consumes any space behind
it, so if it isn't at the end of a sentence, use \LaTeX\ in-
stead.

Quotation Marks
Beginning and ending quotation marks differ. In LaTeX,
use `` (usually on the left side of the keyboard) to begin
a quotation and '' (usually on the right side of the key-
board) to end a quotation:
She said ``three''.
produces
She said ``three''.

Changing the Appearance of Words


There are many ways of changing the appearance of
words to add emphasis, such as underlining, boldfacing,
and italicizing. When over-used, these changes can
make a document hard to read, so they should always be
used sparingly.

LaTeX provides underlining, boldfacing, and italicizing,


but studies have shown that italicizing is most effecting
in stressing without distracting.

Use
\underline{phrase}
to underline a phrase,
\textbf{phrase}
to print a phrase in boldface, and
\emph{phrase}
to italicize a phrase.

Tables, Arrays, and Lists

Constructing Arrays
To construct an array, surround the entries with a
\begin{array}{justification} command and an \end{ar-
ray} command. The justification should consist of l for
left justification, c for centered justification, or r for right
justification. Separate column entries by an &, and end

each line with a . If your array is a matrix, you can sur-


round it with large parentheses \left( and \right). For
example:
$$
\left(
\begin{array}{rcl}
\alpha&\beta&\gamma\\
\delta&\epsilon&\zeta\\
\eta&\theta&\iota\\
\end{array}
\right)
$$
produces

Constructing Tables
To construct a table, surround the entries with a
\begin{tabular}{justification} command and an
\end{tabular} command. The justification should consist
of l for left justification, c for centered justification, or r
for right justification. Separate column entries by a &,

and end each line with a . Use \hline to construct a


horizontal line, and separate the l, c, and r's by a | wher-
ever you want a vertical line. For example:
\begin{tabular}{|r|c|l|}
\hline
Right & Center & Left\\
\hline
alpha&beta&gamma\\
delta&epsilon&zeta\\
eta&theta&iota\\
\hline
\end{tabular}
produces
Right Center Left
alph
beta gamma
a
epsilo
delta zeta
n
eta theta iota

Tables
Tables can be produced in LaTeX using the tabular environment. For example, the text
is coded in LaTeX as follows:
The first five International Congresses of Mathematicians
were held in the following cities:
\begin{quote}
\begin{tabular}{lll}
Chicago&U.S.A.&1893\\
Z\"{u}rich&Switzerland&1897\\
Paris&France&1900\\
Heidelberg&Germany&1904\\
Rome&Italy&1908
\end{tabular}
\end{quote}
The \begin{tabular} command must be followed by a string of characters enclosed within braces
which specifies the format of the table. In the above example, the string {lll} is a format specification
for a table with three columns of left-justified text. Within the body of the table the ampersand
character & is used to separate columns of text within each row, and the double backslash \\ is used to
separate the rows of the table.
The next example shows how to obtain a table with vertical and horizontal lines. The table

is coded in LaTeX as follows:


\begin{tabular}{|r|r|}
\hline
$n$&$n!$\\
\hline
1&1\\
2&2\\
3&6\\
4&24\\
5&120\\
6&720\\
7&5040\\
8&40320\\
9&362880\\
10&3628800\\
\hline
\end{tabular}
In this example the format specification {|r|r|} after \begin{tabular} specifies that the table
should consist of two columns of right-justified text, with vertical lines to the left and to the right of the
table, and between columns.
Within the body of the table, the command \hline produces a horizontal line; this command can only
be placed between the format specification and the body of the table (to produce a line along the top of
the table) or immediately after a row separator (to produce a horizontal line between rows or at the bot-
tom of the table).
In a tabular environment, the format specification after \begin{tabular} should consist of one or
more of the following, enclosed within braces { and }:

l specifies a column of left-justified text


c specifies a column of centred text
r specifies a column of right-justified text
p{width} specifies a left-justified column of the given width
| inserts a vertical line between columns
@{text} inserts the given text between columns

A string str of characters in the format specification can be repeated num times using the construction
*{num}{str}. For example, a table with 15 columns of right-justified text enclosed within vertical lines
can be produced using the format specification {|*{15}{r|}}.

If additional vertical space is required between rows of the table, then this can be produced by specify-
ing the amount of space within square brackets after \\. For example, one would use \\[6pt] to sepa-
rate two rows of the table by 6 points of blank space.
A horizontal line in a table from column i to column j inclusive can be produced using \cline{i-j}.
For example \cline{3-5} produces a horizontal line spanning columns 3, 4 and 5 of some table.

A command of the form \multicolumn{num}{fmt}{text} can be used within the body of a table to
produce an entry spanning several columns. Here num specifies the number of columns to be spanned,
fmt specifies the format for the entry (e.g., l if the entry is to be left-justified entry, or c if the entry is
to be centred), and text is the text of the entry.
Many of these features are used in typesetting the table

which is coded in LaTeX as follows:


\begin{tabular}{|l||l|l||l|l|}
\hline
&\multicolumn{2}{l|}{Singular}&\multicolumn{2}{l|}{Plural}\\
\cline{2-5}
&English&\textbf{Gaeilge}&English&\textbf{Gaeilge}\\
\hline\hline
1st Person&at me&\textbf{agam}&at us&\textbf{againn}\\
2nd Person&at you&\textbf{agat}&at you&\textbf{agaibh}\\
3rd Person&at him&\textbf{aige}&at them&\textbf{acu}\\
&at her&\textbf{aici}& & \\
\hline
\end{tabular}

Matrices and other arrays in LaTeX


Matrices and other arrays are produced in LaTeX using the \textbf{array} environment. For example,
suppose that we wish to typeset the following passage:

This passage is produced by the following input:


The \emph{characteristic polynomial} $\chi(\lambda)$ of the
$3 \times 3$~matrix
\[ \left( \begin{array}{ccc}
a & b & c \\
d & e & f \\
g & h & i \end{array} \right)\]
is given by the formula
\[ \chi(\lambda) = \left| \begin{array}{ccc}
\lambda - a & -b & -c \\
-d & \lambda - e & -f \\
-g & -h & \lambda - i \end{array} \right|.\]
First of all, note the use of \left and \right to produce the large delimiters around the arrays. As we
have already seen, if we use
\left) ... \right)
then the size of the parentheses is chosen to match the subformula that they enclose. Next note the use
of the alignment tab character & to separate the entries of the matrix and the use of \\ to separate the
rows of the matrix, exactly as in the construction of multiline formulae described above. We begin the
array with \begin{array} and end it with \end{array}. The only thing left to explain, therefore, is
the mysterious {ccc} which occurs immediately after \begin{array}. Now each of the c's in {ccc}
represents a column of the matrix and indicates that the entries of the column should be centred. If the c
were replaced by l then the corresponding column would be typeset with all the entries left-justified,
and r would produce a column with all entries right-justified. Thus
\[ \begin{array}{lcr}
\mbox{First number} & x & 8 \\
\mbox{Second number} & y & 15 \\
\mbox{Sum} & x + y & 23 \\
\mbox{Difference} & x - y & -7 \\
\mbox{Product} & xy & 120 \end{array}\]
produces

We can use the array environment to produce formulae such as

Note that both columns of this array are set flush left. Thus we use {ll} immediately after
\begin{array}. The large brace is produced using \left\{. However this requires a corresponding
\right delimiter to match it. We therefore use the \emph{null delimiter} \right. discussed earlier.
This delimiter is invisible. We can therefore obtain the above formula by typing
\[ |x| = \left\{ \begin{array}{ll}
x & \mbox{if $x \geq 0$};\\
-x & \mbox{if $x < 0$}.\end{array} \right. \]

Array
The array environment (not to be confused with the array package) is similar to the tabular
but must be within a math environment. This
\begin{math}
\left(
\begin{array}{clrr}
a+b+c & uv & x-y & 27 \\
x+y & w & +z & 363
\end{array}
\right)
\end{math}

produces

Tabular
Tabular output is supported. When you create the environment you specify how many
columns to have and how the contents are to be aligned (use l, c or r to represent each
column with either left, center or right alignment) and where you want vertical lines (use |).
The contents of the columns are separated by a `&' and rows by \\. Here's a simple example
\begin{tabular}{l|c|r}
left & centre & right\\
more left & more centre & more right\\
\end{tabular}
left centre right
more left more centre more right
To draw a full horizontal line, use \hline otherwise draw a line across selected columns using \cline.
The \multicolumn command allows items to span columns. It takes as its first argument the number of
columns to span. The following, more complicated example shows how to use these facilities.
\begin{tabular}{||l|lr||} \hline
\textbf{Veg} & \multicolumn{2}{|c||}{\textbf{Detail}}\\\hline
carrots & per pound & \pounds 0.75 \\ \cline{2-3}
& each & 20p \\ \hline
mushrooms & dozen & 86p \\ \cline{1-1} \cline{3-3}
toadstools & pick your own & free \\ \hline
\end{tabular}
(n.b. the HTML representation below is inaccurate - too many lines)
Veg Detail
carrots per pound £0.75
each 20p
mushrooms dozen 86p
toadstools pick your own free
Tables won't continue on the next page if they're too long. The longtable or supertabular com-
mands are needed to do this. See the Supertabular document for details and examples.
If the text in a column is too wide for the page, LATEX won't automatically text-wrap. Using p{5cm} in-
stead of c, l or r in the tabular line will wrap-around the text in a 5 cm wide column.

There are various packages to assist with table creation. The array package adds some helpful fea-
tures, including the ability to add formatting commands that control a whole column at a time, like so
\begin{tabular}{>{\ttfamily}l>{\scshape}c>{\Large}r}
Text & More Text & Large Text\\
Left & Centred & Right
\end{tabular}
Text MORE TEXT
Large Text
Left CENTRED Right
The rotating package is useful if you have a wide table that you want to display in landscape mode.
You need to put your table inside \begin{sidewaystable} and \end{sidewaystable}.

If you want the table to have a caption and float (float up the page if it's started right near the foot of a
page, for example), use
\begin{table}[htbp]
\begin{tabular}...
...
\end{tabular}
\caption{...}
\end{table}

Derivatives, Limits, Sums and Integrals


The expressions

are obtained in LaTeX by typing \frac{du}{dt} and \frac{d^2 u}{dx^2} respectively. The
mathematical symbol is produced using \partial. Thus the Heat Equation

is obtained in LaTeX by typing


\[ \frac{\partial u}{\partial t}
= h^2 \left( \frac{\partial^2 u}{\partial x^2}
+ \frac{\partial^2 u}{\partial y^2}
+ \frac{\partial^2 u}{\partial z^2} \right) \]
To obtain mathematical expressions such as

in displayed equations we type \lim_{x \to +\infty}, \inf_{x > s} and \sup_K respectively.
Thus to obtain

(in LaTeX) we type


\[ \lim_{x \to +\infty} \frac{3x^2 +7x^3}{x^2 +5x^4} = 3.\]
To obtain a summation sign such as

we type \sum_{i=1}^{2n}. Thus

is obtained by typing
\[ \sum_{k=1}^n k^2 = \frac{1}{2} n (n+1).\]
We now discuss how to obtain integrals in mathematical documents. A typical integral is the follow-
ing:

This is typeset using


\[ \int_a^b f(x)\,dx.\]
The integral sign is typeset using the control sequence \int, and the limits of integration (in this case
a and b are treated as a subscript and a superscript on the integral sign.
Most integrals occurring in mathematical documents begin with an integral sign and contain one or
more instances of d followed by another (Latin or Greek) letter, as in dx, dy and dt. To obtain the cor-
rect appearance one should put extra space before the d, using \,. Thus

and

are obtained by typing


\[ \int_0^{+\infty} x^n e^{-x} \,dx = n!.\]
\[ \int \cos \theta \,d\theta = \sin \theta.\]
\[ \int_{x^2 + y^2 \leq R^2} f(x,y)\,dx\,dy
= \int_{\theta=0}^{2\pi} \int_{r=0}^R
f(r\cos\theta,r\sin\theta) r\,dr\,d\theta.\]
and
\[ \int_0^R \frac{2x\,dx}{1+x^2} = \log(1+R^2).\]
respectively.
In some multiple integrals (i.e., integrals containing more than one integral sign) one finds that LaTeX
puts too much space between the integral signs. The way to improve the appearance of of the integral is
to use the control sequence \! to remove a thin strip of unwanted space. Thus, for example, the multi-
ple integral

is obtained by typing
\[ \int_0^1 \! \int_0^1 x^2 y^2\,dx\,dy.\]
Had we typed
\[ \int_0^1 \int_0^1 x^2 y^2\,dx\,dy.\]
we would have obtained

A particularly noteworthy example comes when we are typesetting a multiple integral such as

Here we use \! three times to obtain suitable spacing between the integral signs. We typeset this
integral using
\[ \int \!\!\! \int_D f(x,y)\,dx\,dy.\]
Had we typed
\[ \int \int_D f(x,y)\,dx\,dy.\]
we would have obtained

The following (reasonably complicated) passage exhibits a number of the features which we have been
discussing:
One would typeset this in LaTeX by typing
In non-relativistic wave mechanics, the wave function
$\psi(\mathbf{r},t)$ of a particle satisfies the
\emph{Schr\"{o}dinger Wave Equation}
\[ i\hbar\frac{\partial \psi}{\partial t}
= \frac{-\hbar^2}{2m} \left(
\frac{\partial^2}{\partial x^2}
+ \frac{\partial^2}{\partial y^2}
+ \frac{\partial^2}{\partial z^2}
\right) \psi + V \psi.\]
It is customary to normalize the wave equation by
demanding that
\[ \int \!\!\! \int \!\!\! \int_{\textbf{R}^3}
\left| \psi(\mathbf{r},0) \right|^2\,dx\,dy\,dz = 1.\]
A simple calculation using the Schr\"{o}dinger wave
equation shows that
\[ \frac{d}{dt} \int \!\!\! \int \!\!\! \int_{\textbf{R}^3}
\left| \psi(\mathbf{r},t) \right|^2\,dx\,dy\,dz = 0,\]
and hence
\[ \int \!\!\! \int \!\!\! \int_{\textbf{R}^3}
\left| \psi(\mathbf{r},t) \right|^2\,dx\,dy\,dz = 1\]
for all times~$t$. If we normalize the wave function in this
way then, for any (measurable) subset~$V$ of $\textbf{R}^3$
and time~$t$,
\[ \int \!\!\! \int \!\!\! \int_V
\left| \psi(\mathbf{r},t) \right|^2\,dx\,dy\,dz\]
represents the probability that the particle is to be found
within the region~$V$ at time~$t$.

Lists
LaTeX provides the following list environments:
• enumerate for numbered lists,

• itemize for un-numbered lists,

• description for description lists

Numbered lists are produced using


\begin{enumerate} ... \end{enumerate}
The items included in the list should be sandwiched between \begin{enumerate} and
\end{enumerate} and should each be preceded by the control sequence \item (which will
automatically generate the number labelling the item). For example, the text

is generated by LaTeX from the following input:


A \emph{metric space} $(X,d)$ consists of a set~$X$ on
which is defined a \emph{distance function} which assigns
to each pair of points of $X$ a distance between them,
and which satisfies the following four axioms:
\begin{enumerate}
\item
$d(x,y) \geq 0$ for all points $x$ and $y$ of $X$;
\item
$d(x,y) = d(y,x)$ for all points $x$ and $y$ of $X$;
\item
$d(x,z) \leq d(x,y) + d(y,z)$ for all points $x$, $y$
and $z$ of $X$;
\item
$d(x,y) = 0$ if and only if the points $x$ and $y$
coincide.
\end{enumerate}
Un-numbered lists are produced using
\begin{itemize} ... \end{itemize}
Thus if we replace \begin{enumerate} and \end{enumerate} in the above input by
\begin{itemize} and \end{itemize} respectively, LaTeX generates an itemized list in which each
item is preceeded by a `bullet':

Description lists (for glossaries etc.) are produced using


\begin{description} ... \end{description}
The items included in the list should be sandwiched between \begin{description} and
\end{description} and should each be preceded by \item[label], where label is the label to be
assigned to each item. For example, the text

is generated by LaTeX from the following input:


We now list the definitions of \emph{open ball},
\emph{open set} and \emph{closed set} in a metric space.
\begin{description}
\item[open ball]
The \emph{open ball} of radius~$r$ about any point~$x$
is the set of all points of the metric space whose
distance from $x$ is strictly less than $r$;
\item[open set]
A subset of a metric space is an \emph{open set} if,
given any point of the set, some open ball of
sufficiently small radius about that point is contained
wholly within the set;
\item[closed set]
A subset of a metric space is a \emph{closed set} if its
complement is an open set.
\end{description}

Producing White Space in LaTeX


To produce (horizontal) blank space within a paragraph, use \hspace, followed by the length of the
blank space enclosed within braces. The length of the skip should be expressed in a unit recognized by
LaTeX. These recognized units are given in the following table:
pt point (1 in = 72.27 pt)
pc pica (1 pc = 12 pt)
in inch (1 in = 25.4 mm)
bp big point (1 in = 72 bp)
cm centimetre (1 cm = 10 mm)
mm millimetre
dd didot point (1157 dd = 1238 pt)
cc cicero (1 cc = 12 dd)
sp scaled point (65536 sp = 1 pt)
Thus to produce a horizontal blank space of 20 mm in the middle of a paragraph one would type
\hspace{20 mm}.
If LaTeX decides to break between lines at a point in the document where an \hspace is specified, then
no white space is produced. To ensure that white space is produced even at points in the document
where line breaking takes place, one should replace \hspace by \hspace*

To produce (vertical) blank space between paragraphs, use \vspace, followed by the length of the
blank space enclosed within braces. Thus to obtain

one should type


This is the first paragraph of some text. It is
separated from the second paragraph by a vertical skip of
10 millimetres.

\vspace{10 mm}

This is the second paragraph.


If LaTeX decides to introduce at a point in the document where a \vspace is specified, then no white
space is produced. To ensure that white space is produced even at points in the document where page
breaking takes place, one should replace \vspace by \vspace*
We now describe certain features of LaTeX relating to blank spaces and paragraph indentation which
will improve the appearance of the final document. Experienced users of LaTeX will improve the ap-
pearance of their documents if they bear these remarks in mind.
First note that, as a general rule, you should never put a blank space after a left parenthesis or before a
right parenthesis. If you were to put a blank space in these places, then you run the risk that LaTeX
might start a new line immediately after the left parenthesis or before the right parenthesis, leaving the
parenthesis marooned at the beginning or end of a line.
LaTeX has its own rules for deciding the lengths of blank spaces. For instance, LaTeX will put an extra
amount of space after a full stop if it considers that the full stop marks the end of a sentence.
The rule adopted by LaTeX is to regard a period (full stop) as the end of a sentence if it is preceded by
a lowercase letter. If the period is preceded by an uppercase letter then LaTeX assumes that it is not a
full stop but follows the initials of somebody's name.
This works very well in most cases. However LaTeX occasionally gets things wrong. This happens
with a number of common abbreviations (as in `Mr.\ Smith' or in `etc.'), and, in particular, in the names
of journals given in abbreviated form (e.g., `Proc.\ Amer.\ Math.\ Soc.'). The way to overcome this
problem is to put a backslash before the blank space in question. Thus we should type
Mr.\ Smith
etc.\ and
Proc.\ Amer.\ Math.\ Soc.
LaTeX determines itself how to break up a paragraph into lines, and will occasionally hyphenate long
words where this is desirable. However it is sometimes necessary to tell LaTeX not to break at a partic-
ular blank space. The special character used for this purpose is ~. It represents a blank space at which
LaTeX is not allowed to break between lines. It is often desirable to use ~ in names where the fore-
names are represented by initials. Thus to obtain `W. R. Hamilton' it is best to type W.~R.~Hamilton. It
is also desirable in phrases like `Example 7' and `the length l of the rod', obtained by typing
Example~7
and
the length~$l$ of the rod.
LaTeX will automatically indent paragraphs (with the exception of the first paragraph of a new
section). One can prevent LaTeX from indenting a paragraph though by beginning the paragraph with
the control sequence \noindent. Thus one obtains

by typing
\noindent
This is the beginning of a paragraph which is not
indented in the usual way. This has been achieved
by placing an appropriate control sequence at the
beginning of the paragraph.
Conversely, the control sequence \indent forces LaTeX to indent the paragraph

Displayed Quotations
Displayed quotations can be embedded in text using the quote and quotation environments
\begin{quote} ... \end{quote}
and
\begin{quotation} ... \end{quotation}.
The quote environment is recommended for short quotations: the whole quotation is indended in the
quote environment, but the first lines of individual paragraphs are not further indented. The input file
Isaac Newton discovered the basic techiques of
the differential and integral calculus, and
applied them in the study of many problems
in mathematical physics. His main mathematical
works are the \emph{Principia} and the \emph{Optics}.
He summed up his own estimate of his work as follows:
\begin{quote}
I do not know what I may appear to the world; but to
myself I seem to have been only like a boy, playing
on the sea-shore, and diverting myself, in now and
then finding a smoother pebble, or a prettier shell
than ordinary, whilst the great ocean of truth lay
all undiscovered before me.
\end{quote}
In later years Newton became embroiled in a bitter
priority dispute with Leibniz over the discovery
of the basic techniques of calculus.
is typeset by LaTeX as follows:

For longer quotations one may use the quotation environment: the whole quotation is indented, and the
openings of paragraphs are then further indented in the normal fashion.

Pre-Formatted Text
A sequence of lines of text can be incorporated unaltered into a LaTeX document (in a fixed-width
`typewriter' font) using the verbatim environment. The lines should be enclosed between \begin{ver-
batim} and \end{verbatim}. This provides a useful way of listing all or part of a computer program.

The control sequence \verb can be used to incorporate a string of characters unaltered into a paragraph
of text (in a `typewriter' font). The string of characters should be enclosed between two instances of
some character that is not included in the string. The whole should then be preceded by the control se-
quence \verb. For example, \verb/\alpha/ produces \alpha.

Including Graphics in Your Document


Graphic File Formats
There are a number of graphics formats out there, such
as:

1. bmp

2. eps

3. gif

4. jpg

5. pdf

6. ps

LaTeX works best with the postscript formats (eps, ps)


which were around when the program was first created.
For the other formats, LaTeX may or may not work; you
would be safer trying PDFLaTeX, which will produce a
PDF document.

Graphics Package
If you are going to include graphics in your document,
you will need to ask LaTeX to use a package of graphics
commands: place \usepackage{graphicx} in the preamble.
Including Graphics Within Your Document
You use the \includegraphics{graphicfile} command to
include your graphic file in your document.

If you wish to control the size of the document, you can


also specify the height and width:
\includegraphics[height=2in, width = 3in]{graphicfile}.

Bibliographies
For large documents requiring a good deal of revision, it
can be difficult to coordinate references in the body of
the document with the bibliography at its end. LaTeX
provides a mechanism for automatically linking citations
with items in the bibliography. Surround the bibliography
with \begin{thebibliography}{9} and \end{thebibliography}.
For each entry in the bibliography, start with \bibitem{la-
bel}, where label is some mnemonic for the reference.

With the bibliography in place, a citation in the body of


the document is made with \cite{label}, where label is
the same as what occurs in the corresponding
\bibitem{label}.

In order to keep track of new references that have been


added, you will often need to run LaTeX twice before pre-
viewing when using \cite.

What is the 9 in \begin{thebibliography}{9} for? It is a


dummy number indicating how many digits to leave
space for in the numbering of the bibliography. If you
have 10-99 references, use \begin{thebibliography}{99}
instead.

Including graphics in a LaTeX document


There are two ways to incorporate images into your LaTeX document, and both use the graphicx
package by means of putting the command \usepackage{graphicx} near the top of the LaTeX file,
just after the documentclass command.
The two methods are
1. include only PostScript images (esp. ``Encapsulated PostScript'') if your goal is a PostScript
document using dvips
2. include only PDF, PNG, JPEG and GIF images if your goal is a PDF document using pdflatex,
TeXShop, or other PDF-oriented compiler.
In all cases, each image must be in an individual 1-image file; no animation files or multipage
documents.

Only PostScript images


Most mathematical/scientific graphics software allows you to save graphics (figures, diagrams, graphs)
in PostScript form; this includes Mathematica, Maple, Matlab, IDL, and xfig (a marvelous X figure-
drawing program). Even bitmap images like JPEG and PNG files can be converted to PostScript form
with programs like ``xv'' or ``convert''.
Where you want a PostScript image to appear, use the \includegraphics command, possibly with scal-
ing or rotation options, e.g.,
\includegraphics{myfig.eps}
\includegraphics[width=60mm]{myfig.eps}
\includegraphics[height=60mm]{myfig.eps}
\includegraphics[scale=0.75]{myfig.eps}
\includegraphics[angle=45,width=52mm]{myfig.eps}
Of course, any of these can be inserted into a figure environment, and/or a centering environment or a
framebox.
Then you must compile the document with latex followed by dvips -Ppdf, which produces a Post-
Script document with embedded PostScript images. You can convert the PostScript document to PDF
using ``ps2pdf'' or ``dvipdf''.

Two characteristics which the component (Encapsulated) PostScript image files must have are
• no file contains more than one page
• each has a valid BoundingBox line
If the PostScript file does not include a bounding box line, you can insert it using the text editor of your
choice.

Only non-PostScript images


The compiler pdflatex (Unix) and TeXShop (Macintosh) convert LaTeX source directly to PDF, and
do not accept PostScript images. Instead, they take PDF images, as well as bitmap pictures in PNG or
JPEG or GIF format. So to use pdflatex, you must convert any PostScript images to one of these
other forms. For photos, JPEG is best. For other bitmap images, PNG is best. For non-bitmap images
(e.g., graphs, drawings, stuff with text and symbols) it is best to convert to PDF, using the command
epstopdf (in the usual TeX bin directory, e.g., /usr/local/tex/bin/epstopdf). The command
unix> epstopdf myfig.eps
produces the file myfig.pdf, which can then be used in the command
\includegraphics{myfig.pdf}. for compilation with pdflatex or TeXShop.
The possible \includegraphics options with PDF/PNG/JPEG images are much the same as with
PostScript, e.g.,
\includegraphics{myfig.pdf}
\includegraphics[width=60mm]{myfig.png}
\includegraphics[height=60mm]{myfig.jpg}
\includegraphics[scale=0.75]{myfig.pdf}
\includegraphics[angle=45,width=52mm]{myfig.jpg}
With PNG or JPEG you should specify an explicit width or height rather than "scale",
since bitmap images have no intrinsic size, nothing corresponding to Bounding Box infor-
mation, although graphicx seems to use 72 pixels per inch as a default size for bitmap im-
ages.

Working with Graphics: In LaTeX


Working with graphics has been greatly simplified with PDF LaTeX. Using the graphicx package,
you can incorporate graphics in pdf, jpg, png or tif(with one f) formats. If you don't specify the file ex-
tension, it will look for and use whichever one is available. In the preamble, put
\usepackage{graphicx}

to load the graphicx package. To load the graphics file itself in the main body, put
\includegraphics{filename}.

PDF LaTeX produces a pdf document that is ready for printing or posting to the network, and readily
previewed using Acrobat. Hence no special previewer is needed to view graphics other than the one
most of us have already. You can also add an option like height=.., width=.., scale=.., or angle=.. to
specify a height, width, scaling factor, or angle of rotation to manage the size and orientation of your
graphics, eg
\includegraphics[height=3in]{filename}.

The graphics package provides a standard way to include graphics in LaTeX documents using encap-
sulated postscript (eps) format. To use the graphics package, as usual, you need to include the follow-
ing statement in the preamble of your LaTeX document.
\usepackage{graphics}

If you have an image in eps format named, say myimage.eps, in a location accesible to your LaTeX
typsetter, then the simplest way to include the image in your document is to put the following statement
at the place you want the image to appear in your document.
\includegraphics{myimage.eps}

However, this will only work if your image is just the right size. Especially, if you create your eps file
as I have suggested in EPS Format, you will want to crop and scale your image to make it useable.
Suppose for example that when you printed your image to a file, the image was 2 inches by 2 inches
and situated in the upper left hand corner of an 8.5 by 11 letter size sheet with half inch margins at the
top and sides. Then you would crop the image by adding a * after includegraphics, and specifying the
coordinates of the lower left corner of the image followed by the coordinates of the upper right corner
of the image where the origin, (0,0), is situated at the lower left corner of the letter size sheet. Thus the
statement you want to use is
\includegraphics*[0.5in,8.5in][2.5in,10.5in]{myimage.eps}

After cropping, your image may still be too big or too small for your purposes. By putting the image in
a scalebox, and specifying a scale factor, you can magnify or shrink your image. If for example we
wanted to reduce myimage to a one inch square, we would use the following statement to shrink it by a
factor of 0.5
\scalebox{0.5}{\includegraphics*[0.5in,8.5in][2.5in,10.5in]{myimage.eps}}

Although not usually a good idea, you can specify two scale factors, the second, in square brackets
instead of curly braces, would control the vertical stretching while the first, in curly braces as above,
would determine the horizontal stretching.
Finally, once you have cropped and scaled your image, you can put it in a figure, minipage, or picture
environment or some other kind of box to get the image to appear at a suitable place in your printed
document.

Graphics
Graphics can be produced
 from within LaTeX - pictures can be drawn in a picture environment, but you'll find
graph paper handy (xfig can create code for the picture environment). The pstricks
packages (see page ) is far more powerful.
 by any program that can produce Postscript files (for LaTeX) or JPEG, PNG andPDF (for
pdflatex).

Whatever graphics you want to add, you should use the figure environment so that LATEX can cope
sensibly with situations where, for example, you attempt to insert near the bottom of a page a graphic
that's half a page high. The figure environment will float the graphic to the top or bottom of the page,
or on the next page, with preferences that you can provide.
h here
t top of page
b bottom of page
p on a page with no text
Putting ! as the first argument in the square brackets will encourage LATEX to do what you say, even if
the result's sub-optimal. See the online hints about floats in LaTeX for further details.
\begin{figure}[htbp]
\vspace{0.5in}
\caption{0.5 inch of space}
\end{figure}

Figure 1: 0.5 inch of space

It's possible to have more than one graphic in a figure. See the example later on.

Scaling, rotation, clipping, wrap-around and shadows


The graphicx package includes routines that are useful even without graphics.
\reflectbox{Reflect} produces and \resizebox{3cm}{0.2cm}{Stretched} produces . To
scale imported graphics, use some optional arguments
\includegraphics[width=5cm,height=10cm]{yourfile.ps}
would rescale the postscript so that it was 5cm wide and 10cm high. To make the picture 5cm
wide and scale the height in proportion use
\includegraphics[width=5cm]{yourfile.ps}
To rotate anticlockwise by the specified number of degrees, use
\includegraphics[angle=150]{yourfile.ps}
These options can be combined - note that order matters. The following examples demonstrate how to
combine these features and how to use the subfig package to have more than one graphic in a figure.

Figure 2: Tigers

\centering
\begin{figure}[hbtp]
\includegraphics[height=40mm]{/export/ghostfonts/tiger.eps}
\includegraphics[angle=120, height=20mm]{/export/ghostfonts/tiger.eps}
\caption{Tigers}
\end{figure}
% remember to do \usepackage{subfig} at the top of the document!
\begin{figure}[hbtp]
\centering
\subfloat[Small]% \quad on the next line adds spacing
{\includegraphics[height=30mm]{/export/ghostfonts/crest.eps}}\quad
\subfloat[Medium]
{\includegraphics[width=40mm]{CUni3.eps}}\quad
\subfloat[Large]
{\includegraphics[height=50mm]{/export/ghostfonts/crest.eps}}
\caption{3 crests}
\end{figure}

Figure 3: 3 crests

[Small] [Medium]

[Large]
To clip the postscript image use the viewpoint argument. The following fragment would display only
part of the image. The viewport coordinates are in the same units as the bounding box.
\begin{figure}[htbp]
\includegraphics[viewport=200 400 400 600,width=5cm,clip]%
{CUniv3.eps}
\end{figure}
% Use the floatflt package
\begin{floatingfigure}[l]{4cm}
\includegraphics[width=2cm]{/export/ghostfonts/crest.eps}
\caption{Using floatingfigure}
\end{floatingfigure}

Figure 4: Using floatingfigure

4cm

The floatflt package lets you insert a graphic and have the text wrap around it. You can
provide 2 arguments to the floatingfigure command: the first (l or r) selects whether you
want the graphic to be on the left or right of the page. The 2nd argument gives the width of
the graphic. Not all text will flow perfectly around (for example, verbatim text fails, as
illustrated below) so check the final output carefully.
Using the fancybox package gives you access to \shadowbox, \ovalbox, \Ovalbox and \doublebox
commands, which can be used with text or with graphics. For example, \shadowbox{shadow pack-
age} produces shadow package and
\ovalbox{\includegraphics[height=10mm]{CUni3.eps}}
produces . Unfortunately, the fancybox package as
supplied suppresses the table of contents. The locally produced contentsfancy-
box solves this, but may introduce graphics problems.

Colored text
Commands that control foreground and background colors need
\usepackage[dvips]{color}
after the \documentclass line but before \begin{document}.
 \textcolor{colorname}{text} writes text in a color which can be specified by name
(black, white, red, green, blue or a color name you've defined), RGB components,
or grayscale.
 \colorbox{colorname}{text} writes text in a box with a colored background.

 \fcolorbox{framecolor}{boxcolor}{text} writes text in a colored frame.

 \pagecolor{colorname} sets the color of the page's background.

 \definecolor{colorname}{color specification} lets you define new color names.


\definecolor{gold}{rgb}{0.85,.66,0}
This is in \textcolor{red}{red} and this box is \colorbox{gold}{gold}.
Text color can be set using RGB values
(\textcolor[rgb]{0,1,0}{like so}), or \textcolor[gray]{0.2}{shades}
\textcolor[gray]{0.5}{of} \textcolor[gray]{0.8}{grey}.
produces
This is in red and this box is gold. Text color can be set using RGB values (like so), or shades of grey.

Matlab and LaTeX


Matlab has some support for LaTeX production. For example
latex('(sin(x)+2*x+3*x^2)/(5*x+6*x^2)','math.tex')
puts the LaTeX representation of the expression into a file called math.tex. Type
``help latex" inside matlab for details.

Pictures
LATEX has some graphics capabilities. It's much better to import an encapsulated postscript
file. See the LATEX Maths and Graphics document for more details.
\newcounter{cms}
\setlength{\unitlength}{1mm}
\begin{picture}(50,39)
\put(0,7){\makebox(0,0)[bl]{cm}}
\multiput(10,7)(10,0){5}{\addtocounter
{cms}{1}\makebox(0,0)[b]{\arabic{cms}}}
\put(15,20){\circle{6}}
\put(30,20){\circle{6}}
\put(15,20){\circle*{2}}
\put(30,20){\circle*{2}}
\put(10,24){\framebox(25,8){a box}}
\put(10,32){\vector(-2,1){10}}
\multiput(1,0)(1,0){49}{\line(0,1){2,5}}
\multiput(5,0)(10,0){5}{\line(0,1){3,5}}
\thicklines
\put(0,0){\line(1,0){50}}
\multiput(0,0)(10,0){6}{\line(0,1){5}}
\end{picture}

PStricks
The pstricks packages lets you create graphical effects from within LaTeX. See the PSTricks
Tutorial for details. Here are just a few examples to show you its power.
\begin{pspicture}(0,-5)(6,0)
\pscircle*[linecolor=black](0,-4){1}
\pscircle*[linecolor=darkgray](.5,-4){1}
\pscircle*[linecolor=gray](1,-4){1}
\pscircle*[linecolor=lightgray](1.5,-4){1}

\pscurve(-1,-5)(2,0)(3,-2)(5,0)
\psbezier[linecolor=darkgray]%
(-1,-4)(2,0)(3,-2)(5,0)
\psgrid[gridwidth=.4pt, subgriddiv=2,
subgridwidth=.2pt, gridcolor=lightgray,
gridlabels=0](0,-3)(-1,-4)(5,0)%
\end{pspicture}
\begin{pspicture}(0,0)(6,4)
\psset{linecolor=white,linewidth=0pt}
\pstextpath{\pscurve(0,0)(2,2)(4,0)(6,2)}%needs the textpath package
{\textit{Adapted From} ``\TeX{} Unbound'', Alan Hoenig, OUP, 1998 }
\end{pspicture}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy