Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 38 ยท Math Typesetting

Math Modes: Inline and Display Formulas

Start typesetting math in LaTeX: inline and display modes, superscripts, subscripts, grouping with braces, text inside formulas, spacing, and the equation environment.

Mathematics is the reason many people learn LaTeX. Its formulas are laid out by rules that professional typesetters refined over centuries, and you describe them with short, logical commands. This lesson introduces the two math modes, the first operators (powers, indices, grouping) and the habits that keep formulas readable.

Real LaTeX needs a compiler, which this site does not offer, but the formulas you write here use the very same math syntax as the browser library KaTeX. Each editor below renders live, so you can experiment. Whenever a feature differs between KaTeX and real LaTeX, the lesson says so.

Why a separate math mode?

Text and math follow different spacing and font rules. In text, letters are words and are set upright. In math, a single letter such as x is a variable and is set in math italic, and spaces around symbols such as = and + are added automatically. Because of this, you must tell LaTeX when you are writing math. Typing x=y+2 as plain text gives you tight, wrongly spaced upright characters; writing $x=y+2$ gives you proper math.

Inline math

Inline math sits inside a sentence. Surround it with single dollar signs, or with \( and \).

LATEX
The area of a circle is $\pi r^2$, and for $r = 3$ it is about $28.3$.
Newer style: \(a^2 + b^2 = c^2\).

Both forms are identical to LaTeX. The \( ... \) form is recommended for new documents because it gives clearer error messages and nests better with other commands, but $...$ is still far more common in the wild. Inline math is compact: fractions and sums are drawn small so they do not push the lines apart.

Display math

Display math is set on its own line, centered, with larger operators and room above and below. Use \[ and \].

LATEX
The solution of the quadratic equation is
\[
  x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
\]

You will also see $$ ... $$ in old documents. Avoid it: it breaks several options (such as fleqn) and can produce uneven spacing. Use \[ ... \] or the equation environment.

Try both modes in the editor below. The page includes the text and math together: dollars give inline math, double dollars give display.

Inline and display math (KaTeX, same syntax as LaTeX)

Notice how \sum_{i=1}^{n} puts its limits beside the symbol inline but above and below it in display mode. LaTeX makes that decision automatically.

Superscripts and subscripts

^ makes a superscript and _ a subscript. They apply to the next single character or group in braces.

LATEX
$x^2$   $x_1$   $x_i^2$   $2^{10}$   $x^{n+1}$   $a_{ij}$   $e^{-x^2}$

The classic beginner mistake is $2^10$, which prints 2 with a superscript 1 followed by a normal 0. Always use braces for more than one character: $2^{10}$. Powers can nest, as in e^{-x^2}. To put both on one symbol, order does not matter: x_i^2 and x^2_i print the same.

Grouping with braces

Braces group things so a command sees them as one unit. They are not printed.

  • {a+b}^2 raises the whole group a+b; without braces only b would be squared.
  • \frac{1}{2} takes two groups, numerator and denominator.
  • Missing a closing brace gives "Missing } inserted" or "Extra }, or forgotten $".

To print literal braces in math, escape them: \{ 1,2,3 \}.

Spaces in math mode

Math mode ignores the spaces you type and inserts its own, based on the role of each symbol: more around relations (=, <), less around operators (+), none inside a group. You can add manual spaces when needed.

Command Space
\, thin (3/18 em)
\: medium
\; thick
\! negative thin space
\quad 1 em
\qquad 2 em

Typical uses are \int f(x)\,dx (a thin space before dx) and a gap between a formula and a condition: f(x) = 1 \quad \text{if } x > 0.

Text inside math

Words inside a formula would be set as italic variables with no spacing. Use \text{...} (from amsmath) or \mathrm{...} for upright words:

LATEX
$f(x) = 0 \quad \text{for all } x \in \mathbb{R}$
$\mathrm{d}x$      % upright differential, a matter of style

Compare in the editor: the first line with \text looks right, the second without it does not. Type your own formulas, one per line.

Math editor: one formula per line

The equation environment

For a displayed formula that should be numbered (so you can refer to it later) use equation:

LATEX
\begin{equation}
  E = mc^2
  \label{eq:energy}
\end{equation}

LaTeX numbers it (1), (2), ... in order. \label and \ref give you references that follow if the order changes: see Equation~\eqref{eq:energy} (from amsmath). The starred form \begin{equation*} (needs amsmath) is the same without a number, equivalent to \[ ... \]. Referencing is covered fully in the cross-references chapter.

Load amsmath in almost every document with math:

LATEX
\usepackage{amsmath}

It is the American Mathematical Society's package and adds \text, align, matrices, \eqref and many fixes. Its siblings amssymb (more symbols) and amsthm (theorems) go with it.

Common mistakes

  • Forgetting math mode: x^2 outside $ gives "Missing $ inserted".
  • Using * for multiplication; write \cdot or \times instead: a \cdot b.
  • Using plain sin; write the operator \sin x, which sets it upright with correct spacing (more in the next lessons).
  • Mixing $...$ pairs incorrectly across paragraphs: an unmatched dollar sign makes the rest of the paragraph math.
  • Writing long formulas on one line; break them across lines with align (see aligning equations).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which source gives 2 to the power 10 correctly?

    ^ takes one character or a braced group. Without braces only the 1 is raised.
  2. 2. Which is the recommended way to write a displayed, unnumbered formula?

    [ ... ] is the LaTeX way; ( ... ) is inline.
  3. 3. How do you put ordinary words such as 'for all' inside a formula?

    Without \text the letters are treated as separate variables with math spacing.
  4. 4. What does the equation environment add compared with [ ... ]?

    equation numbers the formula; equation* is the unnumbered form.

Summary

  • Math needs math mode: $...$ or \(...\) inline, \[...\] for display.
  • ^ and _ apply to the next character or braced group; use braces for more than one character.
  • Braces group; \text{...} writes words in formulas; \, and \quad add space.
  • equation numbers a formula; load amsmath for most math work.

Next: Math Symbols and Greek Letters