# Why am I getting a double subscript error?

The following compiles just fine: ${a_b}_c$. But when I try to add an accent over the 'a', as in ${\hat a_b}_c$, I get an error message:

? ! Double subscript. l.1187 ${\hat a_b}_ c$

Is there a good reason for getting this error? and how can I fix it? or is it a bug in my tex distribution? I've tried putting in more braces, as in ${{\hat a}_b}_c$, but this apparently does not help.

• What happend if you write $\hat{a}_{b_c}$? Jul 1, 2015 at 4:06
• May be $\hat{a_b}_c$... Jul 1, 2015 at 5:45

It's a feature in TeX. A subformula in math mode is a group of symbols surrounded by braces or by \left-\right. For instance $a+{b+c}$ has a subformula.1

If you type ${(a+b)}^{2}$, the exponent will be higher than in $(a+b)^{2}$, because you are setting an exponent to the whole subformula in the former case, to the parenthesis in the latter case. By the way, the latter is the correct code.

By a choice of Donald Knuth, the creator of TeX, when a subformula happens to only contain an “accent atom”, that is, something like \hat{x} including possible superscript and subscript, the braces around this atom are stripped off and TeX acts as if they had never been there to begin with.

So typing ${\hat a_b}_c$ is exactly the same as typing $\hat a_b_c$.2

But, even if this didn't happen, I'd suggest you to avoid such a construct: the workaround

${{}\hat{a}_b}_c$


produces

and your readers will have a hard time trying to get a sense out of it. Perhaps better is

$(\hat{a}_b)_c$


that gives

1 This is just an example, I don't recommend typing such a thing, but subformulas have their uses.

2 I'd prefer \hat{a} instead of \hat a, but there's no difference because \hat is a macro taking one argument.

Double subscript error occurs when TeX sees a second subscript attached to the main box, and because TeX's accent machinery is very low-level you're seeing an interesting side-effect here. The best fix is to load the accents package, which re-implements accents and fixes up a few infelicitations such as this:

\documentclass{article}
\usepackage{accents}
\begin{document}
${\hat a_b}_c$
\end{document}


Before I remembered that package, though, here are a few lower-level approaches to getting around this problem:

\documentclass[twocolumn]{article}
\begin{document}
\noindent The original:
${a_b}_c$
Hat misplaced:
$\hat {{a}_b}_c$
One (ugly) possibility to separate the 2nd subscript:
${\hat a_b}{\vphantom{a_b}}_c$
A better way:
\newcommand\mathbox[1]{\mbox{$#1$}}
$\mathbox{\hat a_b}_c$
Perhaps a different subscript regime is better?
$\hat a_{b_c}$
\end{document}


i don't know if this is what you need, but try this

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
${a_b}_c$\\
$\hat {{a}_b}_c$\\
\end{document}