LaTeX For Undergraduates

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

L

A
T
E
X for Undergraduates
Jim Hefferon, Saint Michaels College
[email protected]
2013-Jan
Professionals in Mathematics write using the program L
A
T
E
X (pronounced la-tech). This doc-
ument tells you the L
A
T
E
X that you need for writing undergraduate mathematics. It is prescrip-
tive: instead of describing all the possibilities it will just say what to do.
As with any technical material, the only way to learn whats here is enter the commands as
you read and to experiment with your own variants. If you have a problem then google it.
First contact
L
A
T
E
X runs the typesetting engine T
E
X (pronounced tech). It is well known for its abilities with
mathematical and technical text, and for being stable, portable, and virtually bug free. It is Free
software.
Dont use a word processor for L
A
T
E
X. Start your editor emacs and use it to open a new file
test.tex. Enter the source lines below and save the file. Run the command line pdflatex test
to compile the source. Your output is in the file test.pdf, shown after the source.
1 \documentclass{article}
3 \begin{document}
Hello world!
5 \end{document}
Hello world!
You write a L
A
T
E
X source file in a mixture of text and commands. Commands start with a
backslash; an example is \documentclass. The \begin and \end enclose a L
A
T
E
X environment,
a distinct area of the document. A source file has two parts: a preamble setting up the document
and then a document body containing the content, which starts with \begin{document}.
Template With your editor open a new file called template.tex and enter these lines, using
your own name and email.
1 \documentclass[11pt]{article}
2 \usepackage{graphicx}
\usepackage{xcolor}
4 \usepackage{hyperref ,url}
\usepackage{fancyhdr}
6 \usepackage{listings}
page 2 L
A
T
E
X for Undergraduates
\usepackage[left=1.5in,right=1.5in]{geometry}
8 \usepackage{amsmath,amsthm,amssymb}
\newtheorem{thm}{Theorem}
10 \newtheorem{lem}[thm]{Lemma} % numbered in sequence with thm
\newtheorem{cor}[thm]{Corollary}
12 \begin{document}
\title{Sample document}
14 \author{Jim Hef{}feron \\
Saint Michael's College\\
16 \url{[email protected]}}
\date{\today}
18 \maketitle
20 \end{document}
In the future you will start new L
A
T
E
X work by copying this template to a fresh file and working
there. All the examples below assume this and only show material that youve added, that youve
inserted where above there is a blank line.
For example, copy template.tex to first.tex, add this material below \maketitle, and
compile. (Later we will go through the commands systematically.)
1 Elementary calculus suffices to evaluate $C$ if we are clever
2 enough to look at the double integral
\begin{equation*}
4 C^2
=\int_{-\infty}^{+\infty} e^{-x^2} \mathrm{d}x
6 \int_{-\infty}^{+\infty} e^{-y^2} \mathrm{d}y\;.
\end{equation*}
Elementary calculus suffices to evaluate C if we are clever enough to look at the double integral
C
2
=
]
o
o
c
x
2
ux
]
o
o
c

