# More mathematics

Typesetting mathematics is a work of art.
LaTeX knows a lot of the basics (more than any
other), but you often have to fiddle to get best
results---but then the onus is on us to know what
is 'best'. Look at how to produce the mathematics
shown in `Src/maths.pdf`

- include mathematics inline, with the
`\``( ... \``)`environment, or displayed using either the`\``[ ... \``]`or`equation`environments; - set sub- and super-scripts;
- use the
`\frac`command to typeset fractions; and - that many commands type mathematical symbols such as the Greek alphabet.

Thanks to MathJax for typesetting the following interleaved LaTeX fragments.

## AMS-LaTeX

The American Mathematical Society has enormously extended
the mathematical environments, commands, fonts and symbols
in LaTeX. Get into the habit of accessing part of their
extensions by putting `\usepackage{amsmath}` into the
preamble. Investigate other extensions if you can spare the
time.

Often useful are the American Mathematical
Society's symbols: include with `\usepackage{amssymb}`
in the preamble
(download a list of the symbols). *I strongly
recommend you stay within the symbols provided by standard
LaTeX and amssymb*
(listed in the first 32 pages of this summary by Emre
Sremutlu).

*For procrastinators:* interestingly, sketch the
symbol you are looking for into the
Detexify web server and it will list LaTeX
possibilities. But beware, although great fun it is rarely
useful to employ symbols from the 14,283 (Jan 2017) listed
in
The Comprehensive LaTeX Symbol List.

## Relations

LaTeX knows to typeset extra space around relations
`= \approx `and

- inequalities
`< , > , \leq , \geq` - very much so
`\ll , \gg` - set relations
`\in , \subset`

`0<\epsilon\ll1`(not the common error

`0<\epsilon<<1`which produces the ugly \(0<\epsilon<<1\)).

## Delimiters

Common delimiters such as

- parentheses
`(...)` - brackets
`[...]` - braces
`\{...\}` - angle brackets
`\langle...\rangle`(do*not*use the relations < and > for this purpose) - bars
`|...|`or`\|...\|`

`\left(...\right)`as seen in

`Src/maths.tex`, section 1.

See how the delimiters are of reasonable size in these examples \[ \left(a+b\right)\left[1-\frac{b}{a+b} \right]=a\,, \] \[ \sqrt{|xy|}\leq\left|\frac{x+y}{2} \right|, \] even when there is no matching delimiter \[ \int_a^bu\frac{d^2v}{dx^2}\,dx =\left.u\frac{dv}{dx}\right|_a^b -\int_a^b\frac{du}{dx}\frac{dv}{dx} \,dx\,. \] | See how the delimiters are of reasonable size in these examples \[ \left(a+b\right)\left[1-\frac{b}{a+b} \right]=a\,, \] \[ \sqrt{|xy|}\leq\left|\frac{x+y}{2} \right|, \] even when there is no matching delimiter \[ \int_a^bu\frac{d^2v}{dx^2}\,dx =\left.u\frac{dv}{dx}\right|_a^b -\int_a^b\frac{du}{dx}\frac{dv}{dx} \,dx\,. \] |

Note that `\left` and `\right` must be used
in pairs so that LaTeX can determine the size of the
intervening mathematics. If the matching delimiter is not to
appear for any reason, such as splitting a sub-expression
over two lines or for an evaluation bar, then use
`\left.` or `\right.` to mark that boundary of
the delimiter for LaTeX.

`Src/maths.tex` also
shows the `extarticle` class allows you to get
larger fonts, if required: 14pt, 17pt and 20pt.

## Spacing

In the previous examples I used `\,,` and
`\,.` to punctuate at the end of the equations. Both
in and out of maths, LaTeX provides spacing commands.
The two necessary ones are:

`\,`to typeset a thin space;`\quad`to typeset a 'quad' space.

Use these to space the mathematics where needed.

For example, see `Src/maths.tex`, section 2,

- use
`\,`to separate- the infinitesimal from the integrand in integrals,
- punctuation from mathematics (when necessary),
- a number from its abbreviated physical units;

- use
`\quad`to separate two or more equations or text on the one line.

Differentials often need a bit of help with their spacing as in \[ \iint xy^2\,dx\,dy =\frac{1}{6}x^2y^3, \] whereas vector problems often lead to statements such as \[ u=\frac{-y}{x^2+y^2}\,,\quad v=\frac{x}{x^2+y^2}\,, \quad \text{and}\quad w=0\,. \] | Differentials often need a bit of help with their spacing as in \[ \iint xy^2\,dx\,dy =\frac{1}{6}x^2y^3, \] whereas vector problems often lead to statements such as \[ u=\frac{-y}{x^2+y^2}\,,\quad v=\frac{x}{x^2+y^2}\,, \quad \text{and}\quad w=0\,. \] |

Remember to use amsmath `\iint` and
`\iiint` for multiple integrals as otherwise the
spacing is awful. Use the amsmath `\text{...}`
command to include a few words of ordinary text within
mathematics.

Punctuation? The display or not of mathematics is irrelevant: punctuate a sentence as if the mathematical statements, phrases and symbols are an integral part of the sentence.

In particular, avoid the odious proliferation of bad colons: for example avoid "Newton's second law is: \(F=ma\)."; the rule is the two parts of the sentence on either side of a colon must make complete statements.

Occasionally one gets very bad line breaks when using a
list in mathematics such as listing the first twelve primes
\(2,3,5,7,11,13,17,19,23,29,31,37\). In such cases, you may
include `\mathcode`\,="213B` inside the inline maths
environment so that the list breaks. Be discerning.

