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

Postby netheril96 » Sun Oct 10, 2010 3:32 pm

Here is the code
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage{amsmath}
  3. \usepackage[cm-default]{fontspec}
  4. \usepackage{xunicode}
  5. \usepackage{xltxtra}
  6. \begin{document}
  7.  
  8. \begin{equation}
  9. \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
  10. \end{equation}
  11.  
  12. \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
  1. \usepackage[cm-default]{fontspec}
  2. \usepackage{xunicode}
  3. \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

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Postby frabjous » Sun Oct 10, 2010 4:04 pm

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:

  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage{amsmath}
  3. \newsavebox{\myhbar}
  4. \savebox{\myhbar}{$\hbar$}
  5. \usepackage[cm-default]{fontspec}
  6. \usepackage{xltxtra}
  7. \usepackage{xunicode}
  8. \renewcommand*{\hbar}{\mathalpha{\usebox{\myhbar}}}
  9. \begin{document}
  10.  
  11. \begin{equation}
  12. \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
  13. \end{equation}
  14.  
  15. \end{document}


Return to “XeTeX”

Who is online

Users browsing this forum: No registered users and 1 guest