LaTeX Subscript and Superscript: Syntax and Fixes
November 11, 2026 · 9 min read
LaTeX Subscript and Superscript: ^, _, Braces, and Text Mode
A LaTeX subscript uses an underscore and a superscript uses a caret, both inside math mode: $x_1$ gives and $x^2$ gives . Wrap anything longer than one character in braces, as in $x_{i+1}$. This page also covers double-script errors, primes, pre-scripts, text-mode scripts and limits.
Each section says whether its commands work in a compiled LaTeX document, in KaTeX-powered Markdown math, or both. That split matters, because a few common commands compile with pdfLaTeX and fail in a Markdown preview. Our KaTeX vs LaTeX comparison explains why that happens.
LaTeX Subscript and Superscript Syntax: _ and ^ in Math Mode
The underscore _ lowers the next token and the caret ^ raises it. Both work only in math mode: between dollar signs in a LaTeX document, inside an equation environment, or in a Markdown math span. If the dollar delimiters in Markdown are new to you, our Markdown equation guide covers them.
$x_1$, $x^2$, $a_n$ and $10^6$
That line renders as , , and . The script is set in a smaller size and shifted down or up from the baseline of its base.
Outside math mode, both characters are errors in a compiled document. Type x^2 or file_name in running text and pdfLaTeX stops with Missing $ inserted, as the LaTeX2e reference manual describes. Write \_ when you need a literal underscore in text. In Markdown, KaTeX only sees what sits between the dollar signs, so an x^2 outside them stays plain text.
How Do You Subscript More Than One Character in LaTeX?
Put the whole script in braces. A script grabs exactly one token: a single character, or a single command such as \alpha. Anything after that token drops back to normal size, and that's the most common reason a LaTeX subscript looks wrong. A LaTeX superscript follows the same rule.
$x_10$ % x sub 1, then a full-size 0
$x_{10}$ % x sub 10
$e^-x$ % e to the minus, then a full-size x
$e^{-x}$ % e to the minus x
$x_\alpha$ % fine: a command counts as one token
The braces group without printing anything. They also nest, so $e^{-x^2}$ gives with the square sitting on the x inside the exponent.
Single commands work without braces, and even $e^\frac12$ compiles. We prefer to brace every script that isn't one plain character anyway. It costs two keystrokes, reads clearly six months later, and you never have to remember which shortcut a given renderer accepts.
How to Put a Subscript and Superscript Together in LaTeX
To write a superscript and subscript in LaTeX on one symbol, attach both to the same base, in either order. $x_i^2$ and $x^2_i$ produce identical output: . TeX stacks the superscript above the subscript automatically, and KaTeX does the same.
Primes need one rule. The apostrophe is shorthand for ^\prime, so it already counts as a superscript. Put it first and the extra superscript joins it.
$f'_1$ % f prime, sub 1
$f'^2$ % f prime squared, same as f^{\prime 2}
$f^2'$ % Double superscript error
The first two render as and . The third fails in pdfLaTeX and in KaTeX, because the 2 and the prime both try to become the superscript of f. Our LaTeX calculus notation guide covers primes for higher derivatives and Newton's dots.
Tensor notation sometimes needs the subscript to start after the superscript instead of under it. An empty group {} acts as an invisible base: $R^{a}{}_{bcd}$ renders as . Double indices on matrix entries, such as , follow the plain brace rule, and our Markdown matrix guide shows them in context.
Nested Scripts and the Double Subscript Error
A script can carry its own script. $a_{n_i}$ gives , and the exponent tower $2^{2^n}$ gives . Each level gets smaller, down to a minimum size.
The trap is writing two scripts of the same kind in a row on one base.
$x_1_2$ % ! Double subscript.
$x^2^3$ % ! Double superscript.
TeX stops on both, and KaTeX throws the same Double subscript and Double superscript errors. The fix depends on what you meant. For a nested index, write x_{1_2}. For the two-digit index 12, write x_{12}. For an exponent tower, write x^{2^3}.
arXiv's page of double subscript examples notes that its automatic TeX system can't press Return past the error the way you can at a terminal. So a source that "works" locally after a keypress can still fail on submission.
One more lookalike: {x^2}^3 compiles, but the 3 lands just right of the 2 and only slightly higher. Readers can't tell whether you mean a power of a power. Write (x^2)^3 instead.
Upright Labels in Subscripts: \mathrm vs Italic Letters
Math mode treats every letter as a variable and sets it in italics. So $x_{max}$ reads as m times a times x in the subscript. When the subscript is a label rather than a product, set it upright with \mathrm.
$T_{max}$ % three italic variables
$T_{\mathrm{max}}$ % an upright label
$\mathrm{H_2O}$ and $\mathrm{CO_2}$
These render as , , and . Wrapping the whole formula in \mathrm keeps element symbols upright while the digits still drop.
T_{\text{max}} also works, but \text borrows the font of the surrounding text, so the label can turn italic inside an italic theorem. In a LaTeX document, chemists often load the mhchem package and write \ce{H2O}. Core KaTeX doesn't define \ce (KaTeX ships it as a separate extension), so \mathrm is the portable choice for Markdown.
Superscripts in Normal Text: \textsuperscript and \textsubscript
Ordinals, footnote-style markers and chemical formulas in running text don't belong in math mode. For a superscript or subscript in LaTeX body text, use these two text-mode commands.
the 1\textsuperscript{st} and n\textsuperscript{th} terms
release CO\textsubscript{2} into the air
A. Author\textsuperscript{1}, B. Author\textsuperscript{2}
\textsuperscript has been in the LaTeX kernel for a long time. \textsubscript first shipped in the fixltx2e package and joined the kernel with the 2015 release, when all fixltx2e changes became default (LaTeX News 22). On an older installation, \usepackage{fixltx2e} provides it. For numbered notes at the foot of the page, skip manual markers and use the LaTeX footnote commands.
Here's the limitation. KaTeX supports neither command, so neither works in Markdown math. You get an Undefined control sequence error, or the command name in red. In a Markdown file, write $1^{\mathrm{st}}$ or $n^{\mathrm{th}}$, which render as and . You can also use the HTML <sup> and <sub> tags, which our editor's preview renders, and our Markdown subscript and superscript guide compares that route across platforms.
An asterisk superscript needs no command at all. In math mode * already prints the asterisk operator, so $A^*$ and $A^{\ast}$ give the same .
Pre-subscripts and Pre-superscripts Before a Symbol
Isotopes, some tensor conventions and combinatorics put scripts on the left of a symbol. The portable trick is an empty group as the base, followed by the symbol:
${}^{14}_{6}\mathrm{C}$
That renders as in both LaTeX and KaTeX. The catch is alignment. Both scripts start at the same left edge, so the 6 sits under the 1 of 14 rather than the 4.
In a compiled document, two packages fix that:
\usepackage{mathtools} % provides \prescript
\usepackage{amsmath} % provides \sideset
$\prescript{14}{6}{\mathrm{C}}$
$\sideset{_a^b}{_c^d}\sum$
The mathtools \prescript command right-aligns the two left scripts. The amsmath \sideset command puts scripts at all four corners of a big operator such as \sum. Neither command exists in KaTeX, so Markdown math needs the empty group version.
Here are the main examples from this page in a live editor, plus one integral that the next section explains. Change any script and watch the preview update:
Limits on Integrals and Big Operators: \limits and \nolimits
On big operators such as \sum, \prod and \int, the scripts act as limits, and their position depends on the math style. In display math, a sum's limits go under and over the sign, while inline they sit to the side. Integrals keep side limits even in display math.
$$\int\limits_0^1 f(x)\,dx$$ % force under and over
$$\sum\nolimits_{i=1}^{n} x_i$$ % force to the side
Put \limits or \nolimits right after the operator and before the scripts. Both work in LaTeX and KaTeX, and so does \substack for multi-line limits. KaTeX doesn't support the related \displaylimits command, though.
Once you know the brace rule, a LaTeX subscript rarely misbehaves. Most errors come from double scripts, a misplaced prime or a text-mode command that KaTeX doesn't know. Test your formulas in the LaTeX equation editor, which renders with KaTeX and copies a Markdown math snippet. You can also paste the dollar-sign examples above into the Markdown editor and check the live preview.