Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document
Formatting Information — An introduction to typesetting with LATEX
Chapter 1: Writing documents
Section 1.11: Mathematics
As explained on the para ‘Knuth, Donald originally wrote TEX to …’ in the Preface above, TEX was originally written to automate the typesetting of books containing mathematics, because mathematics is typeset differently from normal text. This book does not cover mathematical typesetting, which is explained in detail in many other books and Web pages, so all we will cover here is the existence of the math mode commands, and some characters which have special meaning, so they don’t trip you up elsewhere.
In addition to the 10 special characters listed in § 1.7 above, there are three more characters which only have any meaning inside mathematics mode:
Key | Meaning |
| | Vertical bar |
< | Less-than |
> | Greater-than |
If you type any of these in normal text (that is, outside math mode), you will get very weird things happening and lots of error messages. If you need to print these characters, you must type them using math mode, or use the symbolic names from the textcomp package (\textbrokenbar, \textlangle, and \textrangle).
The hyphen also has a different meaning in math mode, as we saw in the previous section: it typesets as a minus sign, which is both wider and longer than a hyphen, so if you want to write about negative numbers in normal text, you should type the number between inline math delimiters (eg \(-37°\)C.
Delimiters
Plain TEX used the dollar sign to start and end mathematics, and this was carried over into earlier versions of LATEX, so you'll see a lot of equations in older documents and web pages like $E=mc^2$ (and a double-dollar for displayed equations).
LATEX defines \( and \) for inline mathematics like \(E=mc^2\) and \[ and \] for displayed mathematics.
You SHOULD therefore use the LATEX method of \(…\) and \[…\] — Barbara Beeton writes:
The \(…\) and \[…\] make it easier to diagnose beginning/end matches. Remember that when TEX was created, memory was severely limited. so terseness was important. Of course, $ and $$ are still used under the covers, but the LATEX notation, especially the ‘environment’ structure, makes it easier to provide many features not at all easy in basic TEX. For math, I include in that automatic numbering and cross referencing.
Mathematics markup in LATEX is actually not hard, there’s just a lot to learn. Most of it is fairly obvious and straightforward: if you compare the equation below carefully with the code, you’ll see:
the \[ to start display math;
the \bar n for the n̄;
the caret (
^
) for a superscript or upper limit (here, an asterisk (*
)the underscore (
_
) for the subscript or lower limit (here, a j for example)the (s)= ;
a large fraction using \frac{denominator }{enumerator }
and so on. If you know mathematics, you can probably work out the rest by inspection.
\[\bar n^*_j(s)=\frac{ \left\{s\sum^k_{i=1}n_i(0)p^*_{i,k+1}(s)+M^*(s)\right\} \sum^k_{i=1}p_{0i}p^*{ij}(s)} {1-s\sum^k_{i=1}p_{0i}p^*_{i,k+1}(s)} + \sum^k_{i=1}n_i(0)p^*_{ij}(s),\quad (j=1,2,\dots,k).\]
To use math mode inline (that is, within a paragraph), enclose your math expression in \( and \) commands (round parentheses). You can get the much-quoted equation E=mc² by typing \(E=mc^2\), and to get a temperature like -40° you need to type \(-40°\) in order to get the minus sign and the right spacing. Never use the math superscript and a letter o for degrees: all that gets you is a raised italic letter o.
To typeset a math expression as ‘displayed math’ (centered between paragraphs, like the huge equation above), enclose it in the commands \[ and \] (square brackets). Displayed equations can be auto-numbered with the equation environment instead of the \[ and \] commands. The American Mathematical Society (AMS) document classes and styles provide many extended mathematical features.
For a long time, there were very few typefaces with mathematics fonts (§ 6.2 below), basically Computer Modern, Times, Lucida, and Concrete/Euler. This is now changing, and there are new typefaces with math characters, as well as mathematics add-on packages which work with a dozen or more faces (Hartke, 2006), and more are being announced (the notomath package was announced as I wrote this).