**Text mode.** This is the normal, or default, mode of TeX. TeX
stays in that mode unless it encounters a special
instruction that causes it
to switch to one of the math modes, and it returns to text mode following
a corresponding instruction that indicates the end of math mode.

**Ordinary (inline) math mode.**
Mathematical material to be typeset
inline must be surrounded by single dollar signs. For example:
"$a^2 + b^2 = c^2$".
The single dollar signs surrounding this expression
cause TeX to enter and exit (ordinary) math mode.

**Display math mode.**
Material that is
surrounded by a pair of escaped brackets ("\[" and "\]"), or by
"equation environments" such as \begin{align} ... \end{align},
or \begin{equation} ... \end{equation} is being processed by
TeX in "display math mode." This means that the expression enclosed
gets displayed on a separate line (or several lines, in case of
multiline equations). Longer mathematical formulas and
numbered formulas are usually "displayed" in this manner.
Note that the commands for entering and leaving display math mode are
distinct (\begin{...} or \[ for entering and \end{...} or \]), in
contrast to the ordinary math mode, where a single dollar sign
serves both as entry and exit command. This allows for better error
checking.
(This is a major difference between LaTeX and AmSTeX or Plain TeX. In
the latter two TeX versions, a double dollar sign ($$) is used to
indicate the beginning and end of display math mode.
**While the double dollar sign (still)
works in LaTeX, it is not part of the
"official" LaTeX command set (in fact, most books on LaTeX don't even
mention it) and its use is discouraged. Use the bracket pair
"\[", "\]" instead.**)

**Square roots:**
Square roots are generated with the command \sqrt{...}. For example,
$z=\sqrt{x^2+y^2}$.

**Subscripts and superscripts:**
These are indicated by carets (^) and underscores (_), as in
$2^n$ or $a_1$. If the sub/superscript contains more than one
character, it must be enclosed in curly braces, as in $2^{x+y}$.

**Fractions and binomial coefficients:** Fractions are typeset with
$\frac{x}{y}$, where x stands for the numerator and y for the
denominator. There is a similar construct $\binom{x}{y}$ for
binomial coefficients. (The latter is part of the amsmath enhancements
which you get when using "amsart" as documentclass.)

**Sums and integrals:** The symbols for sums and integrals are \sum
and \int, respectively. These are examples of "large" operators, and
their sizes are adjusted by TeX automatically,
depending on the context (e.g., inline vs. display
math). Note that the symbol generated by \sum is very different from
the "cap-Sigma" symbol, \Sigma; the latter should never be used to
denote sums.
TeX uses a simple, but effective
scheme to typeset summation and integration limits:
Namely, lower and upper limits are
specified as sub- and superscripts to \sum and \int. For example,
$\sum_{k=1}^n k = \frac{n(n+1)}{2}$. (Note that the "lower limit"
"k=1" here must be enclosed in braces.)

**Limits:**
The "subscript" trick works also for limits; "\lim" produces the
"lim" symbol, and the expression underneath this symbol
(for example, "x tends to infinity") is typeset as a subscript to \lim:
$\lim_{x\to\infty}f(x)=0$. Here "\to" produces the arrow, and "\infty"
(note the abbreviation - \infinity does not work!) produces the
"infinity" symbol. "\limsup" and "\liminf" work similarly, as do
"\sup" and "\inf" (for supremum and infinimum), and "\max" and "\min"
(for maximum and minimum). For example, $\max_{0\le x\le 1}x(1-x)=1/4$.

Exercise 2.1:Continuity of a function f(x) at a point x=c can be defined in terms of a limit: "f(x) is continuous at x=c if lim .....". Fill in the blanks and typeset the statement first inline, and then with the "lim ..." formula displayed on a single line. Observe how TeX typesets the limit differently, depending on the context.

Exercise 2.2:Typeset the binomial theorem (giving an expansion for (x+y)^n) in TeX, first as an "inline" formula (enclosed in a pair of single dollar signs), then as a displayed formula (enclosed in a pair \[, \]). Compile the TeX file, and observe the differences in the appearance of the output of the inline and the displayed formulas.

**Operators:**
TeX has commands for common mathematical "operators" or "functions",
such as \sin, \cos, \log, \ln, \exp, \arctan, etc. You should always
use these commands instead of
simply typing "sin", "cos", etc., without the backslash.
Using the TeX commands
ensures that the operators get typeset in the proper font and
takes care of the spacing surrounding these operators.

Exercise 2.3:Typeset the addition formula for the sine: sin(x+y) = sin x cos y + cos x sin y, first using the proper TeX commands \sin and \cos and then by just typing sin and cos without the backslash. Observe the difference.

**Parentheses:**
The symbol pairs (), [], and \{ \} (note the backslash!) generate
round, square, and curly parentheses in normal size. They work fine in
math mode, but
mathematical expressions often look better if the parentheses
are enlarged to match the size of the expression. There are ways to
manually enlarge these parentheses (by preceding the symbol with a
command like \big, \bigg, \Big, etc.), but one rarely has to use
these, since TeX can (in most cases) automatically size parentheses.
To let TeX do the sizing, precede the left brace by \left, and the
right brace by \right. This also works for other parentheses-like
constructs, such as the absolute value symbol "|".
Here is an example:

\[ \left|\sum_{i=1}^n a_ib_i\right| \le \left(\sum_{i=1}^n a_i^2\right)^{1/2} \left(\sum_{i=1}^n b_i^2\right)^{1/2} \]

Exercise 2.4:Typeset the above expression and look at the output. (It's a famous mathematical theorem!). Then remove, or comment out, one of the bracket expressions (say, one instance of "\left("), and see what error messages you get. All bracket expressions generated by \left.. or \right.. must occur in pairs, and TeX gives an error message if this is not the case. (The left and right brackets don't have to be of the same type; for example, $\left\[\frac{3}{4}, \frac{4}{5}\right[$ to denote the half-open interval [3/4, 4/5[ is perfectly legal.)

**Multi-line equation environments:**
Things get more complicated if you have multiline equations that need
to be lined up at suitable places. For most situations, the
\begin{align} ... \end{align} environment, and its variant
\begin{align*} ... \end{align*}, are sufficient. As with the equation
environment, the asterisk version does not automatically number
equations.

The use of align is best illustrated with an example:

\begin{align} (a+b)^3 &= (a+b)^2(a+b)\\ &=(a^2+2ab+b^2)(a+b)\\ &=(a^3+2a^2b+ab^2) + (a^2b+2ab^2+b^3)\\ &=a^3+3a^2b+3ab^2+b^3 \end{align}Here a double backslash (\\) is used to separate the lines, and an ampersand symbol (&) is used to indicate the place at which the formulas should be aligned. You can include more than one ampersand symbol per line to specify alignment at multiple columns, but the number of alignment symbols must be the same for each line of the display. Multiple alignments are rarely needed; in almost all cases a single alignment symbol, usually placed right before an equality (or inequality) sign, is enough.

Exercise 2.5:Typeset the above multiline equation, compile it, and look at the output on the screen. Also, make some intentional mistakes (like leaving out the ampersand symbol, or leaving out one of the \\'s), and see what kind of error messages you get. Errors in multiline displays are among the most difficult to track down and diagnose.

Exercise 2.6:Typeset the recurrence defining the Fibbonacci numbers, along with appropriate initial conditions. Use a single line display, with appropriate spacing commands (\quad's) separating the parts.

**Don't try to learn LaTeX by imitating what you see in other papers
(unless you know for sure that the author is a competent LaTeX typist).
Many papers written in LaTeX are done poorly (as far as typesetting
is concerned), and would make very bad example to follow. You are
likely to delevop bad habits (which are hard to shed once you get used
to them) if you learn TeX in this way.
**

A note about display math environments: You will probably be overwhelmed by the variety of display math environments that are available in LaTeX: besides the "align" and "align*" environments discussed above, there is aligned, alignat, gather, gathered, multline, and a few more. However, in practice all you need is align, align*, equation, equation*, and (occasionally) the "cases" environment. I have never felt the need to use any of the other environments.

**Note on the "eqnarray" environment:** This is the standard LaTeX
equation environment, and the one you'll find in books on standard
LaTeX (i.e., LaTeX without the ams extensions). However, I would not
recommend using this environment as
the "align" type environments available with the
ams-enhanced version of LaTeX provide better looking output, more
functionality, and are easier to work with.

Exercise 2.7:As a final exercise in this section, try to typeset the problems of the 2000 UIUC Undergraduate Math Contest. Some hints: Use the following structure:\documentclass{amsart} \begin{document} \begin{enumerate} \item ... \item ... ... \end{enumerate} \end{document}Here each item introduces one problem. The items get automatically numbered, so you shouldn't say "Problem 1"; just add the text of the problem.

Extra credit I:Solve these problems.

Extra credit II:Typeset the solutions to these problems. This is a lot more challenging than typesetting the problems since most solutions involve complex math constructs and/or multiline equtions. (The solutions are on the web, in pdf and ps form. I won't give the URL (that would be too tempting!), but with a little digging, you'll find them.)

* Last modified: Wed 18 Aug 2004 02:31:51 PM CDT
ajh@uiuc.edu
*