LaTeX Input Manual
LaTeX Input Manual
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}
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.
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}
*A space following a control sequence may be obtained by preceding the space with
a backslash \. For example, the sentence *
is obtained by typing
\LaTeX\ is a very powerful computer typesetting program.
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 lengths, known as `hyphens', `en-dashes'
and `em-dashes'. Hyphens are obtained in LaTeX by typing -, en-dashes by typing --
and em-dashes by typing ---.
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.
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}
\section*{Section Headings}
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)
The sizes of fonts used in LaTeX can be determined and changed by means of the
control sequences \tiny, \scriptsize, \footnotesize, \small, \normalsize, \
large, \Large, \LARGE, \huge and \HUGE:
Command Declaration
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}.
Active Characters and Special Symbols in Text
# $ % & \ ^ _ { } ~
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:
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:
To produce (vertical) blank space between paragraphs, use \vspace, followed by the
length of the blank space enclosed within braces. Thus to obtain
3) 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.
4) The special character ~ represents a blank space at which LaTeX is not allowed to
break between lines. It is often desirable to use ~ in names where the forenames 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.
5) One can prevent LaTeX from indenting a paragraph though by beginning the
paragraph with the control sequence \noindent.
Lists:
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).
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
indented in the quote environment, but the first lines of individual paragraphs are not
further indented.
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{verbatim} 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 sequence \verb. For example, \verb/\
alpha/ produces \alpha.
Tables
Tables can be produced in LaTeX using the tabular environment. For example, the text
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 bottom of the table).
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 specifying the amount of space within square brackets after \\. For
example, one would use \\[6pt] to separate 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.
We describe the options available in LaTeX for specifying the overall style of a
document.
A LaTeX document should begin with a \documentclass command and any text to be
printed must be included between \begin{document} and \end{document} commands.
The \begin{document} command is often preceded by commands that set the page-style
and set up user-defined control sequences.
The syntax of the \documentclass command is as follows. The command begins with \
documentclass and ends with the names of one of the available styles, enclosed in
braces. The available styles are article, report, book and letter. Between the ``\
documentclass'' and the name of the document style, one may place a list of options.
These options are separated by commas and the list of options is enclosed in square
brackets (as in the above example). The options available include the following:
11pt
Specifies a size of type known as eleven-point, which is ten percent larger than
the ten-point type normally used.
12pt
Specifies a twelve-point type size, which is twenty percent larger than ten-point.
twocolumn
Produces two-column output.
a4paper
This ensures that the page is appropriately positioned on A4 size paper.
Pages will be automatically numbered at the bottom of the page, unless you specify
otherwise. This can be done using the \pagestyle command. This command should
come after the \documentclass command and before the \begin{document} command.
This command has the syntax \pagestyle{option}, where the option is one of the
following:
plain
The page number is at the foot of the page. This is the default page style for the
article and report document styles.
empty
No page number is printed.
headings
The page number (and any other information determined by the document style)
is put at the top of the page.
myheadings
Similar to the headings pagestyle, except that the material to go at the top of the
page is determined by \markboth and \markright commands (see the LaTeX
manual).
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
LaTeX also allows you to use \( and \) to mark the beginning and the end respectively
of a mathematical formula embedded in text. However this use of \( ... \) is only
permitted in LaTeX: other dialects of TeX such as Plain TeX and AmSTeX use $ ... $.
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 \] .
All the characters on the keyboard have their standard meaning in mathematics mode,
with the exception 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
\# \$ \% \& \_ \{ \} .
Subscripts and superscripts are obtained using the special characters _ and ^ respectively.
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 superscripts (where a superscript is placed on
a superscript) and double subscripts.
Greek Letters:
Here are the control sequences for the standard forms of the lowercase Greek letters:-
Upper case Greek letters are obtained by making the first character of the name upper
case. Here are the control sequence for the uppercase letters:---
``Large'' Operators:
Binary Operations:
Relations:
Negated Relations:
Arrows:
Openings:
Closings:
Alternative Names:
Mathematics Mode:
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
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
All the characters on the keyboard have their standard meaning in mathematics mode,
with the exception 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.
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 superscripts (where a superscript is
placed on a superscript) and double subscripts. ?
(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 typesetting 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).
There is also a `calligraphic' font available in mathematics mode. This is obtained using
the control sequence \mathcal. This font can only be used for uppercase letters. These
calligraphic letters have the form
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 quantities c, o, s, e, c and A and typeset the formula
accordingly.
\sqrt{expression}.
\sqrt[n]{expression}.
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 formulae).
Accents in Mathematics Mode
There are various control sequences for producing underlining, overlining and various
accents in mathematics mode. The following table lists these control sequences, applying
them to the letter a:
The control sequences such as \' and \", used to produce accents in ordinary text, may
not be used in mathematics mode
The frequently used left delimiters include (, [ and {, which are obtained by typing (,
[ and \{ respectively. 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.
Larger delimiters are sometimes required which have the appropriate height to match the
size of the sub formula which they enclose. 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.
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 sub formula. 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}.\]
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 appearance (and readability) of the input file.
The more complicated example
Matrices and other arrays are produced in LaTeX using the \textbf{array} environment.
For example, suppose that we wish to typeset the following passage:
\[ \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
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. \]
The expressions
in displayed equations we type \lim_{x \to +\infty}, \inf_{x > s} and \sup_K
respectively.
is obtained by typing
\[ \sum_{k=1}^n k^2 = \frac{1}{2} n (n+1).\]
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 correct appearance one should put extra space before the d, using
\,. Thus
and
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 the integral is to use the control sequence \! to remove a thin strip of
unwanted space. Thus, for example, the multiple 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
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: