latex3 / unicode-math

XeLaTeX/LuaLaTeX package for using unicode/OpenType maths fonts
http://ctan.org/pkg/unicode-math
LaTeX Project Public License v1.3c
243 stars 28 forks source link

'Improper alphabetic constant' under unicode-math and hyperref #402

Closed adunning closed 6 years ago

adunning commented 7 years ago

When creating a \newcommand using the unicode-math (2017/08/02 v0.8f) and hyperref packages, LuaLaTeX or XeLaTeX fail when parsing the command:

\documentclass{article}
\usepackage{unicode-math}
\newcommand{\euro}{€}

\usepackage[unicode=true]{hyperref}

\begin{document}

\hypertarget{section}{
\section{2\euro{}}\label{section}
}

\end{document}

Error:

! Improper alphabetic constant.
<to be read again> 
\euro 
l.11 }

This came up via https://github.com/jgm/pandoc/issues/3801. It works if one writes € directly instead of \euro, but Pandoc wasn't doing that in the past for compatibility with pdfLaTeX.

Oddly, one can avoid the problem under LuaLaTeX but not XeLaTeX by using the bookmark package instead of hyperref.

wspr commented 6 years ago

Yuck. I'm not sure what I can do here. I could just take the euro sign out of unicode-math, but it sounds like people may be relying on it.

At the moment the machinery that defines \euro is pretty deep but it's not set in concrete — I've had thoughts to change it around for quite some time now.

The way to fix this particular problem is just to write

\AtBeginDocument{\renewcommand{\euro}{€}}

instead — is that enough to overcome the problem for the time being?

adunning commented 6 years ago

Thanks for the suggestion! We solved the problem by switching to writing the Unicode euro symbol directly and using the textcomp package to allow compilation with pdfLaTeX, but the alternate approach is good to know about in case it comes up again.

wspr commented 6 years ago

(Sorry for the slow reply, by the way!)

adunning commented 6 years ago

Not at all! Thanks for looking at it!