2
u .
Building blocks
L
A
T
E
X has a learning curve. We will next establish the basics that you need.
Special characters The backslash is special; you cant just type it in the source or L
A
T
E
X thinks
that you mean a command. To get a backslash in your output use the command \textbackslash.
The other special characters, and the input that will get them in output, are: hash tag \#, dollar
sign \$, percent sign \%, caret \^{}, ampersand \&, underscore \_, curly braces \{ and \}, and
twiddle \~{}.
The percent character % makes the rest of the line a comment.
1
1 The two curves are asmyptotic. % TODO: check spelling
The two curves are asmyptotic.
1
Except if you precede it with a backslash, or in some other cases such as inside a URL.
L
A
T
E
X for Undergraduates page 3
Braces: arguments and grouping Some commands need one or more arguments, given in
curly braces.
1 \title{Sample document}
There is a larger effect at work here: without the braces only the next character would have been
affected by the command, that is, the curly braces group the entire surrounded text. You may
form groups inside your groups, as deeply nested as you need.
You sometimes need an empty group to keep L
A
T
E
X from slurping up whitespace.
1 Without braces, \LaTeX will eat the space
2 but \LaTeX{} is OK.
Without braces, L
A
T
E
Xwill eat the space but L
A
T
E
X is OK.
Some commands have arguments that are optional, enclosed in square brackets.
1 \documentclass[11pt]{article}
Font variations Your documents will stick to the font family Computer Modern. It is a family
because there are a number of associated fonts: boldface that you access with \textbf{boldface}
and italic with \textit{italic} (note that to emphasize something, instead use the command
\emph{text}). You also can get small capitals with \textsc{small caps} and monospace with
\texttt{typewriter}. You can nest these \textbf{\textsc{bold italic}} but it only has
an effect if you have a font with both characteristics.
Usually you dont need to fool with the text size but you can ask for {\large large}, or
{\Large larger}, or {\LARGE larger still} or even {\Huge much too big}. The other
direction has {\small small}, {\footnotesize smaller}, {\scriptsize even smaller},
and {\tiny teeny}.
Quotation marks In your source code do not surround a quote with " marks; L
A
T
E
X makes
the quote start different than the quote end. Start a quote with two opening single quotes (called
grave marks) and end it with two apostrophes.
1 ``Students are taught advanced concepts of Boolean algebra, and
2 formerly unsolvable equations are dealt with by threats of
reprisals.''
4 \textit{---Woody Allen}
Students are taught advanced concepts of Boolean algebra, and formerly unsolvable equations
are dealt with by threats of reprisals. Woody Allen
Technical text often uses single quotes as in the first sentence of the next sectionand you get
those with a single grave and apostrophe.
White characters L
A
T
E
X treats a space character differently than a regular text character such
as an A: consecutive spaces are the same as one space and spaces at the start of a line get ignored.
This allows you to pretty-format your source.
For an explicit space use backslash followed by space. The common use case is for periods that
dont end a sentence, where it also suppresses the extra space L
A
T
E
X may put in at the end of a
sentence.
page 4 L
A
T
E
X for Undergraduates
1 The article appeared in Proc.\ Amer.\ Math.\ Soc.
2 That's where I saw it.
The article appeared in Proc. Amer. Math. Soc. Thats where I saw it.
For a hard space, to tie two words so that there will be no line break between them, use a
twiddle (this too suppresses the after-period space).
1 Mr.~Watson come here I want you.
Mr. Watson come here I want you.
L
A
T
E
X treats a lone end of line character as a space but two consecutive ones, or any blank line,
starts a new paragraph.
1
1 One morning I shot an elephant in my pajamas.
3 What he was doing in my pajamas I'll never know.
One morning I shot an elephant in my pajamas.
What he was doing in my pajamas Ill never know.
You usually only need explicit line breaks inside tables and arrays, but in any event get one with
a double backslash \\.
Space You occasionally need explicit spacing. For extra vertical space between paragraphs, your
first resource is to use one of \smallskip, \medskip, or \bigskip.
1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
2 eiusmod tempor incididunt ut labore et dolore magna aliqua.
4 \smallskip
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
6 nisi ut aliquip ex ea commodo consequat.
8 \bigskip
Duis aute irure dolor in reprehenderit in voluptate velit esse
10 cillum dolore eu fugiat nulla pariatur.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
A convenient unit for explicit vertical space is the ex, which is the height of an x in the current font
so it gives you some portability through font changes. Thus, you might write \vspace{1.5ex}
(or \vspace{2in}). This command has a starred form \vspace*{1.5ex} to insert the space even
where you typically dont want a blank (L
A
T
E
X usually drops vertical space at the end of a page
instead of carrying it to the top of the next page; if you want the space even at the top of the next
page then use the starred form.)
1
Except in a special circumstance, such as a listing of computer code.
L
A
T
E
X for Undergraduates page 5
For horizontal spacing the best unit is the em, something like the width of an M. Often you
can limit yourself to using \, for a small space (3,18-th em), \: (4,18-th em) for a medium space,
\; (5,18-th em) for a large space, \quad for a still larger space (something like an em), \qquad for
twice that space, and finally \! for a negative small space.
1
If you need some other size then use
a command like \hspace{1.618em}. As with vertical space command, the starred form of this
command inserts the space even where you typically dont want it.
Environments L
A
T
E
X lets you have areas of the document with their own rules.
1 \begin{verse}
2 THE ROAD TO WISDOM?
4 Well, it's plain \\
and simple to express. \\
6 Err and err and err again, \\
but less and less and less. \\ % Piet Hein.
8 \end{verse}
THE ROAD TO WISDOM?
Well, its plain
and simple to express.
Err and err and err again,
but less and less and less.
One way in which the verse environment is different from regular text is that it indents the left
and right margin.
Environments nest, so you may have a center environment that surrounds a tabular environ-
ment. However, environments cannot overlap so the tabular environment must end before the
center.
Interpolations Write a hyphen as in Cauchy-Schwartz with one dash Cauchy-Schwartz.
Ranges, such as homework numbers 515 call for an en-dash,
2
which you type using two consec-
utive dashes 5--15. The em-dash
3
marks a break stronger than that marked by parentheses; for
this type three consecutive dashes.
1 \begin{quotation}
``Number theorists are like lotus-eaters---having once tasted of
3 this food they can never give it up.''
\textit{---Leopold Kronecker}
5 \end{quotation}
Number theorists are like lotus-eatershaving once tasted of this food they can
never give it up. Leopold Kronecker
An ellipsis is the three dots that show an intentional omission such as from the middle of a
quote, or an unfinished thought.
1
You most often use these spacing commands in mathematics.
2
It is one en wide.
3
An em wide.
page 6 L
A
T
E
X for Undergraduates
1 Every mathematician worthy of the name has experienced \ldots{}
the state of lucid exaltation in which one thought succeeds
3 another as if miraculously \ldots{}
this feeling may last for hours at a time, even for days.
5 Once you have experienced it, you are eager to repeat it but
unable to do it at will, unless perhaps by dogged work \ldots\,.
7 \textit{---Andre Weil}
Every mathematician worthy of the name has experienced the state of lucid exaltation in
which one thought succeeds another as if miraculously this feeling may last for hours at a
time, even for days. Once you have experienced it, you are eager to repeat it but unable to do it
at will, unless perhaps by dogged work . Andre Weil
Organize your source As with any computer code, sensibly organize your input. Put sentences
on separate lines. Put a half dozen blank lines before a new section. Inside environments indent
text by two spaces (you might do this for only some environments). When you enter matched
things, such as matched curly braces or a \ begin { environment }-\end{ environment } pair, type
the two commands at the same time and then go back to fill in the contents (note that emacs has
<CTL>-c <CTL>-e to help with this).
Document structure
Preamble Documents start by declaring their class.
1 \documentclass[option]{class}
The common classes are article for a short paper, report for longer documents containing several
chapters, book for full-sized books, and beamer for slides. Your template uses the 11pt option to
change the size of your documents main font.
1
A preamble has a list of packages.
2
Your templates preamble brings in the amsmath package
for production of mathematics according to their standards of the American Mathematical Society.
The graphicx package lets you include graphics files, xcolor adds color, fancyhdr lets you change
the headers and footers, and listings is for computer code. The geometry package lets you, among
other things, define the margins.
Other things appear in the preamble. There may be document-specific commands.
1 \newcommand{\myname}{Jim Hef{}feron}
There may also be setup code, for instance to describe the document name and author.
1 \title{Document name}\author{\myname}
Sectioning Divide the document with \section{section title}. Similarly, make subsections
with \subsection{title}.
3
The starred forms, such as \section*{title} omit a number prefix
and a table of contents entry.
1
This is larger than the standard for books and journals but it takes account of professors so old that they cannot read
subscripts of subscripts.
2
A package is an add-on set of L
A
T
E
X commands to help with some task. One of the strengths
of L
A
T
E
X is the availability of a tremendous variety of packages, to do whatever you need; see http://www.ctan.org.
3
Had we based the template on the book class then we would also have a chapter command.
L
A
T
E
X for Undergraduates page 7
Text
Justification L
A
T
E
X will by default use justification, where to make the text align with the left
and right margins the system will stretch or shrink the the spaces between words.
You can alter that with a flushleft, flushright, or center environment.
1 \begin{center}
Here lies Lester Moore. \\
3 Four slugs from a 44. \\
No Les. No Moore.
5 \end{center}
Here lies Lester Moore.
Four slugs from a 44.
No Les. No Moore.
Footnotes As here: Text.\footnote{Another.}. Precede commands with \protect.
Lists Make bullet lists with the itemize environment, numbered lists with enumerate and de-
scriptions with description environment.
1 \begin{description}
2 \item[First.] We can itemize.
\begin{itemize}
4 \item Bullet points
\item are ugly
6 \end{itemize}
\item[Second.] We can enumerate.
8 \begin{enumerate}
\item Sub-enumerations
10 \item are anal.
\end{enumerate}
12 \end{description}
First. We can itemize.
Bullet points
are ugly
Second. We can enumerate.
1. Sub-enumerations
2. are anal.
Tables
Make tables with the tabular environment. Row entries are separated by an ampersand.
page 8 L
A
T
E
X for Undergraduates
1 \begin{center}
2 \begin{tabular}{r|l}
\LaTeX{} abbreviation &unit \\ \hline
4 in &inches \\
pt &typographical points, $1/72.27$~inch \\
6 bp &PostScript point, $1/72$~inch \\
em &something like the width of an `M' in the current font \\
8 ex &something like the height of an `x' in the current font \\
mm &millimeters \\
10 cm &centimeters
\end{tabular}
12 \end{center}
L
A
T
E
X abbreviation unit
in inches
pt typographical points, 1,2.2 inch
bp PostScript point, 1,2 inch
em something like the width of an M in the current font
ex something like the height of an x in the current font
mm millimeters
cm centimeters
That has a column format of r|l so L
A
T
E
X justifies the first column on the right, then there is a verti-
cal rule separating the columns, and then L
A
T
E
X justifies the second column on the left. You can also
use c for a centered column, p{1in} for an inch-wide paragraph column, and @{-\hspace{.5in}}
to put a dash and a space between two columns.
1 \begin{tabular}{rr@{.}l}
2 inch &$2$ &$5$~cm \\
foot &$30$ &\ cm\\
4 yard &$0$ &$9$ meters \\
mile &$1$ &$6$ kilometers
6 \end{tabular}
inch 2.5 cm
foot 30. cm
yard 0. meters
mile 1.6 kilometers
In particular, omit the default intercolumn space with @{} (this includes the half intercolumn space
before the first column or after the last column).
For horizontal rules put \hline after the line ending double backslash. To have the line only
come across columns 2 through 3 use \cline{2-3}.
Inside a tables row, the command \multicolumn{2}{c}{text} will produce the text centered
and spanning two columns. (It suppresses vertical rule column separators so you may want to add
one back as in \multicolumn{2}{c|}{text}; you can also use this property to remove a column
separator with \multicolumn{1}{c}{text}.)
Tables are hard. Some things to watch out for are: (a) fewer rules, especially vertical ones, is
often better (b) columns of numbers are easier to read if the decimals align, as with the prior table
(c) tables may be easier to read if you use \renewcommand{\arraystretch}{1.2} to spread the
L
A
T
E
X for Undergraduates page 9
lines a hair (d) you can distinguish tables from the text body if you use the \small font size and
(e) format the source so that you can easily make changes later.
Here is an example of a complex table whose formatting makes its contents clearer.
1
1 {\renewcommand{\arraystretch}{1.2}\small
\begin{tabular}{@{}rrrrcrrr@{}}
3 &\multicolumn{3}{c}{$w = 8$}
&\hspace{2em}
5 &\multicolumn{3}{c}{$w = 16$} \\
\cline{2-4} \cline{6-8}
7 &$t=0$ &$t=1$ &$t=2$
&&$t=0$ &$t=1$ &$t=2$ \\ \hline
9 $dir=1$ \\
$c_{top,0}$ &0.0790 &0.1692 &0.2945
11 &&0.3670 &0.7187 &3.1815 \\
$c_{top,1}$ &-0.8651 &50.0476 &5.9384
13 &&-9.0714 &297.0923 &46.2143 \\
$c_{top,2}$ &124.2756 &-50.9612 &-14.2721
15 &&128.2265 &-630.5455 &-381.0930\\[2ex]
$dir=0$ \\
17 $c_{top,0}$ &0.0357 &1.2473 &0.2119
&&0.3593 &-0.2755 &2.1764 \\
19 $c_{top,1}$ &-17.9048 &-37.1111 &8.8591
&&-30.7381 &-9.5952 &-3.0000 \\
21 $c_{top,2}$ &105.5518 &232.1160 &-94.7351
&&100.2497 &141.2778 &-259.7326
23 \end{tabular}}
v = 8 v = 16
I = 0 I = 1 I = 2 I = 0 I = 1 I = 2
uI = 1
c
!+^
0.0790 0.1692 0.2945 0.3670 0.7187 3.1815
c
!+J
-0.8651 50.0476 5.9384 -9.0714 297.0923 46.2143
c
!+2
124.2756 -50.9612 -14.2721 128.2265 -630.5455 -381.0930
uI = 0
c
!+^
0.0357 1.2473 0.2119 0.3593 -0.2755 2.1764
c
!+J
-17.9048 -37.1111 8.8591 -30.7381 -9.5952 -3.0000
c
!+2
105.5518 232.1160 -94.7351 100.2497 141.2778 -259.7326
Mathematics
Mathematics is where L
A
T
E
X shines. Surprisingly often it will know what you mean and will make
your work appear exactly as in a professional book or journal, clear and attractive.
1
Adapted from http://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf.
page 10 L
A
T
E
X for Undergraduates
Inline and display Mathematics can appear inline or display, set on a separate line. For inline,
enclose the mathematics in L
A
T
E
Xs mathematics mode delimiters \( and \).
1
1 The composition of two functions is \( f\circ g(x)=f(g(x)) \).
The composition of two functions is g(x) = (g(x)).
1 The number \( \pi(n) \) of primes less than or equal to~\( n \) is
2 asymptotically equal to \( n/\ln(n) \).
The number (n) of primes less than or equal to n is asymptotically equal to n, In(n).
Note that the variable n is set as mathematics leaving out its mathematics delimiters is wrong.
Display style mathematics has more options. Most common is the equation* environment.
1 \begin{equation*}
\int \cos(x)\,dx=\sin(x)+C
3 \end{equation*}
]
co:(x) ux = :In(x) +C
This environments unstarred form will number the equation. More display environment options
are below.
Super- and Subscripts Caret gets you an exponent x^2. You may need to group the symbols
with curly braces to tell L
A
T
E
X what you mean.
1 The expressions \(e^2x\) and \(e^{2x}\) differ.
The expressions c
2
x and c
2x
differ.
Underbar gets you a subscript a_0; again you may need to group, as in a_{0,0}. Sub- and
superscripts can nest and you sometimes want both a subscript and a superscript.
1 \begin{equation*}
\sum_{i=1}^{n_0} i^2
3 \end{equation*}

^
_
l=1
I
2
Fractions Get a fraction with this command.
1 Fractions look different inline \(\frac{1}{2}\)
than in a display
3 \begin{equation*}
\frac{1}{2}
5 \end{equation*}
Fractions look different inline
1
2
than in a display
1
2
1
You sometimes see dollar signs used in place of the backslash parentheses but this way is better.
L
A
T
E
X for Undergraduates page 11
You can also just use a slash, as in x^{3/2}.
1 The derivative operator \(d/dx\) applies to the quadratic function
2 \(f(x)=x^2\) to give
\begin{equation*}
4 \frac{df}{dx}=2x
\end{equation*}
6 so the tangent line at \(x=0\) is horizontal.
The derivative operator u,ux applies to the quadratic function (x) = x
2
to give
u
ux
= 2x
so the tangent line at x = 0 is horizontal.
Roots Square root

x
2
+
2
is \sqrt{x^2+y^2}. Other roots
?

x
3
+
3
use the optional ar-
gument \sqrt[3]{x^3+y^3}.
Symbols Here are most of the symbols you might use in undergraduate classes. For more see the
Comprehensive L
A
T
E
X Symbols List
1
and DeT
E
Xify.
2
With Greek letters, the upper case letters that look just like our everyday Roman letters are
never used for mathematics. The lower case omicron is only rarely used.
Lower case Upper case Lower case Upper case
\alpha A \nu N
\beta B \xi \Xi
\gamma \Gamma o O
\delta \Delta \pi
\epsilon or \varpi \Pi
or \varepsilon E \rho P
\zeta Z \sigma \Sigma
\eta H \tau T
\theta \upsilon \Upsilon
or \vartheta \Theta \phi
\iota I or \varphi \Phi
\kappa K \chi X
\lambda \Lambda \psi \Psi
\mu M \omega \Omega
Here are some non-Greek characters.
R \mathbb{R} \forall \infty \partial
Z \mathbb{Z} \exists \emptyset \nabla
N \mathbb{N} \neg \imath \|
C \mathbb{C} \aleph \jmath \ell
You can decorate symbols in many ways.
1
mirror.ctan.org/info/symbols
2
detexify.kirelabs.org/classify.html
page 12 L
A
T
E
X for Undergraduates
x \vec{x}
tt
f^{\prime\prime} x + \overline{x+y}
x \hat{x} u \dot{a}

