basic latex

70
A Brief Introduction to L A T E X for Bard Students Mostly Gavin Maltby, updated and revised by Ethan Bloch December 2002

Upload: rrc8u

Post on 08-Apr-2015

101 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Basic Latex

A Brief Introduction to LATEXfor Bard Students

Mostly Gavin Maltby, updated and revised by Ethan Bloch

December 2002

Page 2: Basic Latex

Contents

1 Introduction 11.1 This Document . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 What is TEX . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Bard Senior Project Style . . . . . . . . . . . . . . . . . . . . 21.4 The basic idea of using TEX . . . . . . . . . . . . . . . . . . . 21.5 Sample document . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 LATEX Basics 62.1 Document classes . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Inputting AMS-LATEX & the Bard Senior Project Style . . . . 72.3 Sentences and paragraphs . . . . . . . . . . . . . . . . . . . . 82.4 Punctuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.5 Ties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.6 Specially reserved symbols . . . . . . . . . . . . . . . . . . . . 132.7 Control words and symbols . . . . . . . . . . . . . . . . . . . . 142.8 Commands to change text font and size . . . . . . . . . . . . . 172.9 Accents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.10 Over-ruling some of TEX’s choices . . . . . . . . . . . . . . . . 192.11 Commenting your document . . . . . . . . . . . . . . . . . . . 202.12 Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.13 Topmatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.14 Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.15 Sectioning commands . . . . . . . . . . . . . . . . . . . . . . . 222.16 LATEX environments . . . . . . . . . . . . . . . . . . . . . . . . 23

2.16.1 quote and quotation environments . . . . . . . . . . . 232.16.2 center environment . . . . . . . . . . . . . . . . . . . 242.16.3 verbatim environment . . . . . . . . . . . . . . . . . . 252.16.4 itemize, enumerate, description environments . . . 26

i

Page 3: Basic Latex

2.16.5 tabbing environment . . . . . . . . . . . . . . . . . . . 292.16.6 tabular environment . . . . . . . . . . . . . . . . . . . 302.16.7 figure and table environments . . . . . . . . . . . . . 32

2.17 The letter document class . . . . . . . . . . . . . . . . . . . 342.18 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.19 Common pitfalls; Error messages . . . . . . . . . . . . . . . . 36

3 Mathematical Typesetting with LATEX 403.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403.2 Displaying a formula . . . . . . . . . . . . . . . . . . . . . . . 433.3 Using mathematical symbols . . . . . . . . . . . . . . . . . . . 45

3.3.1 Symbols available from the keyboard . . . . . . . . . . 453.3.2 Greek letters . . . . . . . . . . . . . . . . . . . . . . . 463.3.3 Changing math fonts . . . . . . . . . . . . . . . . . . . 463.3.4 Binary operators . . . . . . . . . . . . . . . . . . . . . 473.3.5 Binary relations . . . . . . . . . . . . . . . . . . . . . . 473.3.6 Miscellaneous symbols . . . . . . . . . . . . . . . . . . 483.3.7 Arrow symbols . . . . . . . . . . . . . . . . . . . . . . 483.3.8 Expression delimiters . . . . . . . . . . . . . . . . . . . 49

3.3.9 Operators like

∫and∑

. . . . . . . . . . . . . . . . 50

3.3.10 Accents in math mode . . . . . . . . . . . . . . . . . . 503.4 Some common mathematical structures . . . . . . . . . . . . . 51

3.4.1 Subscripts and superscripts . . . . . . . . . . . . . . . 513.4.2 Primes . . . . . . . . . . . . . . . . . . . . . . . . . . . 533.4.3 Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . 543.4.4 Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . 543.4.5 Ellipsis . . . . . . . . . . . . . . . . . . . . . . . . . . . 553.4.6 Text within an expression . . . . . . . . . . . . . . . . 553.4.7 Log-like functions . . . . . . . . . . . . . . . . . . . . . 553.4.8 Over- and Underlining and bracing . . . . . . . . . . . 573.4.9 Stacking symbols . . . . . . . . . . . . . . . . . . . . . 573.4.10 Operators; Sums, Integrals, etc. . . . . . . . . . . . . . 583.4.11 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 583.4.12 Alignment . . . . . . . . . . . . . . . . . . . . . . . . . 603.4.13 Other Multiline Environments . . . . . . . . . . . . . . 613.4.14 Changes to spacing . . . . . . . . . . . . . . . . . . . . 62

3.5 Macros: Defining your own LATEX commands . . . . . . . . . . 63

ii

Page 4: Basic Latex

3.6 Some Standard TEX Mistakes . . . . . . . . . . . . . . . . . . 643.7 Theorems, Propositions, Lemmas, . . . . . . . . . . . . . . . . . 65

iii

Page 5: Basic Latex

Chapter 1

Introduction

1.1 This Document

This introduction to LATEX is a modified version of the widely used “An intro-duction to TEX and friends” by Gavin Maltby, dated in November 1992. Thatmanual was designed to be used with the then current version of LATEX(knownas LATEX2.09), as opposed to the version of LATEX used in 2002 (known asLATEX2ε). Maltby’s original manual has some commands that are not cur-rently useable; also, it did not incorporate some of the useful mathematicalcommands of AMS-LATEX that are currently available. The manual you arereading is mostly based on Maltby’s manual, but includes some updatedcommands and a few things that Maltby did not have; we have also deleteda few non-essential parts of Maltby in order to keep this manual as brief aspossible.

For a more full introduction to LATEX, a widely available document is“The Not So Short Introduction to LATEX2ε” by Tobias Oetiker, HubertPartl, Irene Hyna and Elisabeth Schlegl. This document, which was origi-nally in German but exists in English translation, is available on the web athttp://www.ctan.org/search/, along with other LATEX references.

1.2 What is TEX

The TEX typesetting system was designed by the eminent Stanford computerscientist Donald Knuth, on commission from the American MathematicalSociety. It was designed with enormous care, to be ultimately powerful and

1

Page 6: Basic Latex

maximally flexible. The enormous success of Knuth’s design is apparent fromthe vast number of diverse applications TEX has found.

To make the raw power of TEX more manageable and user friendly, somemacros (discussed below) must be defined. The most widely use set of macrosfor TEX is called LATEX. We recommend that everyone use LATEX; we will bereferring to LATEX in this manual. It is necessary to use the latest version ofLATEX, which is called LATEX2ε. Do not use earlier versions of LATEX, such asLATEX2.09.

LATEX does not have all the mathematical abilities one might want, and sowe will add to it a set of macro packages and mathematical fonts and symbolsknown as AMS-LATEX, which was commissioned by the American Mathemat-ical Society. We will explain below how to input these packages. Unless oth-erwise noted, all the commands described below are standard LATEX. In thefew situation where we use commands that require the AMS-LATEX packages,we will state the need for these packages.

The common American way to pronounce TEX is “tek.” If you want tobe really fancy, you can say “tech,” where the “ch” is pronounced as in theGerman “Bach” or the Scottish “Loch.” Do NOT say “tex.” Some peoplepronounce LATEX as “lay-tek,” and others say “lah-tek.”

1.3 Bard Senior Project Style

The Bard Senior Project style is a collection of macros for such useful thingsas the senior project title page, acknowledgements and dedication; theorems,lemmas and the like; proper margins; and miscellaneous other matters use-ful for senior projects. This style file, called bardproj.sty, together witha brief manual for using this style file, is available from Ethan Bloch athttp://math.bard.edu/bloch/bardtex.htm. We will describe below how toinput this style file.

1.4 The basic idea of using TEX

TEX is not a WYSISYG word processor. Rather, it is more like a computerprogram, in that you enter various commands (which in TEX usually startwith a backslash) along with your text, and then run the document througha compiler. If there are errors, you are given error messages. If there are

2

Page 7: Basic Latex

no errors, then the program outputs something that can then be viewed.The file with your input, known as the “TEX file,” is a text file that hasthe suffix .tex. The file that TEX produces if there are no errors in theTEX file is called the “DVI file,” and it has the same name as your TEX file,except that it has the suffix .dvi (which is short for “device independent”).This last file can viewed, printed, etc. The particular implementation of TEXvaries from system to system, but the basic ideas of TEX are the same inall implementations. The portability of a TEX document between systems isone of the advantages of TEX.

The basic idea underlying TEX is that the author should be concernedwith content, and with the logical structure of the document, but shouldnot have to worry about nuisance-value formatting details. We inform TEXof the logical structure of our document by telling it when to begin a newparagraph, subsection, section, chapter, theorem, definition, remark, poem,list etc. When typing a particular element of the logical structure, we needpay little attention to how we lay our source file out. Starting a new line, forinstance, entails more than just pressing Return because TEX will just regardthe next word you type as exactly that—the next word in the paragraph.You have to specifically ask for a line to be terminated. Things like this mayseem to be a bit of a nuisance, but it is a small price to pay for the automaticformatting that necessitated it. Further, such small inconveniences have beenlocalized to rare events.

1.5 Sample document

To obtain a feel for how LATEX works, look at the following sample LATEXdocument:

3

Page 8: Basic Latex

\documentclass[12pt]report\usepackageamssymb, amsmath, amsthm, amsfonts

\newcommand\func[3]#1 \colon #2 \to #3

\begindocument

Let $\func p[0, \infty)\mathbbR$ be given by $p(x) = x^2$for all $x \in [0, \infty)$. Then $p$ has no right inverse, butmany left inverses, of which we show two. Let$\func q, r\mathbbR[0, \infty)$ be given by$$q(x) =\begincases\sqrt x,&\textif $x \ge 0$\\1,&\textif $x < 0$,\endcases\qquad \textand\qquadr(x) =\begincases\sqrt x,&\textif $x \ge 0$\\\sin x,&\textif $x < 0$.\endcases$$Both $q$ and $r$ are left inverses for $p$, because $(q \circ p)(x)= q(p(x)) = \sqrt x^2 = x$ for all $x \in [0, \infty)$, and$(r \circ p)(x) = r(p(x)) = \sqrt x^2 = x$ for all $x \in[0, \infty)$. We leave it to the reader to show that $p$ has no right inverse.\enddocument

The above file, which would have a name such as filename.tex, is whatyou type in a word processor (and which must be saved as a text file). Thecompleted TEX file is then run through LATEX, and it produces the followingoutput:

4

Page 9: Basic Latex

Let p : [0,∞) → R be given by p(x) = x2 for all x ∈ [0,∞). Then phas no right inverse, but many left inverses, of which we show two. Letq, r : R → [0,∞) be given by

q(x) =

√x, if x ≥ 0

1, if x < 0,and r(x) =

√x, if x ≥ 0

sinx, if x < 0.

Both q and r are left inverses for p, because (q p)(x) = q(p(x)) =√x2 = x for all x ∈ [0,∞), and (r p)(x) = r(p(x)) =

√x2 = x for all

x ∈ [0,∞). We leave it to the reader to show that p has no right inverse.

Among other things to notice in the TEX file are the first two lines (whichdeclare the type of document, and inputs some extra mathematical packages);the third line (which defines a new LATEX command); the many entries thatbegin with \ (which are LATEX commands); the many $ signs (which denotemath mode); the \begin and \end commands (which denote specialenvironments). All these features will be described in this manual.

5

Page 10: Basic Latex

Chapter 2

LATEX Basics

There are various implementations of TEX available on Windows, Mac andLINUX operating systems. Some of these implementations are free, andothers are commercially available. All implementations work essentially thesame way, in that you start by producing a LATEX source file (known as the“TEX file”), and you then run the file through the TEX compiler, debug thefile as necessary, and view (or print) the result when you have gotten allthe bugs out. How you run the file through the TEX compiler (known as“TEX-ing” the file) depends upon the particular implementation you use. Inthis manual we discuss the ingredients that go into the TEX file.

2.1 Document classes

Every TEX file begins with a declaration of the document class. The mostcommonly used document classes in LATEX are letter, article, report,and book; there are also some useful AMS-LATEX document classes, suchas amsart and amsbook, which make things look a little differently fromthe corresponding regular document classes. The article class is used fordocuments that are to have the appearance of a journal or magazine article.The report class is usually used for larger documents than the article

class. These classess really only differ in their choice of default page size,font, placement of title and author, sectional units, etc. and on how theyformat certain LATEX constructs. You use the same LATEX commands ineach.

There are a number of possible options with each document class, such

6

Page 11: Basic Latex

as font size, columns, etc. The syntax for declaring a document class is asfollows:

\documentclass[options]class

where class is the main document class (e.g. report) and the optional ar-gument options is a list of document class options. Note thatan argumentin square brackets is optional, and can omitted altogether (including thebrackets).

Some of the more common options are the following:

11pt chooses 11-point as the default font size for the document, instead ofthe default 10-point.

12pt chooses 12-point as the default font size.

twoside formats output as left and right pages, as in a book.

twocolumn produces two-column magazine like output.

titlepage applies to the article class only, causing the title and abstract toappear on a page each.

For example, this document starts with the declaration:

\documentclass[12pt]report

2.2 Inputting AMS-LATEX & the Bard Senior

Project Style

Immediately after declaring the document class, add the line:

\usepackageamssymb, amsmath, amsthm, amsfonts

which will allow the user to make use of variousAMS-LATEX fonts, symbolsand other mathematical constructs.

To make use of the Bard Senior Project style, you first need to downloadthe file bardproj.sty from the website given in Section 1.3, and then putthe file in the same folder on your computer as your TEX file. Then, add

7

Page 12: Basic Latex

the following line to your TEX file immediately after declaring the documentclass:

\usepackagebardproj

2.3 Sentences and paragraphs

Paragraph input in LATEX is free-form. You type the words and separatethem by spaces so that LATEX can distinguish between words. For thesepurposes, pressing Return is equivalent to inserting a space—it does notindicate the end of a line, but the end of a word. You tell LATEX that asentence has ended by typing a period followed by a space. LATEX ignoresextra spaces; typing three or three thousand will get you no more spacebetween the words that these spaces separate than typing just one space.Finally, you tell LATEX that a paragraph has ended by leaving one or moreblank lines. In summary: LATEX concerns itself only with the logical conceptsend-of-word, end-of-sentence, and end-of-paragraph. Here is an example:

\documentclassarticle\usepackageamssymb, amsmath, amsthm, amsfonts\begindocumentWords within a sentence are ended by spaces. One spacebetween words is equivalent to any number.Pressing Returnat the end of a lineand starting a new word on the next linejust serves to separatewords, not to cut a line short.The end of a sentence is indicated by a periodfollowed by one or more spaces.

The end of a paragraph is indicated by leaving a blank line.All thismeans that we can type without too much regard for layout, andthe typesetter will sort things out for us.\enddocument

produces the result

8

Page 13: Basic Latex

Words within a sentence are ended by spaces. One space betweenwords is equivalent to any number. Pressing Return at the end of a lineand 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 periodfollowed by one or more spaces.

The end of a paragraph is indicated by leaving a blank line. All thismeans that we can type without too much regard for layout, and thetypesetter will sort things out for us.

Note that we have learned more than just how LATEX recognizes words,sentences and paragraphs. We’ve also seen how to specify our choice of docu-ment class and how to tell LATEX where our document begins and ends. Anymaterial that is to be printed must lie somewhere between the declarationof \begindocument and that of \enddocument. Definitions that are toapply to the entire document can be made before the declaration of the doc-ument beginning. The specification of document class must precede all othermaterial.

In future examples we won’t explicitly display the commands that selectdocument class, input the AMS-LATEX packages, and delimit the start andend of the document. But if you wish to try any of the examples, don’tforget to include those commands. The article document class will do formost of our examples. Of course, the preceding example looks not at all likean article because it is so short and because we specified no title or authorinformation.

LATEX automatically makes ligatures. These are combinations of letterswithin words which should be typeset as a single special symbol because theywill “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

In the first set I let LATEX run as it usually does. In the second I overruledit 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 asingle symbol (a ligature) and in the latter they are comprised of two disjointsymbols. There are other combinations that yields ligatures as well.

LATEX has been taught how to hyphenate the majority of words. It willhyphenate a word if it feels that the overall quality of the paragraph will be

9

Page 14: Basic Latex

