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:

KeyMeaning
|Vertical bar
<Less-than
>Greater-than

If you type any of these in normal text (i.e. 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.

\[\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).\]
        
math-crop 

To use math mode inline (within a paragraph), enclose your math expression in \( and \) commands. 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°\) to get a real minus sign and the right spacing. Never use the math superscript and a letter o for degrees: it looks silly.

To typeset a math expression as ‘displayed math’ (centered between paragraphs, like the huge equation above), enclose it in the commands \[ and \].

Displayed equations can be auto-numbered with the equation environment instead of the \[ and \] commands.

  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.