Mastering Subscripts in Overleaf: From Basics to Advanced Techniques
If you’re working on a scientific paper, a mathematical thesis, or any technical document in Overleaf, you’ll almost certainly need to know how to add a subscript. Fortunately, creating a subscript in Overleaf (which uses the LaTeX typesetting system) is remarkably straightforward. The primary method involves using the underscore character _ within math mode. This article will serve as your complete guide, starting with this simple answer and diving deep into every nuance you’ll need to create professional and polished documents.
In short, to add a subscript, you simply enter math mode with dollar signs $ ... $ and type an underscore _ before the character or group of characters you want to subscript. For a single character, you’d write $x_1$. For multiple characters, you must enclose them in curly braces, like this: $v_{initial}$. Now, let’s explore this fundamental skill in much greater detail.
The Crucial First Step: Understanding Math Mode
Before we can even talk about subscripts, we absolutely have to discuss the concept of “modes” in LaTeX. LaTeX operates in different environments or modes, and the most common two are text mode and math mode. Most of the powerful typesetting commands for formulas, symbols, and, yes, subscripts, are exclusively available in math mode.
Think of it like this: text mode is for writing your paragraphs, sentences, and regular words. Math mode is a special environment designed to format mathematical expressions correctly, with proper spacing, italicized variables, and access to a vast library of symbols. Trying to use a math command in text mode will usually result in an error or unexpected behavior.
How do you enter math mode in Overleaf? You have a few choices:
- Inline Math Mode: For formulas that appear right within your line of text, you enclose them in single dollar signs. For example,
Let the variable be $x$. - Display Math Mode: For larger equations that you want to set apart on their own line and centered, you enclose them in
\[ ... \]. For example,\[ E = mc^2 \] - Equation Environment: For numbered equations, you use the
equationenvironment:\begin{equation} ... \end{equation}. This also automatically puts you into math mode.
For the rest of this guide, remember that the underscore _ command for subscripts is a math mode command. Getting a “Missing $ inserted” error is almost always a sign you’ve used it outside of math mode.
The Basic Subscript: Your Go-To Method
Now that we’ve established the importance of math mode, let’s look at the syntax for creating subscripts. It’s wonderfully simple.
Single Character Subscripts
To make a single letter or number a subscript, you just place an underscore _ right before it. LaTeX will automatically lower it and reduce its size.
Example 1: Chemical Formula
To write the formula for water, H₂O, you would type:
$H_2O$
The_2tells LaTeX to subscript the number 2. Notice that the entire expression is wrapped in dollar signs to enter math mode.
Example 2: Indexed Variable
To denote the ?-th element of a sequence ‘a’, you would type:
$a_i$
Multi-Character Subscripts
What happens when your subscript is longer than a single character, like a word or a multi-digit number? If you just type $log_10$, you might be surprised by the result: only the “1” will be subscripted, and the “0” will be back on the baseline.
This is because the _ command, by default, only applies to the single token that immediately follows it. To tell LaTeX to treat a group of characters as a single unit, you must enclose them in curly braces {...}. This is one of the most fundamental grouping rules in all of LaTeX.
Example 1: Logarithm with base 10
Incorrect:$log_10(x)$→ Renders as log₁0(x)
Correct:$log_{10}(x)$→ Renders correctly as log₁₀(x)
Example 2: A descriptive subscript
To notate the force of gravity, you could write:
$F_{gravity}$
Without the braces, you’d get Fgravity, which is clearly not what you wanted. The braces ensure the entire word “gravity” is properly subscripted.
Advanced Subscript Techniques in Overleaf
Once you’ve mastered the basics, you can start combining subscripts with other commands to create more complex and meaningful mathematical expressions.
Combining Subscripts and Superscripts
It’s very common to need both a subscript and a superscript on the same variable. For this, you use the underscore _ for the subscript and the caret ^ for the superscript. A neat feature of LaTeX is that the order doesn’t matter for the output; $x_i^2$ and $x^2_i$ will produce the exact same visual result. However, for consistency in your source code, it’s a good practice to stick to one order.
Example: A variable with an index and a power
To write xᵢ², you would type:
$x_i^2$or$x^2_i$
Example: Summation Notation
Summation notation is a perfect example of using both. The limits of the sum are added using subscript and superscript.
$\sum_{i=1}^{n} i^2$
Here, the starting conditioni=1is the subscript of the sum symbol, and the ending conditionnis the superscript.
Creating Nested Subscripts (Subscripts of Subscripts)
Sometimes, you might need to create a subscript of a subscript. This is particularly useful in tensor analysis or when dealing with complex indexed families. The logic follows directly from our grouping rule: just use another set of curly braces inside the first one.
Example: A nested index
Let’s say you want to represent an element where the index ‘i’ is itself indexed by ‘k’. You would write this as Aᵢₖ.
The Overleaf code for this is beautifully logical:
$A_{i_k}$
Here,{i_k}is the entire subscript for A. Inside that group,_kcreates a subscript for the ‘i’.
A word of caution: while technically possible, deeply nested subscripts can become very small and difficult to read. Always consider if there’s a clearer way to present your notation.
How to Create Left-Sided Subscripts
While most subscripts appear on the right, some fields like nuclear chemistry or specific mathematical notations require subscripts (and superscripts) on the left side of a character. Standard LaTeX doesn’t have a simple built-in command for this, but it’s easily achieved with the powerful mathtools package.
Here are the steps:
- Load the Package: In your Overleaf preamble (the part of your document before
\begin{document}), add the line:\usepackage{mathtools}. - Use the
\prescriptCommand: The command has a specific structure:\prescript{pre-sub}{pre-super}{argument}. You provide the pre-subscript and pre-superscript, followed by the main character. If you don’t need one of them, you leave the corresponding curly braces empty.
Example: Isotope of Carbon
To write the isotope Carbon-14, which is ¹⁴₆C, you would use:
$\prescript{14}{6}{C}$
Example: Left Subscript Only
If you only need a left-sided subscript, like in the notation ₙX, you leave the superscript argument empty:
$\prescript{}{n}{X}$
How to Add a Subscript in Text Mode
This is one of the most common stumbling blocks for new Overleaf users. What if you need a subscript in a regular sentence, not as part of a mathematical variable? For instance, you’re writing “The chemical formula is H₂O” in your text. If you use $H_2O$, the letters H and O will be italicized, because you’re in math mode. This doesn’t look right for chemical elements.
There are two excellent ways to handle this.
Method 1: The `\textsubscript` Command
The most semantically “correct” way to add a subscript in plain text is by using the \textsubscript{...} command. This command is designed for this exact purpose: it subscripts the content within its braces without changing to math mode’s font style.
Example:
The famous formula is E=mc\textsuperscript{2}, and the formula for water is H\textsubscript{2}O.
(Note:\textsuperscriptis the equivalent command for superscripts in text mode).
This method keeps your text looking like text, which is exactly what you want.
Method 2: Using `\text` or `\mathrm` Inside Math Mode
Sometimes you need the opposite: you are inside a math formula, but you want a subscript to look like normal, upright text instead of an italicized variable. This is common for descriptive subscripts.
For this, you use the \text{...} command, which requires the amsmath package (a must-have for any serious math document, so add \usepackage{amsmath} to your preamble). The \text{...} command allows you to insert normal text inside a math environment.
A similar command is \mathrm{...}, which typesets the text in a roman (upright) font.
\text{...}is generally preferred because it cleverly adapts to the surrounding style. If the formula is in a bold section, the text in\text{...}will also be bold.\mathrm{...}will always be a standard roman font, regardless of the surrounding style.
Example: Comparing `v_{max}` and `v_{\text{max}}`
If you write$v_{max}$, you get ?ₘₐₓ, where “max” is treated as three separate variables (m*a*x).
If you write$v_{\text{max}}$, you get ?ₘₐₓ, where “max” is a single, upright textual unit.
The second version is almost always what is intended for such labels.
Common Problems and How to Fix Them
Even with simple commands, errors can happen. Here’s a quick troubleshooting guide for the most common subscript-related issues in Overleaf.
-
Error: “Missing $ inserted.”
The Cause: You used the underscore character
_outside of math mode. You probably wrote something likeThe variable is x_1.in your text.
The Fix: Remember that_is a special character for math. Enclose your expression in dollar signs:The variable is $x_1$. -
Problem: “My long subscript only shows the first letter.”
The Cause: You tried to subscript multiple characters but forgot to group them. You wrote
$v_initial$instead of$v_{initial}$.
The Fix: Always wrap multi-character subscripts (and superscripts) in curly braces{...}. The correct code is$v_{initial}$. -
Problem: “My subscript is italicized, but I want it to be normal text.”
The Cause: You are using math mode, which typesets single letters as variables (italics). You wrote
$T_{hot}$, which looks like ?ₕₒₜ.
The Fix: Use the\text{...}command inside math mode to specify that the subscript is text. Make sure you have\usepackage{amsmath}in your preamble, and then write$T_{\text{hot}}$. -
Problem: “I just want to type a literal underscore, not a subscript.”
The Cause: You are trying to write something like a filename or variable name, e.g.,
my_file_name, directly in your text.
The Fix: To tell LaTeX to treat a special character as a literal character, you “escape” it with a backslash\. So, you should writemy\_file\_name.
Summary Table of Subscript Commands
To bring it all together, here is a handy table summarizing the different ways to create subscripts in Overleaf.
| Goal | Overleaf Code | Resulting Output (Description) | Notes |
|---|---|---|---|
| Basic single subscript | $x_1$ |
x₁ | Must be in math mode. |
| Basic multi-character subscript | $A_{ij}$ |
Aᵢⱼ | Curly braces {} are essential. |
| Subscript and superscript | $x_i^2$ |
xᵢ² | The order of _ and ^ does not change the output. |
| Nested subscript | $A_{i_k}$ |
Aᵢₖ | Use nested groups with curly braces. |
| Text-style subscript in math | $v_{\text{max}}$ |
vₘₐₓ (with “max” upright) | Requires \usepackage{amsmath}. |
| Subscript in plain text | H\textsubscript{2}O |
H₂O (with “H” and “O” as normal text) | The ideal method for non-mathematical subscripts. |
| Left-sided subscript | $\prescript{}{n}{X}$ |
ₙX | Requires \usepackage{mathtools}. |
| Literal underscore character | file\_name |
file_name | Escape the underscore with a backslash \. |
Conclusion
Adding a subscript in Overleaf is a fundamental skill that hinges on one key concept: using the underscore character _ within math mode. By remembering to enclose your expressions in dollar signs and using curly braces {...} to group multiple characters, you can handle the vast majority of subscripting needs. For more specific cases, understanding the difference between math mode and text mode allows you to choose the right tool for the job, whether it’s the \textsubscript{...} command for plain text or the \text{...} command for descriptive labels in formulas. By mastering these simple yet powerful commands, you’ve taken a significant step toward producing clear, professional, and beautiful documents with Overleaf.