improved. For long words it has been taught several potential hyphenationpositions.

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 them-selves at either the bottom of a page (where it would have to be the first lineof 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 sameheight, no matter what appears on them.

2.4 Punctuation

Typists have a convention whereby a single space is left after a mid-sentencecomma, and two spaces are left after a sentence-ending period. How do weenforce this if LATEX treats a string of spaces just like a single one? Theanswer, unsurprisingly, is that we don’t.

To have a comma followed by the appropriate space, we simplytype a comma follows by at least one space. To end a sentencewe type a period with at least one following space. No space willbe inserted if we type a comma or period followed straight awayby something other than a space, because there are times whenwe won’t require any space, i.e., we do what comes narurally.

will produceTo 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 aperiod with at least one following space. No space will be inserted if wetype a comma or period followed straight away by something other thana 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 andcolons, exclamation marks, question marks etc. if they are followed by aspace. In stretching a line to justify to the right margin, it also knowsthat space after a punctuation character should be more “stretchable” thannormal inter-word space and that space after a sentence-ending period shouldbe stretched more than space after a mid-sentence comma. TEX knows thenature of punctuation if you stick to the simple rules outlined here. As we’vealready said, those rules tell LATEX how to distinguish consecutive words,sentences, phrases, etc.

10

Page 15: Basic Latex

Actually, there is more to ending sentences than mentioned above. SinceLATEX cannot speak English, it works on the assumption that a period followedby a space ends a sentence unless the period follows a capital letter. Thisworks most of the time, but can fail. To get a normal inter-word space aftera 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 toforce a sentence to end after a period that follows a capital letter (rememberthat LATEX assumes this doesn’t end a sentence). This is done by precedingthe period with a \@ command (you can guess from the odd syntax that thisis rarely needed).

It’s time we saw some examples of this. After all, this is our first experi-ence of control symbols (don’t worry, there are many more to come).

We must be careful not to confuse intra-sentence periodswith periods that end a sentence, i.e.\ we must rememberthat our task is to describe the sentence structure. Periodsthat the typesetter requires a little help with typically resultfrom abbreviations, as in etc.\ and others. We have to worksomewhat harder to break a sentence after a capital letter,but that shouldn’t bother us to much if we keep up our intakeof vitamin E\@. All this goes for other sentence-endingpunctuation characters, so I could have said vitamin E\@!Fortunately, these are rare occurrences.

results inWe must be careful not to confuse intra-sentence periods with pe-

riods that end a sentence, i.e. we must remember that our task is todescribe the sentence structure. Periods that the typesetter requires alittle help with typically result from abbreviations, as in etc. and oth-ers. We have to work somewhat harder to break a sentence after acapital letter, but that shouldn’t bother us to much if we keep up ourintake of vitamin E. All this goes for other sentence-ending punctuationcharacters, so I could have said vitamin E! Fortunately, these are rareoccurrences.

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 toeach of ‘, ’, “, and ”. So we proceed like this:

11

Page 16: Basic Latex

‘\LaTeX’ is no conventional word-processor, andto to get quotes, like ‘‘this’’, we type repeated‘ and ’ characters. Note that modernconvention is that ‘‘punctuation comes afterthe closing quote character’’.

which gives just what we want‘LATEX’ is no conventional word-processor, and to to get quotes,

like “this”, we type repeated ‘ and ’ characters. Note that modernconvention is that “punctuation comes after the closing quote character”.

Very rarely, you have three quote characters together. Merely typingthose three quote characters one-after-the-other is ambiguous—how shouldthey be grouped? You tell LATEX how you want them grouped by inserting avery small space called \,.

‘‘\,‘Green ham’ or ‘Eggs?’\,’’ is the question.

gives the desired result

“ ‘Green ham’ or ‘Eggs?’ ” is the question.

Since we have a typesetter at our disposal, we might as well use the correctdashes where we need them. There are three types of dash: the hyphen, theendash, and the emdash. A minus sign is not a dash.

Hyphens are typed as you’d hope, just by typing a - at the point inthe word that you want a hyphen. Don’t forget that LATEX takes care ofhyphenation that is required to produce pretty linebreaks. You only typea 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 onthe keyboard, as in 1--3.

An emdash is a punctuation dash, used at the end of a sentence—I tendto use them too much. To specify an emdash you type three consecutivedashes on the keyboard, as in “. . . a sentence---I tend to. . . ”.

Theorems 1--3 concern the semi-completenessof our new construct---in the case that itsatisfies the first axiom.

yields

12

Page 17: Basic Latex

Theorems 1–3 concern the semi-completeness of our new construct—in the case that it satisfies the first axiom.

2.5 Ties

When you always remember to use ties, you know that you are becomingTEXnically inclined. Ties are used to prevent LATEX from breaking lines atcertain places. LATEX will always choose line breaks that result in the mostaesthetically pleasing paragraph as judged by its stringent rules. But becauseLATEX 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 allrespects except that the line-breaking algorithm will never break a line atthat 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 lineand put the ‘Seuss’ at the beginning of the next.

One should try to get in to the habit of typing ties first-time, not afterwaiting to see if LATEX will make a poor choice This will allow you to makeall sorts of changes to your text without ever having to go back and inserta tie at a point that has migrated to the end of a line from the middle of aline as a result of those changes. Remember, of course, that the line-breaks

Here are some more examples of places where you should remember toplace ties.

Chapter~10 Donald~E. KnuthAppendix~C width~2Figure~1 function~fTheorem~2 1,~2, or~3Lemmas 3 and~4 equals~5

2.6 Specially reserved symbols

In the sequel we will see that the the ten characters

13

Page 18: Basic Latex

# $ % & ~ _ ^ \

are reserved for special use. Indeed, we have seen already that \ and ~ arenon-printing characters that perform special services (and we’ll have a lotmore to say about the use of \).

But what if we need one of these special symbols to appear in our doc-ument? The answer for seven of the symbols is to precede them by a \

character, so forming another control symbol (remember that \ followed bya space was also a control symbol).

It is not 100\% straightforward to typeset thecharacters \$ \& \% \_ \ \, but given theenormous convenience of the use they are normallyreserved for this is a small price to pay.

producesIt is not 100% straightforward to typeset the characters $ & %

, but given the enormous convenience of the use they are normallyreserved for this is a small price to pay.

2.7 Control words and symbols

In typing a document, we can think of ourselves as being in one of twodistinct modes. We are either typing literal text (which will just be set intoneat paragraphs for us) or we are typing text that will be interpreted byLATEX as an instruction to insert a special symbol or to perform some action.Thus we are either typing material that will go straight into the document(with some beautification), or we are giving commands to LATEX.

Some commands are implicit, in that we don’t have to do anything muchextra. For instance, we command LATEX to end the present sentence bytyping a period (that doesn’t follow a capital letter). These are no so muchcommands as part of having to describe the logical structure of a document.

A control word is something of the form \commandname, where the com-mand name is a word made up only of the letters a to z and A to Z. A controlsymbol consists of a \ followed by single symbol that is not a letter.

Here are some examples:

• we have met the control space symbol \ before,

• the commands to set symbols like % and $ are control symbols

14

Page 19: Basic Latex

• \@ was a control symbol that told told LATEX that the very next perioddid really end the sentence,

• \LaTeX is a control word that tell LATEX to insert its own name at thecurrent point,

• \pounds inserts a £ symbol,

• \S inserts a ¶ symbol,

• \emph makes the text in braces be emphasised,

These examples show that control sequences can be used toaccess symbols not available from the keyboard, do some typesetting

tricks like setting the word LATEX the way it does, and change the appearanceof whole chunks of text as with \emph . We’ll be meeting many more ofthese type of control sequences.

Another enormously powerful class of control sequences is those that ac-cept arguments. They tell LATEX to take the parts of text you supply and dosomething with them—like make a fraction by setting the first argument overthe second and drawing a line of the appropriate length between them. Theseare part of what makes LATEX so powerful, and here are some examples.

• \chapterThe beginning causes LATEX to start a new chapter withname “The Beginning”, number it in sequence, typeset the chapterheading in a suitable font, and make an entry in the table of contents,

• \overlinewords causes words to be overlined,

• \fraca+bc+d sets the given two argument as a fraction, doingmost 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 5is in square brackets instead of braces because it is an optional argumentand could be ommited all together (giving the default of square root),

Mandatory arguments are given enclosed by braces, and optional argu-ments enclosed by square brackets. Each command knows how many argu-ments to expect, so you don’t have to provide any indication of that. (Thelast three of the above examples include examples of mathematical typeset-ting, which we will discuss in Chapter 3.)

15

Page 20: Basic Latex

We need to dwell on a TEXnicality for a moment. How does LATEXknow where the name of a control sequence ends? Will it accept both\pounds3 and \pounds 3 in order to set £3? What about \poundsthree

vs. \pounds three? The answer is easy when you remember that a controlword consists only of alphabetic characters, and a control symbol consists ofexactly one nonalphabetic character.

So to determine which control sequence you typed, LATEX does the fol-lowing:

1. when a \ character is encountered, LATEX knows that either a controlsymbol or a control word will follow.

2. If the \ is followed by a nonalphabetic character, then LATEX knowsthat it is a control symbol that you have typed. It then recognizeswhich one it was, typesets it, and goes on to read the character whichfollows the symbol you typed.

3. If the \ is followed by an alphabetic character, then LATEX knows thatit is a control word that you have typed. But it has to work out wherethe name of the control word ends and where the ensuing text takesover again. Since only alphabetic characters are allowed, LATEX readseverything up to just before that first nonalphabetic character as thecontrol sequence name. Since it is common to delimit the end of acontrol word by a space, LATEX will ignore any space that follows acontrol word, since you want that space treated as end-of-control-wordspace rather than interword space.

This has one important consequence: The character in the input fileimmediately after a control symbol will be “seen” by LATEX, but any spacefollowing a control word will be discarded and never processed. This does notaffect one much if you adopt the convention of always typing a space after acontrol sequence name.

There is a rare circumstance where this necessitates a little extra workand thought, which we illustrate by example:

If we type a control word like \LaTeX in the running textthen we must be cautious, because the string of spaces thatcome after it will be discarded by the \LaTeX\ system.

which produces the output

16

Page 21: Basic Latex

If we type a control word like LATEXin the running text then wemust be cautious, because the string of spaces that come after it will bediscarded by the LATEX system.

2.8 Commands to change text font and size

The most commonly used LATEX commands for changing type style are givenbelow. For each of these commands, only the text within the braces willchange appearance.

\textrm Roman \textit italic \textsc Capitals\emph Emphasised \textsl slanted \texttt typewriter

\textbf boldface \textsf sans serif

Each of the type style selection commands selects the specified style butdoes not change the size of font being used. The default type style is roman(you are reading a roman style font now).

Commands for changing type size work differently than commands forchanging type style. The commands for changing type size apply to any textthat follows the command. To limit the area of text over which one of thesecommands has effect (its scope) we make that text into what is called a groupby using braces. Groups are used extensively in LATEX to keep effects localto an area, rather than affecting the whole document. Apart from enhancingusability, this also in a sense protects distinct parts of a document from eachother. To change type size you issue one of the type size changing commandsshown below, which will select the indicated size in the currently active style.

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

17

Page 22: Basic Latex

The point-size option referred to above is that specified in the \documentclasscommand issued at the beginning of the input file. Through it you select thatbase (or default) font for your document to be 10, 11, or 12 point Roman. Ifno options are specified, the default is 10-point Roman. The table shows, forinstance, that if I issue a \large in this document for which I chose the 12ptdocument class option the result will be a 14-point Roman typeface.

Here is an example of text style and size changes:

We \emphemphasize by putting the emphasized textin the braces following the control word, and the samegoes for \textbfemboldened and other style changes.For changing sizes, for example \LARGE large and\scriptsize scriptsize, we put the control word and thetext inside braces.

We emphasize by putting the emphasized text in the braces followingthe control word, and the same goes for emboldened and other style

changes. For changing sizes, for example large and scriptsize, we putthe control word and the text inside braces.

2.9 Accents

LATEX provides many accents, which are accessed through a variety of controlsymbols and single-letter control worlds which accept a single argument—theletter to be accented. These control sequences are:

\‘o o (grave accent) \’o o (acute accent)\^o o (circumflex or “hat”) \"o o (umlaut or dieresis)\~o o (tilde or “squiggle”) \=o o (macron or “bar”)\.o o (dot accent) \uo o (breve accent)\vo o (hacek or “check”) \Ho o (long Hungarian umlaut)\too oo (tie-after accent) \co o (cedilla accent)\do o. (dot-under accent) \bo o

¯(bar-under accent)

Thus we can produce o by typing \’o, a by typing \va, and PalErdos by typing P\’al Erd\"os. Take special care when accenting an ior 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 totype to type exıgent is \uex\u\igent.

18

Page 23: Basic Latex

2.10 Over-ruling some of TEX’s choices

We’ve seen that ties can be used to stop linebreaks occurring between words.But how can we stop LATEX from hyphenating a particular word? Moregenerally, how can we stop it from splitting any given group of charactersacross two lines. The answer is to make that group of characters appears asone solid box, through use of an \mbox command.

For instance, if we wanted to be sure that the word

\emphcurrentitem is not split across linesthen we should type it as \mbox\emphcurrentitem.

If for some reason we wish to break a linein the middle of nowhere, preventing LATEX from justifying that line to theprevailing right margin, the we use the \newline command. One can alsouse the abbreviated form \\.

We start with a short line.\newlineAnd now we continue with the normaltext, remembering that where we pressReturn in the input file probably won’t

correspond to a line break in the finaldocument. More short lines\\are easy, too.

will produce the line breaks we wantWe start with a short line.

And now we continue with the normal text, remembering that where wepress Return in the input file probably won’t correspond to a line breakin the final document. More short linesare easy, too.

A warning is in order: \newline must only end part of a line that is “al-ready set”. It cannot be used to add additional space between paragraphs,nor to leave space for a picture you want to paste in. This is not to be awk-ward, but is just part of LATEX holding up its end of the deal by making youhave to specially request additional vertical space. This prevents unwantedextra space from entering your document.

If you wish to force a page break, use the \newpage command.

19

Page 24: Basic Latex

2.11 Commenting your document

It is handy to be able to make comments to yourself in the source file for adocument. Things like “I must rewrite this section” and “This is version 3of the document” are likely. It would also be useful to be able to make thecompiler ignore certain parts of the document at times. For this purpose wecan use the % character, for all text on an input line that is after a % whichis not part of an occurrence of the control symbol \% is discarded by thecompiler. 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 yieldsThere was a 100% turnout today, an all-time record. This made for

an extremely productive session.

2.12 Footnotes

Footnotes are considered bad form in mathematical writing. If you want touse them nonetheless, inserting footnotes is easy in LATEX, because they willbe positioned and numbered automatically. You just indicate exactly wherethe footnote marker should go, and provide the text of the footnote. Thefootnote text will be placed at the bottom of the present page in a somewhatsmaller 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\footnoteSee for yourself! It’s easy ...work. to conform

No space was typed between the rule and the \footnote, because wewant the footnote marker to appear right next to the last letter of the word.

Multiple footnotes2 are obtained just by using the \footnote commandagain and again.

1See for yourself! It’s easy when you don’t have to do any work.2Here is another footnote

20

Page 25: Basic Latex

2.13 Topmatter

We declare the title and author information using the \title and \author

commands, each of which accept a single argument. Multiple authors are alllisted in the argument of \title, separated by \and’s. The \date commandcan be used to date a document. After we have declared each of these, weissue a \maketitle command to have them typeset for us. In the book andarticle 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 stylefiles determine the placement and the choice of font.

\titleA Thought for the Day\authorFred Basset \and Horace Hosepipe\dateNovember 1992\maketitle

will produce something along the lines of

A Thought for the DayFred Basset Horace Hosepipe

November 1992

This topmatter must appear after the \begindocument and before anyother printing material.

2.14 Labels

One of the great features of LaTEX is that chapters, sections, theorems, equa-tions and the like are numbered automatically. Thus, if you decide to insert anew section in the middle of an existing chapter, everything after that is au-tomatically renumbered. The way automatic numbering works is that every-thing that is numbered is given a label, usually written \labellabelname,where labelname can be any character string starting made of numbers, let-ters and punctuation, starting with a letter. Of course, each labeled itemmust have a unique label. Because the label does not appear in the printedversion of the text, you can choose anything you want for the label; some-thing mnemonic is always a good idea. For example, the label used for thecurrent section of this manual is \labelsec:labels.

21

Page 26: Basic Latex

To refer to the labeled item, for example this section, we would writeSection~\refsec:labels, which would produce Section 2.14. The \ref

command works with chapters, sections, theorems, equations, etc. Such areference could be anywhere in the text, even before the item being referedto.

2.15 Sectioning commands

As part of our task of describing the logical structure of the document, wemust indicate to LATEX where to start sectional units. To do this we makeuse of the sectioning commands, which are:

\part \subsection \paragraph

\chapter \subsubsection \subparagraph

\section

Each sectioning command accepts a single argument—the section headingthat is to be used. LATEX will provide the section numbering (and numberingof subsections within sections, etc.) so there is no need to include any numberin the argument. LATEX will also take care of whatever spacing is requiredto set the new logical unit off from the others, perhaps through a little extraspace and using a larger font. It will also start a new page in the case thata new chapter is begun.

The \part command is used for major subdivisions of substantial docu-ments. The \paragraph and \subparagraph commands are, unfortunatelyconfusing. They are used to section off a modest number of paragraphs oftext—they don’t start new paragraphs (remember that that was done byleaving a blank line in our input file). The names were retained for historicalreasons.

The sectioning command that began the present sectional unit of thisdocument was

\sectionSectioning commands

\labelsec:sectioning

Notice that no section number was given in the above command, and thatis because LATEX numbers the sections automatically!

22

Page 27: Basic Latex

There are occasions when you want a heading to have all the appearanceof a particular sectioning command, but shouldn’t be numbered as a sectionin its own right or produce a table of contents entry. This can be achievedthrough using the *-form of the command, as in \section*.... We’ll seethat many LATEX commands have such a *-form which modify their behaviourslightly.

LATEX can automatically make a table of contents. Just include the com-mand \tableofcontents after the \begindocument command.

2.16 LATEX environments

A very useful concept in the LATEX syntax is that of an environment. Someenvironments are used to display a portion of text, i.e. to set it off from thesurrounding text by indenting it, for example the quote environment. Thecenter environment allows us to centre portions of text.

All the environments are begun by a \beginname command and endedby an \endname, where name is the environment name. These commandsalso serve as begin-group and end-group markers (see Section 2.8), so thatall commands are local to the present environment—they cannot affect textoutside the environment.

We can also have environment embedded within environment within en-vironment and so on, limited only by memory available on the computer. Wemust, however, be careful to check that each of these nested environments isindeed contained within the one just outside of it.

Although LATEX doesn’t care too much for how we format our source file,it is obviously a good idea to lay it out logically and readably anyway. Thishelps minimize errors as well as aids in finding them. For this reason I haveadopted the convention of always placing the environment \begin and \end

commands on lines by themselves.

2.16.1 quote and quotation environments

This environment can be used to display a part of a sentence or paragraph,or even several paragraphs, in such a manner that the material stands outfrom the rest of the text. This can be used to enhance readability, or tosimply emphasise something. Its syntax is simple:

23

Page 28: Basic Latex

Horace smiled and retaliated:\beginquoteYou can mock the non-WYSIWYG nature of \TeX\all you like. You don’t understand that that isprecisely what makes \TeX\ enormously more powerfulthan that lame excuse for a typesetter you use.In your case, what you seeis \emphall you get!\endquoteand then continued with composing his masterpiece of thetypesetting art.

produces the following typeset material:Horace smiled and retaliated:

You can mock the non-WYSIWYG nature of TEX all you like. You don’tunderstand that that is precisely what makes TEX enormously more powerfulthan that lame excuse for a typesetter you use. In your case, what you seeis all you get!

and then continued with composing his masterpiece of the typesettingart.

That is a much more readable manner of presenting Horace’s piece of mindthan embedding it within a regular paragraph. The quote environment wasresponsible for the margins being indented on both sides during the quote.

The quotation environment is used in just the same way as the quote

environment above, but it is intended for setting long quotations of severalparagraphs. It would be suitable for quoting a few paragraphs from the textof some speech, for instance. LATEX treats the given text just like normaltext that it has to set into paragraphs, except that it indents the margins alittle.

2.16.2 center environment

This environment allows the centring of consecutive lines of text, new linesbeing indicated by a \\. If you don’t separate lines with the \\ commandthen you’ll get a centred paragraph the width of the page, which won’t lookany different to normal. If only one line is to be centred, then no \\ isnecessary.

24

Page 29: Basic Latex

The \textttcenter environment takes care of the verticalspacing before and after it, so we don’t need to leave any.\begincenterIf we leave no blank line after the\\\textttcenter environment\\then the ensuing text will not\\be regarded as part of a new\\paragraph, and so will not be indented.\\\endcenter

In this case we left a blank line after the environment,so the new text was regarded as starting a new paragraph.

gives the following textThe center environment takes care of the vertical spacing before

and after it, so we don’t need to leave any.

If we leave no blank line after thecenter environment

then the ensuing text will notbe regarded as part of a new

paragraph, and so will not be indented.

In this case we left a blank line after the environment, so the newtext was regarded as starting a new paragraph.

2.16.3 verbatim environment

We can simulate typed text using the verbatim environment. The \texttt

(typewriter text) type style can be used for simulating typed words, but runsinto trouble if one of the characters in the simulated typed text is a speciallyreserved LATEX character. For instance, \texttttype \newline wouldnot have the desired effect because LATEX would interpret the \newline is aninstruction to start a new line.

The verbatim environment allows the simulation of multiple typed lines.Everything within the environment is typeset in typewriter font exactly as itappears in our source file—obeying spaces and line breaks as in the sourcefile and not recognising the existence of any special symbols.

25

Page 30: Basic Latex

\beginverbatimIn the verbatim environment we can type anythingwe like.So we don’t need to look out for uses of %, $, & etc,nor will control sequences like \newline have anyeffect.\endverbatim

will produce the simulated input text

In the verbatim environment we can type anythingwe like.So we don’t need to look out for uses of %, $, & etc,nor will control sequences like \newline have anyeffect.

The only thing that cannot be typed in the verbatim environment isthe sequence \endverbatim. You might notice that I still managed tosimulate that control sequence above. One can always get what you want inTEX, perhaps with a little creativity.

If we want only to simulate a few typed words, such as when I say touse \newline to start a new line, then the \verb command is used. Thiscommand has a slightly odd syntax, pressed upon it by the use for whichit was intended. It cannot accept an argument, because we may want tosimulate typed text that is enclosed by braces. What one does is to chooseany character that is not in the text to be simulated, and use a pair of thesecharacters as “argument delimiters”. I usually use the @ or " characters, asI rarely have any other uses for them. Thus

use \% to obtain a % sign

is typed as

use \verb"\%" to obtain a \% sign

2.16.4 itemize, enumerate, description environments

LATEX provides three predefined list-making environment, and a “primitive”list environment for designing new list environments of your own. We shalljust describe the predefined ones here.

26

Page 31: Basic Latex

There is delightfully little to learn in order to be able to create lists.The only new command is \item which indicates the beginning of a newlist item (and the end of the last one if this is not the first item). Thiscommand accepts an optional argument (which means you’d enclose it insquare brackets) that can be used to provide an item label. If no optionalargument is given, then LATEX will provide the item label for you; in anitemize list it will bullet the items, in an enumerate list it will number theitems, and in a list of descriptions the default is to have no label (whichwould look a bit odd, so you’re expected to use the optional argument there).

Remember that \item is used to separate list items; it does not acceptthe list item as an argument.

\beginitemize\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 theinput file, but that is just to keep thingsreadable. As always, \LaTeX\ ignores additionalspaces.

\item a blank line between items is ignored, for\LaTeX\ is responsible for spacing items.\item \LaTeX\ is in paragraph-setting mode whenit reads the text of an item, and so willperform all the usual functions\enditemize

produces the following itemised list:

• an item is begun with \item

• if we don’t specify labels, then LATEX will bullet the items for us

• I indent lines after the first in the input file, but that is just to keep things readable.As always, LATEX ignores additional spaces.

• a blank line between items is ignored, for LATEX is responsible for spacing items.

• LATEX is in paragraph-setting mode when it reads the text of an item, and so willperform all the usual functions

Lists can also be embedded within one another, for they are just environ-ments and we said that environments have this property. Remember that we

27

Page 32: Basic Latex

must nest them in the correct order. We demonstrate with the following list,which also shows how to use the enumerate environment.

\noindent I still have to do the following things:\beginenumerate\item Sort out LAN accounts for people on the course\beginitemize\item Have new accounts created for those not alreadyregistered on the LAN

\item Make sure all users have a personal directoryon the data drive\enditemize

\item Have a \TeX\ batch file added to a directory thatis on a public search path\endenumerate

will give the following listI still have to do the following things:

1. Sort out LAN accounts for people on the course

• Have new accounts created for those not already registered on the LAN

• Make sure all users have a personal directory on the data drive

2. Have a TEX batch file added to a directory that is on a public search path

See how I lay the source file out in a readable fashion. This is to assistmyself, not LATEX.

The description environment is, unsurprisingly, for making lists of de-scriptions.

\begindescription\item[\textttitemize] an environment for setting itemised lists.\item[\textttenumerate] an environment for setting numbered lists.\item[\textttdescription] an environment for listing descriptions.\enddescription

will typeset the following descriptions:

itemize an environment for setting itemised lists.

enumerate an environment for setting numbered lists.

description an environment for listing descriptions.

28

Page 33: Basic Latex

2.16.5 tabbing environment

This environment simulates tabbing on typewriters. There one chose the tabstops in advance (analysing the material to be typed for the longest item ineach column) and typed entries consecutively, hitting the tab key to move tothe next tab stop and return to move to the next line.

In the tabbing environment, we proceed similarly. We look for the worst-case line (that which will determine the desired tab stops) and use it to setthe tabs by inserting \= control symbols at the points where we want tabstops. We then discard that line using \kill, since the worst-case line mightnot be the first line in the material we have to type. We then type each line,using \> to move to the next tab stop and \\ to end a line.

\begintabbingCheddar cheese \= Recommended \= \$2.00 \killGreen Ham \> Recommended \> \$2.00Eggs \> 1 a week \> \$1.50Cheddar cheese \> Hmmm \> \$0.80Yak cheese \> Avoid \> \$0.05\endtabbing

gives the following uniformly-tabbed table

Green Ham Recommended $2.00Eggs 1 a week $1.50Cheddar cheese Hmmm $0.80Yak cheese Avoid $0.05

In the format line I chose the longest entry from each of the prospectivecolumns. I lined some of the \> commands up in the source just to keepthings readable.

Remember that excess spaces are ignored. LATEX sets the \killed linenormally and sees where the tab stops requested will be needed in the typesettext. Note also that commands given within the tabbing environment arelocal to the current item.

Actually, we use the above approach in the case that we require uniformlytabbed columns. The format line is not compulsory, and we can define tabstops dynamically. See if you can make sense of the following.

29

Page 34: Basic Latex

\begintabbingEntry 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\endtabbing

which produces

Entry in position 1,1 Entry 1,2 Entry 1,3Entry in position 2,1 Entry 2,2 Entry 2,3Entry 3,1 Entry 3,2 Entry 3,3Entry 4,1 Entry 4,2 Entry 4,3

The are additional commands that can be used within the tabbing envi-ronment to achieve special effects, but we won’t be discussing them here.

2.16.6 tabular environment

The tabular environment is used to produce tables of items, particularlywhen the table is predominantly rectangular and when line drawing is re-quired. LATEX will make most decisions for us; for instance it will aligneverything for us without having to be told which are the longest entries ineach column.

This environment is the first of many that use the TEX “tabbing char-acter” &. This character is used to separate consecutive entries in a row ofa table, array, etc. The end of a row is indicated in the usual manner, byusing \\. In this way the individual cells of the table, or array, are clearlydescribed to LATEX, and it can analyse them to make typesetting decisions.Commands issued within a cell so defined are, again, local to that cell.

The tabular environment is also our first example of an environmentwith arguments. The arguments are given, in braces as usual, just after theclosing brace after the environments name. In the case of tabular there isa single mandatory argument giving the justification of the entries in eachcolumn: l for left justified, r for right justified, and c for centred. Theremust be an entry for each column of the table, and there is no default. Let’sstart with a simple table.

30

Page 35: Basic Latex

\begintabularllrrl\texbfStudent name & \textbfNumber & \textbfTest 1& \textbfTest 2 & \textbfComment\\F. Basset & 865432 & 78 & 85 & Pleasing\\H. Hosepipe & 829134 & 5 & 10 & Improving\\I.N. Middle & 853931 & 48 & 47 & Can make it\endtabular

will produce the following no-frills tableStudent name Number Test 1 Test 2 CommentF. Basset 865432 78 85 PleasingH. Hosepipe 829134 5 10 ImprovingI.N. Middle 853931 48 47 Can make it

Note that a \\ was not necessary at the end of the last row. Also notethat, once again, the alignment of the & characters was for human readability.It is conventional to set columns of numbers with right justification.

A | typed in the tabular environment’s argument causes a vertical lineto be drawn at the indicated position and extending for the height of theentire table. An \hline given in the environment draws a horizontal lineextending the width of the table to be drawn at the vertical position atwhich the command is given. A \clinei-j draws a line spanning columnsi to j, at the vertical position at which the command is given. A repeatedline-drawing command causes a double line to be drawn. We illustrate linedrawing in tables by putting some lines into our first table. We will type thisexample in a somewhat expanded form, trying to make it clear why the linesappear where they do.

\begintabular|l|l|r|r|l|\hline\textbfStudent name & \textbfNumber & \textbfTest 1& \textbfTest 2 & \textbfComment\\\hlineF. Basset & 865432 & 78 & 85 & Pleasing\\\hlineH. Hosepipe & 829134 & 5 & 10 & Improving\\\hlineI.N. Middle & 853931 & 48 & 47 & Can make it\\\hline\endtabular

which will give

31

Page 36: Basic Latex

Student name Number Test 1 Test 2 CommentF. Basset 865432 78 85 PleasingH. Hosepipe 829134 5 10 ImprovingI.N. Middle 853931 48 47 Can make it

That way of laying out the source file makes it clear where the lines willgo. As we (by now) well know, the returns that we pressed after the \\s intyping this table might as well have been spaces as far as LATEX is concerned.Thus it is common to have the \hline commands following the \\s on theinput lines. We will do this in future examples.

The \multicolumn column can be used to overrule the overall format ofthe table for a few columns. The syntax of this command is

\multicolumn n pos item where n is the number of columns of the original format that item is to span,and pos specifies the justification of the new argument.

\begintabular||l|c|c|c|| \hline\multicolumn4|c|\LaTeX\ size changing commands\\ \hlineStyle option & 10pt (default) & \tt 11pt & \tt 12pt\\ \hline\tt\bs footnotesize & 8pt & 9pt & 10pt\\ \hline\tt\bs small & 9pt & 10pt & 11pt\\ \hline\tt\bs large & 12pt & 12pt & 14pt\\ \hline\endtabular

produces the following table:

LATEX size changing commandsStyle option 10pt (default) 11pt 12pt\footnotesize 8pt 9pt 10pt\small 9pt 10pt 11pt\large 12pt 12pt 14pt

2.16.7 figure and table environments

Figures (diagrams, pictures, etc.) and tables (perhaps created with the tabularenvironment) cannot be split across pages. So LATEX provides a mechanismfor “floating” them to a nearby place where there is room for them. This maymean that your figure or table may appear a little later in the document thanits declaration in the source file might suggest. You can suggest to LATEXthat it try to place the figure or table at the present position if there is roomor, failing that, at the top or bottom of the present or following page. Youcan also ask for it to be presented by itself on a “page of floats”.

32

Page 37: Basic Latex

You suggest these options to LATEX through an optional argument to theenvironment. One lists a combination of the letters h, t, b, and p where

ht means that the object should be placed here if there is room, so thatthings 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, butno earlier than the present page.

b means that the object can be placed at the bottom of a text page, but noearlier than the present page.

p means that the object should be set on a page of floats that consists onlyof tables and figures.

A combination of these indicates decreasing order of preference. Thedefault is tbp.

LATEX will also number and caption a figure or table for you, and com-pile a list of tables and a list of figures. Just include \listoffigures and\listoftables next to your \tableofcontents command at the beginningof the document. To caption a table of figure, include \captioncaptiontext just before the \endtable or \endfigure command. Here’s asample source file.

\begintable[ht]\begintabularlrll...\endtabular

\captionMark analysis\endtable

To leave space for a figure that will inserted by some other means at alater date, we can use the \vspace command:

\beginfigure[ht]\vspace9.5cm\captionAn artists impression\endfigure

Including graphics files prepared with drawing packages is possible, butbeyond the scope of this introduction.

33

Page 38: Basic Latex

2.17 The letter document class

To write a letter, we can make use of the letter document class. We givehere a sample letter:

\documentclass[12pt]letter\usepackageamssymb, amsmath, amsthm, amsfonts\begindocument\beginLetterDirector of Public Parks\\Pietermaritzburg Municipality\\Pietermaritzburg

\address(Underneath) Lion Bridge\\Midway down Commercial Road\\Pietermaritzburg\\3200

\signatureF. Basset

\openingKind Sir/Madam,

I wish to complain about the shocking practice offencing off the base of trees. I notice with graveconcern that this has occurred in the park borderingmy stately residence, and I demand thatyou take these obscene obstructions away withoutdelay.

\closingYours anxiously,\endletter\enddocument

2.18 Bibliography

LATEX has a very convenient system of making a bibliography, in that itautomatically numbers bibliographic entries. Below is an example of a bib-liography; such a bibliography is usually put at the very end of a document(right before \enddocument), though in principle it could be put anywhere.(Note that the bibliographic style used below corresponds to the style of theAmerican Mathematical Society, and is somewhat different than other bibli-ographics styles, such as in the humanities.)

34

Page 39: Basic Latex

\beginthebibliography99

\bibitemMARKMarkov, A. A.,\emphUnsolvability of the problem of homeomorphism,Proc. Int. Cong. Math.,1958,pp.~300--306(Russian).

\bibitemMU1Munkres, James R.,\emphTopology, A First Course,Prentice-Hall,Englewood Cliffs, NJ,1975.

\bibitemir63Richards, Ian,\emphOn the classification of noncompact surfaces,Trans. Amer. Math. Soc.,\textbf106~(1963),259--269.

\endthebibliography

The above produces:

35

Page 40: Basic Latex

Bibliography

[1] Markov, A. A., Unsolvability of the problem of homeomorphism, Proc. Int. Cong.Math., 1958, pp. 300–306 (Russian).

[2] Munkres, James R., Topology, A First Course, Prentice-Hall, Englewood Cliffs, NJ,1975.

[3] Richards, Ian, On the classification of noncompact surfaces, Trans. Amer. Math. Soc.,106 (1963), 259–269.

Observe that each new bibiographic item starts with \bibitemlabelname,where labelname is used to refer to the bibliographic entry in the text ofthe document. As is the case with other labels, these bibliographic labelsdo not appear in the printed version of the text, and you can choose any-thing you want for the label, preferably something mnemonic. To refer toa bibliographic item, we would write \citelabelname. Optional addi-tional information, such as chapter or page numbers, can be put in squarebrackets. For example, if we write \citeMU1 we would have [2], whereas\cite[Section 3.1]MU1 yields [2, Section 3.1].

Note that unlike regular text, in the bibliographic items TEX is not both-ered by a period that is not at the end of a sentence, and you do not needto do anything about such periods.

2.19 Common pitfalls; Error messages

By now it should be clear that we have to work quite accurately when prepar-ing a document. Typing errors in the running text can be absorbed, butmessing up a control sequence name will halt the compiler with an errormessage. Before we look at some common errors and some ways to avoidthem, let’s have a look at a sample error message.

You’ll have noticed by now that when you run LATEX on a source file,the transcript of the compiler session is written on a log file. When errors

36

Page 41: Basic Latex

have accumulated to the point that LATEX is hopelessly confused, it is timeto debug your source file. The log file contains a reference to the line, orlines, of your source file that generated the error together with a descriptionof the error.

TEX and LATEX error messages appear frightening at first sight, to saythe least. They are actually very informative, but they can take some get-ting used to. Mistyped control sequences cause little pain, but a missing\endenvironment can cause a good deal of confusion because it has theeffect of making LATEX try to set material into that environment that wasnever intended/designed to fit in such a place. Also, ommiting a mandatoryargument can cause great confusion.

Suppose we type \textbold instead of \textbf in the following line:

this is going to be \textboldvery messy.

This produces the following error message:

! Undefined control sequence.1.683 this is going to be \textbold

very messy.?

That’s not so bad! The line beginning with ! tells us that we have triedto used a control sequence that was not known to LATEX; the 1.683 tells usthat the error occurred on line 683 of the source file; and the error messageis split over two lines with the break occurring at the point where LATEXdetected a problem.

But suppose we try the following

\begintabularllrrlStudent 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

This shows that H.~Hosepipe’s newfound concentration has...

i.e., we omit to provide the \endtabular that delimits the end of theenvironment. Not having been told that the environment is supposed to beconcluded, LATEX will try to set the text of the next paragraph as a table

37

Page 42: Basic Latex

item—and will scream blue murder when it finds that it doesn’t conform tothe syntax demanded.

LaTeX error. See LaTeX manual for explanation.Type H <return> for immediate help.! \begintabular ended by \enddocument.\@latexerr ...diate help.\errmessage #1

\@checkend ...urrenvir \else \@badend #1\fi

\enddocument ->\@checkend document\clearpage \begingroup \if@filesw...

\end #1->\csname end#1\endcsname\@checkend #1\expandafter \endgrou...

l.58 \enddocument

?

Now that’s informative! Actually it is if we agree to ignore all but thethe error indication line (the one beginning with the !) and the line tellingus where LATEX noticed that all was not well (the one beginning 1.58 in thiscase). The rest of the error message you can regard as being for your localTEX wizard to sort your problem out if you are unable to after consulting themanuals. Tough as it looks, we can decipher this message straight away: theerror indicator line tell us that a tabular environment was ended incorrectly(in this case by an \enddocument).

TEX error messages aren’t all that bad once you’ve made enough errorsto get used to a few! Most can be avoided through careful preparation ofthe source file. Typing accurately and knowledge of the command syntax isa 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 fileout as regularly and logically as possible—you will make fewer errorsthat way.

2. It is important that all group delimiters be properly matched, i.e.,braces and \begin. . . \end must come in pairs. A good habit tofall in to is to always type such things in pairs and then move the cursorback between them and type the intervening material.

3. Don’t forget command arguments when they are mandatory. Alwaysask yourself what a particular commands needs from you in order to

38

Page 43: Basic Latex

make the decisions that are required of it.

4. Remember the 10 characters that are specially reserved for comment-ing, table item separation, etc.

5. When we look at mathematical typesetting in the next chapter, we willsee that the same principles apply there.

6. Try to use a text editor that has a TEX mode, or at least one that willmatch brackets for you.

39

Page 44: Basic Latex

Chapter 3

Mathematical Typesetting withLATEX

3.1 Introduction

In text-only documents we saw that our task was to describe the logicalcomponents of each sentence, paragraph, section, table, etc. When we tellLATEX to go into mathematical mode, we have to describe the logical parts ofa formula, matrix, operator, special symbol, etc. LATEX has been taught torecognize a binary operation, a binary relation, a variable, an operator thatexpects limits, and so on. We just need to supply the parts that make upeach of these, and LATEX will automatically leave appropriate space aroundoperators, italicise variables, set an operator name in roman type, leave thecorrect space after colons, place sub- and superscripts in the correct positions(based on what it is you’re working with), choose the correct typesizes, andmore. When you want to revert to setting normal text again, you tell LATEXtoo leave math mode and go back into the mode it was in (paragraphingmode).

LATEX cannot be expected to perform these mode shifts itself, for it is notalways 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 thedefinite article) or a mathematical variable (as in the variable a). There areno reliable rules for LATEX to make such decisions by, so the begin-math andend-math mode switching is left entirely to you.

