I'm trying to typeset a symbol with two hat accents (useful for denoting superoperators in quantum mechanics, for instance), but \hat{\hat{L}} produces too much space between the hats. I found one approach on a LaTeX forum that seems to work, but it requires manual adjustment for each letter that I might want to typeset. If anyone has any suggestions, I'd appreciate it. Thanks!
Asked
Active
Viewed 1.7k times
22
Chris Granade
- 465
2 Answers
26
Well, I wrote that suggestion at LaTeX Community, but there I assumed the person wanted fine-grained control. If you don't, then maybe something like this would be more suitable? You may need to tweak the -0.35ex to your liking, though not separately for each character.
How about this?
\documentclass{article}
\usepackage{amsmath}
\usepackage{accents}
\newlength{\dhatheight}
\newcommand{\doublehat}[1]{%
\settoheight{\dhatheight}{\ensuremath{\hat{#1}}}%
\addtolength{\dhatheight}{-0.35ex}%
\hat{\vphantom{\rule{1pt}{\dhatheight}}%
\smash{\hat{#1}}}}
\begin{document}
$\doublehat{x} \doublehat{L} \doublehat{\prod}$
\end{document}

frabjous
- 41,473
-
That worked beautifully, thank you! One last question, though: would using \mathchoice be a reasonable way of making your code work in a super/subscript context? Once again, thanks for your help! – Chris Granade Feb 07 '11 at 23:58
-
Hmm. I hadn't thought of sub/superscripts. Yeah, \mathchoice could probably work. Do you need help or do you think you can work it out on your own? – frabjous Feb 08 '11 at 00:07
-
I got it. It's not all that elegant, as I'm not used to the intricacies of LaTeX macro writing yet, but it does typeset superscript double-hats quite nicely. http://pastebin.com/XctVhueR – Chris Granade Feb 08 '11 at 00:32
-
The
accentspackage is needed since plain TeX yields good horizontal alignment of the accent only for single characters;amsmathhas some handling of double accents, but only theaccentspackage is able to handle the correct positioning of the\hatover your more complicated construction. – Hendrik Vogt Feb 08 '11 at 11:14 -
2I needed a
\triplehat, so I copied this definition for\doublehat, then renamed it to\triplehat, and finally replaced the two nested references to\hatwith\doublehat. It worked beautifully! – Aaron McDaid Sep 16 '16 at 10:49
6
An alternative macro that doesn't depend on package accents.
\makeatletter
\newcommand{\hathat}[1]{%
\begingroup%
\let\macc@kerna\z@%
\let\macc@kernb\z@%
\let\macc@nucleus\@empty%
\hat{\raisebox{.2ex}{\vphantom{\ensuremath{#1}}}\smash{\hat{#1}}}%
\endgroup%
}
\makeatother
It is inspired by frabjous's answer and David's answer under another question.
An updated solution that supports subscript math style.
\makeatletter
\newcommand{\hathat}[1]{%
\begingroup%
\let\macc@kerna\z@%
\let\macc@kernb\z@%
\let\macc@nucleus\@empty%
\hat{\mathchoice%
{\raisebox{.2ex}{\vphantom{\ensuremath{\displaystyle #1}}}}%
{\raisebox{.2ex}{\vphantom{\ensuremath{\textstyle #1}}}}%
{\raisebox{.16ex}{\vphantom{\ensuremath{\scriptstyle #1}}}}%
{\raisebox{.14ex}{\vphantom{\ensuremath{\scriptscriptstyle #1}}}}%
\smash{\hat{#1}}}%
\endgroup%
}
\makeatother
Tianren Liu
- 458
-
1Works nicely, but .2ex is probably not enough; I'd suggest .35ex, as in frabjous's answer above. – chsk Feb 01 '21 at 17:51
-
How can we make it work as a subscript, e.g., in $\sum_{\hathat{y}}$? Currently when I'm putting it in a subscript, the hats get separated a lot. – pms Feb 05 '23 at 21:24
-
1

amsmathand\hat{\hat{L}}directly. It is also used in manual ofamsmath. – Leo Liu Feb 07 '11 at 18:24