# Drawbacks of redefining math accents with extra leading {}?

As I discovered through the non-bug latex/4253, TeX has a (mis)feature whereby it ignores braces around a \mathaccent construction: ${a_b}_c$ works, but ${\tilde a_b}_c$ fails with a "Double subscript" error. Braces in {a_b} turn that into an atom, which can receive a second subscript, but braces in {\tilde a_b} have no effect. See a question about why this happens for details.

Since ${{}\tilde a_b}_c$ works fine (TeX keeps the surrounding braces), I am wondering whether defining \tilde as {}\mathaccent... rather than \mathaccent... would be better. Will such a leading brace group have any ill effect on spacing (or other things)? Is there a better definition that would not result in confusing double superscript errors?

EDIT: Several commenters ask me incredulously why anyone would want this. I couldn't come up with a good case for double subscripts, only for double superscripts: the square of the derivative of b is typeset {b'}^2 or b'{}^2. What about the square of the derivative of \tilde{b}?

Here, it is possible to get a decent result with \tilde{b}{{}'}^2 (line marked with a star), but I don't think the input is natural. For an example that makes things worse, say \widetilde denotes the Fourier transform, and that I want to take the Fourier transform of b(t)/t, then take its derivative squared. Naturally I would type {\widetilde{\biggl[\frac{b}{t}\biggr]}'}^2. Instead, I need to type \widetilde{\biggl[\frac{b}{r}\biggr]}{\vphantom{\frac{b}{r}}'}^2 or something like that...

That said, I am mostly interested in knowing if adding {} to the start of the definition of \tilde (and \widetilde) would mess up math spacing.

• Would it be worth adding the TeXbook context here? I wonder why in the LaTeX bug report Frank feels that {}\tilde is not 'nice'. – Joseph Wright Jun 6 '13 at 7:19
• @HendrikVogt I agree that this is typically not going to look nice, and that may be a reason for Knuth to make TeX behave that way, who knows. I can probably think up a case where it could be more natural to type things in this way, though, and as you and others commented in the question you link to, one would not expect TeX to produce an error there. – Bruno Le Floch Jun 6 '13 at 9:25
• I can't understand what ${a_b}_c$ or ${{}\tilde{a_b}}_c$ should mean, to begin with, and how a reader should parse the result. – egreg Jun 6 '13 at 9:48
• @Bruno: It would be great if you could think up such a case and add it to the question! (I've deleted my previous comment as it was obsolete.) – Hendrik Vogt Jun 6 '13 at 10:12
• how does this differ in meaning from $\tilde a_{b_c}$? (it does differ in appearance.) – barbara beeton Jun 6 '13 at 12:57

This revised solution addresses the requirement to be able to scale the result to different math style sizes. To do that, features of the scalerel package are employed to import the current math style into the revised definition of \tilde.

And, as with the original solution, it provides the desired syntax and does it without frontloading the \tilde with a {}, and it readily takes subsequent sub and superscripts. A key feature of this solution is that the revised definition starts with the original \tilde definition, and ends on the argument of the \tilde, so that it should behave relative to adjacent math matter in expected ways.

\documentclass[]{article}%
\usepackage{scalerel}
\let\savetilde\tilde
\def\tilde#1{%
\ThisStyle{\savetilde{\phantom{\SavedStyle#1}}%
\setbox0=\hbox{$\SavedStyle#1$}\kern-\wd0#1}}
\parskip .8ex
\begin{document}
${\tilde a_b}_c$\par
${\tilde{b}'}^2$ No BOOM!\par
$\tilde b'^2$ Natural input\par
$(\tilde{b}')^2$ correct, per tohecz\par
$\scriptstyle{\tilde a_b}_c$\par
$\scriptstyle{\tilde{b}'}^2$ No BOOM!\par
$\scriptstyle\tilde b'^2$ Natural input\par
$\scriptstyle(\tilde{b}')^2$ correct, per tohecz\par
$\scriptscriptstyle{\tilde a_b}_c$\par
$\scriptscriptstyle{\tilde{b}'}^2$ No BOOM!\par
$\scriptscriptstyle\tilde b'^2$ Natural input\par
$\scriptscriptstyle(\tilde{b}')^2$ correct, per tohecz\par
Would otherwise cause tilde errors:\par
${\tilde{a}^b}^c$
${{\tilde{a}}^b}^c$
\end{document}


The last line in the above MWE were given by egreg as examples of what breaks with \tilde at Double superscript error involving tilde. They work with the current redefinition.

ORIGINAL SOLUTION (does not scale with smaller math styles) It provides the desired syntax; it does it without frontloading the \tilde with a {}, and it readily takes subsequent sub and superscripts.

\documentclass[]{article}%
\usepackage{stackengine}
\stackMath
\let\svtilde\tilde
\def\tilde#1{\stackengine{0pt}{}{\svtilde{\phantom{#1}}}{O}{l}{F}{T}{L}#1%
}
\parskip 1ex
\begin{document}
${\tilde a_b}_c$\par
${\tilde{b}'}^2$ No BOOM!\par
$\tilde b'^2$ Natural input\par
$(\tilde{b}')^2$ correct, per tohecz
\end{document}


This answer is the same approach I took at A simple solution to using widebar on subscripted symbol with small space with the subscript

• Of course, the correct thing to do is (\tilde{b}')^2. – yo' Mar 1 '14 at 22:03
• @tohecz This question is more related to \mathaccent handling of TeX instead of math notation I think. They are probably examples for L3 code development. – percusse Mar 1 '14 at 22:16