The symbol $ is specially reserved by LATEX as the “math shift” symbol

40

Page 45: Basic Latex

(see Section 2.6). When LATEX starts setting a document it is in paragraphingmode, ready to set lines of the input file into paragraphs. It remains in thismode until it encounters a $ symbol, which shifts LATEX into mathematicalmode. It reads everything up to the next $ sign in this mathemtical mode,and then shifts back to the mode it was in before we took it in to math 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 betweenthem and type the mathematical expression. If the math-shift symbols in adocument are not matched, then LATEX will become confused because it willbe trying to set non-mathematical material as mathematics.

For those who find having the same symbol for both math-begin andmath-end confusing or dangerous, there are two control symbols that performthe same operations: the control symbol \( is a begin-math instruction, andthe control symbol \) is an end-math instruction. Because it is easy to“lose” a $ sign when typing a long formula, a math environment is providedfor such occasions: you can use \beginmath and \endmath as the math-shift instructions. However, most often the $ sign suffices.

Let’s have a look at some mathematics.

\LaTeX\ is normally in paragraphing mode, whereit expects to find the usual paragraph material. Includinga mathematical expression, like $2x+3y - 4z= -1$, in theparagraph text is easy.Typing the above expression without entering mathmode produces the incorrect result: 2x+3y - 4z= -1

