3

I am using XeLaTeX with the packages fontspec,xunicode,xlxtra (which I believe is pretty standard) to process my documents into a PDF file with the TeX Gyre Pagella font.

I have been doing so successfully for quite some time, but when using the standard LaTeX symbol \hbar, upon processing an error is thrown

LaTeX Warning: Command \hbar invalid in math mode on input line 86

and the symbol appears instead as a regular "h" which partially overlaps with the previous character.

Here is a minimal code example:

\documentclass{article}     
\usepackage{fontspec,xunicode,xltxtra}  
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{TeX Gyre Pagella}
\begin{document}
hbar by itself:  $\hbar$\\
hbar with a preceeding character:   $o\hbar$
\end{document}
2
  • Can you give a minimal example of code?
    – egreg
    Jan 23, 2012 at 15:17
  • Minimal code added; thanks for the reminder. Jan 23, 2012 at 15:23

2 Answers 2

3

It seems to be a bug with xunicode.

Mixing Computer Modern Math with Pagella (Palatino) is not a good choice (but this is not related to the problem).

\documentclass{article}
\usepackage{mathpazo} % get Palatino math  
\usepackage{fontspec} % xunicode is not needed, nor xltxtra
\defaultfontfeatures{Ligatures=TeX} % syntax compatible with LuaLaTeX
\setmainfont{TeX Gyre Pagella}

% Magic formula for make \hbar not throwing a spurious message
% However, \hbar won't work in text mode, which should not be a problem
\expandafter\let\expandafter\hbar\csname ?-\string\hbar\endcsname
% End of magic code

\begin{document}
hbar by itself:  $\hbar$\\
hbar with a preceeding character:   $o\hbar$
\end{document}
2
  • Thanks! It turns out that you do need the Palatino math font in order to get the \hbar to work. (Commenting out \usepackage{mathpazo} breaks that \hbar) Jan 23, 2012 at 17:26
  • @WilliamKennerly You have to call fontspec with the option no-math, I believe, if mathpazo is not loaded.
    – egreg
    Jan 23, 2012 at 17:31
0

You can put \newcommand{\hbarhorizline}{\mathchar'26\mkern-7mu h} in preamble and then used this new command \hbarhorizline in the formulas. If one has in the formula any symbol directly before it, then one needs to add space before \hbarhorizline to avoid overlap in this way $G\ \hbarhorizline$.

You must log in to answer this question.

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