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).
\widetildeto span justTorT_2. – Mico Jan 15 '19 at 04:02T. 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 '19 at 04:15{{}\widetilde{T}_2}_k– egreg Jan 17 '19 at 20:39\mathaccentissue I spotted your explanation, on which @HendrikVogt elaborated. – LSpice Jan 17 '19 at 20:40