will produce the following paragraphLATEX is normally in paragraphing mode, where it expects to find

the usual paragraph material. Including a mathematical expression, like2x + 3y − 4z = −1, in the paragraph text is easy. Typing the aboveexpression without entering math mode produces the incorrect result:2x+3y - 4z= -1

Notice that LATEX sets space around the binary relation = and spacearound the binary operators + and − on the left hand side of the equation,ignoring the spacing we typed in the input. It was also able to recognize thatthe −1 on the right hand side of the equation was a unary minus—negatingthe 1 rather than being used to indicate subtraction—and so did not putspace around it. It also italicised the variables x, y, and z. However, it didnot italicise the number 1.

In typing a mathematical expression we must remember to keep the fol-

41

Page 46: Basic Latex

lowing in mind:

1. All letters that are not part of an argument to some control sequencewill be italicised. So typing $f(x)>0 for x > 1$ will produce

f(x) > 0forx > 1

instead of the expression

f(x) > 0 for x > 1

that we intended. Numerals and punctuation marks are set in normalroman type but LATEX will take care of the spacing around punctuationsymbols, as in

$f(x,y) \geq 0$

which producesf(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 tomath mode to type the symbol, you’ll get things like “the constant a”.

3. Some symbols have a different meaning when typed in math mode. Notonly do ordinary letters become variables, but symbols such as - and+ are now interpreted as mathematical symbols. Thus in math mode -

is no longer considered a hyphen, but as a minus sign.

4. LATEX ignores all spaces and carriage returns when in math mode,without exception. So typing something like the constant$ a$ willproduce “the constanta”. You should have typed the constant $a$.LATEX is responsible for all spacing when in math mode, and (as inparagraphing mode) you have to specially ask to have spacing changed.Even if LATEX does ignore all spaces when in math mode you should (asalways in TEX) still employ spaces to keep your source file readable.

One could type either

42

Page 47: Basic Latex

$f(x, y) = 2 (x+ y)y/(5xy - 3 )$

or

$f(x,y) = 2(x+y)y / (5xy-3)$

and you’d still get the correct result

f(x, y) = 2(x + y)y/(5xy − 3) .

There are some places where LATEX’s automatic spacing can go wrong.For instance, if we wish to speak of the x–y plane then one has to know thatit is an endash that is supposed to be placed between the x and the y, not aminus sign (as $x-y$ would produce). But typing $x--y$ will produce x−−ysince both dashes are interpreted as minus signs. To avoid speaking of thex− y plane or the x−−y plane, we should type it as the $x$--$y$ plane.Fortunately, LATEX can recognize and cope with by far the majority of ourmathematical 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 arereserved for delimiting groups in the input file. Looking back to Section 2.6,we see how it should be done:

$ \ x: f(x)>0 \ $

Math shift commands also behave as scope delimiters, so that commandsissued in an expression cannot affect anything else in a document.

3.2 Displaying a formula

LATEX considers an expression $ ... $ to be word-like in the sense that itconsiders it to be eligible for splitting across lines of a paragraph (but with-out hyphenation, of course). LATEX tries to avoid it splitting mathematicalformulas across lines, , but when there is no other way, it will split a for-mula at a suitable place. But there are some expressions which are just too

43

Page 48: Basic Latex

long to fit into the running text without looking awkward. These are best“displayed” on a line by themselves. Also, some expressions are sufficientlyimportant that they should be made to stand out. These, too, should bedisplayed on a line of their own.

The mechanism for displaying an expression is the display math mode,which is begun by typing $$ and ended by typing the same sequence (whichagain means that we’d better be sure to type them in pairs). Correspondingto the alternatives \( and \) that we had for the math shift character $, wemay use \[ and \] as the display-math shift sequences. One can also use theenvironment

\begindisplaymath ... \enddisplaymath

which is equivalent to $$ ... $$ and is suitable for use with long displayedexpressions. If you wish LATEX to number your equations for you you can usethe environment

\beginequation\labellabelname ... \endequation

which is the same as the displaymath environment, except that an equa-tion number will be generated. You do not write an equation number—LATEX takes care of that. As discussed in Section 2.14, the name labelname

does not appear in the printed version of the text, and you can choose any-thing you want for the label. To refer to the numbered equation, writeEquation~\reflabelname.

It is poor style to have a displayed expression either begin a paragraphor be a paragraph by itself. This can be avoided if you agree never to leavea blank line in your input file before a math display.

We will see later how to typeset an expression that is to span multiplelines. 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$$\cal B_a(f) = \ L_a+r(f) : r > 0 \,$$and these are easily seen to be completely regular.

which produces

44

Page 49: Basic Latex

For each a for which the Lebesgue-set La(f) = ∅ we define

Ba(f) = La+r(f) : r > 0,

and these are easily seen to be completely regular.

We have not yet seen all the commands in the above formula, but we willsee them later in this chapter.

3.3 Using mathematical symbols

Mathematical symbols in LATEX are obtained by control words, most of whichare quite mnemonic. None of the control words for mathematical symbolsaccepts an argument, but we’ll soon see that some of them prepare LATEXfor something that might follow. For instance, when you ask for the symbol‘∑

’ LATEX is warned that any sub- or superscripts that follow should bepositioned appropriately as limits to a summation.

Some of the symbols behave differently depending on where they are used.For instance, when I ask for

∑ni=1 ai within the running text, the limits are

places differently to when I ask for that expression to be displayed:

n∑i=1

ai .

I typed nothing different here—just asked for display math mode.It is important to note that almost all of the special math symbols are

unavailable in ordinary paragraphing mode. If you need to use one there,then use an in-line math expression $...$.

3.3.1 Symbols available from the keyboard

A small percentage of the available symbols can be obtained from just asingle key press. They are + − = < > | / ( ) [ ] and ∗. Note that these mustbe typed within math mode to be interpreted as math symbols.

Of course, all of a–z, A–Z, the numerals 0, 1, 2, . . . , 9 and the punctua-tion characters , ; and : are available directly from the keyboard. Alphabeticletters will be assumed to be variables that are to be italicised, unless toldotherwise (see Section 3.4.6). The numerals receive no special attention, ap-pearing precisely as in normal paragraphing mode. The punctuation symbolsare still set in standard roman type when read in math mode, but a little

45

Page 50: Basic Latex

space is left after them so that expressions like xi : i = 1, 2, . . . , 10 look likethey should. Note that this means that normal sentence punctuation shouldnot migrate into an expression.

3.3.2 Greek letters

Each lowercase Greek letter is accessed by typing the control word of thesame name as the symbol, using all lowercase letters.

α \alpha β \beta γ \gamma δ \deltaε \epsilon ε \varepsilon ζ \zeta η \etaθ \theta ϑ \vartheta ι \iota κ \kappaλ \lambda µ \mu ν \nu ξ \xiπ \pi \varpi ρ \rho \varrhoσ \sigma ς \varsigma τ \tau υ \upsilonφ \phi ϕ \varphi χ \chi ψ \psiω \omega

To obtain an uppercase Greek letter, simply capitalize the first letter ofits name:

Γ \Gamma ∆ \Delta Θ \Theta Λ \LambdaΞ \Xi Π \Pi Σ \Sigma Υ \UpsilonΦ \Phi Ψ \Psi Ω \Omega

3.3.3 Changing math fonts

Suppose that we want to write the sentence

For every x ∈ R, we have a set Fx.

We would obtain the blackboard bold and calligraphic uppercase lettersin the above sentence by writing

For every $x \in \mathbbR$, we have a set $\mathcalF_x$.

These two font change command, which work only in math mode, andonly for uppercase letters, are \mathbb and \mathcal .

We list here all the blackboard bold and calligraphic letters, so that wecan see, for reference purposes, what they all look like:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

ABCDEFGHIJKLMNOPQRST UVWXYZ

46

Page 51: Basic Latex

There are other change of text style commands that work specifically inmath mode, including \mathbf (bold), \mathsf (sans serif) and\mathit (italic). Use these commands only in math mode, and don’tuse the regular change of text style commands (for example \textbf inmath mode).

3.3.4 Binary operators

LATEX has been taught to recognize binary operators and set the appropriatespace either side of one—i.e., it sets the first argument followed by a littlespace, then the operator followed by the same little space and finally thesecond argument. The binary operators that are available are the follow-ing (recall that the binary operators +, −, and ∗ can be typed from thekeyboard):

± \pm ∩ \cap \diamond ⊕ \oplus∓ \mp ∪ \cup \bigtriangleup \ominus× \times \uplus \bigtriangledown ⊗ \otimes÷ \div \sqcap \triangleleft \oslash∗ \ast \sqcup \triangleright \odot \star ∨ \vee ∧ \wedge © \bigcirc† \dagger \ \setminus \amalg \circ‡ \ddagger · \cdot \wr • \bullet

Here are some examples:

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)

