Math Mode – How to Typeset Upright Characters in Math Mode

formattingitalicmath-mode

As described in this answer, constants should be typeset upright, not in italics. However the symbol for reduced Planck's constant (ħ, \hbar) is in italics by default. This is especially obvious when using both h and \hbar in one equation. How do I make LaTeX typeset ħ upright?

ħ = h/2π


EDIT: I've tried \mathrm, \text, \textup, none of them works.

Best Answer

I won't delve into the issue whether this should be done or not.

The LaTeX kernel defines

\def\hbar{{\mathchar'26\mkern-9muh}}

and as such \mathrm{\hbar} should give an upright \hbar. However, the negative space of 9 math units is a wee bit too much for the upright letter; 8mu looks better, so you can use

\renewcommand*{\hbar}{{\mkern-1mu\mathchar'26\mkern-8mu\mathrm{h}}}

Care should be taken when font packages are loaded, for many of them contain \hbar as symbol. Obvious example: amssymb. In this case the redefinition of \hbar bust be issued after loading any font packages. To be on the safe side the above redefinition could be put into a \AtBeginDocument hook

\AtBeginDocument{\renewcommand*{\hbar}{{\mkern-1mu\mathchar'26\mkern-8mu\mathrm{h}}}}

EDIT To lower the bar a little the safest way is IMO to put it into a box and lower it by an amount relative to the height of the box.

\documentclass{article}

\begin{document}

\renewcommand*{\hbar}{{\mkern-1mu\mathchar'26\mkern-8mu\mathrm{h}}}
$\hbar \scriptstyle\hbar \scriptscriptstyle\hbar$

\renewcommand*{\hbar}{{\mathpalette\hbaraux\relax\mathrm{h}}}
\newcommand*{\hbaraux}[2]{\sbox0{\mathsurround=0pt$#1\mathchar'26$}\mkern-1mu\lower.07\ht0\box0\mkern-8mu}
$\hbar \scriptstyle\hbar \scriptscriptstyle\hbar$

\end{document}

enter image description here