## LaTeX forum ⇒ XeTeX ⇒ \hbar not resolved

Information and discussion about XeTeX, an alternative for pdfTeX based on e-Tex
netheril96
Posts: 10
Joined: Wed Sep 22, 2010 5:03 am

### \hbar not resolved

Here is the code
\documentclass[11pt,a4paper]{article}\usepackage{amsmath}\usepackage[cm-default]{fontspec}\usepackage{xunicode}\usepackage{xltxtra}\begin{document} \begin{equation}\Delta E=-\vec{\mu}_J\cdot\vec{B}=g\frac{e}{2m_e}\vec{P}_J\cdot\vec{B}=Mg\hbar\frac{e}{2m_e}B=Mg\mu_BB\end{equation} \end{document}

When running XeLaTeX, the log file says "LaTeX Warning: Command \hbar invalid in math mode on input line 9" and \hbar becomes normal h.

If I delete
\usepackage[cm-default]{fontspec}\usepackage{xunicode}\usepackage{xltxtra}

it will resolve normally.

Any way to solve this? I am using XeLaTeX because I need to deal with Chinese characters.
Thank you

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Looks like a bug to me. Perhaps it ought to be reported to the xetex mailing list. Anyway, in the meantime you could try something like this as a workaround:

\documentclass[11pt,a4paper]{article}\usepackage{amsmath}\newsavebox{\myhbar}\savebox{\myhbar}{$\hbar$}\usepackage[cm-default]{fontspec}\usepackage{xltxtra}\usepackage{xunicode}\renewcommand*{\hbar}{\mathalpha{\usebox{\myhbar}}}\begin{document} \begin{equation}     \Delta E=-\vec{\mu}_J\cdot\vec{B}=g\frac{e}{2m_e}\vec{P}_J\cdot\vec{B}=Mg\hbar\frac{e}{2m_e}B=Mg\mu_BB\end{equation} \end{document}