[Tex/LaTex] Why does \widehat behave differently if I insert \hspace{0pt}

accentsmath-mode

I am getting some inexplicable behaviour from \widehat:

\documentclass[12pt,a4paper]{article}
\usepackage{amsfonts}
\begin{document}
\[
\fbox{$\widehat{\mathcal{C}}$}, 
\fbox{$\widehat{\hspace{0pt}\mathcal{C}}$}, 
\fbox{$\widehat{\mathcal{C}\hspace{0pt}}$},
\fbox{$\widehat{\hspace{0pt}\mathcal{C}\hspace{0pt}}$}
\]
\end{document}

output

Notice that the hat is misaligned in the first instance, but correctly aligned in all the other instances. Why does \hspace{0pt} make such a difference?

Also, how can I replicate this effect for other alignment problems? At the moment I am having trouble with the bounding boxes for the script font I am using…

Best Answer

If you put an accent over a single character, TeX uses information in the font metrics to shift the accent to take some account of the slope of the italic letters. Which is why the first one shifts. If you put an accent over a more complicated math list then it's just centered over the list.

Related Question