## Arrays

Frequently we need to set mathematics in a tabular format.

The usual reason is to typeset a matrix using an amsmath matrix environment such as

\begin{bmatrix} ... & ... & ... & ... \\ ... & ... & ... & ... \\ ... & ... & ... & ... \end{bmatrix}

for a matrix of 3 rows and four columns, see `Src/maths.tex`, Section 3. Use
environments `matrix` for an array without brackets,
and `pmatrix` environment for an array with
parentheses. The `cases` environment puts a brace on
the left and no delimiter on the right for mathematical case
statements.

Arrays of mathematics are typeset using one of the matrix environments as in \[\begin{bmatrix} 1 & x & 0 \\ 0 & 1 & -1 \end{bmatrix}\begin{bmatrix} 1 \\ y \\ 1 \end{bmatrix} =\begin{bmatrix} 1+xy \\ y-1 \end{bmatrix}. \] Case statements use cases: \[|x|=\begin{cases} x & \text{if }x\geq 0\,, \\ -x & \text{if }x< 0\,. \end{cases} \] Many arrays have lots of dots all over the place as in \[\begin{matrix} -2 & 1 & 0 & 0 & \cdots & 0 \\ 1 & -2 & 1 & 0 & \cdots & 0 \\ 0 & 1 & -2 & 1 & \cdots & 0 \\ 0 & 0 & 1 & -2 & \ddots & \vdots \\ \vdots & \vdots & \vdots & \ddots & \ddots & 1 \\ 0 & 0 & 0 & \cdots & 1 & -2 \end{matrix} \] | Arrays of mathematics are typeset using one of the matrix environments as in \[ \begin{bmatrix} 1 & x & 0 \\ 0 & 1 & -1 \end{bmatrix}\begin{bmatrix} 1 \\ y \\ 1 \end{bmatrix} =\begin{bmatrix} 1+xy \\ y-1 \end{bmatrix}. \] Case statements use cases: \[ |x|=\begin{cases} x & \text{if }x\geq 0\,, \\ -x & \text{if }x< 0\,. \end{cases} \] Many arrays have lots of dots all over the place as in \[ \begin{matrix} -2 & 1 & 0 & 0 & \cdots & 0 \\ 1 & -2 & 1 & 0 & \cdots & 0 \\ 0 & 1 & -2 & 1 & \cdots & 0 \\ 0 & 0 & 1 & -2 & \ddots & \vdots \\ \vdots & \vdots & \vdots & \ddots & \ddots & 1 \\ 0 & 0 & 0 & \cdots & 1 & -2 \end{matrix} \] |

Note that LaTeX has a variety of ellipses:

`\cdots`to type three dots horizontally (at the height of the centre of a + sign);`\ldots`to type three dots horizontally (at the height of a comma); use this outside of mathematics also, do*not*use '...' to typeset three dots;`\vdots`for three vertical dots; and`\ddots`for three diagonal dots.

Arrays embedded within arrays give more scope for
your imagination. If a `matrix` environment is not
quite flexible enough, then use the `array`
environment which is the same as the tabular environment but
for mathematics.

## Equation arrays

Often we want to align related equations together, or to
align each line of a multi-line derivation. The
`eqnarray` mathematics environment does this.

The eqnarray environment assumes three columns: the left column right justified; the middle column, centred; and the right column left justified:

\begin{eqnarray} ... & ... & ... \\ ... & ... & ... \\ ... & ... & ... \end{eqnarray}

Each line will be numbered by LaTeX, unless you specify
`\nonumber` in a lines, or unless you use the * form
of eqnarray. See Section 4 in `Src/maths.tex`.

In the flow of a fluid film we may report \[\begin{aligned} u_\alpha & = \epsilon^2 \kappa_{xxx} \left( y-\frac{1}{2}y^2 \right), &(1) \\ v & = \epsilon^3 \kappa_{xxx} y\,, &(2) \\ p & = \epsilon \kappa_{xx}\,. &(3) \end{aligned}\] Alternatively, the curl of a vector field \((u,v,w)\) may be written with only one equation number: \[\begin{aligned} \omega_1 & = \frac{\partial w}{\partial y} -\frac{\partial v}{\partial z}\,, \\ \omega_2 & = \frac{\partial u}{\partial z} -\frac{\partial w}{\partial x}\,, &(4) \\ \omega_3 & = \frac{\partial v}{\partial x} -\frac{\partial u}{\partial y}\,. \end{aligned}\] Whereas a derivation may look like \[\begin{aligned} (p\wedge q)\vee(p\wedge\neg q) & = p\wedge(q\vee\neg q) \quad\text{by distributive law} \\ & = p\wedge T \quad\text{by excluded middle} \\ & = p \quad\text{by identity.} \end{aligned}\] | In the flow of a fluid film we may report \begin{eqnarray} u_\alpha & = & \epsilon^2 \kappa_{xxx} \left( y-\frac{1}{2}y^2 \right), \label{equ} \\ v & = & \epsilon^3 \kappa_{xxx} y\,, \label{eqv} \\ p & = & \epsilon \kappa_{xx}\,. \label{eqp} \end{eqnarray} Alternatively, the curl of a vector field $(u,v,w)$ may be written with only one equation number: \begin{eqnarray} \omega_1 & = & \frac{\partial w}{\partial y} -\frac{\partial v}{\partial z}\,, \nonumber \\ \omega_2 & = & \frac{\partial u}{\partial z} -\frac{\partial w}{\partial x}\,, \label{eqcurl} \\ \omega_3 & = & \frac{\partial v}{\partial x} -\frac{\partial u}{\partial y}\,. \nonumber \end{eqnarray} Whereas a derivation may look like \begin{eqnarray*} (p\wedge q)\vee(p\wedge\neg q) & = & p\wedge(q\vee\neg q) \quad\text{by distributive law} \\ & = & p\wedge T \quad\text{by excluded middle} \\ & = & p \quad\text{by identity.} \end{eqnarray*} |

(There is a package `breqn` that promises
good automatic line-breaking of long equations and math
deductions, but as of 2018 it is not yet developed enough to
be widely useful.)

### Subequation numbering

Another useful facility of `\usepackage{amsmath}`
is the `subequations` environment. It generates
labels for the enclosed mathematics which are a base number
followed by a,b,c,... in sequence, as illustrated below.

\[\begin{aligned} u_\alpha & = \epsilon^2 \kappa_{xxx} \left( y-\frac{1}{2}y^2 \right), &(5a) \\ v & = \epsilon^3 \kappa_{xxx} y\,, &(5b) \\ p & = \epsilon \kappa_{xx}\,. &(5c) \end{aligned}\] Cross-reference to any individual equation or to the collective (5). | \begin{subequations}\label{eqf} \begin{eqnarray} u_\alpha & = & \epsilon^2 \kappa_{xxx} \left( y-\frac{1}{2}y^2 \right), \label{equ} \\ v & = & \epsilon^3 \kappa_{xxx} y\,, \label{eqv} \\ p & = & \epsilon \kappa_{xx}\,. \label{eqp} \end{eqnarray} \end{subequations} Cross-reference to any individual equation or to the collective \eqref{eqf}. |

I once typeset a four line equation and discussed its
implications in terms of the 'first line', 'second line', and
so on. Unfortunately the journal's layout editor ruined my
discussion by merging the four lines into two! I should
have used `subequations` with labels for each of the
four lines, and cross-referenced to the individual labelled
lines.

## Functions

