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.

2
  • Your question isn't easy to understand. Please add a graphical explanation. May 23 at 9:29
  • I don't know how to explain it better than the package documentation does, but I've now linked that for reference. May 23 at 9:36

1 Answer 1

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.

6
  • 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? May 23 at 9:46
  • 1
    @ChristofferØstfeldt Added.
    – egreg
    May 23 at 9:53
  • What is the difference between this \RenewCommandCopy solution and just using \let\Hat=\hat?
    – Gaussler
    May 23 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). May 23 at 10:43
  • 1
    @ChristofferØstfeldt For older LaTeX you can use \LetLtxMacro from the letltxmacro package.
    – egreg
    May 23 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.