9

How can I center double widehats on X? It works well on Y, but the second widehat on the X has a different center.

Code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    $\widehat{\widehat{Y}}$ \hspace{1cm}    $\widehat{\widehat{X}}$
\end{document}

Output:

enter image description here

2
  • 2
    This is not amsmath per se, it shows without it. It is core math-mode issue so probably tag should be edited.
    – user691586
    Jun 7 at 7:22
  • If you can switch to unicode-math (and use lualatex/xelatex), it might be an option, since there it looks better.
    – mickep
    Jun 7 at 7:52

1 Answer 1

6

I don't know an automated solution, but in the code below I define a macro \wdoublehat with optional argument a math glue and \wdoublehat[1.5mu]{X} appears to be somewhat satisfactory, as it would be for letter Z as well, but for other letters you should adjust the 1.5mu, and for Y not use optional argument.

The screenshot shows that the root cause is the position of the letter inside its bounding box. The placement (and size) of the external \widehat clearly depends on this bounding box (the first \widehat seems to know more, perhaps some italic correction thing or other data associated to the glyph that it queries; but the external one appears to use only the bounding box of its (now not a letter) argument). The problem with X is that relative to the mid point of the bounding box the (top) of the letter is far more to the right than is the case with Y.

\documentclass{article}
\usepackage{amsmath}
%\usepackage{mathtools}
\begin{document}
    
\makeatletter
\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{{\fboxsep-\fboxrule\fbox{$\x$}} }
\makeatother

\makeatletter
\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{{\fboxsep-\fboxrule\fbox{$\widehat{\x}$}} }
\makeatother

\makeatletter
\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{$\widehat{\hbox{\fboxsep-\fboxrule\fbox{$\widehat{\x}$}}}$ } 
\makeatother

\makeatletter
\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{$\widehat{\widehat{\x}}$ } 
\makeatother

\newcommand\wdoublehat[2][0mu]{\mskip#1\widehat{\mskip-#1\widehat{#2}\mskip#1}\mskip-#1\relax}

\makeatletter
\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{$\wdoublehat[1.5mu]{\x}$ } 
\makeatother


\end{document}

output (the next to last line show nested \widehat, the last line shows using \wdoublehat and 1.5mu shift)

widehat double

Again:

\documentclass{article}
\usepackage{amsmath}
\newcommand\wdoublehat[2][0mu]{\mskip#1\widehat{\mskip-#1\widehat{#2}\mskip#1}\mskip-#1\relax}

\begin{document}
\makeatletter
$\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{\widehat{\widehat{\x}}}$ (nested, no shift)
\makeatother

\makeatletter
$\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{\wdoublehat[1.5mu]{\x}}$ (1.5mu shift)
\makeatother

\makeatletter
$\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{\wdoublehat[2mu]{\x}}$ (2mu shift)
\makeatother

\makeatletter
$\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{\wdoublehat[2.5mu]{\x}}$ (2.5mu shift)
\makeatother

\makeatletter
$\@tfor\x:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do{\wdoublehat[3mu]{\x}}$ (3mu shift)
\makeatother

\end{document}

more demo

(there is in this screenshot some ink above left of X on first line which is a Q descender from the full document from which I took screenshot: don't go get a scrub-sponge to clean your screen!)

It is possible to store in an array like structure the per-letter needed shifts and then the usage would be automatic. But this is better left to user to define in preamble once and for all such \doublehatX etc... commands using suitably the \wdoublehat[<mu shift>] from this answer.

7
  • Wouldn't it be "better" to compose a two-level accent, with the two placed directly one above the other, and then applying the composite to the ideal location for a single accent? Jun 7 at 16:23
  • @barbarabeeton nice suggestion! I currently have no idea if you can manage to then let TeX's \mathaccent work with that. I would perhaps need to revisit TeX by Topic and/or some dreaded Appendix G of the TeXBook...
    – user691586
    Jun 7 at 17:20
  • Obviously it would be easier if doubled accents were in Unicode and/or in fonts. I seem to remember this being addressed in the days of "plain TeX", and I think one of my TeX friends was involved. I'll explore. Jun 7 at 17:37
  • Memory worked. An article in the 1987 TUG proceedigs, in the TeXniques, not TUGboat, at ttps://tug.org/texniques/tn05/tn05complete.pdf on (printed) pages 5-26. By Christina Thiele, "TeX, Linguistics, and Journal Production". The relevant concept is the definition of \diatop, on p.12. I haven't compared the code with yours in detail, but it might be worth testing. Jun 7 at 21:45
  • Oops! There's an omission in that definition. In the first line, \def\diatop[#il#2]{{\setbox1=... there should be a \leavevmode before \setbox1. (Correction provided by author, who has a better memory than mine.) Jun 7 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .