...

Math 2784 (or 2794W) University of Connecticut AN INTRODUCTION TO L TEX

by user

on
Category: Documents
51

views

Report

Comments

Transcript

Math 2784 (or 2794W) University of Connecticut AN INTRODUCTION TO L TEX
AN INTRODUCTION TO LATEX
Math 2784 (or 2794W)
University of Connecticut
Date: Sept. 2, 2009.
Contents
1. Introduction
2. Typesetting equations
3. User-Defined Commands and Operators
4. Theorems and Definitions
5. Relations
6. Phancy Phonts
7. Lists
8. Set-theoretic/Algebraic expressions
9. Some calculus
10. Some linear algebra
11. Tables
12. Pictures
13. Bibliography
References
1
1
3
4
5
5
5
6
7
8
9
10
10
10
AN INTRODUCTION TO LATEX
1
1. Introduction
This handout discusses the preparation of mathematical documents using LATEX. Look at
the file \math27842794Wformat.tex with your favorite text editor to see how mathematical
(and typesetting) commands described below are written.
This file can also be used as a template for the preparation of your paper. With this in
mind, open the file \math27842794Wpaper.tex with your favorite text editor and save it as
mathlastname.tex (where you write your last name instead in the name of the file). If you
need any LATEX construction, an equation for example, just find a similar one in this or other
LATEX file, copy, paste and edit.
If you use Apple computers in the Math department, you can open any LATEX file by
clicking on it. There is a “typeset” button which you use to see the results of your editing,
and then to print the paper. While the edited changes you make go through after typesetting
once, sometimes you have to typeset two or three times to see all the corresponding changes
in equation numbers, the table of contents, and cross references. When equations get moved
around they have to be renumbered, but on the first pass at typesetting LATEX won’t fix all
the cross-references (for instance) but only notices they need to be changed. It will fix things
up better the second (or third) time.
If you use UNIX or LINUX, then you can open a LATEX file with a text editor. Also you
can open a terminal window and use the command latex mathlastname to typset the
edited and saved file. Typically the command xdvi mathlastname is used to see the results
of your editing, and dvips mathlastname is used for printing.
There are free versions of LATEX for Windows. See http://www.ams.org/tex/ for more on
LATEX and http://www.cs.queensu.ca/home/gradseries/help/stuff/symbols.pdf for a
very large list of LATEX symbols. (Warning: Not all the symbols there work without having
special packages installed, so try a symbol out once to see LATEX recognizes it before deciding
to use it.) Online tutorials at http://www.comp.leeds.ac.uk/andyr/misc/latex/ might
be helpful, especially tutorials 4, 6, 8, and 10.
A little history. This typesetting system was originally designed by Donald Knuth,
who named it TeX, or TEX. Leslie Lamport made improvements on TEX and slapped the
first two initials of his last name on the result, thus giving us LATEX. If you want to get
TEXnical about it, the system is pronounced like this: TEX = tek and LATEX = “lay-tek” (or
“la-tek”), but not “teks” or “lay-teks”. This ends our little history. For more information,
see http://www.tug/org/whatis.html.
2. Typesetting equations
In LATEX, math in a line of text is entered and exited using a single dollar sign: $x > 1$
comes out as x > 1. This is the cardinal rule!
To type a mathematical expression on its own line, there are a few options. If you don’t
want the expression to be numbered (for instance, you won’t be referring back to it later
on), then use double dollar signs: $$f(x) = 2x - 5$$ comes out on its own line as
f (x) = 2x − 5.
But maybe you want the equation to have a number on the side, like this:
Z b
(2.1)
f 0 (x) dx = f (b) − f (a).
a
2
AN INTRODUCTION TO LATEX
This equation was typeset using the commands \begin{equation} and \end{equation}.
A number on the side is produced. NOTE: All LATEX commands begin with a backslash \.
How do you refer back to a displayed equation? The command to use is \ref but we have
to label the equation to give it a name to refer back to.1 You do not want to refer to the
above equation by actually typing in an equation number in your file, since the equation may
get moved and then the number changes. Let LATEX handle that problem for you! The above
equation was labelled eqn-one by adding \label{eqn-one} after typing \begin{equation}
above. You can refer back to the equation by typing (\ref{eqn-one}). The result: (2.1).
2
There is no reason at all to call your equations eqn-one, eqn-two, and so on.2 You could
just as well call them something else. For instance, consider the following famous formula:
√
−b ± b2 − 4ac
(2.2)
r=
.
2a
The label for this equation is holycow, but you can’t see that from the output in the formula.
The reference command (\ref{holycow}) produces something innocent-looking: (2.2). A
more reasonable label for (2.2) might have been, say, qformula or qf. Anyway, the point of
using labels is that even when things get moved around (and they sure will) this referencing
system will regenerate correct numbers for everything.
Quite generally, the command \label{name} is used to label equations, theorems, sections,
and anything else you want to refer back to later, which you do as \ref{name}. Put whatever
you want in “name” to be the label you need when making references elsewhere to that item.
For instance, right now we are in Section 2. The section was (arbitrarily) called tsetsec
by typing \label{tsetsec} on the line in the file where the section starts. The command
\ref{tsetsec} anywhere in the file produces the number of this section.
The commands \begin{eqnarray∗}, \end{eqnarray∗} get used for unnumbered stacked
equations such as
(x + y)2 =
=
=
>
(x + y)(x + y)
x2 + xy + yx + y 2
x2 + 2xy + y 2
0.
If we want to number one of those equations, say to get
(2.3)
(x + y)2 =
=
=
>
(x + y)(x + y)
x2 + xy + yx + y 2
x2 + 2xy + y 2
0
with the third equation numbered in the margin but not the others, use \begin{eqnarray},
\end{eqnarray} – without the asterisks – and add \label{name} at the end of the line you
want labeled (calling it “name” or whatever else you want) while putting \nonumber at the
end of the lines you don’t want labeled. Now (2.3) is available for referencing purposes.
1Here’s
a footnote, produced with \footnote.
another footnote, using \edit. It leaves a number in the margin. Use this when making editing
notes to yourself.
2Here’s
AN INTRODUCTION TO LATEX
3
Sometimes things are defined in cases, like the absolute value function
(
x, if x ≥ 0,
|x| :=
−x, if x < 0.
The brace is generated using \begin{cases},\end{cases}. All text in math mode, by
default, is put in italics. To tell LATEX to keep certain text in math mode unitalicized, like
“if” in the definition above of the absolute value, write \text{if}. If you don’t do this,
then “if” gets italicized and the output is ugly:
(
x, if x ≥ 0,
|x| :=
−x, if x < 0.
Finally, you might want to make something on a line of text appear as large as it would
a
in a displayed equation. Use \displaystyle{}. For instance,
is obtained using
b+c
\displaystyle{\frac{a}{b+c}}. Without using displaystyle, the fraction in text looks
a
smaller: b+c
.
3. User-Defined Commands and Operators
How do you make a new command? For instance, let’s suppose you are going to be typing
the notation for real numbers, R, a lot. You could type \mathbf R (in math mode, e.g., inside
dollar signs) each time. That is tedious. It’s better to create your own little command to
abbreviate this. Look at the top of the file and you’ll see \RR is introduced as a shortcut for R
with the command \newcommand{\RR}{\mathbf R}. Also included are shortcut commands
for C, Z, Z/mZ, and Q. Shortcuts for the alternate fonts R, C, Z, Z/mZ, and Q are at the
top of the file as well. If you are going to be writing M a lot and you don’t want to write
out \mathcal M each time, the line \newcommand{\calM}{\mathcal M} at the top of the file
lets you instead write \calM to produce what you expect: M. Marvelous.
In addition to user-defined commands, there are user-defined operators. An operator is
something like sin or det which is applied to something else: sin π, det A. To ensure the right
amount of spacing after the operator, it should be defined as an operator rather than as a
command if it is not already part of LATEX. While \sin and \det are already part of LATEX,
consider the following examples.
Example 3.1. The default LATEX real and imaginary part operators are \Re and \Im, which
come out like < and =, e.g., =(2 + 3i) = 3. How ugly! See the top of the file for new
operators \re and \im. Now we can write Im(2 + 3i) = 3. That’s better.
Example 3.2. Although LATEX has an operator \det for the determinant of a matrix, it has
no default operator for the trace! Look at the top of the file to see how the new operator
\Tr is defined, which lets us write things like Tr( 20 14 ) = 6.
Example 3.3. We want to refer to a probability using the shorthand “Prob” while in math
mode. At the top of the file a user-defined operator \Prob has been defined, so we can write
Rb
2
Prob(a ≤ x ≤ b) = √12π a e−x /2 dx and Prob is not in italics. If we wrote plain “Prob”
Rb
2
there without a special code for it, we’d get P rob(a ≤ x ≤ b) = √12π a e−x /2 dx. Yucko.
The final topic for this section is commands
R bwith variable entries. Here’s the idea. Suppose
you will often need to write something like a f (x) dx with a lot of different functions. You
4
AN INTRODUCTION TO LATEX
could type \int_a^b \sin x\,dx, \int_a^b e^x\,dx, and so on each time. But wouldn’t
it be nicer to type only the new function f (x) (whatever function it happens to be) each
time and have the surrounding material automated? Here’s how: A new command \intf is
defined at the top of the file in the following way:
\newcommand{\intf}[1]{\int_a^b{#1}\,dx}.
The [1] after \intf tells LATEX that this command allows one variable input, and the structure of the command tells LATEX where to put the variable. (Look for the #1 in the command.)
Rb
For instance, typing just \intf{\sin x} returns a sin x dx and typing \intf{e^x} returns
Rb x
e dx.
a
If you want the bounds of integration adjustable too, use a 3-variable command \intfb,
defined at the top of the file as
\newcommand{\intfb}[3]{\int_{#1}^{#2}_{#3}\,dx}.
R5
Rb
Then \intfb{0}{5}{e^x} returns 0 ex dx and \intfb{3}{b}{\cos x} returns 3 cos x dx.
4. Theorems and Definitions
Your paper probably will include theorems, corollaries, definitions, remarks, and so on.
The file math27842794Wpaper.tex has included special commands at the top which will
properly number and format all of these together according to the section of your paper.
Use \begin{theorem},\end{theorem} when starting and ending your theorems. Theorems are automatically typset in italics. Here’s one.
Theorem 4.1 (Pythagoras). If a, b, and c are the sides of a right triangle, with c the
hypotenuse, then c2 = a2 + b2 .
The name Pythagoras is tacked on in square brackets [,] after \begin{theorem}. Of
course you don’t have to attribute your theorems.
All theorem-like environments (which means lemmas, theorems, corollaries, and conjectures) are typeset the same way. Here is a lemma.
Lemma 4.2. Let W and W 0 be subspaces of Rn . Then dim(W + W 0 ) = dim W + dim W 0 if
and only if W ∩ W 0 = {0}.
In addition to theorem-like environments, there are definition-like environments. That
means: definitions, examples, and remarks In these environments text is unitalicized by
default. Produce a definition, for instance, using \begin{definition},\end{definition}.
Definition 4.3. A function is called smooth when it is infinitely differentiable.
Remark 4.4. Remarks are easy to produce, using \begin{remark},\end{remark}. Use this
environment if there is something unusual (perhaps an easy misunderstanding) you want to
draw to the reader’s attention.
When you want to start and end a proof, use \begin{proof},\end{proof}. Let’s see
how it looks as output. The box at the end of the proof is generated by the \end{proof}
command.
Theorem 4.5. If x and y are real and x2 − xy + y 2 = 0 then x = 0 and y = 0.
Proof. We complete the square: x2 − xy + y 2 = (x − 21 y)2 + 43 y 2 . This expression is always
non-negative, so it vanishes only when x − 12 y = 0 and y = 0. Then x = 0, so both x and y
vanish.
AN INTRODUCTION TO LATEX
5
NOTE: References to equations always have parentheses around them: “By equation
(4.1)” or “Using (4.1)”, for example. There is no automatic parethesis generator in LaTeX:
you need to type them yourself. In contrast to equations, references to theorems, lemmas,
and examples do not have parentheses: Theorem 1.3, Lemma 4.6, and Example 5.2.
5. Relations
Here is an assortment of mathematical things you might want to type. Check out the
commands which produce them in the file.
def ?
< > ≤ ≥ ∼
= ∼ ≡ ≈ = = ⊂ ⊆ ×
7→
→ ← ↔ −→ ←− ←→ ⇒ ⇐ ⇔ =⇒ ⇐= ⇐⇒
→
c ~a −
f
b c ∞ â abc
abc −
abc
→ ã abc ı  ı̂ ̂
sin cos tan arctan log ln exp dim lim
The dotless ı and  are available since decorated i’s and j’s like î and ĵ look weird with the
dot.
Example 5.1. You can choose between limθ→0 (sin θ)/θ = 1 or limθ→0 sinθ θ = 1. The tiny
fraction is hard to read. Maybe it’s better in the displayed version
sin θ
lim
= 1.
θ→0 θ
If you leave off the backslash on the sine function, say you write $sin \theta$ in haste,
it will come out like this: sinθ. Ugh. If you forget both backslashes, as $sin theta$, you
get sintheta. Ouch. Don’t forget backslashes! sin θ = $\sin \theta$.
Example 5.2. The congruence relation in modular arithmetic is expressed using \bmod, not
\mod. Compare 18 ≡ 8 mod 5 and 18 ≡ 8 mod 5. There is too much space between the 8
and the “mod” in the second one (bmod is short for “binary mod,” as in“mod as a binary
relation”).
Things get negated by putting \not in front of them, leading to 6=, 6≡, 6≈, and so on.
6. Phancy Phonts
To get bold ordinary text, use \bf: this = {\bf this}. If you don’t mark the start
and end of your bold text with curly braces, then everything following it is in bold.
To get bold in math mode, use \mathbf: v 6= 0 is ${\mathbf v} \not= {\mathbf 0}$.
Do you want italics? Or CALLIGRAPHIC? Or underlines? Or gothic? Or GOTHIC?
Don0 t write your paper this way.
7. Lists
Here is the same two-item list in three forms, using \begin{itemize}, \end{itemize} for
the first two and \begin{enumerate}, \end{enumerate} for the third. Look at the file to
see how the (default) bullets are turned into letters in the second version.
• eiπ = −1
• 65 = 12 + 82 = 42 + 72
(a) eiπ = −1
(b) 65 = 12 + 82 = 42 + 72
6
AN INTRODUCTION TO LATEX
(1) eiπ = −1
(2) 65 = 12 + 82 = 42 + 72
8. Set-theoretic/Algebraic expressions
To write that x belongs to R, use \in: x ∈ R. (If it’s not, then x 6∈ R, using \not\in.)
A set is indicated with curly braces, which are typeset as \{,}\. For instance,
{x ∈ R : sin x = 0} = {kπ : k ∈ Z}.
It is essential that you use the backslash with those curly braces or they are not recognized
as set braces and they don’t show up. You’d get
x ∈ R : sin x = 0 = kπ : k ∈ Z,
which looks weird.
Unions and intersections are denoted with \cup and \cap: A ∪ B, A ∩ B. The empty set
is \emptyset: ∅.
√
√
Square roots: \sqrt{10} = 10. For n-th roots, \sqrt[n]{10} = n 10. To indicate
positive and negative (plus/minus) together, \pm{2} = ±2.
x
Fractions are produced using \frac, e.g., 3x−1
is \frac{x}{3x-1}. A fraction that is hard
to read on a line of text can always
be put on its own line using double dollar signs.
Binomial coefficients are nx = \binom{x}{n}.
To indicate collected terms with braces from below, using \underbrace:
x
· · + x} = nx.
| + ·{z
n times
If the word “times” was not placed in text mode, it comes out in italics, which looks bad:
x
· · + x} = nx.
| + ·{z
n times
Use \overbrace for braces from above:
n times
z }| {
x + · · · + x = nx.
Underbraces look better than overbraces. To generate the · · · between the plus signs, use
\cdots (center dots); don’t just type three dots or you get ..., which is too low and cramped.
We’ll meet more kinds of dots when we see a big matrix in Section 10.
Here is a factored polynomial:
cn xn + cn−1 xn−1 + · · · + c1 + c0 = cn (x − r1 )(x − r2 ) · · · (x − rn ).
Greek letters are typed in math mode by writing the name of the letter preceded by a
backslash, so α is \alpha, π is \pi, and Π (capital pi) is \Pi. (There is no \Alpha since
that’s just A, which is nothing special.) The first five lowercase Greek letters are
α,
β,
γ,
δ,
ε.
The capital Gamma and Delta are typed as \Gamma and \Delta and come out as Γ and ∆.
There are two versions of lowercase epsilon and phi: ε and , ϕ and φ. The first choices
look better. They are \varepsilon and \varphi.
AN INTRODUCTION TO LATEX
7
If you want to typeset a summation sign, do not use Σ = \Sigma. Instead type \sum,
which will adapt the size of the
place subscripts and superscripts on it correctly,
P Σ and
2
either in paragraph mode like N
n
=
N (N + 1)(2N + 1)/6 or in displayed mode like
n=1
N
X
n=1
n2 =
N (N + 1)(2N + 1)
.
6
Similarly, products (if you need them) are typed as \prod, not as \Pi, e.g.,
n! =
n
Y
j.
j=1
9. Some calculus
An integral from a to b is \int_a^b:
∞
Z ∞
−x
−x e dx = −e 0
0
lim (−e−b + 1)
=
b→∞
= 1.
The vertical line with the bounds of integration would usually be only as tall as the nearby
e−x term. To get it as tall as the integral sign, a hidden extra integral sign was inserted right
after that e−x using \phantom{\int} and then several backspace commands \! brought the
vertical line back up to the e−x . Clever!
A double integral is \iint:
ZZ
Z ∞ Z 2π
2
−x2 −y 2
e
e−r r dr dθ = π.
dx dy =
R2
Triple integrals are \iiint:
Evaluating a derivative:
0
RRR
0
.
d x
1 − x2 3
=
=− .
2
2
2
dx x=2 1 + x
(1 + x ) x=2
25
x
The command \left(,\right) is used around 1+x
2 to get properly sized left and right
parentheses in the displayed equation. If you just use plain (,) then you get something silly:
(
x
).
1 + x2
An ordinary and partial differential equation:
2
d2 y
dy
+ (sin x)
+ (cos x)y = 0,
2
dx
dx
∂ 2f
∂f
=
.
2
∂x
∂t
8
AN INTRODUCTION TO LATEX
10. Some linear algebra
In text, a 2 × 2 matrix is produced using (\begin{smallmatrix},\end{smallmatrix}).
For instance, look at this: ( ac db ). If you forget to include the parentheses, then you get a
poor floating array ac db which very much wants its parentheses!
Here are matrices multiplied by vectors




1 2 0  
1 2 0  
 4 9 1  5
 4 9 1  5

 4 ,

 
 3 2 0 
 3 2 0  4 .
3
3
9 1 3
9 1 3
They are produced using \begin{array},\end{array}. The different borders are produced
using \left(,\right) in the code for the first matrix and \left[,\right] in the code for
the second matrix. The command {ccc} which is in the LATEX code for the matrices after
\begin{array} tells LATEX that there are 3 columns (so 3 c’s). The column vectors (which
are really 1-column matrices) are produced using {c} after \begin{array}. A monster
matrix can be done too:


λ 1 ··· 0 0
 0 λ ··· 0 0 
 . . .
.. .. 
 .. ..
.
.
. . 
.

 0 0 ··· µ 4 
0 0 ··· 1 ν
Here the command {ccccc} is used since this matrix is built out of 5 columns. Notice the
effect of \cdots (center dots), \vdots (vertical dots), and \ddots (diagonal dots) in the
code which generated this nice matrix.
Instead of surrounding a matrix with parentheses, we can use other delimiters such as
\left|,\right| and it looks like a determinant:
a b = ad − bc.
det A = c d Perpendicularity is indicated with \perp and the transpose operation with \top:
v ⊥ w,
V ⊥,
A> .
The length of a vector can be indicated with double parallel lines, which are produced
with \Vert: k (the capital V is important, since \vert outputs |, a single vertical line), so
the Cauchy-Schwarz inequality says
|v · w| ≤ kvkkwk.
If you literally typed in parallel lines as ||, then the inequality looks less nice:
|v · w| ≤ ||v||||w||.
A common notation for inner products is hv, wi. These brackets are obtained using
\langle,\rangle. If you use ordinary less than and greater than signs, you get the uglier
< v, w >.
AN INTRODUCTION TO LATEX
9
11. Tables
Table 1 gives a two-column table without borders. In Table 2 there are boundaries added
all around and a double line down the middle. The code for tables can be found in the
file. The first table has the columns centered using {c|c}, while the second table has its
first column left justified and its second column right justified using {|l||r|}. The vertical
lines appearing in these commands tell LATEX where to place vertical lines in the tables.
Appropriately placed \hline commands tell LATEX where to put horizontal lines.
One problem when you insert lines across rows in a table is that expressions may appear
too close to the lines. Take a look at Table 3. To fix this, user-defined commands called
\tfix and \bfix (shorthand for topfix and bottomfix) will insert space in the tables and
the improvements are seen in Tables 4 and 5.
Integers
Real polynomials
Positive
Monic
Irreducible
Prime
Composite
Reducible
±1
Non-zero constant
??
Derivative
Table 1. Useful analogies
Integers
Real polynomials
Positive
Monic
Prime
Irreducible
Composite
Reducible
±1
Non-zero constant
??
Derivative
Table 2. Useful analogies
a
b
5
a mod 11
1
502
−a4
Table 3. Too
c d 13
−1 23 57
4
93 81 10
squished
a
b
c
d
a5 mod 11
1
−1
2
3
1
3
7
5
4
502
−a4 93 81 10
Table 4. Better top spacing
10
AN INTRODUCTION TO LATEX
a
b
c
d
a5 mod 11
1
−1
2
3
1
3
7
5
4
502
−a4 93 81 10
Table 5. Better top and bottom spacing
12. Pictures
It is possible to make some pictures in LaTeX, but it is also possible (and perhaps easier)
to create pictures in another format and import them to your LaTeX file. See Figure 1,
which is an imported .jpg image.
Figure 1. The solved cube
13. Bibliography
Some sample books, web pages, and articles (from journals and conference proceedings) appear below in the reference section, which is generated using \begin{thebibliography}{N},
\end{thebibliography}, where N is the number of references. (To be honest, N can be any
number, for instance in the file it is actually 5 while there are 6 references; one was added
at the last minute. Just some number belongs in the N position.) If you want to cite a
reference use \cite{name} (not \ref{name}), like this: \cite{irros} is [2]. If you want to
cite a page or specific result from a reference, you could do [2, p. 340], [2, pp. 340–342], or
[2, Theorem 20.1.1]. Place a tilde in the space between p. or pp. and the page numbers
to prevent a line break in that space. Take a look at the file to see how the citations were
produced just above to know what this is about.
References
[1] B. H. Gross and J. T. Tate, Commentary on algebra, pp. 335–336 in: “A Century of Mathematics in
America, Part II,” Amer. Math. Soc., Providence, 1989.
[2] K. Ireland and M. Rosen, “A Classical Introduction to Modern Number Theory,” 2nd ed., SpringerVerlag, New York, 1990.
[3] T. J. Kaczynski, Another proof of Wedderburn’s theorem, Amer. Math. Monthly 71 (1964), 652–653.
[4] M-A. Knus, A. Merkurjev, M. Rost, J-P. Tignol, “The Book of Involutions,” Amer. Math. Society,
Providence, 1998.
[5] P. Roquette, Class field theory in characteristic p, its origin and development, pp. 549–631 in: “Class
field theory – its centenary and prospect,” Math. Soc. Japan, Tokyo, 2001.
AN INTRODUCTION TO LATEX
11
[6] N. J. A. Sloane, On-line Encyclopedia of Integer Sequences, http://www.research.att.com/∼njas/
sequences/.
Fly UP