XeTeX\hbar not resolved

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

\hbar not resolved

Post by netheril96 »

Here is the code

Code: Select all

\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

Code: Select all

\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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

\hbar not resolved

Post by frabjous »

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:

Code: Select all

\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}
Post Reply