3

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.

m93a
  • 271
  • 6
    Opinions on the subject tend to differ but the bit about upright constants usually refer to math constants. Physical constants are usually written italic. I have never seen upright c, h and whatnot. (Theoretical physicist talking here.) – campa Feb 05 '20 at 09:51
  • 1
    In fact, I'm pretty sure ISO norms dictate (for whatever reason) upright for mathematical and italics for physical constants. In my experience, most mathematicians do not see the point of this distinction but many physicists abide by it. (Including myself.) – campa Feb 05 '20 at 09:57
  • I'm pretty sure it's somewhere in “ISO 80000-1:2009”. Or maybe “-3” or “-7”. But I'm not sure it really matters, as each of these PDFs are sold at $160 ‍♂️️. But if you find a way to access those, I'll gladly read them. – m93a Feb 05 '20 at 10:09
  • Have you tried \mathrm{\hbar}? – Henri Menke Feb 05 '20 at 10:09
  • \usepackage{tipa} \textcrh – Nico Feb 05 '20 at 10:13
  • BTW, \hbar is not a true constant, because it's only known up to a certain precision, so it actually changes each time the measurements get better. – Henri Menke Feb 05 '20 at 10:17
  • 3
    @HenriMenke Not since May 2019 any more :-) – campa Feb 05 '20 at 10:20
  • In Unicode, in the Letterlike Symbols code block, letters like ℋ ℌ ℍ ℎ ℏ are defined as script, fraktur, double-struck, italic, etc. – Cicada Feb 05 '20 at 11:24
  • @Nico just adding \usepackage{tipa} breaks my document. @Cicada “ℏ” may be defined as italic in Unicode, that doesn't mean there isn't also a “ħ” symbol. – m93a Feb 05 '20 at 12:24
  • 4
    @campa I remember that the “rationale” for typesetting physical constants in italic type was that their value is bound to change because of better measurements. Of course now this is absurd (it was to begin with, actually), because the speed of light and the Planck constant are defined as *exact* values. – egreg Feb 05 '20 at 13:30
  • @m93a What tex-distribution and documentclass are you using? You can have a look at the package manual on p.14 "Crossed H". I'm not sure if this is what you are looking for. – Nico Feb 05 '20 at 14:27
  • @m93a Make sure that you include \usepackage{tipa} after \documentclass and before \begin{document} e.g. \documentclass{article} \usepackage{tipa} \begin{document} \textcrh \end{document} – Nico Feb 05 '20 at 16:23
  • @Nico In empty document this works fine, but as soon as I add it to the document where I needed ħ, just adding \usepackage{tipa} breaks several existing equations and xelatex refuses to build the document. The equations fail with: Font shape \T3/lmr/m/n' undefined (Font) using `T3/cmr/m/n' instead.` and several other errors. – m93a Feb 05 '20 at 17:08
  • It's unclear why anyone should think "constants should be typeset upright". Also for dimensionless, non-changing constants like Bernoilli numbers or the number pi, or for the infinitesimals dx or dy in an integral this simply isn't what people normally do. Only numerals are usually upright, and abbreviated names when used as subscript or superscript. – Jos Bergervoet Sep 25 '21 at 12:54
  • @JosBergervoet This is not the correct place to discuss this. Use the link provided in my question and find out / express your concern there. – m93a Sep 26 '21 at 16:44

1 Answers1

8

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

campa
  • 31,130
  • 1
    Did you try it in context? You need \mkern-1mu in front of \mathchar. The total amount of backspacing should be 9mu, because that's the width of the bar. – egreg Feb 05 '20 at 13:27
  • @egreg Yes, I did; apparently in my typical use cases no big difference did show up. But of course you are right... – campa Feb 05 '20 at 13:36
  • 3
    The difference is subtle, but noticeable: in this picture the top has a simple h, the middle the \hbar without the \mkern-1mu and the bottom the fixed symbol. – egreg Feb 05 '20 at 13:42
  • I found that in subscripts and superscripts, this macro fails. Doing $A^\hbar$ is enough to reproduce the issue. I have no idea why, though, as the original \hbar works fine… – m93a Feb 08 '20 at 14:38
  • @m93a I've just tried it and it works without problems for me. How does the macro fail? – campa Feb 08 '20 at 14:42
  • Oh my bad. I edited the code to make the bar appear lower and than forgot about it. Your code works great. This is quite embarrassing, sorry to waste your time ️. In my code I used \raisebox which didn't work properly in the superscript. Do you have any idea how to lower the bar without breaking the superscripts? Thanks! :) – m93a Feb 08 '20 at 15:30
  • 1
    @m93a See edit. – campa Feb 08 '20 at 15:46