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\).
Result
The compiled example

Open in the editor

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$.
Result
The compiled example

Open in the editor

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.

eiπ+1=0\begin{equation} e^{i\pi} + 1 = 0 \end{equation}

Open this formula in the editor

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}$.
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages