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.
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 < and > for this purpose)
- bars |...| or \|...\|
etc, come in various sizes to cope with different sub-expressions that they surround. The easiest way to get the size nearly correct is to use the modifying commands as in \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 for any reason, such as splitting a sub-expression over two lines or for an evaluation bar, the matching delimiter is not to appear, 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;
- \quad to typeset a 'quad' space;
- \! to typeset a negative thin 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, and to separate punctuation from an equation;
- use some negative space, \!\!\!, in multi-dimensional integrals to bring the integral signs closer together;
- use \quad to separate two or more equations or text on the one line.
Observe, both before and after, the use of the \mbox{...} command to include a few words of ordinary text within mathematics.
Arrays
Frequently we need to set mathematics in a tabular format.
For example, arrays are typeset within a mathematics environment by the array environment (very similar to the tabular environment).
The structure is
\begin{array}{argument}
... & ... & ... & ... \\
... & ... & ... & ... \\
... & ... & ... & ...
\end{array} for an array of 3 rows and four columns. As in tabular, the argument consists of the letters r, c or l to indicate that the corresponding columns are to be typeset right, centered or left justified, see Src/maths.tex, Section 3.
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 get typeset three dots;
- \vdots for three vertical dots; and
- \ddots for three diagonal dots.
Arrays may also be used to lay out information in special ways. Arrays embedded within arrays give more scope for your imagination.
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 format is the same as a tabular or array environment, except that the eqnarray environment assumes three columns: the left column right justified; the centre, 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, \bigcup, etc.
See Section 5 in Src/maths.tex.
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.
A simple example is that LaTeX does not have a predefined Airy function so we define our own as:
\newcommand{\Ai}{\mbox{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
\newcommand{\D}[2]{\frac{\partial #2}{\partial #1}}
\newcommand{\DD}[2]{\frac{\partial^2 #2}{\partial #1^2}}
\renewcommand{\vec}[1]{\mbox{\boldmath$#1$}} 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.
AMS-LaTeX
The American Mathematical Society has enormously extended the mathematical environments, commands, fonts and symbols in LaTeX. Investigate if you can spare the time.