phd-thesis-template icon indicating copy to clipboard operation
phd-thesis-template copied to clipboard

symbol \hbar from amsmath is not working

Open AvalasJT opened this issue 3 years ago • 4 comments

Hi everyone,

I've got a strange error when I use "\hbar" in my equations. While compiling I get the error message "Undefined control sequence. [..] \hbar"

amsmath, amsfonts and amssymb are all included as far as I can tell.

The same equations are working with "\hslash" instead of "\hbar" but it looks slightly different.

Although I get the "undefined control sequence"-error I can't define a new command \hbar: "\newcommand{\hbar} {\mathchar'26\mkern-7.5mu h}" results in an error: "Command \hbar already defined. ...ommand{\hbar} {\mathchar'26\mkern-7.5mu h}"

Does anyone know how to solve that issu or had simmilar problems? Thanks and cheers, Jonas

AvalasJT avatar Jun 30 '21 13:06 AvalasJT

Seems the error does not occur with XeLaTeX, though the \hbar looks like \hslash.

Alternatively, if you comment out \pdfglyphtounicode{hbar}{0127} at line 2086 in the file glyphtounicode.tex the error does not appear, but \hbar again looks like \hslash.

Why \hbar looks like \hslash has been pointed out before, with both being assigned to U+210F instead of \hbar being set to something like U+0127, which is empty in some fonts, or the almost identical U+045B.

Looks like another package is be redefining \hbar. If you use \show\hbar the log file displays hbar=\protected macro: ->\hslash, even though amssymb has \hbar and \hslash as being different.

GR8DAN avatar Jul 09 '21 17:07 GR8DAN

Dear GR8DAN,

thanks for your answer! Actually I already tried to comment out line 2086 in the glyphtounicode.tex file but that didn't change anything for me. I will check again, if I changed by accident the file in my template folder instead of my thesis folder or something like that.

But as that also doesn't change the appearance of \hbar here is a workaround I found in the meantime which seems to be working for me: In the main tex file you can use \renewcommand{\hbar}{\mathchar'26\mkern-9mu h} to get the \hbar back again. The command has to be placed within the \begin{document} block.

Best wishes, Jonas

AvalasJT avatar Jul 10 '21 09:07 AvalasJT

Thanks Your suggestion (\renewcommand{\hbar}{\mathchar'26\mkern-9mu h}) did't work in my LaTeX environment (Overleaf), though \def\hbar{\mathit{^^^^0127}} did (from https://tex.stackexchange.com/questions/448490/hbar-not-displayed-with-fontspec-on-xelatex-lualatex).

GR8DAN avatar Jul 11 '21 23:07 GR8DAN

FWIW, I'm seeing a variant of this from within LyX. Haven't tracked down the details. Same document worked great 3-4 years ago; I just tried to reexport to PDF and boom, it fails.

linas avatar Jan 20 '24 05:01 linas