Inline and display math in LaTeX (dollar signs, brackets, equation)
Inline math stands inside a line of text between $...$ or \(...\). Display math gets a centred line of its own: \[...\] without a number, the equation environment with a number.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{amsmath}Formula inside a line of text
$...$ and \(...\) give the same output. \(...\) has different opening and closing marks, so a mark that is missing or doubled is reported as Bad math environment delimiter at the place where it happens.
The equation $a^2 + b^2 = c^2$ holds for \(a, b, c > 0\).Formula on its own line
\[...\] centres the formula and puts space above and below it. Leave no empty line in front of \[ when the formula belongs to the sentence: an empty line starts a new paragraph and adds more space above the formula.
The roots are
\[
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]
if $a \neq 0$.Display formula with a number
The equation environment sets the formula as \[...\] does and adds a number at the right margin. equation* from amsmath leaves the number out.
\begin{equation}
e^{i\pi} + 1 = 0
\end{equation}Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Display size inside a line of text
Inline formulas are set compactly: fractions are small and limits stand beside the sum sign. \displaystyle at the start of the formula switches to the layout of a display formula; the line then needs more height. \textstyle does the opposite inside a display formula.
Compact: $\sum_{i=1}^{n} \frac{1}{i}$,
display size: $\displaystyle\sum_{i=1}^{n} \frac{1}{i}$.Pitfalls
$$...$$is plain TeX and still found in many documents. In LaTeX it ignores the class optionfleqn: the formula stays centred while every\[...\]moves to the left. Write\[...\].- A missing
$stops with Missing $ inserted, and a$$that is closed by a single$with Display math should end with $$. - A dollar sign as a character in text is
\$.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Error Missing $ inserted
- Error Bad math environment delimiter
- Error Display math should end with $$
- How-to Number equations in LaTeX
- Package
amsmath