Researa LogoReseara
Start free
Learn Hub/GUIDE 07 / 13Mathematics
Quick syntax:x_{i,j}^{(k)} + \mathrm{H_2O} = E_0

Subscripts and Superscripts in LaTeX

In math, ^ raises and _ lowers. The one rule that saves most errors: anything longer than one character goes in braces. This guide also covers text outside math, chemical formulas, primes and limits under operators.

The basics

$x^2$        % x squared
$x_i$        % x sub i
$x_i^2$      % both; the order does not matter
$x^{10}$     % braces for more than one character
$x_{i+1}$

Without braces only the first character moves: $x^10$ prints x¹ followed by a normal 0. This is the most common slip, and LaTeX does not warn about it.

Nesting

$e^{x^2}$
$a_{i_j}$
$e^{-\frac{x^2}{2\sigma^2}}$

Each level needs its own braces. Writing two scripts in a row, such as $x^a^b$, stops the compile with "Double superscript": write $x^{ab}$ or ${x^a}^b$, depending on what you mean.

Words as indices

$T_{\text{max}}$      % right: max is a word
$T_{max}$             % wrong: reads as m times a times x

Letters in math are variables and are set in italics. When an index is a word or an abbreviation, wrap it in \text (amsmath) or \mathrm.

Outside math

The 1\textsuperscript{st} prototype
H\textsubscript{2}O

^ and _ only work in math; in normal text they stop the compile with "Missing $ inserted". Use \textsuperscript and \textsubscript, which are built in. In French, write 1\up{er} or 2\ieme with babel's French option.

Chemistry

Element symbols are upright, so $H_2O$ is wrong: it sets H and O in italics as if they were variables. The mhchem package handles formulas, charges, isotopes and reactions:

\usepackage[version=4]{mhchem}   % preamble

\ce{H2O}, \ce{CO2}, \ce{SO4^2-}
\ce{^{14}_{6}C}
\ce{2H2 + O2 -> 2H2O}

Without mhchem, use upright letters: $\mathrm{H_2O}$ and ${}^{14}_{6}\mathrm{C}$.

Primes

$f'(x)$     $f''(x)$     $f'_n(x)$

An apostrophe in math is a prime. It is the same as ^{\prime}, only easier to type.

Limits under sums and other operators

\[
  \sum_{i=1}^{n} x_i \qquad \prod_{k=1}^{n} k \qquad \lim_{x \to \infty} f(x)
\]

In display math, the indices of \sum, \prod and \lim sit above and below the symbol; in a sentence they move to the side so the line stays the normal height. \sum\limits_{i=1}^{n} forces them above and below, \nolimits to the side.

Several conditions under a sum

\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i

Symbols above or below another

a \overset{\text{def}}{=} b
\underset{\theta}{\operatorname{argmin}} \, L(\theta)

\overset and \underset come from amsmath and replace the older \stackrel.

Quick reference

You wantWrite
Exponentx^2, x^{2n}
Indexx_i, x_{i+1}
Word as indexT_{\text{max}}
Superscript in text1\textsuperscript{st}
Subscript in textH\textsubscript{2}O
Chemical formula\ce{H2SO4} (mhchem)
Derivativef'(x), f''(x)
Stacked conditions\sum_{\substack{i \\ j}}

Where to go next

READY TO WRITE YOUR REPORT OR THESIS?

Write in Researa. Present in Researa Slides.

Draft your LaTeX manuscript with AI assistance and verified citations, then turn your finished PDF into a defense slide deck in minutes.