LaTeX knows how to typeset a lot of mathematical functions.

- Trigonometric and other elementary functions are defined
by the obvious corresponding command name. For example,
`\sin x`or`\exp(i\theta)`. - Subscripts on more complicated functions, such as
`\lim_{..}`and`\max_{...}`are appropriately placed under the function name. - And the same goes for both sub- and super-scripts on
large operators such as
`\sum`,`\prod`and`\bigcup`.

See Section 5 in `Src/maths.tex`. Typeset
*all* multicharacter mathematical names in upright
roman: when a command is not available, use amsmath
`\operatorname{...}` as in the Reynolds number
`\operatorname{Re}`.

Elementary functions are typeset properly, even to the extent of providing a thin space if followed by a single letter argument: \[ \exp(i\theta)=\cos\theta +i\sin\theta\,,\quad \sinh(\log x)=\frac{1}{2} \left( x-\frac{1}{x} \right). \] With sub- and super-scripts placed properly on more complicated functions, \[ \lim_{q\to\infty}\|f(x)\|_q =\max_{x}|f(x)|, \] and large operators, such as integrals and \[\begin{aligned} e^x &= \sum_{n=0}^\infty \frac{x^n}{n!} \quad\text{where }n!=\prod_{i=1}^n i\,, \\ \overline{U_\alpha} & = \bigcap_\alpha U_\alpha\,. \end{aligned}\] In inline mathematics the scripts are correctly placed to the side in order to conserve vertical space, as in \(1/(1-x)=\sum_{n=0}^\infty x^n.\) | Elementary functions are typeset properly, even to the extent of providing a thin space if followed by a single letter argument: \[ \exp(i\theta)=\cos\theta +i\sin\theta\,,\quad \sinh(\log x)=\frac{1}{2} \left( x-\frac{1}{x} \right). \] With sub- and super-scripts placed properly on more complicated functions, \[ \lim_{q\to\infty}\|f(x)\|_q =\max_{x}|f(x)|, \] and large operators, such as integrals and \begin{eqnarray*} e^x &=& \sum_{n=0}^\infty \frac{x^n}{n!} \quad\text{where }n!=\prod_{i=1}^n i\,, \\ \overline{U_\alpha} & = & \bigcap_\alpha U_\alpha\,. \end{eqnarray*} In inline mathematics the scripts are correctly placed to the side in order to conserve vertical space, as in \( 1/(1-x)=\sum_{n=0}^\infty x^n. \) |

## Accents

In the example of set intersection an overline is typeset over the sets \(U_\alpha\) (the overline denotes an operation). However, if we want an overline to denote a distinct quantity that has a close relation to something else, then a mathematical accent is used.

Common mathematical accents over a single character, say a, are:

`\bar a`to put an overbar over a;`\tilde a`to put '~' over a;`\hat a`to put '^' over a;`\dot a`to put a single dot over a;`\ddot a`to put a double dot over a; and`\vec a`to put a little arrow over a.

If necessary, accents may be stacked on top of each
other. See Section 6 in `Src/maths.tex`.

Mathematical accents are performed by a short command with one argument, such as \[ \tilde f(\omega)=\frac{1}{2\pi} \int_{-\infty}^\infty f(x)e^{-i\omega x}\,dx\,, \] or \[ \dot{\vec \omega}=\vec r\times\vec I\,. \] | Mathematical accents are performed by a short command with one argument, such as \[ \tilde f(\omega)=\frac{1}{2\pi} \int_{-\infty}^\infty f(x) e^{-i\omega x}\,dx\,, \] or \[ \dot{\vec \omega}=\vec r\times\vec I\,. \] |

## Command definitions

LaTeX provides a facility for you to define your very own commands.

Since LaTeX does not have a predefined Airy function we define our own:

\newcommand{\Ai}{\operatorname{Ai}}

and then use the command `\Ai` wherever
needed.

The Airy function, \(\newcommand{\Ai}{\operatorname{Ai}}\Ai(x)\), may be incorrectly defined as this integral \[ \Ai x=\int\exp(s^3+isx)\,ds\,. \] | The Airy function, $\Ai(x)$, may be incorrectly defined as this integral \[ \Ai x=\int\exp(s^3+isx)\,ds\,. \] |

More useful commands involve arguments; I give three of my favourites. The first two, with two arguments, define partial derivative commands

