How to write a subscript in LaTeX

In math mode, _ makes a subscript and^ makes a superscript. No package is needed.

subscript.tex
\documentclass{article}
\begin{document}
Inline: $x_1$ and $x^2$.

Display:
\[
x_i^2 + y_{ij}
\]
\end{document}

Both characters work only in math mode. Outside it, LaTeX stops withMissing $ inserted.

More than one character: use braces

_ and ^ apply to the next single character or the next braced group. Without braces, only the first character moves.

braces.tex
$x_10$     % wrong: 1 is lowered, 0 is not
$x_{10}$   % right
$e^{-x^2}$ % braces nest

Subscript and superscript together

Write them in either order. LaTeX stacks them at the same position rather than one after the other.

both.tex
\[
x_i^2 \qquad A_{ij}^{k} \qquad \sum_{i=1}^{n} x_i
\]

To put a subscript on a symbol that already has a superscript, such as a prime, keep the order explicit: f'_n isf-prime with subscript n.

Words in a subscript

Math mode sets letters in italic as if they were variables. A label such as "max" or "total" should be upright, so wrap it in\text{...}. That command comes fromamsmath. \mathrm{...} is the core alternative.

text-subscript.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$v_{\text{max}}$ \quad $v_{max}$ \quad $T_{\mathrm{in}}$
\end{document}

The middle one, v_{max}, is set as the productm·a·x. That is the most common subscript mistake.

Subscripts in ordinary text

Outside math mode, use \textsubscript{...} for a subscript and \textsuperscript{...} for a superscript. Both are core LaTeX.

textsubscript.tex
H\textsubscript{2}O, the 3\textsuperscript{rd} sample

Chemical formulas

For one or two formulas, $\mathrm{H_2O}$ is enough. For a document with many, load the mhchem package and write\ce{H2O}, \ce{CO2} or\ce{SO4^2-}. It sets the subscripts, charges and upright type for you.

chemistry.tex
\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}
\ce{H2O} \quad \ce{CO2} \quad \ce{SO4^2-}
\end{document}

Common mistakes

Templates that use this

Units, chemical formulas and indices lean on sub- and superscripts. See the laboratory report templates, the simple lab report, or theamsart article for maths-heavy papers.

Related

Subscripts are heavily used inmatrices andfractions. The same symbols appear in themath symbols reference. New to LaTeX? Start with LaTeX for beginners, or pick up a document from thethesis templates.