2

The realhats package changes the \hat{} command, such that LaTeX places a random, funny hat on top of the variable, instead of the normal "^"-shape. I would like to use the package to get funny hats in a few places, but need the normal \hat{} to work unchanged.

Can this be easily achieved?

edit: see the package documentation for a visual example of what the package does.

1 Answers1

4

The \Hat command when amsmath is loaded is defined as an alias to \hat. You can reuse this command to produce the standard \hat accent.

\documentclass{article}
\usepackage{amsmath}

\RenewCommandCopy{\Hat}{\hat} \usepackage{realhats}

\begin{document}

$\hat{a}+\Hat{a}$

\end{document}

enter image description here

Here's how you can have \hat to typeset the standard one and \realhat the “real” one.

\documentclass{article}
\usepackage{amsmath}

\NewCommandCopy{\HAT}{\hat} \usepackage{realhats} \NewCommandCopy{\realhat}{\hat} \RenewCommandCopy{\hat}{\HAT}

\begin{document}

$\realhat{a}+\hat{a}$

\end{document}

Comment
In my opinion, the realhats package should define \realhat and offer an option, say override, to replace \hat with \realhat.

egreg
  • 1,121,712
  • Thanks a lot. That is a good step of the way at least. Is there a further hack to flip the two? Just to avoid having to change 100s of equations already typeset with \hat? – Christoffer Østfeldt May 23 '22 at 09:46
  • 1
    @ChristofferØstfeldt Added. – egreg May 23 '22 at 09:53
  • What is the difference between this \RenewCommandCopy solution and just using \let\Hat=\hat? – Gaussler May 23 '22 at 10:30
  • I've marked the answer as accepted. Only thing left to add, is that it requires a new-ish version of LaTeX, as the commands used are not available in, e.g., TeX live 2019 (the version installed on Ubuntu 20.04, for example). – Christoffer Østfeldt May 23 '22 at 10:43
  • 1
    @ChristofferØstfeldt For older LaTeX you can use \LetLtxMacro from the letltxmacro package. – egreg May 23 '22 at 11:01
  • @Gaussler: see https://tex.stackexchange.com/questions/88001/when-to-use-letltxmacro – Willie Wong May 23 '22 at 16:56