\newcommand{\D}[2]{\frac{\partial #2}{\partial #1}} \newcommand{\DD}[2]{\frac{\partial^2 #2}{\partial #1^2}} \renewcommand{\vec}[1]{\boldsymbol{#1}}

and the last, with one argument, *redefines* the
`\vec` command to denote vectors by boldface
characters (rather than have an arrow accent).

Within a definition, `#n` denotes a
placeholder for the `n`th supplied argument. See
these in use in Section 7 of `Src/maths.tex`.

This vector identity serves nicely to illustrate two of the new commands: \[ \newcommand{\D}[2]{\frac{\partial #2}{\partial #1}} \renewcommand{\vec}[1]{\mathbf{#1}} \vec\nabla\times\vec q =\vec i\left(\D yw-\D zv\right) +\vec j\left(\D zu-\D xw\right) +\vec k\left(\D xv-\D yu\right). \] | This vector identity serves nicely to illustrate two of the new commands: \[ \vec\nabla\times\vec q =\vec i\left(\D yw-\D zv\right) +\vec j\left(\D zu-\D xw\right) +\vec k\left(\D xv-\D yu\right). \] |

Students, and markers, want the numbering of sections to suit the exercise numbers of assignments. For example, when an assignment is composed of Exercises 35.1, 35.2, and 42.1, redefine section numbering by

\renewcommand{\thesection}{Exercise~\ifcase\arabic{section} \or35.1\or35.2\or42.1\else\fi}

Then start each successive exercise with simply the
logical `\section{}`, or include explanatory text in
the exercise title with `\section{explanatory
text}`.

You will have noticed that LaTeX is very verbose.
Many people define their own abbreviations for the common
command structures so that they are quicker to type. *Do
not do this*; it makes your LaTeX much less
portable and harder to read. Instead, *setup your
editor* to cater for the verbosity; use command
definitions only to give you *new logical patterns*,
such as the partial differentiation.

One can use commands at a higher level of abstraction:
the following creates a command that defines commands. Here
`\Bb` empowers us to consistently define commands
such as `\CC`, `\NN` and `\RR` to
consistently generate \(\mathbb C\), \(\mathbb N\)
and\(~\mathbb R\).

\newcommand{\Bb}[1]{% \expandafter\def\csname#1#1\endcsname% {\ensuremath{\mathbb #1}}} \Bb C\Bb N\Bb R

Recall that typesetting multi-line mathematics is an art normally too hard for computer recipes. Nonetheless, if you need to be automatically flexible about multi-line mathematics, and you do not mind some rough typesetting, then perhaps invoke `\parbox{}{}` to help via the following command:

\newcommand{\parmath}[1]{\parbox[t]{0.8\linewidth}% {\raggedright\linespread{1.2}\selectfont\(#1\)}} \[ u_1=\parmath{ -2 \gamma \epsilon^{2} s_{2}+\mu \epsilon^{3} \big( \frac{3}{8} s_{2}+\frac{1}{8} s_{1} i\big)+\epsilon^{3} \big( -\frac{81}{32} s_{4} s_{2}^{2}-\frac{27}{16} s_{4} s_{2} s_{1} i+\frac{9}{32} s_{4} s_{1}^{2}+\frac{27}{32} s_{3} s_{2}^{2} i-\frac{9}{16} s_{3} s_{2} s_{1}-\frac{3}{32} s_{3} s_{1}^{2} i\big) +\int_a^b 1-2x+3x^2-4x^3\,dx } \](The promising

`breqn`package is not yet reliable enough for general use.)

## Theorems et al.

Repeating the end of the section on Environments, LaTeX does not by default provide an environment for theorems. Instead LaTeX provides an environment for you to create theorem-like environments (extended by the American Mathematical Society). I recommend you include the following in your preambles:

\usepackage{amsthm} % optional \newtheorem{theorem}{Theorem} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{definition}[theorem]{Definition}

Thereafter, as seen in Section 8 of `Src/maths.tex`, you use the
following environments as appropriate:

\begin{theorem}...\end{theorem} \begin{corollary}...\end{corollary} \begin{lemma}...\end{lemma} \begin{definition}...\end{definition} \begin{proof}...\end{proof}

The last proof environment is from the `amsthm` package.

Label and cross-reference these as usual.

Such environments obtained from `\newtheorem` may
also have an optional argument to provide a name to the
'theorem'. For example,

\begin{definition}[right-angled triangles]...\end{definition}