\chapter{Equation Formatting}
\label{MATH}
Many technical papers contain equations like
$$ x = {{-b \pm \sqrt{b^{2}-4ac}}\over{2a}} $$
Needless to say, this sort of thing is normally pretty hard
to type so that it looks good, even on a typewriter that has all the special
symbols.
\LaTeX\ has three environments which constitute ``mathematics
mode.'' In mathematics mode, \LaTeX's rules and control
sequences are changed somewhat so as to facilitate the
formatting of equations. These environments are
{\tt math} (for formulas that appear in the text, like
``$x^2+y^2=0$''), {\tt displaymath} (for formulas
that are displayed separately from the text, like the quadratic
formula that introduced this section), and {\tt equation}
(which is just like display math, except that it adds
an equation number at the right margin).
To make all this easier to type,
\LaTeX\ lets you type \verb|\(| and \verb|\)| instead
of \verb|\begin{math}| and \verb|\end{math}|, and
\verb|\[| and \verb|\]| instead of \verb|\begin{displaymath}|
and \verb|\end{displaymath}|. Even easier, you can
type a dollar sign instead of \verb|\(| and \verb|\)|,
so you can type \verb|$x+y=0$| to produce ``$x+y=0$.''
{\sl The \TeX book\/} contains no fewer than four complete
chapters on setting equations in mathematics mode, so
it's safe to conclude that it's a pretty large subject.
However, this introductory paper isn't concerned
with the complete details of
mathematics mode, so we'll only include a few
outstanding rules.
\section{Basic Rules of Math Mode}
Mathematics mode differs from \LaTeX's usual operation
in a number of important ways.
\begin{enumerate}
\item All spaces are ignored. This includes new lines
and tab characters. \LaTeX\ is assumed to know all
about spacing equations, and has a series of
control characters for inserting spaces ``manually'',
like ``\verb|\ |'' (that's a control symbol consisting
of a backslash followed by a space).
\item Alphabetic characters are in a special font, math
italic. Math italic is a lot like text italic, but
the character spacing is slightly different. You
can switch to roman (or other) fonts via \verb|\rm|
and the like, but spaces are still ignored between
the words.
%emacs-mathOK
\item Many control sequences, like the ones that
produce Greek letters ($\alpha$--%
$\omega$), only work in mathematics mode and produce
errors at other times.
\item You can't start a new paragraph inside a formula,
so don't leave a blank line in any math environment.
If you do, \LaTeX\ will think that you're trying
to leave mathematics mode, and an error will result.
\end{enumerate}
\section{Subscripts and Superscripts}
To get something to print as a subscript, just put it in
braces and put an underbar (\verb|_|) in front of it. For
example, ``$x_2$'' is typed as ``\verb|$x_{2}$|''. Similarly,
superscripts are represented with the circumflex (\verb|^|,
also known as a caret or ``up-arrow'').
You can do both at once:
\begin{verbatim}
$x^{1}_{2}$
\end{verbatim}
produces ``$x^{1}_{2}$''. Furthermore, the superscript can
be the first thing that happens in math mode. The word
``su$^{\rm per}_{\rm b}$script'' was typed as
\begin{verbatim}
su$^{\rm per}_{\rm b}$script
\end{verbatim}
This example also demonstrates that subscripts and superscripts
can be something other than numerals, and emphasizes that
alphabetics normally appear in math italic type (requiring
\verb|\rm| to get normal roman letters).
\section{Mathematical Symbols}
\LaTeX\ has a dazzling array of mathematical symbols, all
of which are only available in math mode. To produce
Greek letters like ``$\omega$'' (omega) you type
\verb|$\omega$|. The capital omega ($\Omega$) is pronounced
\verb|$\Omega$|. You can also get boldface versions
of these characters. Some of the other mathematical
glyphs that are recognizable by non-mathematicians
%emacs-mathOK
are \verb|\times| (seen in ``$5\times5=31_{\rm eight}$''),
\verb|\infty| ($\infty$) and the popular \verb|\bullet|
($\bullet$). A complete list of symbols can be found
in Appendix~F of {\sl The \TeX book} on pages 434--439.
A quick perusal of the complete list will show that many
characters are named according to their mathematical
significance, so that mathematical input is ``pronounced''
in a manner similar to the terminology of mathematics.
\section{Logs and Sins}
Some mathematical words like ``log'' and ``sin'' are
conventionally
print\-ed in roman letters, not italic. \LaTeX\ provides
control words like \verb|\log| that automatically produce
the corresponding word in roman letters in math mode.
Some of these (notably \verb|\lim|) behave interestingly with
respect to subscripts. For example, typing
\begin{verbatim}
\[ \lim_{n \to \infty} x_{n} = 0 \]
\end{verbatim}
produces
\[ \lim_{n \to \infty} x_{n} = 0 \]
with the subscript appearing {\sl below\/} the word, which is
the
usual mathematical appearance of ``lim''.
\section{Fractions}
While you can say things like \verb|$x/y$| most of the time
to produce ``$x/y$'', sometimes you need to do things like
``$1\over2$''. For this, the control sequence \verb|\frac|
is available. It takes two parameters: the numerator
and the denominator. For example, ``$1\over2$'' can
be typed as ``\verb|$\frac{1}{2}$|'' and the quadratic
formula which began this chapter can be typed as
\begin{verbatim}
\[ x = \frac{-b \pm \sqrt{b^{2}-4ac} }
{2a} \]
\end{verbatim}
Since it's possible to produce fairly ugly output using
\verb|\frac|, it is recommended that you consider carefully
whether or not a simple slash will do.
This example also demonstrated the \verb|\sqrt| control word.
You can also get other roots by supplying an optional
parameter. For example \verb|$\sqrt[3]{x^{3}}$| produces
$\sqrt[3]{x^{3}}$.
\section{Some Random Examples}
This section will close with a short chrestomathy that might
enable you figure out how to format similar equations by
analogy. Mathematics mode is a big topic, and you should
read one of the reference works for complete details.
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \sum_{n=1}^{m} n = 5 \]
\end{verbatim}
produces:
\[ \sum_{n=1}^{m} n = 5 \]
\smallskip\hrule\smallskip
\begin{verbatim}
\begin{equation}
\int_{-1}^{-1}x\,dx
\end{equation}
\end{verbatim}
produces:
\begin{equation}
\int_{-1}^{-1}x\,dx
\end{equation}
The \verb|\,| control sequence produces a ``thin space.''
\LaTeX\ actually has four different math-mode spacing
control characters:
\begin{center}
\def\bs{\char`\\}
\begin{tabular}{|c| l| l|}
\hline
{\sl Sequence}& \multicolumn{1}{|c|}{\sl Name} & {\sl Example}\\
\hline
\tt \bs; & Thick space & $x\;x$\\
\tt \bs: & Medium space & $x\:x$\\
\tt \bs, & Thin space & $x\,x$\\
\ & \it(no space) & $xx$\\
\tt \bs! & Negative space & $x\!x$\\
\hline
\end{tabular}
\end{center}
Negative space is rarely used.
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \hat{a} \equiv \tilde{n} + \bar{\jmath} \]
\end{verbatim}
produces:
\[ \hat{a} \equiv \tilde{n} + \bar{\jmath} \]
There are ten different accent marks that can be placed
above mathematical symbols, and the control words
used for them are {\sl different\/} from the control
symbols used for accenting normal text characters. See
page~135 of {\sl The \TeX book\/} for a complete list.
\smallskip\hrule\smallskip
\begin{verbatim}
\[ e^{i\theta} = \cos\theta + i\sin\theta \]
\end{verbatim}
produces:
\[ e^{i\theta} = \cos\theta + i\sin\theta \]
\smallskip\hrule\smallskip
\begin{verbatim}
\[ x_{\rm max} - x_{\rm min} \]
\end{verbatim}
produces:
\[ x_{\rm max} - x_{\rm min} \]
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \sqrt{1+\sqrt{1+\sqrt{1+x}}} \]
\end{verbatim}
produces:
\[ \sqrt{1+\sqrt{1+\sqrt{1+x}}} \]
\smallskip\hrule\smallskip
\begin{verbatim}
$ \langle x,y \rangle$
\end{verbatim}
produces ``$ \langle x,y \rangle$''.
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \left( \frac {x+y}{z+2} \right) \]
\end{verbatim}
produces:
\[ \left( \frac {x+y}{z+2} \right) \]
Various kinds of brackets, parentheses, and the like can
be used with \verb|\left| and \verb|\right|. These
produce brackets big enough to surround whatever is
between them. However, for every \verb|\left|, there
must be a \verb|\right|, although they need not be the
same type of bracket.
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \left\langle
\frac {2(x+y)}
{|z|}
\right\rangle
\]
\end{verbatim}
produces:
\[ \left\langle \frac{2(x+y)}
{|z|} \right\rangle \]
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \left |
\begin{array}{ccc}
42 & 39 & 11 \\
23 & 5 & 9 \\
7 & 17 & 27
\end{array}
\right | = -18602
\]
\end{verbatim}
produces:
\[ \left |
\begin{array}{ccc}
42 & 39 & 11 \\
23 & 5 & 9 \\
7 & 17 & 27
\end{array}
\right | = -18602
\]
The {\tt array} environment is a math-mode version
of the {\tt tabular} environment.
\smallskip\hrule\smallskip
\begin{verbatim}
\[ \delta_{ij} = \left\{
\begin{array}{ll}
y & {\rm if\ } y>0\\
z+y & {\rm otherwise}
\end{array}
\right. \]
\end{verbatim}
produces:
\[ \delta_{ij} = \left\{
\begin{array}{ll}
y & {\rm if\ } y>0\\
z+y & {\rm otherwise}
\end{array}
\right. \]
The \verb|\right.| closes the \verb|\left\{| without printing
anything.
Since spaces are ignored in mathematics mode, the control character
\verb|\ | (i.e., a backslash followed
by a space) is necessary to insert a space after ``if''.
You aren't necessarily expected to understand all this.
\epigram{The confusion and complexity of the Fourth Branch,
{\tensf Math}, are extreme.}{GWYN JONES and THOMAS JONES}{The Mabinogion}
\endinput
21-May-90 15:09:11-EDT,10957;000000000000
Return-Path:
Received: from rand.org by MATH.AMS.COM via SMTP with TCP; Mon,
21 May 90 15:08:38-EDT
Received: from monty.rand.org by rand.org; Mon,
21 May 90 11:45:03 -0700
Received: from hercules by monty; Mon, 21 May 90 11:43:11 PDT
Received: from localhost by hercules; Mon, 21 May 90 11:43:09 PDT
Message-Id: <9005211843.AA04309@hercules>
To: bnb@math.ams.com
Subject: math.tex
Date: Mon, 21 May 90 11:43:08 PDT
From: Michael Urban