Latex N
Latex N
Latex N
Gavin Maltby
November 1992
Contents
i
2.4.24 The letter document style . . . . . . . . . . . . . . . . . . . . . . 34
2.4.25 Common pitfalls; Error messages . . . . . . . . . . . . . . . . . . . 34
2.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
ii
List of Tables
iii
Chapter 1
TEX is well known to be the typesetting package, and a vast cult of TEX lovers has evolved.
But to the beginning TEX user, or to someone wondering if they should bother changing
to TEX, it is often not clear what all the fuss is about. After all, are not both WordPerfect
and Ventura Publisher capable of high quality output? Newcomers have often already seen
what TEX is capable of (many books, journals, letters are now prepared with TEX) and so
expect to find a tremendously powerful and friendly package. In fact they do, but that fact
is well hidden in one’s initial TEX experiences. In this chapter we describe a little of what
makes TEX great, and why other packages cannot even begin to compete. Be warned that
a little patience is required—TEX’s virtues are rather subtle to begin with. But when the
penny drops, you will wonder how you ever put up with anything different.
1
ultimate precision was limited because of the mechanical nature of things and by time
considerations. TEX prepares a page in an analogous manner (putting your characters
and formulae into “boxes” which are then “glued” together to form the page), but has
the advantage of enormous precision because placement calculations are performed by
computer. Indeed, TEX’s internal unit (the “scaled point”) is about one-hundredth of the
wavelength of natural light!
“But conventional word processors run on computers , too”, you object. Yes, but
their fundamental limitation is that they try to “keep up” with you and “typeset” your
document as you type. This means that it can only make decisions at a local level (eg, it
decides where to break a line just as you type the end of the line). TEX’s secret is that
it waits until you have typed the whole document before it typesets a single thing! This
means that TEX can make decisions of a global nature in order to optimise the aesthetic
appeal of your document. It has been taught what looks good and what looks bad (having
been given a measure of the “badness” of various possibilities) and makes choices for your
document that are designed to make it “minimally bad”.
But TEX’s virtues run much deeper than that, which is just as well because it is possible
to get satisfactory, though imperfect, results from some word processors. One of TEX’s
strongest points is its ability to typeset complicated formulae with ease. Not only does
TEX make hundreds of special symbols easily accessible, it will lay them out for you in
your formulae. It has been taught all the spacing, size, font, . . . conventions that printers
have decided look best in typeset formulae. Although, of course, it doesn’t understand any
mathematics it knows the grammar of mathematics—it recognises binary relations, binary
operators, unary operators, etc. and has been taught how these parts should be set. It is
consequently rather difficult to get an equation to look bad in TEX.
Another advantage of compiling a document after it is typed is that cross-referencing
can be done. You can label and refer back to chapters, sections, tables etc. by name rather
than absolute number, and TEX will number and cross-reference these for you. Similarly,
it will compile a table of contents, glossary, index and bibliography for you.
Essential to the spirit of TEX is that it formats the document whilst you just take care
of the content, making for increased productivity. The cross-referencing just mentioned
is just part of this. Many more labour-saving mechanisms are provided for through style
files. These are generic descriptions of classes of documents, teaching TEX just how each
class likes to be formatted. This is taught in terms of font preferences, default page sizes,
placement of title, author, date, etc. For instance, a paper style file could teach TEX
that when typesetting a theorem it should embolden the part that states the theorem
number and typeset the text of the theorem statement in slanted Roman typeface (as
in many journals). The typist simply provides and indication that a theorem is being
stated, and then types the text of the theorem without bothering to choose any fonts or
do any formatting—all that is done by the style file. Style files exist for all manner of
document—letters, articles, papers, books, proceedings, review articles, and so on.
In addition to style files, there are macro packages. A macro is just a definition of a
new TEX command in terms of existing ones. Don’t think small when you think of macros!
When typing a document that has a lot of repetition in it, say the same expression is used
2
again and again in different different equations, you can define a macro in your document
to abbreviate that expression. But macros can teach TEX how to typeset all sorts of
complicated structures, not just parts of an equation. Many macro packages (files that
are just collections of definitions) have been written to teach TEX all sorts of applications.
There are specialist maths packages (AMS-TEX, AMS-LaTEX), general purpose packages
(LaTEX), packages for setting tree diagrams, Feynmann diagrams, languages like Chinese,
Arabic and Ancient Greek, orchestral scores, and many, many more. All these are freely
available, a spin-off of the giant TEX cult.
Another facet of the design of TEX allows it to use practically any output device. In
fact, TEX doesn’t talk to any printers, screens, phototypesetters at all! Instead, when a
document is compiled a device independent (.dvi) is produced—TEX does not compile
with any particular output device in mind. Printer drivers are then invoked on this .dvi
file and, in consultation with the font data for that printer, produce output suitable for
the particular device. You can choose an HP Laserjet driver, or an Apple LaserWriter
driver, or a dot matrix driver etc. All use the same .dvi file as input (and remember
the material in there is set to enormous accuracy) and attempt to image that file on the
particular device as faithfully as possible. If you are using a top of the line laser printer or
phototypesetter, then TEX’s massive internal precision will not be wasted. Alternatively,
a dot matrix printer will give a coarse approximation of the ideal image that is suitable
only for proof-reading. In addition to portability, these .dvi files help ensure that there
are very few printing surprises when you move from one device to another: how many
times has your favourite word-processor made you reformat a document when you wish to
change printers?
There are many other motivations one could cite for the superiority of TEX. But it is
time that we started to get our hands dirty. One last comment: TEX was not designed to
supplant secretaries and professional printers—it was designed to aid them in their work
and, in the words of the TEX designer Donald Knuth, allow them to “go forward and
create masterpieces of the publishing art”.It also allows those who generate the material
to be typeset—mathematicians, physicists, computer scientists, etc—to prepare their own
documents in a language that is intimately linked to the language we use for writing such
material.
The novice reader will still have no idea of what a TEX source file looks like. Indeed,
why do we keep referring to it as a source file? The fact of the matter is that TEX is
essentially a programming language. Just as in any compiled language (e.g., Pascal, C)
one prepares a source file and submits it to the compiler which attempts to produce an
object file (.dvi file in the TEX case). To learn TEX is to learn the command syntax of
the commands that can be used in the source file.
3
of how to get from there to a printout are given. Those details are left to site-specific
documents.
The average user loses little in using TEX on, say, a PC rather than on a bigger machine.
Indeed, compilation times on the new PCs begin to rival those on a Sun Sparc Station 2 (no
slouch). Running on top of DOS can cause memory problems when very large documents
are being prepared. That aside, the quality of the document is not affected because of
the careful design of TEX—whether you work on a a machine with massive floating point
precision or a modest XT the .dvi files produced on compilation will be identical; and
when those files are submitted to printer equivalent printer drivers (say for an HP LaserJet
III attached to a Sun in one case and a PC in the other) the output will be identical
because the font information they draw on is identical.
By the nature of TEX most time is spent editing the source document (before submitting
it for compilation). No special interface is necessary here, you just use your favourite text
editor (perhaps customising it to enhance TEXnical typing. Thus TEX user interfaces are
usually small and simple, often even missing. One frequently uses TEX at command line
level, just running the editor, compiler etc. as you need them. Sometimes a TEXshell
program is present, which runs these for you when you choose various menu options.
Whatever the interface, there are just a few basic steps to preparing a document:
2. Glance through the material you have to type, and decide what definitions might be
made to save you a lot of time. Also, decide on the overall structure of the prospective
document (e.g., will the largest sectional unit be a chapter or a part?). If you are
going to compose as you type, then pause a moment to think ahead and plan the
structure of your document. The importance of this step cannot be overstressed, for
it makes clear in your mind what you want from TEX.
3. Prepare your input file, specifying only the content and the logical structure (parts,
sections, theorems,...) thereof and forgetting about formatting details.
4. Submit your input, or source, file to the TEX compiler for compilation of a .dvi file.
5. If the compiler finds anything in your source file strongly objectionable, say incorrect
command syntax, then return to editing.
7. Go back to editing your document until glaring errors have been taken care of.
8. Make a printout of your compiled document, and check for those errors that you
failed to notice on the screen.
4
Performing these steps may be effected through typing at the system prompt (barebones
technique) or through choosing menu options in a TEXshell program. The latter will
probably provide some conveniences to make your life easier.
If you think this sounds like a lot of work, it is time that you consult with the TEX
spirit! Sure your first couple of tries may be hesitant, but before long you’ll find that you
can take less time to prepare a document on TEX than on any other package.
5
Chapter 2
6
preprint style and the paper will appear completely different with no other changes to the
source code! To create their style file, a journal just needed to tweak the standard AMS
prepint style: for instance, the original preprint style places author addresses at the very
end of a paper; If a journal wishes this to appear on the first page then they just modify
their in-house version of the style file, and the change will be effected without having to
change the file submitted by the author.
LaTEX was written for more general usage. It lacks some of the mathematical finesse
inherited by AMS-TEX from the vast experience of the AMS technical staff, but more than
makes up for this in its ability to enhance the typesetting of letters, books, poetry, etc.
LaTEX also scores high points for its enhanced command syntax.
With AMS-TEX and LaTEX being released at around the same time (1984–1985), there
were born many AMS-TEX literate but LaTEX illiterate users, and conversely. LaTEX was
easier to learn because of its more friendly syntax, and also provided powerful cross-
referencing commands that AMS-TEX did not. So the AMS commissioned another project
to furnish LaTEX users with the additional power of AMS-TEX while not compromising the
LaTEX command syntax or cross-referencing commands. This resulted in the AMS-LaTEX
macro package and associated style file for submission to journals.
That is why we will kick off our TEX careers with LaTEX! It is easier to learn and provides
many conveniences, and the user who requires additional mathematical typesetting prowess
can easily move on to AMS-LaTEX. Much of what we say will be true for TEX itself, but we
shall regard LaTEX as the lowest common-denominator. By far the majority of LaTEX and
AMS-LaTEX users will never have to learn “raw” TEX, for they will be shielded from direct
exposure by the numerous powerful macro packages. In the rare case that something way
out of the ordinary is required, the local TEX guru can be consulted.
7
not once forced a new line up until this point in the present document.
11pt chooses 11-point as the default font size for the document, instead of the default
10-point.
titlepage applies to the article style only, causing the title and abstract to appear on a page
each.
In fact there are many, many more document style options but we won’t mention any
more here.
8
2.4 Preparing a non-mathematical document
We assume that you have read the local guides to TEX at your site and have decided which
system environment you want to work in. There you have been shown how to perform the
steps required to produce a printed document from a LaTEX source file.
9
Words within a sentence are ended by spaces. One space between words is equiv-
alent to any number. We are only interested in separating one word from the next,
not in formatting the space between them. For these purposes, pressing Return at
the end of a line and starting a new word on the next line just serves to separate
words, not to cut a line short. The end of a sentence is indicated by a period followed
by one or more spaces.
The end of a paragraph is indicated by leaving a blank line. All this means that
we can type without too much regard for layout, and the typesetter will sort things
out for us.
Perhaps you would like to try running LaTEX on the above input. Consult your local
guide for details.
Note that we have learned more than just how LaTEX recognises words, sentences and
paragraphs. We’ve also seen how to specify our choice of document style and how to tell
LaTEX where our document begins and ends. Any material that is to be printed must lie
somewhere between the declaration of \begin{document} and that of \end{document}.
Definitions that are to apply to the entire document can be made before the declaration
of the document beginning. The specification of document style must precede all other
material.
In future examples we won’t explicitly display the commands that select document style
and delimit the start and end of the document. But if you wish to try any of the examples,
don’t forget to include those commands. The article document style will do for most of
our examples. Of course, the preceding example looks not at all like an article because it
is so short and because we specified no title or author information.
Most of what you need to know to type regular text is contained in the example above.
When you consider that by far the majority of any document consists of straight text, it
is obvious that LaTEX makes this fabulously straightforward. LaTEX will do all the routine
work of formatting, and we simply get on with the business of composing.
LaTEX does more than simply choose pleasing line breaks and provide natural spacing
when setting a paragraph. Remember we said that TEX has inherited the knowledge of
generations of professional printers—well part of that knowledge includes being on the
look-out for ligatures. These are combinations of letters within words which should be
typeset as a single special symbol because they will “clash” with each if this is not done.
Have a look at these words
flight, flagstaff, chaff, fixation
and compare them with these
flight, flagstaff, chaff, fixation
See the difference? In the first set I let LaTEX run as it usually does. In the second I
overruled it somewhat, and stopped it from creating ligatures. Notice how the ‘fl’, ‘ff’, and
‘fi’ combinations are different in the two sets—in the former they form a single symbol (a
ligature) and in the latter they are comprised of two disjoint symbols. There are other
combinations that yields ligatures, but we don’t have to bother remembering any of them
because LaTEX will take care of these, too.
10
Notice, too, that LaTEX has been taught how to hyphenate the majority of words. It
will hyphenate a word if it feels that the overall quality of the paragraph will be improved.
For long words it has been taught several potential hyphenation positions.
LaTEX also goes to a lot of trouble to try to choose pleasing page breaks. It avoids
“widows”, which are single lines of a paragraph occurring by themselves at either the
bottom of a page (where it would have to be the first line of a paragraph) or at the top of
a page (where it would have to be the last). It also “vertically justifies” your page so that
all pages have exactly the same height, no matter what appears on them. As testimony to
the success of the pagebreaking algorithm, I have (to this point) not once chosen a page
break in this document.
2.4.2 Punctuation
Typists have a convention whereby a single space is left after a mid-sentence comma, and
two spaces are left after a sentence-ending period. How do we enforce this if LaTEX treats
a string of spaces just like a single one? The answer, unsurprisingly, is that we don’t.
To have a comma followed by the appropriate space, we simply
type a comma follows by at least one space. To end a sentence
we type a period with at least one following space. No space will
be inserted if we type a comma or period followed straight away
by something other than a space, because there are times when
we won’t require any space, i.e., we do what comes narurally.
will produce
To have a comma followed by the appropriate space, we simply type a comma
follows by at least one space. To end a sentence we type a period with at least one
following space. No space will be inserted if we type a comma or period followed
straight away by something other than a space, because there are times when we
won’t require any space, i.e., we do what comes naturally.
LaTEX will produce suitable space after commas, periods, semi-colons and colons, excla-
mation marks, question marks etc. if they are followed by a space. In stretching a line to
justify to the right margin, it also knows that space after a punctuation character should
be more “stretchable” than normal inter-word space and that space after a sentence-ending
period should be stretched more than space after a mid-sentence comma. TEX knows the
nature of punctuation if you stick to the simple rules outlined here. As we’ve already said,
those rules tell LaTEX how to distinguish consecutive words, sentences, phrases, etc.
Actually, there is more to ending sentences than mentioned above. Since LaTEX cannot
speak English, it works on the assumption that a period followed by a space ends a sentence
unless the period follows a capital letter. This works most of the time, but can fail. To get
a normal inter-word space after a period that doesn’t end a sentence, follow the period by
a control space—a \ (a \ character followed by a space or return). Very rarely, you will
have to force a sentence to end after a period that follows a capital letter (remember that
LaTEX assumes this doesn’t end a sentence). This is done by preceding the period with a
\@ command (you can guess from the odd syntax that this is rarely needed).
11
It’s time we saw some examples of this. After all, this is our first experience of control
symbols (don’t worry, there are many more to come).
We must be careful not to confuse intra-sentence periods
with periods that end a sentence, i.e.\ we must remember
that our task is to describe the sentence structure. Periods
that the typesetter requires a little help with typically result
>from abbreviations, as in etc.\ and others. We have to work
somewhat harder to break a sentence after a capital letter,
but that shouldn’t bother us to much if we keep up our intake
of vitamin E\@. All this goes for other sentence-ending
punctuation characters, so I could have said vitamin E\@!
Fortunately, these are rare occurrences.
results in
We must be careful not to confuse intra-sentence periods with periods that end a
sentence, i.e. we must remember that our task is to describe the sentence structure.
Periods that the typesetter requires a little help with typically result ¿from abbrevi-
ations, as in etc. and others. We have to work somewhat harder to break a sentence
after a capital letter, but that shouldn’t bother us to much if we keep up our intake
of vitamin E. All this goes for other sentence-ending punctuation characters, so I
could have said vitamin E! Fortunately, these are rare occurrences.
Quotation marks is another area where LaTEX will do some work for us. Keyboards
have the characters ‘, ’, and " but we want to to have access to each of ‘, ’, “, and ”. So
we proceed like this:
‘\LaTeX’ is no conventional word-processor, and
to to get quotes, like ‘‘this’’, we type repeated
‘ and ’ characters. Note that modern
convention is that ‘‘punctuation comes after
the closing quote character’’.
12
Hyphens are typed as you’d hope, just by typing a - at the point in the word that
you want a hyphen. Don’t forget that LaTEX takes care of hyphenation that is required
to produce pretty linebreaks. You only type a hyphen when you explicitly want one to
appear, as in a combination like “inter-college”.
An endash is the correct dash to use in indicating number ranges, as in “questions 1–3”.
To specify an endash you type two consecutive dashes on the keyboard, as in 1--3.
An emdash is a punctuation dash, used at the end of a sentence—I tend to use them
too much. To specify an emdash you type three consecutive dashes on the keyboard, as in
“. . . a sentence---I tend to. . . ”.
Theorems 1--3 concern the semi-completeness
of our new construct---in the case that it
satisfies the first axiom.
yields
Theorems 1–3 concern the semi-completeness of our new construct—in the case
that it satisfies the first axiom.
2.4.3 Ties
When you always remember to use ties, you know that you are becoming TEXnically
inclined. Ties are used to prevent LaTEX from breaking lines at certain places. LaTEX will
always choose line breaks that result in the most aesthetically pleasing paragraph as judged
by its stringent rules. But because LaTEX does not actually understand the material it is
setting so beautifully, it can make some poor choices.
A tie is the character ~. It behaves as a normal interword space in all respects except
that the line-breaking algorithm will never break a line at that point. Thus
Dr. Seuss should be typed as Dr.~Seuss
for this makes sure that LaTEX will never leave the ‘Dr’ at the end of one line and put the
‘Seuss’ at the beginning of the next.
One should try to get in to the habit of typing ties first-time, not after waiting to see
if LaTEX will make a poor choice. This will allow you to make all sorts of changes to your
text without ever having to go back and insert a tie at a point that has migrated to the
end of a line from the middle of a line as a result of those changes. Remember, of course,
that the line-breaks
Here are some more examples of places where you should remember to place ties.
13
Chapter~10 Donald~E. Knuth
Appendix~C width~2
Figure~1 function~f
Theorem~2 1,~2, or~3
Lemmas 3 and~4 equals~5
produces
It is not 100% straightforward to typeset the characters $ & % { }, but given
the enormous convenience of the use they are normally reserved for this is a small
price to pay.
14
• we have met the control space symbol \ before,
• \@ was a control symbol that told told LaTEX that the very next period did really
end the sentence,
• \LaTeX is a control word that tell LaTEX to insert its own name at the current point,
• \S inserts a ¶ symbol,
• \chapter{The beginning} causes LaTEX to start a new chapter with name “The
Beginning”, number it in sequence, typeset the chapter heading in a suitable font,
and make an entry in the table of contents,
• \frac{a+b}{c+d} sets the given two argument as a fraction, doing most of the dirty
work for us: a+b
c+d
,
√
• \sqrt[5]{a+b} typesets the fifth-root of a + b, like this: 5 a + b. The 5 is in square
brackets instead of braces because it is an optional argument and could be ommited
all together (giving the default of square root),
Mandatory arguments are given enclosed by braces, and optional arguments enclosed
by square brackets. Each command knows how many arguments to expect, so you don’t
have to provide any indication of that.
We have actually jumped the gun a little. The above examples include examples of
mathematical typesetting, and we haven’t yet seen how to tell LaTEX that it is typesetting
maths as opposed to some other random string of symbols that it doesn’t understand
either. We’ll come to mathematical typesetting in good time.
15
We need to dwell on a TEXnicality for a moment. How does LaTEX know where the
name of a control sequence ends? Will it accept both \pounds3 and \pounds 3 in order to
set £3, and will \emWalrus and \em Walrus both be acceptable in order to get Walrus?
The answer is easy when you remember that a control word consists only of alphabetic
characters, and a control symbol consists of exactly one nonalphabetic character.
So to determine which control sequence you typed, LaTEX does the following:
This has one important consequence: The character in the input file immediately after
a control symbol will be “seen” by LaTEX, but any space following a control word will be
discarded and never processed. This does not affect one much if you adopt the convention
of always typing a space after a control sequence name.
There is a rare circumstance where this necessitates a little extra work and thought,
which we illustrate by example:
If we type a control word like \LaTeX in the running text
then we must be cautious, because the string of spaces that
come after it will be discarded by the \LaTeX\ system.
16
emboldened or emphasised are very large, and it would be a nuisance to have to enclose
such an argument in argument-enclosing braces.
To delimit the area of text over which one of these commands has effect (its scope) we
make that text into what is called a group. Groups are used extensively in LaTEX to keep
effects local to an area, rather than affecting the whole document. Apart from enhancing
usability, this also in a sense protects distinct parts of a document from each other.
The LaTEX commands for changing type style are given in table 2.1, and those for
changing type size are given in table 2.2. Commands for selecting fonts other than these
are not discussed here.
\rm Roman \it italic \sc Capitals
\em Emphasised \sl slanted \tt typewriter
\bf boldface \sf sans serif
Table 2.1: Commands for selecting type styles
Each of the type style selection commands selects the specified style but does not change
the size of font being used. The default type style is roman (you are reading a roman style
font now). To change type size you issue one of the type size changing commands in
table 2.2, which will select the indicated size in the currently active style. The release of
LaTEX 3.0 (the present version is 2.09) will see the New Font Selection Scheme in place as
a standard feature. This makes font matters much easier to deal with.
size default (10pt) 11pt option 12pt option
\tiny 5pt 6pt 6pt
\scriptsize 7pt 8pt 8pt
\footnotesize 8pt 9pt 10pt
\small 9pt 10pt 11pt
\normalsize 10pt 11pt 12pt
\large 12pt 12pt 14pt
\Large 14pt 14pt 17pt
\LARGE 17pt 17pt 20pt
\huge 20pt 20pt 25pt
\Huge 25pt 25pt 25pt
Table 2.2: LaTEX size-changing commands.
The point-size option referred to in table 2.2 is that specified in the \documentstyle
command issued at the beginning of the input file. Through it you select that base (or
default) font for your document to be 10, 11, or 12 point Roman. If no options are specified,
the default is 10-point Roman. The table shows, for instance, that if I issue a \large in this
document for which I chose the 12pt document style option the result will be a 14-point
Roman typeface.
We mentioned that to restrict the scope of a type-changing command we will set the
text to be affected off in a group. Let’s look at an example of this.
17
When we want to {\em emphasise\/} some text we
use the {\tt em} command, and use grouping to
restrict the scope. We can change font {\large sizes}
in much the same way. We can also obtain {\it italicised},
{\bf emboldened}, {\sc Capitals} and {\sf sans serif} styles.
When we want to emphasise some text we use the em command, and use grouping
to restrict the scope. We can change font sizes in much the same way. We can also
obtain italicised, emboldened, Capitals and sans serif styles.
Notice how clever grouping allows us to do all that without once having to use \rm or
\normalsize.
One more thing slipped into that example—an italic correction \/. This is a very small
amount of additional space that we asked to be inserted to allow for the change from
sloping emphasised text to upright text, because the interword space has been made to
look less substantial from the terminal sloping character. One has to keep an eye open for
circumstances where this is necessary. See the effect of omitting an italic correction after
the emphasised text earlier in this paragraph.
One might expect, by now, that LaTEX would insert an italic correction for us. But
there are enough occasions when it is not wanted, and there is no good rule for LaTEX to
use to decide just when to do it for us. So the italic correction is always left up to the
typist.
2.4.7 Accents
LaTEX provides accents for just about all occasions. They are accessed through a variety
of control symbols and single-letter control worlds which accept a single argument—the
letter to be accented. These control sequences are detailed in table 2.3.
Thus we can produce ó by typing \’{o}, ǎ by typing \v{a}, and Pál Erdös by typing
P\’{a}l Erd\"{o}s. Take special care when accenting an i or a j, for they should lose
their dots when accented. Use the control words \i and \j to produce dotless versions of
these letters. Thus the best way to type to type ĕxı̆gent is \u{e}x\u{\i}gent.
18
\‘{o} ò (grave accent)
\’{o} ó (acute accent)
\^{o} ô (circumflex or “hat”)
\"{o} ö (umlaut or dieresis)
\~{o} õ (tilde or “squiggle”)
\={o} ō (macron or “bar”)
\.{o} ȯ (dot accent)
\u{o} ŏ (breve accent)
\v{o} ǒ (háček or “check”)
\H{o} ő (long Hungarian umlaut)
\t{oo} oo (tie-after accent)
\c{o} o̧ (cedilla accent)
\d{o} o. (dot-under accent)
\b{o} o (bar-under accent)
¯
Table 2.3: Control sequences for accents
19
2.4.9 Commenting your document
It is handy to be able to make comments to yourself in the source file for a document.
Things like “I must rewrite this section” and “This is version 3 of the document” are
likely. It would also be useful to be able to make the compiler ignore certain parts of the
document at times. For this purpose we can use the % character, for all text on an input
line that is after a % which is not part of an occurrence of the control symbol \% is discarded
by the compiler. Here is an example:
There was a 100\% turnout today,
an all-time record. %perhaps I should check this claim!
%Indeed, there are lots of unsubstantiated claims here!
This made for an extremely productive session.
will yields
There was a 100% turnout today, an all-time record. This made for an extremely
productive session.
2.4.10 Footnotes
Inserting footnotes is easy—LaTEX will position and number them for you. You just indicate
exactly where the footnote marker should go, and provide the text of the footnote. The
footnote text will be placed at the bottom of the present page in a somewhat smaller
font, and be separated from the main text by a short horizontal rule1 to conform with
convention. The footnote in the last line was typed like this:
...rule\footnote{See for yourself! It’s easy ...work.} to conform
No space was typed between the rule and the \footnote, because we want the footnote
marker to appear right next to the last letter of the word.
Multiple footnotes2 are obtained just by using the \footnote command again and
again.
2.4.11 Topmatter
We declare the title and author information using the \title and \author commands,
each of which accept a single argument. Multiple authors are all listed in the argument of
\title, separated by \and’s. The \date command can be used to date a document. After
we have declared each of these, we issue a \maketitle command to have them typeset for
us. In the book and article document styles this will result in a separate page; in the
article style the “top matter” will be placed at the top of the first page. The style files
determine the placement and the choice of font.
1
See for yourself! It’s easy when you don’t have to do any work.
2
Here is another footnote
20
\title{A Thought for the Day}
\author{Fred Basset \and Horace Hosepipe}
\date{November 1992}
\maketitle
This topmatter must appear after the \begin{document} and before any other printing
material.
21
\subsection{Sectioning commands}
and that was all that was required to get the numbered section name and the table of
contents entry.
There are occasions when you want a heading to have all the appearance of a particular
sectioning command, but shouldn’t be numbered as a section in its own right or produce
a table of contents entry. This can be achieved through using the *-form of the command,
as in \section*{...}. We’ll see that many LaTEX commands have such a *-form which
modify their behaviour slightly.
Not only will LaTEX number your sectional units for you, it will compile a table of
contents too. Just include the command \tableofcontents after the \begin{document}
command and after the topmatter that should precede it.
2.4.14 em environment
We start with a very simple environment, one which provides an alternative to the \em
command. Remember that \em does not accept an argument; it applies to everything
3
See section 2.4.6
22
within its scope as dictated by the group within which it is used. This can be tricky if we
wish to emphasise a large amount of text, for we may forget a group-delimiting brace and
so upset the entire grouping structure of our document. In cases where we fear this might
happen, we can proceed as follows.
\begin{em}
We must always be careful to match our group-delimiting
braces correctly. If the braces in a document are unevenly
matched then \LaTeX\ will become confused because we will
have, in effect, indicated different scopes than we
intended for commands.
\end{em}
23
Horace smiled and retaliated:
You can mock the non-WYSIWYG nature of TEX all you like. You don’t understand that that
is precisely what makes TEX enormously more powerful than that lame excuse for a typesetter
you use. And I’ll bet that from start to finish of preparing a document I’m quicker than you
are, even if you do type at twice the speed and have the so-called advantage of WYSIWYG.
In your case, what you see is all you get!
and then continued with composing his masterpiece of the typesetting art.
That is a much more readable manner of presenting Horace’s piece of mind than em-
bedding it within a regular paragraph. The quote environment was responsible for the
margins being indented on both sides during the quote. This example has also been used
to show how the commands that begin and end an environment restrict the scope of com-
mands issued within that environment: The \em at the beginning of the quote did not
affect the text following the quote. We have also learned here that if we use \em within al-
ready emphasised text, the result is roman type—and we don’t require an italic correction
here because the final letter of ‘all’ was not sloping to the right.
The quotation environment is used in just the same way as the quote environment
above, but it is intended for setting long quotations of several paragraphs. It would be
suitable for quoting a few paragraphs from the text of some speech, for instance. LaTEX
treats the given text just like normal text that it has to set into paragraphs, except that
it indents the margins a little.
24
Roses are red
Violets are blue
I think TEX is great
And so will you!
Roses are still red
Violets are still blue
I’m schizophrenic
And so am I.
In this case we left a blank line after the environment, so the new text was
regarded as starting a new paragraph.
25
We can stop \LaTeX\ from justifying each line to both the
left and the right margins.
\begin{flushright}
The {\tt flushright} environment is\\
used for text with an even right margin\\
and a ragged left margin.
\end{flushright}
\begin{flushleft}
and the {\tt flushleft} environment is\\
used for text with an even left margin\\
and a ragged right margin.
\end{flushleft}
One must be wary not to lapse into “word-processing” mode when using these environ-
ments. Remember that pressing return at the end of a line in the input file does not serve
to end the current line there, but just to indicate the end of another word. We have to use
the \\ command to end a line.
26
\begin{verbatim}
In the verbatim environment we can type anything
we like.
So we don’t need to look out for uses of %, $, & etc,
nor will control sequences like \newline have any
effect.
\end{verbatim}
The only thing that cannot be typed in the verbatim environment is the sequence
\end{verbatim}. You might notice that I still managed to simulate that control sequence
above. One can always get what you want in TEX, perhaps with a little creativity.
If we want only to simulate a few typed words, such as when I say to use \newline
to start a new line, then the \verb command is used. This command has a slightly odd
syntax, pressed upon it by the use for which it was intended. It cannot accept an argument,
because we may want to simulate typed text that is enclosed by {braces}. What one does
is to choose any character that is not in the text to be simulated, and use a pair of these
characters as “argument delimiters”. I usually use the @ or " characters, as I rarely have
any other uses for them. Thus
use % to obtain a % sign
is typed as
use \verb"\%" to obtain a \% sign
27
expected to use the optional argument there).
Remember that \item is used to separate list items; it does not accept the list item as
an argument.
\begin{itemize}
\item an item is begun with \verb@\item@
\item if we don’t specify labels, then
\LaTeX\ will bullet the items for us
\item I indent lines after the first in the
input file, but that is just to keep things
readable. As always, \LaTeX\ ignores additional
spaces.
Lists can also be embedded within one another, for they are just environments and
we said that environments have this property. Remember that we must nest them in the
correct order. We demonstrate with the following list, which also shows how to use the
enumerate environment.
28
\noindent I still have to do the following things:
\begin{enumerate}
\item Sort out LAN accounts for people on the course
\begin{itemize}
\item Have new accounts created for those not already
registered on the LAN
\item Make sure all users have a personal directory
on the data drive
\item Give read and scan rights to users in the \TeX\
directories
\item Add users to the appropriate LAN print queues
\end{itemize}
\item Have a \TeX\ batch file added to a directory that
is on a public search path
\item Finish typing these course notes and proof-read them
\item Photocopy and bind the finished notes
\end{enumerate}
See how I lay the source file out in a readable fashion. This is to assist myself, not
LaTEX.
The description environment is, unsurprisingly, for making lists of descriptions.
\begin{description}
\item[\tt itemize] an environment for setting itemised lists.
\item[\tt enumerate] an environment for setting numbered lists.
\item[\tt description] an environment for listing descriptions.
\end{description}
29
Note that the scope of the \tt commands used in the item labels was restricted to the
labels.
In the format line I chose the longest entry ¿from each of the prospective columns. I
lined some of the \> commands up in the source just to keep things readable.
Remember that excess spaces are ignored. LaTEX sets the \killed line normally and
sees where the tab stops requested will be needed in the typeset text. Note also that
commands given within the tabbing environment are local to the current item.
Actually, we use the above approach in the case that we require uniformly tabbed
columns. The format line is not compulsory, and we can define tab stops dynamically. See
if you can make sense of the following.
\begin{tabbing}
Entry in position 1,1 \= Entry 1,2 \= Entry 1,3\\
Entry in position 2,1 \> Entry 2,2 \> Entry 2,3\\
Entry 3,1 \= Entry 3,2 \> Entry 3,3\\
Entry 4,1 \> Entry 4,2 \> Entry 4,3
\end{tabbing}
30
which produces
The are additional commands that can be used within the tabbing environment to
achieve special effects, but we won’t be discussing them here.
31
A | typed in the tabular environment’s argument causes a vertical line to be drawn
at the indicated position and extending for the height of the entire table. An \hline given
in the environment draws a horizontal line extending the width of the table to be drawn at
the vertical position at which the command is given. A \cline{i-j} draws a line spanning
columns i to j, at the vertical position at which the command is given. A repeated line-
drawing command causes a double line to be drawn. We illustrate line drawing in tables by
putting some lines into our first table. We will type this example in a somewhat expanded
form, trying to make it clear why the lines appear where they do.
\begin{tabular}{|l|l|r|r|l|}
\hline
\bf Student name & \bf Number & \bf Test 1 & \bf Test 2 & \bf Comment\\
\hline
F. Basset & 865432 & 78 & 85 & Pleasing\\
\hline
H. Hosepipe & 829134 & 5 & 10 & Improving\\
\hline
I.N. Middle & 853931 & 48 & 47 & Can make it\\
\hline
\end{tabular}
32
LaTEX size changing commands
Style option 10pt (default) 11pt 12pt
\footnotesize 8pt 9pt 10pt
\small 9pt 10pt 11pt
\large 12pt 12pt 14pt
h means that the object should be placed here if there is room, so that things will appear
in the same order as in the source file,
t means that the object can be placed at the top of the of a text page, but no earlier than
the present page.
b means that the object can be placed at the bottom of a text page, but no earlier than
the present page.
p means that the object should be set on a page of floats that consists only of tables and
figures.
To leave space for a figure that will inserted by some other means at a later date, we
can use the \vspace command:
33
\begin{figure}[htbp]
\vspace{9.5cm}
\caption{An artists impression}
\end{figure}
Including graphics files prepared with drawing packages is possible, but beyond the
scope of this introduction.
34
\documentstyle[12pt]{letter}
\begin{document}
\address{(Underneath) Lion Bridge\\
Midway down Commercial Road\\
Pietermaritzburg\\
3200}
\signature{F. Basset\\
Public nuisance}
\opening{Kind Sir/Madam}
\closing{Yours anxiously}
\end{letter}
\end{document}
35
! Undefined control sequence.
1.683 this is going to be {\bold
very} messy.
?
That not so bad! The line beginning with ! tells us that we have tried to used a control
sequence that was not known to LaTEX; the 1.683 tells us that the error occurred on line
683 of the source file; and the error message is split over two lines with the break occurring
at the point where LaTEX detected a problem.
But suppose we try the following
\begin{tabular}{llrrl}
Student name & Number & Test 1 & Test 2 & Comment\\
F. Basset & 865432 & 78 & 85 & Pleasing\\
H. Hosepipe & 829134 & 5 & 10 & Improving\\
I.N. Middle & 853931 & 48 & 47 & Can make it
i.e., we omit to provide the \end{tabular} that delimits the end of the environment.
Not having been told that the environment is supposed to be concluded, LaTEX will try to
set the text of the next paragraph as a table item—and will scream blue murder when it
finds that it doesn’t conform to the syntax demanded.
LaTeX error. See LaTeX manual for explanation.
Type H <return> for immediate help.
! \begin{tabular} ended by \end{document}.
\@latexerr ...diate help.}\errmessage {#1}
Now that’s informative! Actually it is if we agree to ignore all but the the error
indication line (the one beginning with the !) and the line telling us where LaTEX noticed
that all was not well (the one beginning 1.58 in this case). The rest of the error message
you can regard as being for your local TEX wizard to sort your problem out if you are unable
to after consulting the manuals. Tough as it looks, we can decipher this message straight
away: the error indicator line tell us that a tabular environment was ended incorrectly
(in this case by an \end{document}).
TEX error messages aren’t all that bad once you’ve made enough errors to get used
36
to a few! Most can be avoided through careful preparation of the source file. Typing
accurately and knowledge of the command syntax is a good start, but there are some other
precautions that make good sense:
1. Even if LaTEX is happy with free-form input, try to lay your input file out as regularly
and logically as possible. See our examples of environments for formats to adopt.
2. It is important that all group delimiters be properly matched, i.e., braces and \begin{}. . . \end{}
must come in pairs. A good habit to fall in to is to always type such things in pairs
and then move the cursor back between them and type the intervening material.
3. Don’t forget command arguments when they are mandatory. Always ask yourself
what a particular commands needs from you in order to make the decisions that are
required of it.
4. Remember the 10 characters that are specially reserved for commenting, table item
separation, etc.
5. When we look at mathematical typesetting in the next chapter, we will see that the
same principles apply there.
6. Try to use a text editor that has a TEX mode, or at least one that will match brackets
for you.
2.5 Summary
We have learned pretty much all we need to know in order to prepare non-mathematical
documents. There has been quite a lot of material, all told, but we’re fortunate that the
average document requires only a fraction of what we’ve listed here. Furthermore, we’ll
find that what we’ve learned equips us with a good deal of the framework needed for
mathematical typesetting.
The important thing to extract from this chapter is some feel for what I termed the
“spirit of TEX” at the chapter beginning. I cannot emphasise enough the importance of
getting your mind out of “word processing” mode and into “typesetting” mode. Always
keep uppermost in your mind the task at hand: you are to describe the logical content
of the document to LaTEX, so furnishing it with enough information to perform all the
formatting for you.
Many of the earlier sections of this chapter will become trivially easy to you after
just a little experimentation with LaTEX. The best way to learn the syntax of the more
complicated environments is to use them—try typesetting the examples, for instance. It is
important that you come to terms with the tabular environment, for its syntax is typical
of many of the mathematical constructs that we will use.
If you have not already done so, then now is the time to try preparing some documents
of your own. Try including all the material from this chapter, for that is the best way to
37
remember it all. When the initial lack of familiarity wears off, you’ll find that LaTEX is
really a whole lot friendlier and easier to use than you expected.
We must also recognise that there is a lot more to some of the command than detailed
here. Some accept optional argumnets that were not mentioned, others have more options
than we considered. And even once we have a full description of each command, there is
still much to be learned for there is much that can be achieved through creative use of
some of the environments.
38
Chapter 3
The last chapter taught us a good deal of what we need to know in order to prepare quite
complicated non-mathematical documents. There are still a number of useful topics that
we have not covered (such as cross-referencing), but we’ll defer discussion of those until
a later chapter. In the present chapter, we’ll learn how LaTEX typesets mathematics. It
should come as no surprise that LaTEX does most of the work for us.
3.1 Introduction
In text-only documents we saw that our task was to describe the logical components of
each sentence, paragraph, section, table, etc. When we tell LaTEX to go into mathematical
mode, we have to describe the logical parts of a formula, matrix, operator, special symbol,
etc. TEX has been taught to recognize a binary operation, a binary relation, a variable, an
operator that expects limits, and so on. We just need to supply the parts that make up
each of these, and TEX will take care of the rest. It will leave appropriate space around
operators, italicise variables, set an operator name in roman type, leave the correct space
after colons, place sub- and superscripts in the correct positions (based on what it is you’re
working with), choose the correct typesizes, . . . the list of things it has been taught is
enormous. When you want to revert to setting normal text again, you tell LaTEX too leave
maths mode and go back into the mode it was in (paragraphing mode).
LaTEX cannot be expected to perform these mode shifts itself, for it is not always clear
just when it is mathematics that has been typed. For example, should an isolated letter
a in the input file be regarded as a word (as in the definite article) or a mathematical
variable (as in the variable a). There are no reliable rules for LaTEX to make such decisions
by, so the begin-math and end-math mode switching is left entirely to you.
The symbol $ is specially reserved1 by LaTEX as the “math shift” symbol. When LaTEX
starts setting a document it is in paragraphing mode, ready to set lines of the input file into
paragraphs. It remains in this mode until it encounters a $ symbol, which shifts LaTEX
into mathematical mode. It now knows to be on the look-out for the components of a
1
See section 2.4.4
39
mathematical expression, rather than for words and paragraphs. It reads everything up to
the next $ sign in this mathemtical mode, and then shifts back to paragraphing mode (i.e.
the mode it was in before we took it in to maths mode).
You must be careful to balance your begin-math and end-math symbols. It is often
a good idea to type two $ symbols and then move back between them and type the
mathematical expression. If the math-shift symbols in a document are not matched, then
LaTEX will become confused because it will be trying to set non-mathematical material as
mathematics.
For those who find having the same symbol for both math-begin and math-end con-
fusing or dangerous, there are two control symbols that perform the same operations: the
control symbol \( is a begin-math instruction, and the control symbol \) is an end-math
instruction. Since it is easy to “lose” a $ sign when typing a long formula, a math environ-
ment is provided for such occasions: you can use \begin{math} and \end{math} as the
math-shift instructions. Of course, you could just decide to use $ and take your chances.
Let’s have a look at some mathematics.
\LaTeX\ is normally in paragraphing mode, where
it expects to find the usual paragraph material. Including
a mathematical expression, like $2x+3y - 4z= -1$, in the
paragraph text is easy. \TeX\ has been taught to recognize
the basic elements of an expression, and typeset them appropriately,
choosing spacing, positioning, fonts, and so on.
Typing the above expression without entering maths
mode produces the incorrect result: 2x+3y - 4z= -1
1. All letters that are not part of an argument to some control sequence will be italicised.
Arguments to control sequences will be set according to the definition of the command
used. So typing $f(x)>0 for x > 1$ will produce
40
instead of the expression
f (x) > 0 for x > 1
that we intended. Numerals and punctuation marks are set in normal roman type
but LaTEX will take care of the spacing around punctuation symbols, as in
$f(x,y) \geq 0$
which produces
f (x, y) ≥ 0 .
2. Even a single letter can constitute a formula, as in “the constant a”. To type this
you enter $a$ in your source file. If you do not go in to maths mode to type the
symbol, you’ll get things like “the constant a”.
3. Some symbols have a different meaning when typed in maths mode. Not only do
ordinary letters become variables, but symbols such as - and + are now interpreted
as mathematical symbols. Thus in maths mode - is no longer considered a hyphen,
but as a minus sign.
4. LaTEX ignores all spaces and carriage returns when in maths mode, without exception.
So typing something like the constant$ a$ will produce “the constanta”. You
should have typed the constant $a$. LaTEX is responsible for all spacing when in
maths mode, and (as in paragraphing mode) you have to specially ask to have spacing
changed. Even if LaTEX does ignore all spaces when in maths mode you should (as
always in TEX) still employ spaces to keep your source file readable.
The above means that, at least for most material, a typist need not understand the
mathematics in order to typeset it correctly. And even if one does understand the math-
ematics, LaTEX is there to make sure that you adhere to accepted typesetting conventions
(whether you were aware of their existence or not).
So one could type either
$f(x, y) = 2 (x+ y)y/(5xy - 3 )$
or
There are some places where this can go wrong. For instance, if we wish to speak of
the x-y plane then one has to know that it is an endash that is supposed to be placed
between the x and the y, not a minus sign (as $x-y$ would produce). But typing $x--y$
41
will produce x − −y since both dashes are interpreted as minus signs. To avoid speaking
of the x − y plane or the x − −y plane, we should type it as the $x$--$y$ plane. We are
fortunate that LaTEX can recognise and cope with by far the majority of our mathematical
typesetting needs.
Another thing to look out for is the use of braces in an expression. Typing
${x : f(x)>0}$
will not produce any braces. This is because, as we well know, braces are reserved for
delimiting groups in the input file. Looking back to section 2.4.4, we see how it should be
done:
$ \{ x: f(x)>0 \} $
Math shift commands also behave as scope delimiters, so that commands issued in an
expression cannot affect anything else in a document.
which is equivalent to $$ ... $$ and is suitable for use with long displayed expressions.
If you wish LaTEX to number your equations for you you can use the environment
which is the same as the displaymath environment, except that an equation number will
be generated.
It is poor style to have a displayed expression either begin a paragraph or be a paragraph
by itself. This can be avoided if you agree to never leave a blank line in your input file
42
before a math display.
We will see later how to typeset an expression that is to span multiple lines. For now,
let’s look at an example of displaying an expression:
For each $a$ for which the Lebesgue-set $L_a(f) \neq \emptyset$ we define
$$ % We could have used \begin{displaymath} here
{\cal B}_a(f) = \{ L_{a+r}(f) : r > 0 \},
$$ % and \end{displaymath} here
and these are easily seen to be completely regular.
which produces
For each a for which the Lebesgue-set La (f ) 6= ∅ we define
Again, I typed nothing different here—just asked for display math mode.
It is important to note that almost all of the special maths symbols are unavailable
in ordinary paragraphing mode. If you need to use one there, then use an in-line math
expression $...$.
43
3.3.1 Symbols available from the keyboard
A small percentage of the available symbols can be obtained from just a single key press.
They are + − = < > | / ( ) [ ] and ∗. Note that these must be typed within maths mode
to be interpreted as math symbols.
Of course, all of a–z, A–Z, the numerals 0, 1, 2, . . . , 9 and the punctuation characters ,
; and : are available directly from the keyboard. Alphabetic letters will be assumed to be
variables that are to be italicised, unless told otherwise2 . The numerals receive no special
attention, appearing precisely as in normal paragraphing mode. The punctuation symbols
are still set in standard roman type when read in maths mode, but a little space is left
after them so that expressions like {xi : i = 1, 2, . . . , 10} look like they should. Note that
this means that normal sentence punctuation should not migrate into an expression.
2
See section 3.4.6
44
± \pm ∩ \cap \diamond ⊕ \oplus
∓ \mp ∪ \cup 4 \bigtriangleup \ominus
× \times ] \uplus 5 \bigtriangledown ⊗ \otimes
÷ \div u \sqcap / \triangleleft \oslash
∗ \ast t \sqcup . \triangleright \odot
? \star ∨ \vee ∧ \wedge
\bigcirc
† \dagger \ \setminus q \amalg ◦ \circ
‡ \ddagger · \cdot o \wr • \bullet
to obtain
for the filter F we have ϕ(F ) = G.
There is no need to tabulate all the calligraphic letters, since they are all obtained by
just a type style changing command. We will just list them so that we can see, for reference
purposes, what they all look like. Here they are:
Type To produce
$a+b$ a+b
$(a+b) \ otimes c$ (a + b) ⊗ c
$(a \vee b) \wedge c$ (a ∨ b) ∧ c
$X - (A \cap B) = (X-A) \cup (X-B)$ X − (A ∩ B) = (X − A) ∪ (X − B)
45
3.3.5 Binary relations
LaTEX has been taught to recognize the use of binary relations, too. Table 3.4 shows those
available via LaTEX control words. There are a few that you can obtain directly from the
keyboard: <, >, =, and |.
To negate a symbol you can precede the control word that gives the symbol by a \not.
Some symbols come with ready-made negations, which should be used above the \not’ing
method because the slope of the negating line is just slightly changed to look more pleasing.
Thus \notin should be used above \not\in, and \neq should be used above \not =.
If negating a symbol produces a slash whose horizontal positioning is not to your liking,
then use the math spacing characters described in section 3.4.12 to adjust it.
3
See section 3.3.10
46
3.3.7 Arrow symbols
LaTEX has a multitude of arrow symbols, which it will set the correct space around. Note
that vertical arrows can all be used as delimiters—see section 3.3.8. The available symbols
are listed in table 3.6.
← \leftarrow ←− \longleftarrow ↑ \uparrow
⇐ \Leftarrow ⇐= \Longleftarrow ⇑ \Uparrow
→ \rightarrow −→ \longrightarrow ↓ \downarrow
⇒ \Rightarrow =⇒ \Longrightarrow ⇓ \Downarrow
↔ \leftrightarrow ←→ \longleftrightarrow l \updownarrow
⇔ \Leftrightarrow ⇐⇒ \Longleftrightarrow m \Updownarrow
7 → \mapsto 7−→ \longmapsto % \nearrow
←- \hookleftarrow ,→ \hookrightarrow & \searrow
( \leftharpoonup * \rightharpoonup . \swarrow
) \leftharpoondown + \rightharpoondown - \nwarrow
*
) \rightleftharpoons ; \leadsto
LaTEX will scale delimiters to the correct size (determined by what they enclose) for you,
if you ask it to. There are times when you don’t want a delimiter to be scaled, so it is left
up to you to ask for scaling.
To ask that a delimter be scaleable, you precede it by \left or \right according as
it is the left or right member of the pair. Scaled delimiters must be balanced correctly.
It sometimes occurs, as in the right-hand example above, that only one member of a
delimiting pair is to be visible. For this purpose, use the commands \left. and \right.
which will produce no visible delimiter but can be used to correctly balance the delimiters
in an expression. For examples of the use of delimiters, see section 3.4.11 where we learn
about arrays.
Table 3.7 shows the symbols that LaTEX will recognise as delimiters, i.e. symbols that
may follow a \left or a \right. Note that you have to use \left\{ and \right\} in
order to get scaled braces.
Z X
3.3.9 Operators like and
These behave differently when used in display-math mode as compared with in-text math
mode. When used in text, they will appear in their small form and any limits provided
47
( ( ) ) ↑ \uparrow
[ ] ] ] ↓ \downarrow
{ \{ } \} l \updownarrow
b \lfloor c \rfloor ⇑ \Uparrow
d \lceil e \rceil ⇓ \Downarrow
h \langle i \rangle m \Updownarrow
/ / \ \backslash
| — k \|
Table 3.8 describes what variable-size symbols are available, showing both the small
(in text) and the large (displayed) form of each. In section 3.4.1 we will learn how to place
limits on these operators.
PX T\ JK
\sum \bigcap \bigodot
QY S[ NO
\prod \bigcup \bigotimes
`a FG LM
\coprod \bigsqcup \bigoplus
Z
R W_ U]
\int \bigvee \biguplus
I
H V^
\oint \bigwedge
3.3.10 Accents
The accenting commands that we learned for paragraphing mode do not apply in maths
mode. Consult table 3.9 to see how to accent a symbol in maths mode (all the examples
there accent the symbol u, but they work with any letter). Remember that i and j should
lose their dots when accented, so \imath and \jmath should be used.
There also exist commands that give a “wide hat” or a “wide tilde” to their argument,
\widehat and \widetilde.
û \hat{u} ú \acute{u} ū \bar{u} u̇ \dot{u}
ǔ \check{u} ù \grave{u} ~u \vec{u} ü \ddot{u}
ŭ \breve{u} ũ \tilde{u}
48
3.4 Some common mathematical structures
In this section we shall begin to learn how to manipulate all the symbols listed in section 3.3.
Indeed, by the end of this section we’ll be able to typeset some quite large expressions. In
the section following this we will learn how use various alignment environments that allow
us to prepare material like multi-line expressions and arrays.
Type To produce
$x^2$ x2
$a^b$ ab
$Y^X$ YX
$\gamma^2$ γ2
$(A+B)^2$ (A + B)2
h 2 in
x +1
$\left[ \frac{x^2+1}{x^2 + y^2} \right]^n$ x2 +y 2
Subscripts of a single character are equally easy—you just use the underscore character
_ where you used ^ for superscripting:
Type To produce
$x_2$ x2
$x_i$ xi
$\Gamma_1(x)$ Γ1 (x)
Now let’s see how to set a sub- or superscript that consists of more than just one
character. This is no more difficult than before if we remember the following rule: _ and ^
set the group that follows them as a sub- and superscripts to the group that precedes the sub-
and superscript symbols. We see now now that our initial examples worked by considering
a single character to be a group by itself. Here are some examples:
49
Type To produce
$a^2b^3$ a2 b3
$2^{21}$ 221
$2^21$ 22 1
$a^{x+1}$ ax+1
2
$a^{x^2+1}$ ax +1
$(x+1)^3$ (x + 1)3
$\Gamma_{\alpha\beta\gamma}$ Γαβγ
${}_1A_2$ 1 A2
In the very last example we see a case of setting a subscript to an empty group, which
resulted in a kind of “pre-subscript”. With some imagination this can be put to all sorts
of uses.
In all of the above examples the sub- and superscripts were set to single-character
groups. Nowhere did we group an expression before sub- or superscripting it. Even in
setting the expression (x + 1)3 , the superscript 3 was really only set to the character ). If
we had wanted to group the (x + 1) before setting the superscript, we would have typed
${(x+1)}^3$ which gives (x + 1)3 , with the superscript slightly raised. One has to go
to this trouble because, to most people, something like (xa )b is just as acceptable and as
readable as (xa )b . It also has the advantage of aligning the base lines in expressions such
as
(ab)−2 = [(ab)−1 ]2 = [b−1 a−1 ]2 = b−1 a−1 b−1 a−1
which looks more pleasing than if we use additional grouping to force
and the latter has rather more braces in it that require balancing.
Here are some more examples, showing how LaTEX will set things just as we want
without any further work on our part:
Type To produce
z
$x^{y^z}$ xy
2
$2^{(2^2)}$ 2(2 )
2ℵ0
$2^{2^{2^{\aleph_0}}}$ 22
d
$\Gamma^{z_c^d}$ Γz c
We can also make use of empty groups in order to stagger sub- and superscripts to an
expression, as in
$\Gamma_{\alpha\beta}{}^{\gamma}{}_\delta$
50
which will yield
Γαβ γ δ
One can specify the sub- and superscripts to a group in any order, but it is best to be
consistent. The most natural order seems to be to have subscripts first, but you may think
otherwise. It is also a good idea to always include your sub- and superscripts in braces (i.e.
make them a group), whether they consist of just a single character or not. This enhances
readability and also helps avoid the unfortunate case where you believe that a particular
control word gives a single symbol yet it really is defined in terms of several.
3.4.2 Primes
LaTEX provides the control word \prime (0) for priming symbols. Note that it is not
automatically at the superscript height, so that to get f 0 you would have to type
$f^\prime$ .
To make lighter work of this, LaTEX will interpret a right-quote character as a prime if used
in maths mode. Thus we can type
$f’(g(x)) g’(x) h’’(x)$
in order to get
f 0 (g(x))g 0 (x)h00 (x) .
3.4.3 Fractions
LaTEX provides the \frac command that accepts two arguments: the numerator and the
denominator (in that order). Before we look at examples of its use, let us just note that
many simple in-text fractions are often better written in the form num/den, as with 3/8
which can be typed as $3/8$. This is also often the better form for a fraction that occurs
within some expression.
Type To produce
x+1
$\frac{x+1}{x+2}$
x+2
1
$\frac{1}{x^2+1}$ 2
x +1
1 + x2
$\frac{1+x^2}{x^2+y^2} + x^2 y$ + x2 y
x2 + y 2
1
$\frac{1}{1 + \frac{x}{2}}$
1 + x2
1
$\frac{1}{1+x/2}$
1 + x/2
51
3.4.4 Roots
The \sqrt command accepts two arguments. The first, and optional, argument specifies
what order of root you desire if it is anything other than the square root. The second, and
mandatory, argument specifies the expression that the root sign should enclose:
Type To produce
√
$\sqrt{a+b}$ a+b
√
5
$\sqrt[5]{a+b}$ a+b
r
n 1+x
$\sqrt[n]{\frac{1+x}{1+x^2}}$ 2
√1 + x
x+1
$\frac{\sqrt{x+1}} {\sqrt[3]{x^3+1}}$ √3
x3 + 1
3.4.5 Ellipsis
Simply typing three periods in a row will not give the correct spacing of the periods if it is
an ellipsis that is desired. So LaTEX provides the commands \ldots and \cdots. Centered
ellipsis should be used between symbols like +, −, ∗, ×, and =. Here are some examples:
Type To produce
$a_1+ \cdots + a_n$ a1 + · · · + a n
$x_1 \times x_2 \times \cdots \times x_n$ x1 × x2 × · · · × xn
$v_1 = v_2 = \cdots = v_n = 0$ v1 = v2 = · · · = vn = 0
$f(x_1,\ldots,x_n) = 0$ f (x1 , . . . , xn ) = 0
Type To produce
$f_i(x) \leq 0 \mbox{ for } x \in I$ fi (x) ≤ 0 for x ∈ I
$\Gamma(n)=(n-1)! \mbox{ when $n$ is an integer}$ Γ(n) = (n − 1)! when n is an integer
In section 3.4.12 we’ll learn of some special spacing commands that can be used in math
mode. These are often very useful in positioning text within an expression, enhancing
readability and logical layout.
52
\arccos \cos \csc \exp \ker \limsup \min \sinh
\arcsin \cosh \deg \gcd \lg \ln \Pr \sup
\arctan \cot \det \hom \lim \log \sec \tan
\arg \coth \dim \inf \liminf \max \sin \tanh
Type To produce
$f(x)=\sin x + \log(x^2)$ f (x) = sin x + log(x2 )
$\delta = \min \{ \delta_1, \delta_2 \}$ δ = min{δ1 , δ2 }
$\chi(X) = \sup_{x\in X} \chi(x)$ χ(X) = supx∈X χ(x)
$\lim_{n \rightarrow \infty} S_n = \gamma$ limn→∞ Sn = γ
Notice how LaTEX does more than just set an operation like sup in roman type. It also
knew where a subscript to that operator should go.
53
Type To produce
$\overline{a+bi} = a- bi$ a + bi = a − bi
$\overline{\overline{a+bi}} = a+bi$ a + bi = a + bi
will produce
n terms
z }| {
A = A×A ×...× A
n
and
∀x ∃y(y x)
| {z }
scope of ∀
Type To produce
f∗
$X \stackrel{f^*}{\rightarrow}Y$ X →Y
4
$f(x) \stackrel{\triangle}{=} x^2 + 1$ f (x) = x2 + 1
Type To produce
PN
$\sum_{i=1}^{N} a_i$ ai
R b i=1
$\int_a^b f$ f
Ha
$\oint_{\cal C}f(x)\,dx$ f (x) dx
QC
$\prod_{\alpha \in A} X_\alpha$ α∈A Xα
P
$\lim_{N\rightarrow\infty}\sum_{i=1}^{N}f(x_i)\Delta x_i$ limN →∞ N i=1 f (xi )∆xi
54
We’ll have more to say about the use of \, in section 3.4.12. Let’s have a look at each
of those expressions when displayed:
X
N Z b I Y X
N
ai , f , f (x) dx , Xα , lim f (xi )∆xi
a C N →∞
i=1 α∈A i=1
3.4.11 Arrays
The array environment is provided for typesetting arrays and array-like material. It
accepts two arguments, one optional and one mandatory. The optional argument specifies
the vertical alignment of the array—use t, b, or c to align the top, bottom, or centre of the
array with the centreline of the line it occurs on (the default being c). The second argument
is as for the tabular environment: a series of l, r, and c’s that specify the number of
columns and the justification of these columns. The body of the array environment uses
the same syntax as the tabular environment to specify the individual entries of the array.
For instance the input
... let $A = \begin{array}{rrr}
12 & 3 & 4\\
-2 & 1 & 0\\
3 & 7 & 9
\end{array}$ ...
which produces
a11 a12 ··· a1n
a21 a22 ··· a2n
det A = . .. .. ..
.. . . .
am1 am2 · · · amn
55
The array environment is often used to typeset material that is not, strictly speaking,
an array:
f(x) = \left\{ \begin{array}{ll}
x & \mbox{for $x<1$}\\
x^2 & \mbox{for $x \geq 1$}
\end{array} \right.
Type To produce
√
$\sqrt{2} \, x$ 2x
Rb
$\int_a^b f(x)\,dx$ a
f (x) dx
$\Gamma_{\!2}$ Γ2
R bR d
$\int_a^b \! \int_c^d f(x,y)\,dx\,dy$ a c f (x, y) dx dy
$x / \! \sin x$ x/sin x
√
$\sqrt{\,\sin x}$ sin x
3.5 Alignment
Recall that the $equation$ environment can be used to display and automatically number
a single- line equation4 . The eqnarray environment is used for displaying and automati-
cally numbering either a single expression that spreads over several lines or multiple expres-
sions, while taking care of alignment for us. The syntax is similar to that of the tabular
and array environments, except that no argument is necessary to declare the number and
4
See section 3.2
56
justification of columns. The eqnarray* environment does this without numbering any
equations.
\begin{eqnarray}
(a+b)(a+b) & = & a^2 + 2ab + b^2\\
(a+b)(a-b) & = & a^2 - b^2
\end{eqnarray}
will give
See how we identify the columns so as to line the = signs up. We can also leave entries
empty, to obtain effect like the following:
\begin{eqnarray*}
\frac{d}{dx} \sin x & = & \lim_{h\rightarrow0}\frac{\sin(x+h)-\sin x}{h}\\
& = & \lim_{h\rightarrow0}\frac{\sin x\cos h + \cos x\sinh - \sin x}{h}\\
& = & \lim_{h\rightarrow0}\frac{\sin x(\cos h-1)}{h} + \cos x\frac{\sin h}{h}\\
& = & \cos x
\end{eqnarray*}
which produces
d sin(x + h) − sin x
sin x = lim
dx h→0 h
sin x cos h + cos x sinh − sin x
= lim
h→0
( h )
sin x(cos h − 1) sin h
= lim + cos x
h→0 h h
= cos x
57
The first argument to \newtheorem defines a new theorem-like environment name of
your own choosing. The second argument contains the text that you want inserted when
your theorem is proclaimed:
\begin{thm} $X$ is normal if, and only if, each pair of disjoint
closed sets in $X$ is completely separated.
\end{thm}
Theorem 1 X is normal if, and only if, each pair of disjoint closed sets in X is completely
separated.
Notice that LaTEX italicises the theorem statement, and that you still have to shift in
to maths mode when you want to set symbols and expression. Typically, it is the style
file that determines what a theorem will appear like—so don’t go changing this if you
are preparing for submission for publication (because the journal staff want to substitute
their production style for your document style choice, and not be over-ridden by other
commands).
58
In the next chapter we will look, very briefly, at a number of LaTEX commands that we
have not yet considered. Nothing exciting on the mathematical front, but there is some
other important material (e.g. cross-referencing and page-sizing). For now, let’s look at
the “way forward” with respect to mathematical typesetting.
3.8 AMS-LaTEX
Back in the introduction we said that AMS-LaTEX was just a big macro package, the result
of a marriage of LaTEX and AMS-TEX designed to endow the powerful general-purpose
LaTEX package with the mathematical prowess of AMS-TEX without compromising the
LaTEX syntax. Most of that is true, except that AMS-LaTEX is really just a document-
style option (like 12pt) that can be used within a “tweaked LaTEX”. The most visible part
of this tweak is the new font selection scheme of Mittelbach and Schöpf, discussed more
fully in the next chapter. Almost every LaTEX command and environment survived the
transition to AMS-LaTEX, the exceptions being those that were considered redundant or
under-used (space is at a premium with such a big package). The tweaked LaTEX package
is therefore able to deal with practically every existing LaTEX document, giving just a few
(often pleasant) surprises.
With the amstex style option, one can just start a LaTEX document with
to gain access to the TEXnical excellence of the AMS technical staff. It is not necessary to
have read The Joy of TEX (the AMS-TEX reference guide) to be able to use the amstex
option, for AMS-LaTEX comes with its own reference guide. Even so, The Joy of TeX is
still highly recommended reading. The syntax of AMS-TEX has been changed to that of
LaTEX, but one can perform that transformation as you read “Joy” and still learn much of
the art of technical typesetting. Nowhere else will you find so comprehensive a coverage
of the conventions and pitfalls of mathematical typesetting. In addition, Joy lists all the
extra symbols that are available through the amstex option (if you thought LaTEX had
a fair selection of esoteric symbols, just wait ’til you see those!) and provides in-depth
accounts where the AMS-LaTEX documentation is brief.
Just as AMS-TEX comes with the AMS preprint style (amsppt), AMS-LaTEX comes
with a specialist style file for preparation of articles with AMS-LaTEX for submission to
journals: amsart. The AMS-LaTEX User’s Guide is quite short and very terse in its
explanations (assuming you to be competent in LaTEX), but is supplemented by a large
body of examples and a comprehensive sample article that is a showcase of the abilities of
the amsart style. You must read both these documents to really learn AMS-LaTEX. The
AMS also distributes a guide to authors who wish to submit using AMS-LaTEX, and this
is a must-read once you are familiar with some of AMS-LaTEX.
59