4

As the title suggests, I am trying to use \hbar in conjunction with the mlmodern and amsfonts packages. I need to use the \hbar provided by mlmodern, but when amsfonts is loaded, I get the original CM/LM.

I have tried the following, which results in an undefined control sequence error for $\hbar$:

\documentclass{article}

\usepackage{mlmodern} \let\mlmhbar\hbar

\usepackage{amsfonts} \let\amshbar\hbar

\begin{document}

\def\hbar{\mlmhbar}

$\hbar$

\end{document}

Any advice is appreciated.

1 Answers1

3

You need to use \NewCommandCopy, because \hbar is defined as a robust command.

\documentclass{article}

\usepackage{mlmodern} \NewCommandCopy{\mlmhbar}{\hbar}

\usepackage{amsfonts} \NewCommandCopy{\amshbar}{\hbar}% just for the comparison

\RenewCommandCopy{\hbar}{\mlmhbar}

\begin{document}

$h\hbar$ $h\amshbar$

\end{document}

enter image description here

However, you can see that the bar with MLModern hits the serif of “h”.

\documentclass{article}

\usepackage{mlmodern}

\usepackage{amsfonts} \NewCommandCopy{\amshbar}{\hbar}% just for the comparison

\makeatletter \RenewDocumentCommand{\hbar}{}{% {\mathpalette\hbar@bar\relax\mkern -9muh}% } \newcommand{\hbar@bar}[2]{\raisebox{-0.075\height}{$\m@th#1\mathchar'26$}} \makeatother

\begin{document}

$h\hbar$ $h\amshbar$

$\scriptstyle h\hbar$

\end{document}

enter image description here

egreg
  • 1,121,712