Introduction to Subscripts and Superscripts
In the world of typesetting, especially for technical, scientific, and mathematical documents, subscripts and superscripts are essential. Whether you are writing a simple algebraic equation like $x^2$, a chemical formula like $H_2O$, or complex calculus involving summations and integrals, LaTeX provides a powerful and intuitive way to handle these notations.
Subscripts are characters positioned slightly below the normal line of type, while superscripts are positioned slightly above. In LaTeX, these are handled using two primary characters:
- The underscore (
_) for subscripts. - The caret (
^) for superscripts.
Before we dive into the syntax, it is important to remember that subscripts and superscripts are considered mathematical notation. Therefore, they must almost always be placed inside Math Mode (surrounded by $ ... $ for inline math or \[ ... \] for display math).
Basic Syntax and the "Single Character" Rule
The simplest way to create a script is to follow the base character with either an underscore or a caret.
Basic Examples
$x^2$ % Superscript: x squared
$a_n$ % Subscript: a sub n
$x^2 + y^2 = r^2$ % A complete equationWarning: A common beginner mistake is trying to use
_or^in regular text mode. If you typethe value is x_iwithout dollar signs, LaTeX will throw an error saying "Missing $ inserted." Always wrap your math in$.
The Single Character Rule
By default, LaTeX only applies the subscript or superscript command to the very next character.
If you type $x^10$, LaTeX interprets this as "x to the power of 1, followed by a normal 0." The result will look like $x^10$. To include multiple characters in a script, you must group them using curly braces {}.
$x^10$ % Incorrect: results in x to the 1st power, then a 0
$x^{10}$ % Correct: results in x to the 10th powerBest Practice: Many experienced LaTeX users always use curly braces, even for single characters (e.g., $x^{2}$), to avoid errors and make the code more readable.
Combining Subscripts and Superscripts
Often, a single variable will require both a subscript and a superscript. In LaTeX, you can provide both in any order.
Simultaneous Scripts
You can write x_i^2 or x^2_i. Both will produce the same output where the "2" is directly above the "i".
$a_1^2 + a_2^2 = a_3^2$
% The order does not matter:
$x_{base}^{exponent}$
$x^{exponent}_{base}$Nested Scripts
Sometimes you need a "script within a script," such as $e^{x^2}$. This is achieved by nesting the commands inside the curly braces.
$e^{x^2}$ % x squared is the exponent of e
$a_{n_i}$ % i is a subscript of n, which is a subscript of a
$2^{2^{2^x}}$ % Multiple levels of nestingLaTeX automatically scales the font size smaller as you go deeper into nested scripts to maintain readability.
Scripts with Mathematical Operators
Certain mathematical operators, such as summations ($\sum$), integrals ($\int$), and limits ($\lim$), treat subscripts and superscripts differently based on the "math style" being used.
Inline vs. Display Style
- Inline Math (
$...$): To save vertical space within a paragraph, LaTeX places scripts to the side of the operator. - Display Math (
\[...\]or\begin{equation}): LaTeX places scripts directly above and below the operator for better clarity.
% Inline style (scripts appear to the side)
The sum $\sum_{i=1}^{n} i$ is useful.
% Display style (scripts appear above and below)
\[
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
\]Using \limits and \nolimits
If you want to force the "above/below" behavior in inline math, you can use the \limits command. Conversely, \nolimits forces the side behavior in display math.
% Force limits to be above/below in a sentence
$\sum\limits_{i=1}^{10} x_i$Working with Text in Scripts
In scientific writing, we often use words as subscripts, such as $V_{initial}$ or $T_{max}$. However, if you simply type $V_{initial}$, LaTeX treats "initial" as a string of mathematical variables ($i \times n \times i \times t...$), resulting in italicized, poorly spaced letters.
To fix this, use the \text{} command from the amsmath package.
\usepackage{amsmath} % Required in your preamble
% Incorrect (italicized and bad spacing)
$V_{initial}$
% Correct (upright text)
$V_{\text{initial}}$Note: Using
\text{}ensures the subscript matches the font of the surrounding document and handles spacing correctly for human-readable words.
Common Mistakes and Best Practices
To ensure your LaTeX documents compile correctly and look professional, keep these tips in mind:
- Forgetting the curly braces: Always use
{}for scripts longer than one character. Even for$x_{i}$, it helps prevent logic errors later. - Empty scripts: If you accidentally type
x^, LaTeX will expect something to follow. If nothing does, it may cause an error. - Double scripts: You cannot have two subscripts on the same level like
$x_i_j$. LaTeX will get confused. If you want $x$ with two subscripts, group them:$x_{i,j}$or$x_{i_j}$depending on your intent. - Chemistry notation: While you can use subscripts for chemistry (e.g.,
$H_2O$), for complex formulas, it is better to use themhchempackage, which simplifies the syntax to\ce{H2O}. - Placement before the base: Occasionally, you might need a superscript before a variable (like in nuclear notation). You can do this by attaching the script to an empty group
{}.
% Nuclear notation for Carbon-14
${}^{14}_{6}\text{C}$By mastering subscripts and superscripts, you have unlocked the ability to typeset the vast majority of mathematical and scientific notation. Practice by trying to recreate formulas from a textbook to get comfortable with nesting and grouping!
