# Double subscript [duplicate]

I have some macros whose expansion generates something like:

\documentclass{amsart}
\begin{document}
$${T_2}_k$$
\end{document}


This compiles fine; technically there's a double subscript, but the braces hide it from TeX. However, under some circumstances, the macros generate something like:

\documentclass{amsart}
\begin{document}
$${\widetilde T_2}_k$$
\end{document}


This generates the error

! Double subscript.
l.3 $${\widetilde T_2}_ k$$
?


If I were generating the text directly, I could just do $$\widetilde T_{2k}$$ or similar, but that's not an option here.

Question 1. Why does the first document compile, and the second generate an error?

Question 2. Without changing the definitions of the macros, is there any way to make something like

\documentclass{amsart}
\newcommand\macroa{\widetilde T_2}
\newcommand\macrob[1]{#1_k}
\begin{document}
$$\macrob\macroa$$
\end{document}


compile—e.g., by adding braces, as would work if the first definition were instead:

\documentclass{amsart}
\newcommand\macroa{T_2}
\newcommand\macrob[1]{#1_k}
\begin{document}
$$\macrob{{\macroa}}$$
\end{document}


?

EDIT: Now that I realise that this is an error with mathaccents in general rather than just with \widetilde, I see that a nice expansion by @HendrikVogt of an answer by @egreg does the necessary digging into TeX's internals to see what is going on. In particular,

\documentclass{amsart}
\newcommand\macroa{\widetilde T_2}
\newcommand\macrob[1]{#1_k}
\begin{document}
$$\macrob{{{}\macroa}}$$
\end{document}


works (although the apparently more natural

\documentclass{amsart}
\newcommand\macroa{\widetilde T_2}
\newcommand\macrob[1]{#1_k}
\begin{document}
$$\macrob{{}\macroa}$$
\end{document}


doesn't).

## marked as duplicate by LSpice, egreg, Community♦Jan 17 at 21:03

• Please clarify whether you want \widetilde to span just T or T_2. – Mico Jan 15 at 4:02
• @Mico, I want it to span just T. However, that part is behaving correctly; it's just the double subscript that puzzles me, since I can't see how an accent could change the subscript handling. – LSpice Jan 15 at 4:15
• This is known. While I look for the duplicate, use {{}\widetilde{T}_2}_k – egreg Jan 17 at 20:39
• @egreg, indeed, once I realised it was a \mathaccent issue I spotted your explanation, on which @‍HendrikVogt elaborated. – LSpice Jan 17 at 20:40