## 2010年12月13日星期一

### LaTeX: More mathematics

Typesetting mathematics is a work of art. LaTeX knows a lot of the basics, but you often have to fiddle to get the results you require. Look at how to produce the mathematics shown in Src/maths.pdf

• include mathematics inline, with the math environment, or displayed using the displaymath 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.

## 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.

## Relations

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

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

etc.

## Delimiters

Delimiting

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

etc, come in various sizes to cope with different sub-expressions that they surround. Easily get the size nearly correct using the modifying commands \left(...\right) as seen in Src/maths.tex, section 1.

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.

## Spacing

In the previous examples I used \,, and \,. to punctuate at the end of the equations. Both in and out of maths, LaTeX provides the commands:

• \, to typeset a thin space;
• \to typeset a normal 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 an equation,
• a number from its physical units;
• use \quad to separate two or more equations or text on the one line.

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.

## 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.

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.

## 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}.

## Accents

In the example of set intersection an overline is typeset over the sets U (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.

## 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 as:

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

and then use the command \Ai wherever needed.

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


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

Note that within a definition, #n denotes a placeholder for the nth supplied argument. See these in use in Section 7 of Src/maths.tex.

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.

## Summary

Typesetting with mathematics is an art. LaTeX helps with all its structures, but there are still many decisions you will have to make. Look to learn more than the basics.