7

With \usepackage{fontspec}, \hbar does not show up correctly. Tested on LaTeX2e <2018-04-01> patch level 5 and fontspec.sty 2018/07/30 vv2.6h.

\documentclass{article}
\usepackage{fontspec}
\begin{document}
[$\hbar$]
\end{document}

With LuaLaTeX: hbar-lualatex

With XeLaTeX:

hbar-xelatex

I found that

  • Adding \usepackage{unicode-math}

or

  • \usepackage[no-math]{fontspec}

can resolve this problem, but I'm not sure which is better.

2 Answers 2

3

The definition of hbar is quite encoding dependant. As fontspec changes the operator font it breaks.

You could redefine it if you don't want to switch to unicode-math:

\documentclass{article}
\usepackage{fontspec}

\begin{document}\pagestyle{empty}

\def\hbar{{\mathchar175\mkern-9muh}}
[$\hbar$]

\def\hbar{\mathit{^^^^0127}}

[$\hbar$]

\end{document}

enter image description here

3
  • Thanks, but why fontspec does not give that kind of redefinition? Accents (\grave, \acute, \bar etc.) are all handled specially so that operators font is always used, according to fontspec-math.dtx... Aug 31, 2018 at 3:37
  • Perhaps Will overlooked it. Open an issue at the github page. Aug 31, 2018 at 6:21
2

The character used for the bar in legacy math fonts has a different code in Unicode.

\documentclass{article}
\usepackage{fontspec}

\renewcommand{\hbar}{{\mathchar"AF\mkern-9mu h}}

\begin{document}

[$h$]

[$\hbar$]

\sbox0{$h$}\the\wd0

\sbox0{$\hbar$}\the\wd0

\end{document}

enter image description here

The difference in width is slightly more than 0.00004 millimeters, less than the difference with pdflatex. The bar is a bit higher, though.

The standard definition for \hbar is

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

and \mathchar'26 refers to the character in slot octal 26 (decimal 22) in math group 0 (the standard text font). This is the same character used for the macron accent, which in OpenType fonts is at slot 0xAF. Depending on the font it can be higher or lower.

Note that Unicode has a special slot for the Planck constants

U+201E PLANCK CONSTANT
U+201F PLANCK CONSTANT OVER TWO PI

and unicode-math will define \hbar to select the latter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .