Octree LogoOctree

Subscripts and Superscripts in LaTeX

Subscripts and superscripts are essential building blocks of mathematical, scientific, and technical writing in LaTeX. From chemical formulas like H₂O to polynomial exponents like x², from footnote markers to tensor notation, mastering subscript and superscript syntax is fundamental to producing professional documents.

Basic Superscripts

In LaTeX math mode, you create superscripts using the caret symbol (^). For a single character, you can place it directly after the caret. For multiple characters, wrap them in curly braces.

% Single character superscript
$x^2$

% Multiple characters require braces
$x^{2n}$
$e^{i\pi}$

% Without braces, only the first character is raised
$x^10$    % renders as x^1 followed by 0
$x^{10}$  % renders correctly as x to the power of 10

The braces tell LaTeX to treat everything inside them as a single group. This is one of the most common sources of errors for beginners — always use braces when your superscript contains more than one character.

Basic Subscripts

Subscripts work the same way as superscripts, but use the underscore character (_) instead of the caret. Again, single characters can be placed directly after the underscore, while multiple characters need curly braces.

% Single character subscript
$x_i$

% Multiple characters require braces
$x_{i+1}$
$a_{max}$

% Without braces, only the first character is lowered
$x_10$    % renders as x_1 followed by 0
$x_{10}$  % renders correctly as x sub 10

Subscripts are widely used for indexing variables, chemical formulas, and labeling quantities in scientific notation.

Combining Subscripts and Superscripts

LaTeX allows you to apply both a subscript and a superscript to the same base element. The order in which you write them does not matter — LaTeX will position them correctly.

% Subscript and superscript on the same element
$x_i^2$
$x^2_i$    % same result as above

% More complex examples
$a_{n}^{2}$
$T_{\mu\nu}^{\alpha\beta}$   % tensor notation

% Simultaneous notation in physics
{}^{14}_{6}C$    % carbon-14 isotope notation
{}^{A}_{Z}X$    % general isotope notation

When combining subscripts and superscripts, LaTeX automatically handles the vertical positioning. Both are attached to the same base, so they appear neatly aligned.

Nested Subscripts and Superscripts

You can nest subscripts and superscripts inside each other for more complex expressions. Each level of nesting requires its own set of braces.

% Nested superscript (e to the x squared)
$e^{x^2}$

% Nested subscript
$a_{i_{j}}$

% Deeply nested expressions
$e^{e^{e^x}}$    % tower of exponentials
$x_{a_{b_{c}}}$  % triple-nested subscript

% Practical example: Gaussian function
$e^{-\frac{x^2}{2\sigma^2}}$

While LaTeX supports arbitrary nesting depth, keep readability in mind. For very complex expressions, consider breaking them into smaller parts using \newcommand or restructuring the formula.

Subscripts and Superscripts in Text Mode

The caret and underscore operators only work in math mode. To add superscripts and subscripts in regular text, use the \textsuperscript{} and \textsubscript{} commands.

% Superscript in text mode
This is the 1\textsuperscript{st} edition.
The 2\textsuperscript{nd} floor.
March 3\textsuperscript{rd}, 2026.

% Subscript in text mode (requires fixltx2e or newer LaTeX)
H\textsubscript{2}O is water.
CO\textsubscript{2} is carbon dioxide.

% Note: \textsubscript is available natively in
% LaTeX versions from 2015 onward.
% For older versions, add \usepackage{fixltx2e}

These commands are especially useful for ordinal numbers (1st, 2nd, 3rd), chemical formulas written outside of math mode, and footnote-style markers.

Common Use Cases

Subscripts and superscripts appear across many disciplines. Here are the most common scenarios:

Use CaseLaTeX CodeDescription
Chemistry$H_2O$Chemical formulas with subscript atom counts
Exponents$x^n$Powers and polynomial terms
Derivatives$f'(x)$Prime notation for derivatives
Tensors$T_{\mu\nu}$Tensor indices in physics
Isotopes{}^{14}_{6}C$Nuclear isotope notation
Sequences$a_{n+1}$Indexed sequences and series
Limits$\lim_{x \to 0}$Limit notation in calculus

Prime Notation