3.3.5 Binary relations

LATEX has been taught to recognize the use of binary relations, too. Thebinary relations that are available are the following (recall that the binaryrelations <, >, =, and | can be typed from the keyboard):

47

Page 52: Basic Latex

≤ \leq ≥ \geq ≡ \equiv |= \models≺ \prec \succ ∼ \sim ⊥ \perp# \preceq $ \succeq % \simeq | \mid& \ll ' \gg ( \asymp ‖ \parallel⊂ \subset ⊃ \supset ≈ \approx \bowtie⊆ \subseteq ⊇ \supseteq ∼= \cong \Join \sqsubset \sqsupset = \neq \smile/ \sqsubseteq 0 \sqsupseteq

.= \doteq ! \frown∈ \in 1 \ni ∝ \propto3 \vdash 4 \dashv

To negate a symbol you can precede the control word that gives thesymbol by a \not. Some symbols come with ready-made negations, whichshould be used above the \not’ing method because the slope of the negatingline is just slightly changed to look more pleasing. Thus \notin should beused above \not\in, and \neq should be used above \not =.

If negating a symbol produces a slash whose horizontal positioning isnot to your liking, then use the math spacing characters described in Sec-tion 3.4.14 to adjust it.

3.3.6 Miscellaneous symbols

There are various miscellaneous symbols that these are available only in mathmode:

ℵ \aleph ′ \prime ∀ \forall ∞ \infty \hbar ∅ \emptyset ∃ \exists \Boxı \imath ∇ \nabla ¬ \neg \triangle \jmath

√\surd # \flat \triangle

$ \ell : \top % \natural ♣ \clubsuit℘ \wp ⊥ \bot ' \sharp ♦ \diamondsuit= \Re ‖ \| \ \backslash ♥ \heartsuit? \Im ∠ \angle ∂ \partial ♠ \spadesuit \mho

Note that \imath and \jmath should be used when you need to accentan i or a j in math mode (see Section 3.3.10)—you cannot use \i or \j thatwere available in paragraphing mode.

3.3.7 Arrow symbols

LATEX has a multitude of arrow symbols, around which it will set the correctspace around. Note that vertical arrows can all be used as delimiters—see

48

Page 53: Basic Latex

Section 3.3.8. The available arrow symbols are:

← \leftarrow ←− \longleftarrow ↑ \uparrow⇐ \Leftarrow ⇐= \Longleftarrow ⇑ \Uparrow→ \rightarrow −→ \longrightarrow ↓ \downarrow⇒ \Rightarrow =⇒ \Longrightarrow ⇓ \Downarrow↔ \leftrightarrow ←→ \longleftrightarrow d \updownarrow⇔ \Leftrightarrow ⇐⇒ \Longleftrightarrow f \Updownarrowg→ \mapsto g−→ \longmapsto \nearrow← \hookleftarrow → \hookrightarrow \searrow \leftharpoonup \rightharpoonup \swarrow \leftharpoondown \rightharpoondown \nwarrow \rightleftharpoons \leadsto

3.3.8 Expression delimiters

A pair of delimters often enclose an expression, as in[a11 a12

a21 a22

]and f(x) =

x if x < 1x2 if x ≥ 1

.

LATEX will scale delimiters to the correct size (determined by what they en-close) for you, if you ask it to. There are times when you don’t want adelimiter 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 mustbe balanced correctly. It sometimes occurs, as in the right-hand exampleabove, that only one member of a delimiting pair is to be visible. For thispurpose, use the commands \left. and \right. which will produce novisible delimiter but can be used to correctly balance the delimiters in anexpression. For examples of the use of delimiters, see Section 3.4.11, wherewe learn about arrays. The available delimiters are:

( ( ) ) ↑ \uparrow[ ] ] ] ↓ \downarrow \ \ d \updownarrowl \lfloor m \rfloor ⇑ \Uparrown \lceil o \rceil ⇓ \Downarrow〈 \langle 〉 \rangle f \Updownarrow/ / \ \backslash| — ‖ \|

49

Page 54: Basic Latex

3.3.9 Operators like

∫and∑

These behave differently when used in display-math mode as compared within-text math mode. When used in text, they will appear in their small formand any limits provided will be set so as to reduce the overall height of theoperator, as in

∑Ni=1 fi. When used in display-math mode, LATEX will choose

to use the larger form and will not try to reduce the height of the operator,as in

N∑i=1

fi .

If you want one of these operators to be used in text, but you want it tolook as it does when it is in display-math mode, simply insert the com-mand \displaystyle at the start of the in-text math mode. For example, if

we write $\displaystyle \sum_i=1^Nf_i$, we will obtain

N∑i=1

fi even

though it is in text. (The \displaystyle command should be used withcaution, because the resulting changes to line spacing often looks rather un-pleasant, as in the previous sentence.

The available operators of this type are:

∑∑\sum

⋂ ⋂\bigcap

⊙⊙\bigodot∏∏

\prod⋃ ⋃

\bigcup⊗⊗

\bigotimes∐∐\coprod

⊔ ⊔\bigsqcup

⊕⊕\bigoplus∫ ∫

\int∨ ∨

\bigvee⊎ ⊎

\biguplus∮ ∮\oint

∧ ∧\bigwedge

In Section 3.4.1 we will learn how to place limits on these operators.

3.3.10 Accents in math mode

The accenting commands that we learned for paragraphing mode do notapply in math mode. Instead, we use the following command:

u \hatu u \acuteu u \baru u \dotuu \checku u \graveu 2u \vecu u \ddotuu \breveu u \tildeu

50

Page 55: Basic Latex

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 “widehat” or a “wide tilde” to their argument, \widehat and \widetilde.

3.4 Some common mathematical structures

In this section we shall begin to learn how to manipulate all the symbolslisted in section 3.3. Indeed, by the end of this section we’ll be able to typesetsome quite large expressions. In the section following this we will learn howuse various alignment environments that allow us to prepare material likemulti-line expressions and arrays.

3.4.1 Subscripts and superscripts

Specifying a sub- or superscript is as easy as you’d hope—you just givean indication that you want a sub- or superscript to the last expressionand provide the material to be placed there, and LATEX will position thingscorrectly. So sub- and superscripting a single symbol, an operator, or a bigarray all involve the same input, and LATEX places the material according towhat the expression is that is being sub- or superscripted:

x2 ,N∏

i=1

Xi ,

a11 a12 a13

a21 a22 a23

a31 a32 a33

2

.

To tell LATEX that you want a single character set as a superscript tothe last expression, you just type a ^ before it. The “last expression” is thepreceding group or, if there is no preceding group, the single character orsymbol that the ^ follows:

Type To produce

$x^2$ x2

$\gamma^b$ γb

$(A+B)^2$ (A+B)2

$\left[ \fracx^2+1x^2 + y^2 \right]^n$[

x2+1x2+y2

]nSubscripts of a single character are equally easy—you just use the under-

score character _ where you used ^ for superscripting:

51

Page 56: Basic Latex

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 thanjust one character. This is no more difficult than before if we remember thefollowing rule: The symbols _ and ^ set the group that follows them as asub- and superscripts to the group that precedes the sub- and superscriptsymbols. We see now now that our initial examples worked by considering asingle character to be a group by itself. Here are some examples:

Type To produce

$a^2b^3$ a2b3

$2^21$ 221

$2^21$ 221

$a^x+1$ ax+1

$a^x^2+1$ ax2+1

$(x+1)^3$ (x + 1)3

$\Gamma_\alpha\beta\gamma$ Γαβγ

$_1A_2$ 1A2

In the very last example we see a case of setting a subscript to an emptygroup, which resulted in a kind of “pre-subscript”.

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 super-scripting it. Even in setting the expression (x + 1)3, the superscript 3 wasreally only set to the character ). If we had wanted to group the (x + 1) be-fore 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 troublebecause, to most people, something like (xa)b is just as acceptable and asreadable as (xa)b. It also has the advantage of aligning the base lines inexpressions such as

(ab)−2 = [(ab)−1]2 = [b−1a−1]2 = b−1a−1b−1a−1

which looks more pleasing than if we use additional grouping to force

(ab)−2 = [(ab)−1]2

= [b−1a−1]2

= b−1a−1b−1a−1 ,

52

Page 57: Basic Latex

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

$x^y^z$ xyz

$2^(2^2)$ 2(22)

$2^2^2^\aleph_0$ 222ℵ0

$\Gamma^z_c^d$ Γzdc

We can also make use of empty groups in order to stagger sub- andsuperscripts to an expression, as in

$\Gamma_\alpha\beta^\gamma_\delta$

which will yield

Γαβγ

δ

One can specify the sub- and superscripts to a group in any order, but it isbest to be consistent. The most natural order seems to be to have subscriptsfirst, but you may think otherwise.

3.4.2 Primes

LATEX provides the control word \prime (′) for priming symbols. Note thatit is not automatically at the superscript height, so that to get f ′ you wouldhave to type

$f^\prime$ .

To make lighter work of this, LATEX will interpret a right-quote character asa prime if used in math mode. Thus we can type

$f’(g(x)) g’(x) h’’(x)$

in order to get

f ′(g(x))g′(x)h′′(x) .

53

Page 58: Basic Latex

3.4.3 Fractions

LATEX provides the \frac command that accepts two arguments: the numer-ator and the denominator (in that order). Before we look at examples of itsuse, let us just note that many simple in-text fractions are often better writ-ten in the form num/den, as with 3/8 which can be typed as $3/8$. This isalso often the better form for a fraction that occurs within some expression.

Type To produce

$\fracx+1x+2$x+ 1x+ 2

$\frac1x^2+1$1

x2 + 1

$\frac1+x^2x^2+y^2 + x^2 y$1 + x2

x2 + y2+ x2y

$\frac11 + \fracx2$1

1 + x2

$\frac11+x/2$1

1 + x/2

3.4.4 Roots

The \sqrt command accepts two arguments. The first, and optional, argu-ment specifies what order of root you desire if it is anything other than thesquare root. The second, and mandatory, argument specifies the expressionthat the root sign should enclose:

Type To produce

$\sqrta+b$√a+ b

$\sqrt[5]a+b$ 5√a+ b

$\sqrt[n]\frac1+x1+x^2$ n

√1 + x1 + x2

$\frac\sqrtx+1 \sqrt[3]x^3+1$

√x+ 1

3√x3 + 1

54

Page 59: Basic Latex

3.4.5 Ellipsis

Simply typing three periods in a row will not give the correct spacing of theperiods 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 + · · ·+ an$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

3.4.6 Text within an expression

One can use the \text command to insert normal text into an expres-sion. This command forces LATEX temporarily out of math mode, so that itsargument will be treated as normal text. It’s use is simple, but we must bewary on one count: remember that LATEX ignores all space characters whenin math mode; so to surround words in an expression that were placed by an\text command by space you must include the space in the \text argument.

Type To produce

$f_i(x) \leq 0 \text for x \in I$ fi(x) ≤ 0 for x ∈ I$\Gamma(n)=(n-1)! \text when $n$ is an integer$ Γ(n) = (n− 1)! when n is an integer

In section 3.4.14 we’ll learn of some special spacing commands that canbe used in math mode. These are often very useful in positioning text withinan expression, enhancing readability and logical layout.

3.4.7 Log-like functions

There are a number of function names and operation symbols that should beset in normal (roman) type in an expression, such as in

f(θ) = sin θ + log(θ + 1)− sinh(θ2 + 1)

55

Page 60: Basic Latex

and

limh→0

sin h

h= 1 .

We know that simply typing $log\theta$ would produce the incorrectresult

logθ

and that using $\mboxlog\theta$ would leave us having to insert a littleextra space between the log and the θ

logθ .

So LATEX provides a collection of “log-like functions” defined as control se-quences. The following table shows those that are available.

\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

Here are some examples of log-like functions:

Type To produce

$f(x)=\sin x + \log(x^2)$ f(x) = sinx+ 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 romantype. It also knew where a subscript to that operator should go.

As is the case with operators, when a log-like function takes a sub-script, it looks different when in text and when in display, though thatdifference can be overridden with the \displaystyle command. Compare$\lim_x \rightarrow 0 f(x)$, which produces limx→0 f(x), with$$\lim_x \rightarrow 0 f(x)$$, which produces

limx→0

f(x),

with $\displaystyle \lim_x \rightarrow 0 f(x)$, which produces limx→0

f(x).

56

Page 61: Basic Latex

3.4.8 Over- and Underlining and bracing

The \underline command will place an unbroken line under its argument,and the \overline command will place an unbroken line over its argument.These two commands can also be used in normal paragraphing mode (but becareful: LATEX will not break the line within an under- or overlined phrase,so don’t go operating on large phrases).

You can place horizontal braces above or below an expression by makingthat expression the argument of \overbrace or \underbrace. You can placea label on an overbrace (resp. underbrace) by superscripting (resp. subscript-ing) the group defined by the bracing command.

Type To produce

$\overlinea+bi = a- bi$ a+ bi = a− bi$\overline\overlinea+bi = a+bi$ a+ bi = a+ bi

And some examples of horizontal bracing:

$A^n=\overbraceA \times A \times \ldots \times A^\mbox$n$ terms$

$\forall x \underbrace\exists y (y \succ x)_\mboxscope of $\forall$$

will produce

An =

n terms︷ ︸︸ ︷A× A× . . .× A

and∀x ∃y(y x)︸ ︷︷ ︸

scope of ∀

3.4.9 Stacking symbols

LATEX allows you to set one symbol above another through the \stackrel

command. This command accepts two arguments, and sets the first centrallyabove the second.

Type To produce

$X \stackrelf^*\rightarrowY$ Xf∗→ Y

$f(x) \stackrel\triangle= x^2 + 1$ f(x)= x2 + 1

57

Page 62: Basic Latex

3.4.10 Operators; Sums, Integrals, etc.

