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.10: Mathematics

As explained in the para ‘Knuth, Donald originally wrote TEX to …’ in the Preface, TEX was originally written to automate the typesetting of books containing mathematics, and 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.6, there are three more characters which only have any meaning inside mathematics mode:

|Vertical bar

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, so if you want to write about negative numbers outside math mode, you need to type the number using inline math delimiters.

Mathematics markup in LATEX is actually not hard, there’s just a lot to learn. Most of it is fairly obvious and straightfoward, though: if you compare the equation below carefully with the code, you’ll see:

  • the \[ to start display math;

  • the \bar n for the ;

  • the caret (^) for a superscript or upper limit asterisk (*)

  • the underscore (_) for the subscript or lower limit j;

  • the (s)= ;

  • a large fraction using \frac.

and so on. If you know mathematics, you can probably work out the rest by inspection.

\[\bar n^*_j(s)=\frac{
{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), 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).

  1. Bear in mind that the degree symbol is a non-ASCII character, so you must specify what input encoding you are using if you want to type it: see the example of the inputenc package in § 1.8. If you don’t want to use non-ASCII characters (or if you are using a system which cannot generate them), you can use the command \textdegree to get the degree sign. 

  2. You will also see dollar signs used for math mode. This is quite common but deprecated: it’s what plain TEX used in the days before LATEX, and the habit got ingrained in many mathematicians. It still works as a convenient shorthand like $x=y$, as do double-dollars for display-mode math like $$E=mc^2$$, but they are only mentioned here to warn readers seeing them in other authors’ work that \(...\) and \[...\] are the proper LATEX commands.