kks32 / phd-thesis-template

A LaTeX / XeLaTeX / LuaLaTeX PhD thesis template for Cambridge University Engineering Department (CUED)
http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/ThesisStyle/
MIT License
833 stars 400 forks source link

symbol \hbar from amsmath is not working #223

Open AvalasJT opened 3 years ago

AvalasJT commented 3 years ago

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

GR8DAN commented 3 years ago

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.

AvalasJT commented 3 years ago

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

GR8DAN commented 3 years ago

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).

linas commented 10 months ago

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.