Getting Started With LaTeX - 1
Getting Started With LaTeX - 1
By David R. Wilkins
2nd Edition
Copyright David R. Wilkins 1995
In addition to the HTML pages listed below, the primer Getting Started with LaTeX is also available in
the form of a LaTeX2e input file, and as a DVI file (which can for example be viewed on X-terminals
using some World-Wide Web browsers including NCSA Mosaic.)
• Introduction to LaTeX
o TeX and LaTeX
o A Typical LaTeX Input File
o Characters and Control Sequences
• Producing Simple Documents using LaTeX
o Producing a LaTeX Input File
o Producing Ordinary Text using LaTeX
o Blank Spaces and Carriage Returns in the Input File
o Quotation Marks and Dashes
o Section Headings in LaTeX
o Changing Fonts in Text Mode
o Accents and other Symbols used in Text
o Active Characters and Special Symbols in Text
• Producing Mathematical Formulae using LaTeX
o Mathematics Mode
o Characters in Mathematics Mode
o Superscripts and Subscripts
o Greek Letters
o Mathematical Symbols
o Changing Fonts in Mathematics Mode
o Standard Functions (sin, cos etc.)
o Text Embedded in Displayed Equations
o Fractions and Roots
o Ellipsis (i.e., `three dots')
o Accents in Mathematics Mode
o Brackets and Norms
o Multiline Formulae in LaTeX
o Matrices and other arrays in LaTeX
o Derivatives, Limits, Sums and Integrals
• Further Features of LaTeX
o Producing White Space in LaTeX
o Lists
o Displayed Quotations
o Pre-Formatted Text
o Tables
o The Preamble of the LaTeX Input file
o Defining your own Control Sequences in LaTeX
o Theorem Environments
D.R. Wilkins
School of Mathematics
Trinity College, Dublin
([email protected])
TeX and LaTeX
TeX is a computer program for typesetting documents, created by D. E. Knuth. It takes a suitably
prepared computer file and converts it to a form that may be printed on many kinds of printers,
including dot-matrix printers, laser printers and high-resolution typesetting machines. A number of
well-established publishers now use TeX in order to typeset books and mathematical journals.
Simple documents that do not contain mathematical formulae or tables may be produced very easily:
the body of the text is typed in essentially unaltered (though observing certain rules regarding quotation
marks and punctuation dashes). Typesetting mathematics is somewhat more involved, but even here
TeX is comparatively straightforward to use when one considers the complexity of some of the
formulae that it is required to typeset.
LaTeX, written by L. B. Lamport, is one of a number of `dialects' of TeX. It is particularly suited to the
production of long articles and books, since it has facilities for the automatic numbering of chapters,
sections, theorems, equations etc., and also has facilities for cross-referencing. It is probably one of the
most suitable version of LaTeX for beginners to use.
This introduction describes basic features of LaTeX2e, released in 1994. Further information on LaTeX
is to be found in the 2nd edition of LaTeX User's Guide and Reference Manual by Leslie Lamport, and
in The LaTeX Companion by Michel Goossens, Frank Mittelbach and Alexander Samarin.
The LaTeX program reads in text from a suitably prepared input file, and creates a `DVI file' which
encodes information on the fonts to be used and the positioning of the characters on the printed page.
There are many programs available that can translate the `DVI file' into page description languages
such as `PostScript', or convert it into the format appropriate for previewing the document on a
computer screen or printing it out on dot-matrix printers.
Here is an example of a typical LaTeX input file:
\documentclass[a4paper,12pt]{article}
\begin{document}
One may readily verify that if $f$ and $g$ are continuous
functions on $D$ then the functions $f+g$, $f-g$ and
$f.g$ are continuous. If in addition $g$ is everywhere
non-zero then $f/g$ is continuous.
\end{document}
Most characters on the keyboard, such as letters and numbers, have their usual meaning. However the
characters
\{}$^_%~#&
are used for special purposes within LaTeX. Thus typing one of these characters will not produce the
corresponding character in the final document. Of course these characters are very rarely used in
ordinary text, and there are methods of producing them when they are required in the final document.
In order to typeset a mathematical document it is necessary to produce a considerable number of
special mathematical symbols, and to change fonts where appropriate. Mathematical documents often
contain arrays of numbers or symbols (matrices) and other complicated expressions. These are
produced in LaTeX using control sequences. Most control sequences consist of a backslash \ followed
by a string of (upper or lower case) letters. For example, \delta, \emph and \to are control sequences:
the control sequence \delta produces the greek letter , the control sequence \emph, when followed by
text enclosed within braces, will cause that text to be emphasized (usually by typesetting it in an italic
font), and the control sequence \to (or \rightarrow) produces the arrow .
There is another type of control sequence which consists of a backslash followed by a single character
that is not a letter. Examples of control sequences of this type are \{, \" and \$.
The `braces' { and } are used for grouping: the characters they enclose are treated as a single `group',
which can be specified as an `argument' of a control sequence such as \emph, or as a superscript or
subscript in a mathematical formula. Control sequences included in such a group apply only to the
contents of the group.
The special character $ is used when embedding mathematical expressions in paragraphs of ordinary
text in order to change into and out of `mathematics mode'.
The special characters ^ and _ are used in mathematical expressions to produce superscripts and
subscripts respectively.
The special character % is used to introduce `comments' into the input file that do not appear in the
final document: all characters occuring after % on any line of the input file are ignored by LaTeX.
The special character # is used to specify arguments in definitions of control sequences. The special
character & is used when typesetting tables in order to separate entries in different columns.
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}
To produce a simple document using LaTeX one should create a LaTeX input file, beginning with a
\documentclass command and the \begin{document} command, as described above. The input file
should end with the \end{document} command, and the text of the document should be sandwiched
between the \begin{document} and \end{document} commands in the manner described below.
If one merely wishes to type in ordinary text, without complicated mathematical formulae or special
effects such as font changes, then one merely has to type it in as it is, leaving a completely blank line
between successive paragraphs. You do not have to worry about paragraph indentation: LaTeX will
automatically indent all paragraphs with the exception of the first paragraph of a new section (unless
you take special action to override the conventions adopted by LaTeX)
For example, suppose that we wish to create a document containing the following paragraphs:
To create this document using LaTeX we use the following input file:
\documentclass[a4paper,12pt]{article}
\begin{document}
\end{document}
Having created the input file, one then has to run it through the LaTeX program and then print it out the
resulting output file (known as a `DVI' file).
LaTeX treats the carriage return at the end of a line as though it were a blank space. Similarly LaTeX
treats tab characters as blank spaces. Moreover, LaTeX regards a sequence of blank spaces as though it
were a single space, and similarly it will ignore blank spaces at the beginning or end of a line in the
input file. Thus, for example, if we type
This is
a
silly
example of LaTeX input
with many spaces.
It follows immediately from this that one will obtain the same results whether one types one space or
two spaces after a full stop: LaTeX does not distinguish between the two cases.
Any spaces which follow a control sequence will be ignored by LaTeX.
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.
(Here the control sequence \LaTeX is used to produce the LaTeX logo.)
A blank space should not occur in the input file after a left parenthesis or before a right parenthesis.
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.
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}
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:
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}.
#$%&_{}
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:
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
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