TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to redefine \hat{H} as \hat{\cal H} only for this particular letter (for Hamiltonian symbol in physics). Thank you very much.

share|improve this question
I should note that \cal has been deprecated since 1994 and that \mathcal{H} is the preferred syntax. – egreg Jul 11 '13 at 12:48
Whether or not it's possible, macro-ing away the syntax in a way such as requested is a bad idea in any language. Ultimately it is just a form of code obfuscation. – Chris White Jul 11 '13 at 20:16
up vote 9 down vote accepted

Well I guess that there are two ways of proceeding here:

  • Use the "find and replace" tool of your editor to replace all the matches of \hat{H} by \hat{\mathcal{H}} or

  • a bit more appealing... in the preamble of the document define a new command, say \newcommand*{\hham}{\hat{\mathcal{H}}}. Then use the "find and replace" tool of your editor to replace all the matches of \hat{H} by \hham

A MWE would be



The relation,
\[\hham\psi_n = E_n\psi_n\]
is valid for every  eigenstate $\psi_n$ of the Hamiltonian $\hham$.


share|improve this answer
Thank you. I have wondered if there is any possibility to do so without having to overwrite all \hat{H} in the document using find/replace tool. But the second way seems quite suitable for me. Thank you again. – Honza Zubáč Jul 11 '13 at 13:02
@HonzaZubáč: Yes, the newcommands are very helpful to define "structures" that you will use over and over through the document, specially because if you want to change all of them to another symbol, e.g. \mathcal{H} to \mathbb{H}, you need to do it once... at the definition. Changing subject, I'd like to remind you that you are invited to vote up the useful answers, and "check mark" the one you found accurate to your needs. Cheers. – Dox Jul 11 '13 at 13:12

The easiest way is to define a new command \hatH:

\[ \hatH \]


A redefinition of \hat is far more complicate, because of TeX rules in math. \hat expands to \mathaccent that does not parse its base as "argument" but as <math field>. The latter can be a math symbol or a sub formula. This cannot be parsed by a macro argument in a 100% compatible manner.

An approximation is the following example that tests the cases that an H or {H} is following \hat:


    \@ifnextchar H{%

\[ \hatH \hat H \hat{H} \hat x \hat{x} \hat{ab} \]


share|improve this answer
Shouldn't \cal H be \mathcal{H}? – egreg Jul 11 '13 at 12:40
@egreg: \cal H is shorter and it is inside a sub formula, because the curly braces are not argument braces. \hat expands to \mathaccent that expects a <math field> that can be a symbol or a sub formula. – Heiko Oberdiek Jul 11 '13 at 13:18
Deprecated commands such as \it or \cal are not guaranteed to be in all classes. – egreg Jul 11 '13 at 13:20
@egreg: Thanks, I have already changed the answer accordingly (and extended with an approximated redefinition of \hat). – Heiko Oberdiek Jul 11 '13 at 13:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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