\hyphenation{super-script}
\title{Maths in \LaTeX: Part~1, Back to Basics}
\author[R.~A. Bailey]{R.~A. Bailey\\Goldsmiths'
College, University of London}

\def\realrm{\rmfamily\upshape}
\newtheorem{prequestion}{Question}
\newtheorem{preanswer}{Answer}
\renewcommand{\thepreanswer}{}
\newenvironment{question}{\begin{prequestion}\realrm}{\end{prequestion}}
\newenvironment{answer}{\begin{preanswer}\realrm}{\end{preanswer}}
\newtheorem{preqn}{Exercise}
\newenvironment{qn}{\begin{preqn}\realrm}{\end{preqn}}
\newcommand{\latexword}[1]{{\ttfamily\upshape #1}}
\newcommand{\theoremheadfont}[1]{{\textbf{#1}}}

\newcommand{\lamport}{{\it \LaTeX: A Document Preparation System\/} by Leslie 
Lamport}
\newcommand{\shortlamp}{\emph{The Manual}}

\begin{Article}
\section{Introduction}
The book \lamport\ is rather coy about Mathematics. It simply does not reveal 
the full range of Mathematical expressions that can be correctly typeset 
without going outside \LaTeX. The result is that some Mathematical authors, 
while attracted to the generic mark-up of \LaTeX, believe that they need to use
plain \TeX\ or \AmSTeX\
to write their documents.

This sequence of tutorials seeks to correct that impression, by
explaining what Mathematical expressions can be typeset with \LaTeX\ 
without the need for the \latexword{amstex} package. Perhaps this will
provoke someone else to write a tutorial on that package. The first
part is mostly, but not entirely, devoted to things which you can find
in \shortlamp, even though you may have overlooked some of them.
Succeeding parts (in the next and later issues of \BV) will be mostly
about Mathematical goodies provided by \TeX\ but upon which
\shortlamp\ is silent, even though they are necessary and quite easy
to use. The final part will deal with arrays, concentrating on their
use in Mathematics.

These are tutorials, so I expect you, the reader, to do some work.
Every so often comes a group of exercises, which you are supposed to
do. Use \LaTeX\ to typeset everything in the exercise except sentences
in italics, which are instructions. If you are not satisfied that you
can do the exercise, then write to me with hard copy of your input and
output (no email address before we go to press, I'm afraid): I will
include a solution in the following issue of \BV.

A word on fonts. Fonts in Mathematics are handled differently in
\LaTeX\ 2.09, in NFSS, and in \LaTeXe.  Rather than compare these
systems every time that I mention fonts, I shall limit myself to
\LaTeX\ 2.09. With any luck, this will enrage some knowledgeable
person enough to write an article on handling of Maths fonts in
different flavours of \LaTeX.

\section{What does it look like?}

\subsection{Maths Mode}
\AllTeX\ has a special state, called {\em Maths mode}, which it must
be in to recognize Mathematical expressions and typeset them properly.
Maths mode in \LaTeX\ is everything between |\(| and~|\)|,
or, alternatively, everything between |$| and~|$|. The
parentheses are better for trapping errors, because it is obvious
whether the left or right one is missing, if any. A missing~|$|
causes \AllTeX\ to swap Maths mode and ordinary mode from then
onwards, giving strange output but no errors until it eventually meets
something like |x^2| that it cannot interpret in the wrong mode.
On the other hand, the dollar signs are easier to type, and easier to
see in your input file.

In Maths mode most symbols are typeset as if they represent single-letter 
variables. A string of three letters will be set as if those three variables 
should be multiplied together. Fancy features like kerns and ligatures, which 
are used in normal text to help the reader interpret letter-strings as words, 
are turned off. Letters are set in the special font known as {\em Maths 
italic\/} which is usually used for variables.

Almost all spaces that you type are ignored. \AllTeX\ thinks that it
knows better than you do how Mathematics should be spaced, and it is
probably right to think so.

Don't stay in Maths mode for too long just because you are too lazy to type a 
few |$|~signs. Everything between the~|$|s should be Maths. A common 
mistake by beginners is to forget that a punctuation sign,  like a comma, may 
have a different meaning in Maths from its meaning in text. In
\begin{quote}
the scalars $a$, $b$ and $c$
\end{quote}
we have a textual list containing three mathematical objects, so the input file 
contains
\begin{verbatim}
   the scalars $a$, $b$ and $c$
\end{verbatim}
That comma is a textual one. The lazy typist types
\begin{verbatim}
   the scalars $a, b$ and $c$
\end{verbatim}
and obtains
\begin{quote}
   the scalars $a, b$ and $c$
\end{quote}
On the other hand, in 
\begin{quote}
the vector $(a,b,c)$
\end{quote}
there is a single Mathematical object, so it is correct to type
\begin{verbatim}
   the vector $(a,b,c)$
\end{verbatim}
or, equally well,
\begin{verbatim}
   the vector $(a, b, c)$
\end{verbatim}
These commas are part of the Mathematical notation.

\subsection{Basic symbols}
The basic symbols are the numerals {\tt 1}, {\tt 2}, \ldots, the Latin 
letters {\tt a}, {\tt b}, \ldots, {\tt z}, {\tt A}, \ldots, {\tt Z}, and the 
Greek letters |\alpha|, |\beta|, |\gamma|, \ldots, 
|\omega|, |A|, |B|, |\Gamma|, \ldots,~|\Omega|. 
If you don't know the standard English spellings of Greek letters, look on 
page~43 of \shortlamp. Upper-case Greek letters which are conventionally the 
same as their Latin equivalents do not have special commands. Some Greek letters 
have variants: |\varepsilon|,  for example.

The obvious symbols for operators are the keyboard symbols |+|
and~{\tt -}.  If you forget to go into Maths mode (a common temptation
when typing a table of data), the symbol~{\tt -} will not look like a
minus sign. Outside Maths mode the~|+| will look like a plus
sign, but the spacing will be wrong. In Maths mode \AllTeX\ knows what
is the proper spacing to put around binary operators like~\verb|+|
and~{\tt -}; it also knows the proper spacing to surround binary
relations like~{\tt =}.  Try typing the following both inside Maths
mode and outside it, and compare the results.
\begin{verbatim}
   1 +2 =  3          4-1 = 3
   1 -4 = -3         -2+7 =+5 
\end{verbatim}
Also try~{\tt >} outside Maths mode: you may be surprised.
\label{symsec}

\subsection{Sub- and superscripts}
Subscripts are introduced with~|_|: for example, |x_n| gives~$x_n$.
If there is more than one thing in the subscript you have to use braces, as in
\verb!x_{n+1}! for~$x_{n+1}$. You can type |x_{n}| for $x_{n}$ if you 
want, but it makes your input file less readable.

Superscripts are done similarly, using~|^|: thus |y^3| for~$y^3$ and 
|y^{-1}| for~$y^{-1}$.

A sub- and superscript can be put on the same symbol in either order: 
|x_n^2| and |x^2_n| both produce~$x_n^2$. Double subscripts or 
superscripts are obtained by using braces in the obvious way: |x_{n_2}| 
and |n^{m^2}|.

To put a sub- or superscript {\em before\/} a symbol, precede it with 
|{}|. Otherwise the sub- or superscript attaches itself to the previous 
thing, which may well be something like $+$ or~$=$.

In an expression such as ${(X+Y)^2}$, strictly speaking \TeX\ thinks it is 
putting the superscript on the right parenthesis if 
you type \verb!(X+Y)^2!, and 
it positions the superscript in accordance with that thought. If this really 
offends you, you can force \TeX\ to share your logic by typing 
\verb!{(X+Y)}^2!, but you may not always prefer the result.

\subsection{Modifying symbols}
To turn~$x$ into~$x'$ type~|x'|. You do not need to think of the prime as 
a superscript.

Some common modifiers are exemplified in
\[
\begin{tabular}{cc@{\qquad}cc}
|\bar{x}|  & $\bar{x}$ & |\tilde{x}| & $\tilde{x}$\\
|\hat{x}| & $\hat{x}$ & |\vec{x}| & $\vec{x}$
\end{tabular}
\]
A few more such decorations are shown on page~51 of \shortlamp. If any
of them is used over an~$i$ or a~$j$ then the dotless versions of
those letters should be used: |\imath| and |\jmath|.

There are wide versions of |\hat| and |\tilde|:
\[
\begin{tabular}{c@{\qquad}c}
\verb!\widehat{a+b}! & $\widehat{a+b}$\\
|\widetilde{1-\theta}| & $\widetilde{1-\theta}$
\end{tabular}
\]
There are also wide versions of |\bar| and |\vec| but with less 
obvious names: I'll cover these in a later tutorial.

Logically, a decoration such as |\hat| may modify the whole of a 
subscripted expression such as~$x_2$; you usually mean `the estimate of~$x_2$' 
rather than `the second part of~$\hat{x}$'. However, both $\hat{x_2}$ and 
$\widehat{x_2}$ simply look wrong, so you have to let aesthetics triumph over 
logic and type |\hat{x}_2|.

\subsection{Dots}
To get a line of dots to show that some items have been missed out, use 
|\ldots| if the missing items are normally aligned on their baselines, 
such as letters, or |\cdots| if the missing items are normally aligned on 
the centreline, such as binary operators. If the missing items are part of a 
textual list, don't forget to come out of Maths mode and to put a comma at the 
end of the dots.
\[
\begin{tabular}{c}
|for $i=1$, $2$, \ldots, $10$|\\
|the vector $(x_1, x_2, \ldots, x_n)$|\\
|$a_1 + a_2 + \cdots + a_n$|\\
|$y_1 = y_2 = \cdots = y_7$|
\end{tabular}
\]
If you think that the dollar signs round the numerals in the first example are 
unnecessary, try embedding that phrase in a piece of italic text.

\subsection{Square roots}
Type |\sqrt{2}| to obtain $\sqrt{2}$. The same technique works for more 
complicated expressions than~$2$: you don't have to do anything to make the 
root sign the right size. For example,
\begin{quote}
\verb!\sqrt{n^2+6}! \qquad $\sqrt{n^2+6}$
\end{quote}
Other roots, such as cube roots, are obtained by putting in an optional 
argument:
\begin{quote}
|\sqrt[3]{8} = 2| \qquad $\sqrt[3]{8} = 2$
\end{quote}
The simple symbol for a square root is |\surd|.

Don't abuse \TeX's wizardry by using |\sqrt| for a large expression in 
text or in a complicated display. The mess obscures the message.

\subsection{Displayed Maths}
To get a single line of displayed Maths, type the contents between |\[| 
and~|\]|. You should not start a paragraph with displayed Maths, but may 
end one. If the displayed Maths is in the middle of a paragraph, remember not 
to leave blank lines around it in your input file.

Displayed Maths may also be typed between |$$| and~|$$|, but the 
effect is not quite the same. For example, the document option 
\latexword{fleqn} aligns displayed Maths on the left if you use |\[| and 
|\]|, but not if you use |$$|.

To put a short piece of text in displayed Maths, insert it in |\mbox|, 
remembering to include any necessary spaces that would be ignored in Maths 
mode.
\begin{verbatim}
     \[ a=b \mbox{ if } c=d \]
\end{verbatim}
Don't try to use |\mbox| in a similar way to put short text 
between pieces of Maths in text: it inhibits line-breaks.

\subsection{Words as labels}
Sometimes you want to attach natural-language words to Mathematical symbols to 
label them. For example, you might have analogous quantities associated with 
the rows and columns of a rectangular array, and wish to indicate this by using
the same symbol, say~$Q$, with different subscripts. It simply will not do to 
type |Q_{rows}|, because this gives $Q_{rows}$, where the subscript looks 
like the product of $r$~by $o$ by \ldots. And it is no good putting {\tt rows} 
in an |\mbox|, because it will come out too big. Once something has been 
put in a box, it doesn't change size. You have to type 
|Q_{\rm rows}| to get $Q_\mathrm{rows}$.
(Did you remember the caveat about fonts?)

If this seems too much trouble, you might decide to abbreviate to $Q_r$ 
and~$Q_c$. But this will not do either, 
because the subscripts look like variables 
into which numbers, say, could be substituted. If you don't want to mislead 
your readers, you should type |Q_{\rm r}|.

\subsection{Fractions}
A built-up fraction is made with |\frac|:
\begin{quote}
|\frac{n}{m}| \qquad $\displaystyle\frac{n}{m}$
\end{quote}
This comes out larger in displayed Maths than in text. It is better to use the 
solidus, as in $n/m$, for most fractions in text, with the exception of a few 
simple common fractions like~$\frac{1}{2}$.

Of course, fractions can be put inside other fractions with no bother:
\[
\begin{tabular}{c}
\verb!\frac{a(b+c)}{5 + \frac{1}{xy}}! \\[2\jot]
$\displaystyle \frac{a(b+c)}{5 + \frac{1}{xy}}$
\end{tabular}
\]

\subsection{Binary operators}
In the golden olden days of golf-ball typewriters, it was a luxury to
a Mathematician to have the symbol for direct sum, or for union.
\AllTeX\ not only has the symbols; it knows that they are operators,
and gives them the correct spacing for infix operators, and has
reasonably good ideas about where to break lines near them. A few of
the common ones are:
\[
\begin{tabular}{cc@{\qquad}cc@{\qquad}cc}
\verb!+! & $+$ & \verb!-! & $-$ & \verb!\pm! & $\pm$\\
\verb!\times! & $\times$ & \verb!\div! & $\div$ & \verb!\oplus! & $\oplus$\\
\verb!\cup! & $\cup$ & \verb!\cap! & $\cap$ & \verb!\wedge! & $\wedge$.
\end{tabular}
\]
There are many more on page~44.

In fact, \AllTeX\ is even cleverer than this. If a binary operator
doesn't find itself between two things it can operate on then it
becomes a simple symbol, and spaces and line-breaks adjust
accordingly. You should have noticed this if you did the exercise
suggested above.%in Section~\ref{symsec}.

\subsection{Binary relations}
\AllTeX\ also knows about infix relations, such as
\[
\begin{tabular}{cc@{\qquad}cc@{\qquad}cc}
\verb!=! & $=$ & \verb!\in! & $\in$ & \verb!\subset! & $\subset$\\
\verb!<! & $<$ & \verb!\leq! & $\leq$ & \verb!\perp! & $\perp$.
\end{tabular}
\]
More are shown on page~44. Don't confuse~$\in$ with either of the epsilons.

Compare \verb!\mid! with~\verb!|!. The former is a relation, while the latter 
is just a symbol. So which should you use for `divides'?

Relations can be negated by preceding them with |\not|:
%\begin{quote}
\[
\verb!Z_2 \times Z_2 \not\cong Z_4! \qquad 
Z_2 \times Z_2 \not\cong Z_4
\]
%\end{quote}
This doesn't work quite right for~$\in$, so there is the special command 
|\notin|. Also, |\ne| is a useful shorthand for |\not=|.

\subsection{Fonts in Maths}
(Did you remember the caveat about fonts?)

For something like script letters use |\cal|, as in |${\cal F}(x)$|
for $\mathcal{F}(x)$. The braces give the scope of |\cal|: for a
single Mathematical letter such as~$\mathcal H$ you can get away with
|$\cal H$|.  Only upper-case Latin letters may be modified by |\cal|.

In some branches of Mathematics, constants are shown in Roman type. So the base
of natural logarithms is |{\rm e}|.

For bold letters, you can use |\bf| to modify 
Latin letters and upper-case Greek ones:
\[
\verb!{\bf Mv} = a{\bf w}! \qquad \mathbf{Mv} = a\mathbf{w}
\]
For lower-case Greek letters, and for non-letters, you have to use a
cumbersome construction:
\begin{quote}
\verb!\mbox{\boldmath $\lambda$}! \qquad \mbox{\boldmath $\lambda$}
\end{quote}
Because of the box, this does not change size properly in sub- and 
superscripts.

\subsection{Writing Maths}
The ability to produce beautiful Mathematical formulae is no licence to produce
poor Mathematical writing. Remember that relations are verbs. It is impossible 
to parse the sentence
\begin{quote}
Therefore $n=56$ is the sample size.
\end{quote}
but
\begin{quote}
The equation $x^2+9=0$ has no real roots.
\end{quote}
is fine.

Don't start a sentence with notation: the reader doesn't get the right visual 
clue. If possible, avoid putting notation immediately after {\em any\/} 
punctuation, unless it is part of a list. This saves the reader from having to 
work out if the punctuation is Mathematical or textual. Similarly, avoid 
abbreviations like `iid' and `e.g.'\ which might be mistaken for notation at a 
first glance.

\section{Exercises}
\begin{qn}
The zeros of the quadratic $ax^2 + bx + c$ are
\[
\frac{-b\pm \sqrt{b^2 - 4ac}}{2a} .
\]
\end{qn}

\begin{qn}
The upper 5\% point of the $\chi^2_6$ distribution is 12.592.
\end{qn}

\begin{qn}
If $\nu= n_1 + n_2 -2 $ and
\[
s^2 = \frac{(n_1 -1)s_1^2 + (n_2-1)s_2^2}{n_1 + n_2 -2}
\]
then
\[
\frac{\bar{X}_1 - \bar{X}_2}{s\surd(\frac{1}{n_1} + \frac{1}{n_2})}
\]
is distributed as $t_\nu$.
\label{tdist}
\end{qn}

\begin{qn}
By choosing bases, it follows that the subspaces $Z_1$, \ldots, $Z_r$ span~$V$;
hence it follows that $V$ is the direct sum $V=Z_1 \oplus \cdots \oplus Z_r$, 
as asserted.
\end{qn}

\begin{qn}
If $\mathcal M$ and $\mathcal N$ are subspaces of a finite-dimensional inner product 
space $\mathcal V$ then
\[
(\mathcal{M} + \mathcal{N})^\perp = \mathcal{M}^\perp \cap \mathcal{N}^\perp
\]
and
\[
(\mathcal{M} \cap \mathcal{N})^\perp = \mathcal{M}^\perp + \mathcal{N}^\perp.
\]
Moreover, $\mathcal{M}^\perp \cong \mathcal{V}/\mathcal{N}$.
\end{qn}

\begin{qn}
The sum of squares for the linear model $V_\mathrm{protein} 
+ V_\mathrm{fishmeal}$ 
is $1559378$.
\end{qn}

\begin{qn}
\newcommand{\bbeta}{\mbox{\boldmath $\beta$}}
\newcommand{\bep}{\mbox{\boldmath $\varepsilon$}}
The usual regression equation is
$\mathbf{Y} = \mathbf{X}\bbeta + \bep$, where
$\mathbf{Y}$ is an $n\times 1$ vector, $\mathbf{X}$ 
is an $n\times p $ matrix, $\bbeta$ 
is the $p\times1$ vector of unknown parameters, and $\bep$ is the $n\times1$ 
vector of random errors. The least-squares estimate $\widehat{\bbeta}$ of the 
parameters is given by
\[
\widehat{\bbeta} = (\mathbf{X}'\mathbf{X})^{-1}\mathbf{X}'\mathbf{Y}.
\]
\end{qn}

\begin{qn}
The $T$-orders are $p(x)^{e_1}$, $p(x)^{e_2}$ and $p(x)^{e_3}$, where $e_1 >e_2
\geq e_3$. This implies that $p(x)^{e_1}\mid\eta(x)^{e_1-d}$ and hence that
$\eta(x) = \psi(x)p(x)^d$ for some polynomial $\psi(x)$.
\end{qn}


\begin{qn}
We have $t\in A\setminus B$ if and only if \[t \in A \mbox{ and } t\notin B.\]
\end{qn}


\begin{qn}
Pascal's triangle is based on the identity
\[
{}^{n-1}\mathrm{C}_{k} + {}^{n-1}\mathrm{C}_{k-1} = {}^{n}\mathrm{C}_{k}.
\]
\end{qn}

\end{Article}