Each of the operation symbols listed in Section 3.3.9 can occur with limits.They are specified as sub- and superscripts to the operator, and LATEX willposition them appropriately. In an in-text formula they will appear in more-or-less the usual scripting positions; but in a displayed formula they will beset below and above the symbol (which will also be a little larger). Thefollowing should give you an idea of how to use them:

Type To produce

$\sum_i=1^N a_i$∑N

i=1 ai

$\int_a^b f$∫ b

a f

$\oint_\cal Cf(x)\,dx$∮C f(x) dx

$\prod_\alpha \in A X_\alpha$∏

α∈AXα

$\lim_N\rightarrow\infty\sum_i=1^Nf(x_i)\Delta x_i$ limN→∞∑N

i=1 f(xi)∆xi

We’ll have more to say about the use of \, in section 3.4.14. Let’s havea look at each of those expressions when displayed:

N∑i=1

ai ,

∫ b

a

f ,

∮Cf(x) dx ,

∏α∈A

Xα , limN→∞

N∑i=1

f(xi)∆xi

3.4.11 Arrays

The array environment is provided for typesetting arrays and array-like ma-terial. It accepts two arguments, one optional and one mandatory. Theoptional argument specifies the vertical alignment of the array—use t, b, orc to align the top, bottom, or centre of the array with the centreline of theline it occurs on (the default being c). The second argument is as for thetabular environment: a series of l, r, and c’s that specify the number ofcolumns and the justification of these columns. The body of the array en-vironment uses the same syntax as the tabular environment to specify theindividual entries of the array.

For instance the input

58

Page 63: Basic Latex

let $A = \left[\beginarrayrrr12 & 3 & 4\\-2 & 1 & 0\\3 & 7 & 9\endarray\right] $

will produce the output

let A =

12 3 4−2 1 0

3 7 9

Note that we had to choose and supply the enclosing brackets ourselves(they are not placed for us so that we can use the array environment forarray-like material; also, we get to choose what type of brackets we want thisway). As in the tabular environment, the scope of a command given insidea matrix entry is restricted to that entry.

We can use ellipsis within arrays as in the following example:

\det A = \left| \beginarraycccca_11 & a_12 & \cdots & a_1n\\a_21 & a_22 & \cdots & a_2n\\\vdots & \vdots & \ddots & \vdots\\a_m1 & a_m2 & \cdots & a_mn\endarray \right|

which produces

detA =

∣∣∣∣∣∣∣∣∣a11 a12 · · · a1n

a21 a22 · · · a2n

......

. . ....

am1 am2 · · · amn

∣∣∣∣∣∣∣∣∣A special case of an array is the cases environment, which is as follows:

f(x) = \begincasesx & \textfor $x<1$\\

x^2 & \textfor $x \geq 1$\endcases.

which will yield

f(x) =

x for x < 1x2 for x ≥ 1

.

59

Page 64: Basic Latex

3.4.12 Alignment

Recall that the equation environment can be used to display and automati-cally number a single-line equation (see Section 3.2). The align environmentis used for displaying and automatically numbering either a single expressionthat spreads over several lines or multiple expressions, while taking care ofalignment for us. The align* environment does this without numbering anyequations. It is necessary to input the amsmath package to use the align

and align* environments. Do NOT use $$ ... $$ symbols when using thealign environment.

\beginalign(a+b)(a+b) & = a^2 + 2ab + b^2\\(a+b)(a-b) & = a^2 - b^2\endalign

will give

(a + b)(a + b) = a2 + 2ab + b2 (3.1)

(a + b)(a− b) = a2 − b2 (3.2)

Observe that the & sign is used to mark the place in each line that isaligned. We can also leave entries empty, to obtain effect like the following:

\beginalign*\fracddx \sin x & = \lim_h\rightarrow0\frac\sin(x+h)-\sin xh\\& = \lim_h\rightarrow0\frac\sin x\cos h + \cos x\sinh - \sin xh\\& = \lim_h\rightarrow0\frac\sin x(\cos h-1)h + \cos x\frac\sin hh\\& = \cos x\endalign*

which produces

60

Page 65: Basic Latex

d

dxsin x = lim

h→0

sin(x + h)− sin x

h

= limh→0

sin x cos h + cos x sinh− sin x

h

= limh→0

sin x(cos h− 1)

h+ cos x

sin h

h

= cos x

3.4.13 Other Multiline Environments

The gather environment is used for displaying consecutive displayed equa-tions, but keeps the equations close to each other, rather than having themspread out, which is what would happen is each equation were put in itsown $$ . . . $$ environment. The syntax is similar to that of the align

environment, except that no & signs are used, because there is no alignment.The gather* environment does the same thing without numbering any equa-tions. It is necessary to input the amsmath package to use the gather andgather* environments. Do NOT use $$ ... $$ symbols when using thegather environment. Here is an example:

\begingather*(a+b)^2 = a^2 + 2ab + b^2\\(a+b)^3 = a^3 + 3a^2b + 3ab^2 + b^3\endgather*

will give

(a + b)2 = a2 + 2ab + b2

(a + b)3 = a3 + 3a2b + 3ab2 + b3

By comparison,

$$(a+b)^2 = a^2 + 2ab + b^2$$$$(a+b)^3 = a^3 + 3a^2b + 3ab^2 + b^3$$

will give

61

Page 66: Basic Latex

(a + b)2 = a2 + 2ab + b2

(a + b)3 = a3 + 3a2b + 3ab2 + b3

which has extra space between the two equations.Another useful environment is multline, which is used for breaking up a

long equation. (Note: it does NOT say multiline.) The syntax is similar tothat of the align environment, but again there are no & signs, because thereis no alignment. The multline* environment does the same thing withoutnumbering any equations. It is necessary to input the amsmath package touse the multline and multline* environments. For example:

\beginmultline\sum_\sigma^n \in K \frac(-1)^n(n-1)2 =- \sum_\sigma^n-1 \in K T_n(\sigma^n-1) (-1)^\dim \sigma^n-1\\- \sum_\sigma^n \in K T_n(\sigma^n) (-1)^\dim \sigma^n.\endmultline

will give

∑σn∈K

(−1)n(n− 1)

2= −

∑σn−1∈K

Tn(σn−1)(−1)dim σn−1

−∑

σn∈K

Tn(σn)(−1)dim σn

. (3.3)

3.4.14 Changes to spacing

Sometimes the default LATEX spacing needs adjusting. For these purposes wehave the following spacing commands:

\, thin space \: medium space\! negative thin space \; thick space\quad a quad of space \qquad two quads of space

The spacing commands \,, \quad, and \qquad can be used in paragraph-ing mode, too. Here are some examples of these spacing commands used tomake subtle modifications to some expressions.

62

Page 67: Basic Latex

Type To produce

$\sqrt2 \, x$√

2x

$\int_a^b f(x)\,dx$∫ b

af(x) dx

$\Gamma_\!2$ Γ2

$\int_a^b \! \int_c^d f(x,y)\,dx\,dy$∫ b

a

∫ d

cf(x, y) dx dy

$x / \! \sin x$ x/sinx

$\sqrt\,\sin x$√

sinx

3.5 Macros: Defining your own LATEX com-

mands

One of the most useful TEX features for saving effort when typing mathe-matical formulas is the use of macros. For example, suppose that you needto write the formula (x1, . . . , xn) repeatedly. It would be tedious to type$(x_1, \ldots, x_n)$ over and over. Instead, we create a macro for thisformula. To do so, insert the following line after the declaration of documentclass and insertion of packages, and before \begindocument:

\newcommand\vec(x_1, \ldots, x_n)

Then, every time you want to write (x1, . . . , xn), all you need to do is write$\vec$.

There are three important points to keep in mind when defining macros:(1) Do not include the $ signs in the formula given in \newcommand; includingthe $ signs in the macro would cause problems. (2) Use a mnemonic namewhen defining a macro, but do not use a name that TEX already uses. (3)TEX is case sensitive; that is, the name \vec is not the same as \Vec.

Next, suppose that in some places you want to write (x1, . . . , xn), andother places you want to write (x1, . . . , xk). It would be silly to make adifferent macro for each of these two formulas. Rather, we use a variable inthe macro. For example, we could use:

\newcommand\vecn[1](x_1, \ldots, x_#1)

Then, if we want the formula (x1, . . . , xk) we would write $\vecn k$, orequivalently $\vecnk$. (Do not write $\vecnk$ to try to obtain (x1, . . . , xk),

63

Page 68: Basic Latex

because TEX will then look for a macro called \vecnk, which is not what youdefined, and so you will receive an error message.) If we want the formula(x1, . . . , xk+1) we would simply write $\vecnk+1$.

It is possible to have more than one variable in a macro. For example,suppose that in some places you want to write (x1, . . . , xn), and other placesyou want to write (y1, . . . , yk). We could then use the macro:

\newcommand\vecxn[2](#1_1, \ldots, #1_#2)

Then, if we want the formula (x1, . . . , xk) we would write $\vecxn xn$, andif we want the formula (w1, . . . , wr−3) we would write $\vecxn wr-3$.

As a rule of thumb, if you use any built up mathematical formula morethan a few times, it is worth making a macro for it.

Finally, we point out that LATEX, AMS-LATEX, and the Bard SeniorProject style are themselves just lengthy collections of TEX macros.

3.6 Some Standard TEX Mistakes

To write a set such asx ∈ R | x2 < π

we write

\x \in \mathbbR \mid x^2 < \pi\

Observe that the curly brackets are written \ and \, and that the ver-tical line is written \mid, NOT | (which would produce the wrong spacing).

To write an inner product such as

〈x, y〉

we write

\langle x, y \rangle

Observe that the brackets are written \langle and \rangle, NOT < and> (which would produce the wrong spacing).

To write a function such as

f : A → B

we write

64

Page 69: Basic Latex

f\colon A \to B

Observe that the colon is written \colon, NOT : (which would producethe wrong spacing).

3.7 Theorems, Propositions, Lemmas, . . .

Mathematical documents often contain theorem-like structures such as “the-orems”, “propositions” and “conjectures”. If you use the Bard Senior Projectstyle, as discussed in Section 1.3, then everything concerning the formattingand numbering of theorems, definitions, end of proof symbol, and the like isautomatically taken care of—so you can skip this section. For that reason,the Bard Senior Project style is very much recommended.

If, for some reason, you want to do your own theorem formatting, thennear the beginning of the document you should have something like thefollowing:

\newtheoremthmTheorem\newtheorempropProposition\newtheormconjecConjecture\newtheoremwildshotHypothesis % make it sound good!

The first argument to \newtheorem defines a new theorem-like environ-ment name of your own choosing. The second argument contains the textthat you want inserted when your theorem is proclaimed:

\beginthm\labelthm:normal $X$ is normal if, and only if,each pair of disjoint closed sets in $X$ is completely separated.\endthm

\beginwildshot % remember, we chose the name ’wildshot’The property of Moore extends to all objects of the class $\Sigma$.\endwildshot

which will produce the following:

Theorem 1. X is normal if, and only if, each pair of disjoint closed sets inX is completely separated.

Hypothesis 1. The property of Moore extends to all objects of the class Σ.

65

Page 70: Basic Latex

Notice that LATEX italicises the theorem statement, and that you stillhave to shift in to math 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 yourdocument class choice, and not be over-ridden by other commands).

LATEX automatically numbers theorems and the like. To refer to a theo-rem or similar structure, use the theorem’s label in the say way that you referto chapter and section names. For example, to refer to the theorem writtenabove, simply write Theorem~\refthm:normal, which will produce The-orem 1. It is possible to have different structures, such as theorems andlemmas, be numbered consecutively, but we will not discuss that here; pleasesee other LATEX manuals.

66