Math environments
7.1 Math environments
A formula in a L A R ∞ TEX document can be typeset inline, like the congruence a ≡ b (θ) or the integral 2
e −x dx = −∞ √ π, or displayed, as in
Notice how changing these two formulas from inline to displayed affects their appear- ance.
Inline and displayed math formulas are typeset using the math environments math and displaymath, respectively. Because math formulas occur so frequently, L A TEX has abbreviations: the special braces \( and \) or $ are used for the math environment, and \[ and \] for the displaymath environment. 1 So our inline example may be typed as
$a \equiv b \pod{\theta}$ or \( a \equiv b \pod{\theta} \) or \begin{math}
a \equiv b \pod{\theta} \end{math}
The displayed example can be typed as \[
\int_{-\infty}^{\infty} e^{-x^{2}} \, dx = \sqrt{\pi} \]
or \begin{displaymath}
\int_{-\infty}^{\infty} e^{-x^{2}} \, dx = \sqrt{\pi} \end{displaymath}
Using $ as a delimiter for a math environment is a bit of an anomaly, since the same character is used as both an opening and closing delimiter. This dual purpose use makes it more difficult for L A TEX to diagnose an incorrect use of $. For instance,
1 TEX uses $$ to open and close a displayed math environment. In L A TEX, this may occasionally cause problems. Don’t do it! Try the fleqn document class option of amsart (see Section 11.5) as an example of
what can go wrong.
7.1 Math environments 153
Let $a be a real number, and let $f$ be a function.
would be interpreted by L A TEX as follows:
Let is ordinary text $a be a real number, and let $
is math
f is interpreted as ordinary text $ be a function.
is thought to be a math environment (opened by $) that should be closed by the next $ in the paragraph
Because the paragraph ends with no more dollar signs appearing, you get the error message
!! Missing $ inserted. <inserted text>
l.29 and giving you the line number of the end of the paragraph. This message tells you that
L A TEX would place a $ at the end of the paragraph when it proceeds with the typesetting.
Press Return and L A TEX produces the following:
Let abearealnumber, andletfbeaf unction. The text that ended up in a math environment is run together because math environ-
ments ignore spaces (see Section 7.2). If you use \( and \) as special braces for the math environment, L A TEX handles the same mistake more elegantly:
Let \( a be a real number, and let \( f \) be a function. gives the error message
! LaTeX Error: Bad math environment delimiter. l.25 Let \( a be a real number, and let \(
f \) be a function.
L A TEX realizes that the first \( opens a math environment, so the second \( must be in error. In this case, the line number in the error message is correct. Throughout this book, like nearly everyone else, I use $ to delimit inline math.
Rule
Math environments No blank lines are permitted in a math or displaymath environment.
154 Chapter 7 Typing math
If you violate this rule, L A TEX generates an error message,
! Missing $ inserted. <inserted text>
... l.7
where the line number points inside the environment. Multiline math environments, such as the examples in Sections 3.4.2–3.4.3, are discussed in Chapter 9.