In LaTeX, the apostrophe character (') is a shorthand for a superscript prime symbol. This is commonly used for derivatives and transformed variables.

% Single prime (first derivative)
$f'(x)$

% Double prime (second derivative)
$f''(x)$

% Triple prime (third derivative)
$f'''(x)$

% Combining primes with subscripts
$f'_n(x)$

% Equivalent explicit notation
$f^{\prime}(x)$
$f^{\prime\prime}(x)$

% Using primes with other superscripts
$f'^2(x)$          % prime squared
$f^{\prime 2}(x)$  % same thing, explicit

The apostrophe shorthand is generally preferred because it's easier to type and produces identical output to the explicit \prime command.

The amsmath Package

The amsmath package from the American Mathematical Society provides advanced commands for positioning subscripts and superscripts in specialized contexts.

\usepackage{amsmath}

% \overset: place a symbol above another
$\overset{!}{=}$        % "!" above "="
$\overset{\sim}{x}$     % tilde above x

% \underset: place a symbol below another
$\underset{n \to \infty}{\lim}$

% \sideset: add subscripts/superscripts to large operators
$\sideset{_a^b}{_c^d}{\sum}$

% \substack: stacked subscripts (multi-line conditions)
$\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i$

% \stackrel: deprecated, use \overset instead
% $\stackrel{\text{def}}{=}$

The \substack command is particularly useful for sums and products with multiple conditions in the subscript position.

Limits-Style Subscripts

Large operators like \sum, \prod, \lim, and\int have a special behavior: in display mode, their subscripts and superscripts appear directly below and above the operator. In inline mode, they appear to the side.

% Display style: limits appear above and below
\[
  \sum_{i=1}^{n} x_i \qquad
  \prod_{k=1}^{n} k \qquad
  \lim_{x \to \infty} f(x)
\]

% Inline style: limits appear to the side
The sum $\sum_{i=1}^{n} x_i$ is computed inline.

% Force display-style limits in inline mode
The sum $\displaystyle\sum_{i=1}^{n} x_i$ uses display style.

% Force inline-style limits in display mode
\[
  \textstyle\sum_{i=1}^{n} x_i
\]

% Use \limits and \nolimits for explicit control
$\sum\limits_{i=1}^{n}$     % force limits style
$\sum\nolimits_{i=1}^{n}$   % force inline style

The \limits and \nolimits commands give you fine-grained control over whether subscripts and superscripts appear in limits position (above/below) or inline position (to the side).

Quick Reference Table

CommandExampleOutput Description
^$x^2$x squared
_$x_i$x sub i
^{}$x^{2n}$x to the 2n
_{}$x_{i+1}$x sub i+1
_i^j$x_i^j$x sub i, superscript j
\textsuperscript1\textsuperscript{st}1st (in text mode)
\textsubscriptH\textsubscript{2}OH2O (in text mode)
'$f'(x)$f prime of x
\overset$\overset{!}{=}$= with ! above
\underset$\underset{x}{\min}$min with x below
\substack$\sum_{\substack{i\\j}}$Sum with stacked subscripts

Common Mistakes

Here are the most frequent errors when working with subscripts and superscripts in LaTeX, and how to avoid them:

  • Forgetting braces for multi-character subscripts/superscripts — Writing$x^10$ instead of $x^{10}$. Without braces, only the first character is raised or lowered.
  • Using ^ or _ outside math mode — The caret and underscore are math-mode operators. Using them in text mode causes a compilation error. Use\textsuperscript{} and \textsubscript{} instead.
  • Double subscripts or superscripts — Writing $x^a^b$ causes an error. Use $x^{ab}$ or {x^a{'}'}^b$ depending on your intent.
  • Missing dollar signs — Forgetting to enter math mode before using subscript or superscript operators. Always wrap expressions in $...$ or\[...\].
  • Unbalanced braces — Every opening brace must have a matching closing brace. Complex nested expressions are especially prone to this error.
% WRONG: multi-character without braces
$x^10$         % renders as x^1 then 0
$a_max$        % renders as a_m then ax

% CORRECT: use braces
$x^{10}$
$a_{max}$

% WRONG: ^ outside math mode
This is x^2    % compilation error

% CORRECT: use math mode or text commands
This is $x^2$
This is x\textsuperscript{2}

% WRONG: double superscript
$x^a^b$        % error: Double superscript

% CORRECT: group appropriately
$x^{ab}$       % a and b together as superscript
{x^a}^b$      % b is superscript of (x^a)

Next Steps

Now that you've mastered subscripts and superscripts, explore these related topics:

Free LaTeX Tools

Ready to start writing?

Try Octree — the AI-powered LaTeX editor that makes writing faster and easier.

Try Octree Free →