[Tex/LaTex] LaTeX superscripts problem with widetilde

superscriptstilde

I tried to put a superscript (squared) with a \xi variable in the \widetilde :

$\widetilde{\xi}^2 = (\widetilde{\xi})^2 \neq \widetilde{\xi^2}$

gives
enter image description here

Which seems to be se same things, whereas it is absolutly not ! So, I'm looking for some way to put my squared in \widetilde{\xi}^2 slightly higher than my \widetilde.

This problem doesn't occur with a "small variable" like an x :

$\widetilde{x}^2 = (\widetilde{x})^2 \neq \widetilde{^2}$

givesenter image description here

which places correctly and readably my squared without any doubt.

Any ideas ?

Best Answer

After all, this might indeed be the answer you are looking for. The reciprocal placement of a math accent and of a superscript (and/or subscript) is subject, when the “accentee” consists of a single character, to an exceptional treatment which is detailed in Rule 12 of Appendix G of The TeXbook (p. 443), and that can be informally described as the super-/sub-script being “fastened” directly to the character being accented. To inhibit application of this exception, it suffices to add, under the accent, “something” that takes up no space, for example \mkern 0mu.

Here is a MWE:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\newcommand*{\ShowLists}{%
%   \begingroup
%       \showboxbreadth = 1000
%       \showboxdepth = 10
%       \tracingonline = 1
%       \showlists
%   \endgroup
}



\begin{document}

Test:
\( \widetilde{\xi}^{2}+\widetilde{\xi\mkern 0mu}^{2}\ShowLists \).
\ShowLists
Other test:
\( \tilde{\xi}^{2}+\tilde{\xi\mkern 0mu}^{2}\ShowLists \).\ShowLists

\end{document}

And this is the output it produces:

Output of the code

If you uncomment the body of the definition of the \ShowLists command, some tracing information will be shown during compilation, that explains exactly what is going on.


Addition

It turned out that the OP wasn’t quite satisfied with the above solution: the exponent gets raised too much. Then we propose a completely different method, which puts the superscript at the same vertical position that an exponent affixed to a parenthesis would be placed at. Note, however, that this causes the superscript to clash with the tilde, so a little amount of space needs to be added on its left. Note also that the braces around \mathstrut are not superfluous! (This is because \mathstrut does not produce an atom by itself, but “something else” that is not capable of carrying super-/sub-scripts.)

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.



\begin{document}

A completely different approach:
\( \widetilde{\xi}^{2} \neq \widetilde{\xi}{\mathstrut}^{\>2} \).

\end{document}

The output in this second case is:

Output of the 2nd code sample