LaTeX error · Math mode
Double subscript
Quick answer
TeX allows one subscript and one superscript per base. In $a_i_j$ the second _ has no base of its own, so TeX stops with "Double subscript" (and x^2^3 gives "Double superscript"). Decide what you mean and say it with braces: a_{ij} for a two-letter index, a_{i_j} for a subscript on the subscript, or {a_i}_j for a subscript on the whole expression.
The error in the log
This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.
! Double subscript.
l.3 The entry $a_i_
j$ of the matrix.
I treat `x_1_2' essentially like `x_1{}_2'.Why it happens
- A multi-character index typed without braces, such as
a_i_jfor the matrix entry a with indices i and j. - A nested script (a subscript of a subscript) written as
x_n_kinstead ofx_{n_k}. - A macro that already adds a subscript, used with another
_after it, for example\newcommand{\xs}{x_i}followed by\xs_j. - A prime after a superscript, as in
f^2': the prime is itself a superscript. Writef'^2, which LaTeX merges into one superscript, or{f^2}'.
How to fix it
Put everything that belongs in one index inside a single pair of braces. a_{ij} typesets both letters as one subscript; a_{i,j} adds a comma, which reads better with longer indices.
If you really want a script on a script, nest it: x_{n_k} puts k below n. To attach a second subscript to an expression that already has one, brace the expression first: {a_i}_j.
Broken: reproduces the error
\documentclass{article}
\begin{document}
The entry $a_i_j$ of the matrix.
\end{document}Try this in Octree — free LaTeX editor with AI, compiles in your browser
Fixed: compiles cleanly
\documentclass{article}
\begin{document}
The entry $a_{ij}$ of the matrix, the sequence $x_{n_k}$
and the power $x^{2^3}$.
\end{document}Double superscript
! Double superscript.
l.3 $x^2^
3$The same rule applies to superscripts: x^2^3 has two ^ on one base. Write x^{2^3} for a tower of powers or {x^2}^3 for (x²)³, which most readers would rather see as (x^2)^3.
A prime counts as a superscript, so f^2' triggers it too. Put the prime first, f'^2, which LaTeX combines into a single superscript, or brace the power: {f^2}'.
Related errors
- Missing $ inserted – A math-only symbol (
_,^,\alpha) was used in text, or math mode was left early. - Missing } inserted – A brace group was still open when math mode or a table cell ended.
- Extra }, or forgotten $ – A
}with no matching{, or a group that crosses a$boundary. - All LaTeX errors and warnings – The full list, grouped by cause
Frequently Asked Questions
How do I write a subscript with two letters in LaTeX?
Put both letters in braces: a_{ij}. Without braces only the first character after the underscore becomes the subscript, and a second underscore causes the "Double subscript" error.
How do I write a subscript of a subscript?
Nest it inside braces: x_{n_k} puts k as a subscript of n, which is itself the subscript of x. The inner script is set in an even smaller size automatically.
Why do I get "Double superscript" with a prime?
In math mode a prime is a superscript, so f^2' puts two superscripts on f. Write the prime first, f'^2, which LaTeX merges into one superscript, or brace the power: {f^2}'.
Paste your document into Octree — compile errors get a Fix with AI button
When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.
Fix it in Octree →