x + \overbrace{x+y}

t
f^\prime u \ddot{a} x +
_
\underbrace{x+y}
(Use \imath and \jmath for characters that are the regular italic letters but with the dot missing,
because a vector bar over a dotted letter looks awkward.) You can also use \boldsymbol{x} and
\widehat{x+y}.
Mathematicians use dots to show an omission. Weve seen low horizontal dots as in l =
[0, 1, 2, from \mathbb{N}=\{0,1,2,\,\ldots\} and there are also centered horizontal dots as
in 5050 = 1 ++100 from 5050=1+\cdots+100. Vertical dots \vdots and diagonal dots \ddots
often appear in matrices.
Some standard named symbols use an abbreviation set in Roman type.
co: \cos ucIun \arctan cx \exp IIn \lim
:In \sin co:l \cosh ucI \det In \inf
Iun \tan :Inl \sinh nIn \min :u \sup
:cc \sec Iunl \tanh nux \max IInIn \liminf
c:c \csc coIl \coth uIn \dim IIn:u \limsup
coI \cot In \ln gcu \gcd lon \hom
ucco: \arccos Iog \log ucg \deg lc \ker
uc:In \arcsin Ig \lg ug \arg
These are common undergraduate operators and relations.
\pm \circ \oplus \odot
\div \cup \ominus \vee
\cdot \cap \otimes \wedge
\times \ast \oslash \mid
Some operators resize to fit their context.

\sum

\iint \bigcap

\bigwedge

\prod

iiint \bigcup

\int

\oint \bigvee
You will need arrows.
\leftarrow \longleftarrow \mapsto
\rightarrow or \to \Longleftarrow \longmapsto
\leftrightarrow \downarrow
\Leftarrow \uparrow
\Rightarrow \updownarrow
\Leftrightarrow \Uparrow
For instance, write a function definition R R with f\colon\mathbb{R}\to\mathbb{R}.
Symbols that surround an expression are fences.
( ) () [ [ [] [ \{\}
\langle\rangle \lfloor\rfloor \lceil\rceil
| \|\|
L
A
T
E
X for Undergraduates page 13
Write \left and \right in front of a fence to get automatically determined sizes. There must be
as many \lefts are \rights and they must be on the same output line. To use an only one-sided
fence with \left, on the other side write \right., including the period.
1 \begin{equation*}
\left.\frac{\partial f}{\partial x}\right|_{x_0}
3 \end{equation*}

x
x
^
If L
A
T
E
X gets the fence size wrong you can do it by hand with one of \big, \Big, \bigg, or \Bigg.
Arrays and Matrices An array is a rectangular arrangement of mathematics. You make an
array in mathematical text much like you make a table in plain text.
1 \begin{equation*}
\begin{array}{ccccc}
3 0 &1 &2 &3 &\ldots \\
\updownarrow &\updownarrow &\updownarrow &\updownarrow \\
5 0 &2 &4 &6 &\ldots
\end{array}
7 \end{equation*}
0 1 2 3

0 2 4 6
Sometimes a functions definition is by cases, which is a special kind of array.
1 \begin{equation*}
f(n)=\begin{cases}
3 0 &\text{if \(n=0\)} \\
1 &\text{if \(n=1\)} \\
5 f(n-1)+f(n-2) &\text{otherwise}
\end{cases}
7 \end{equation*}
(n) =

0 if n = 0
1 if n = 1
(n 1) +(n 2) otherwise
A matrix is an array surrounded by a fence. There is a convenient abbreviation.
page 14 L
A
T
E
X for Undergraduates
1 \begin{equation*}
\begin{pmatrix}
3 a &b \\
c &d
5 \end{pmatrix}
\begin{pmatrix}
7 x \\
y
9 \end{pmatrix}
=
11 \begin{pmatrix}
ax+by \\
13 cx+dy
\end{pmatrix}
15 \end{equation*}
\
u I
c u
;\
x

;
=
\
ux +I
cx +u
;
In addition to not specifying the parentheses, you dont specify how many columns and that
each is centered because pmatrix assumes a default of a good number of centered columns. For
determinants use vmatrix, which also doesnt need a column specifier.
1 \begin{equation*}
\begin{vmatrix}
3 a &b \\
c &d
5 \end{vmatrix}
=ad-bc
7 \end{equation*}

u I
c u

= uu Ic
Theorems In the preamble of template.tex you declare the theorem environments that you
might use.
1 \newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma} % numbered in sequence with thm
3 \newtheorem{cor}[thm]{Corollary}
In the body of your document use it this way.
L
A
T
E
X for Undergraduates page 15
1 \begin{thm}[Lindeberg -L\'evy]
Let \( \{X_i \mid i\in\mathbb{N}\} \) be a sequence of
3 independent identically distributed random variables ,
all with mean~\( \mu \) and finite variance~\( \sigma^2 \).
5 Then as \( n \) approaches infinity and where \( S_n \) is the
sample average \( (X_1+\cdots+X_n)/n \), the random variables
7 \( \sqrt{n}(S_n-\mu) \) converge in distribution to a normal
\( \mathcal{N}(0,\sigma^2) \).
9 \end{thm}
\begin{proof}
11 See the appendix.
\end{proof}
13 \begin{cor}
Samples are distributed Normally.
15 \end{cor}
Theorem 1 (Lindeberg-Lvy). Let [X
l
I l be a sequence of independent identically
distributed random variables, all with mean and finite variance
2
. Then as n approaches
infinity and where S

is the sample average (X


1
++X

),n, the random variables



n(S

)
converge in distribution to a normal (0,
2
).
Proof. See the appendix.
Corollary 2. Samples are distributed Normally.
Complex displayed equations There are many more options for displayed equations but well
only see two. One is for when you need to make a too-long displayed line into multiple lines.
1 \begin{multline*}
2 H_c=\frac{1}{2n} \sum^n_{l=0}(-1)^{l}(n-{l})^{p-2}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i} \\
4 \cdot[(n-l )-(n_i-l _i)]^{n_i-l _i}\cdot
[(n-l )^2-\sum^p_{j=1}(n_i-l _i)^2]
6 \end{multline*}
H
c
=
1
2n

_
l=u
(1)
l
(n I)
]2
_
l
J
l

=l
]
]
l=1
\
n
l
I
l
)
[(n I) (n
l
I
l
)[

1
l
1
[(n I)
2

]
_
|=1
(n
l
I
l
)
2
[
Another is for when you want to align equations.
page 16 L
A
T
E
X for Undergraduates
1 \begin{align*}
e^{x} &=\sum_{n\in 1..\infty} \frac{1}{n!}x^n \\
3 &=1+x+\frac{x^2}{2}+\frac{x^3}{3!}+\frac{x^4}{4!}
+\frac{x^5}{5!}+\frac{x^6}{6!}+\cdots
5 \end{align*}
c
x
=
_
1..o
1
n'
x

= 1 +x +
x
2
2
+
x
3
3'
+
x
4
4'
+
x
5
5'
+
x

6'
+
For both of these the unstarred version will number the equation.
Recipes Here are some miscellaneous examples, taken from undergraduate mathematics.
1 \begin{equation*}
\int_{x=1}^{x=\infty} e^{-x}\,dx
3 \end{equation*}
]
x=o
x=1
c
x
ux
1 \begin{equation*}
\{ n\in\mathbb{N} \mid \text{\( n \) is even} \}
3 \end{equation*}
[n l n is even
1 The boiling point of $\text{H}_2\text{O}$ is $212^{\circ}$F.
The boiling point of H
2
O is 212

F.
Verbatim and Listings
The verbatim environment outputs its contents just as it is input, with all line breaks and spaces.
For inline material use \verb!verbatim text! (you can use any character in place of the excla-
mation points, but it must be the same character in both places).
For computer code your template has brought in the listings package.
1 \begin{lstlisting}
2 while True:
print "Hello World!"
4 \end{lstlisting}
1 while True:
2 print "Hello World!"
L
A
T
E
X for Undergraduates page 17
Graphics
Include graphics in the JPG, PNG, or PDF formats
1
1 \begin{center}
\includegraphics[width=.4\textwidth]{Keytar-platypus.png}
3 \end{center}
Besides width, you can specify height or scale or leave the option off to get the graphic at its
natural size (although in this Venn diagram picture, nothing is natural).
References
Labels and references To refer to something, first label it and then reference it.
1 \section{Bases and dimension} \label{sec:BasesAndDimension}
This is section~\ref{sec:BasesAndDimension},
3 starting on page~\pageref{sec:BasesAndDimension}.
The label text sec:BasesAndDimension is arbitrary, but good practice is to give labels a memo-
rable name with a prefix describing what it labels.
References can point to something later in the document. L
A
T
E
X does this by saving each
labels information in an auxiliary file. It then starts any run by looking for the .aux file from the
previous run. This explains why you sometimes get the message, You should run L
A
T
E
X again to
get references right and in your document references look like this.
1 \section{Bases and dimension} \label{sec:BasesAndDimension}
This is section~\ref{sec:BasesAndDimension},
3 starting on page~\pageref{sec:BasesAndDimension}.
Bases and dimension
This is section ??, starting on page ??.
L
A
T
E
X has found a reference without an associated label (yet), or a reference that has changed. The
solution is to compile again.
Hyper-references The template is set up to makes your cross-references into hyperlinks.
To get a link to a web address, that appears in a suitable font and hyphenates sensibly, use
the url command.
1
Graphic from Tenso Graphics at http://tensographics.com/post/7267021251/math-available-at-threadless.
page 18 L
A
T
E
X for Undergraduates
1 My home machine is \url{http://joshua.smcvt.edu}.
My home machine is http://joshua.smcvt.edu.
You can make a link out of any text.
1 See the \href{http://joshua.smcvt.edu/proofs}{book's home page}.
See the books home page.
Bibliography There are advanced bibliographic options for L
A
T
E
X but a structure like this one
will take you a long way.
1 The most often recommended \LaTeX{} tutorial is~\cite{lshort2e}.
\begin{thebibliography}{9}
3 \bibitem{lshort2e}T.~Oetiker; H.~Partl; I.~Hyna; E.~Schlegl:
\textit{The Not-So-Short Introduction to \LaTeX}
5 (2001)
\end{thebibliography}
The parameter 9 to the thebibliography environment tells L
A
T
E
X that the widest bibliography
reference number will be no wider than the single digit.
Advanced material
There is a great deal to explore in the L
A
T
E
X and T
E
X ecosystem. Becoming a T
E
X wizard is a long
journey. This section may give you a taste of the power of the tool.
Breaking Encourage L
A
T
E
X to break a line with \linebreak[2]; the number can be from 0 to
4, in order of increasing encouragement. Omitting the optional argument is the same as using a 4,
and essentially requires a break.
L
A
T
E
X will also force a line break with \\ or \newline; the difference from the prior paragraph
is that here the broken line will not be justified. You can add vertical space between the two lines
with an optional argument \\[2ex]. The starred forms \\* and \newline* prohibit a page break.
Encourage a page break with \pagebreak[2], where again the optional argument runs from 0
to 4 and leaving off the argument is the same as specifying a 4. To start on a new page by filling
the bottom of the old with blank space use \clearpage or \cleardoublepage, which leaves an
entire blank page (new chapters should start on an odd page so you sometimes want to leave an
extra blank page).
Page styles Set indents for paragraphs with \setlength{\parindent}{2em}. Set the space
between paragraphs as in \setlength{\parskip}{1ex plus 0.5ex minus 0.2ex} (the plus
and minus gives it some stretch and shrink to cope with what comes in the page). Both commands
go in the preamble.
You can adjust the headers and footers on pages. This document uses this arrangement.
1 \fancypagestyle{firstpage}{%
2 \fancyhf{} % clear all six fields
\renewcommand{\headrulewidth}{0pt}
4 \renewcommand{\footrulewidth}{0pt}
L
A
T
E
X for Undergraduates page 19
}
6 \fancypagestyle{followingpage}{%
\fancyhf{}
8 \fancyhead[RE,LO]{\LaTeX{} tutorial}
\fancyhead[LE,RO]{page \thepage}
10 \renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
12 }
\pagestyle{followingpage}
14 % \AtBeginDocument{\thispagestyle{firstpage}}
Briefly, on the first page there is no header or footer, and no head or foot rule (thin line across the
page head). All other pages are of type followingpage and have a small head rule. They also have
headers that on the right side of even-numbered pages have the words L
A
T
E
X tutorial and on the
other side have the page number.
Including other files You can split long documents into conveniently-sized files. To include
material from filename.tex use \include{filename}.
1
1 \begin{document}
2 \tableofcontents
\include{preface}
4 \include{chapter1}
\include{chapter2}
6 \end{document}
To speed up your development cycle by not recompiling parts that are not changing, put this
in the preamble with a list of all the files in the document.
1 \includeonly{% preface,
2 chapter1,
% chapter2,
4 }
Comment out the files you are not working on and compile. The document will still have cross-
references to the omitted material, but will otherwise only include the part that you left in.
Version control Because L
A
T
E
X is text-based it works well with the advanced source code ver-
sion control systems. For instance, Mercurial took the source of this document with the commands
cd tutorial , followed by hg init then hg add tutorial .tex and hg add tutorial .cls.
1
You cannot include a file from an included file and included material causes a page break before and after the inclusion.

You might also like