1

I am having problems with disappearing kernings when using unicode-math, glossaries and hyperref. This creates a lot of ugly spacings if not corrected somehow. I tried to correct the kerning manually, by adding \mkern2mu to the glossary entry, but this can create ugly spacing at other places There is the optional argument of \gls{}[], that helps with this, but this is only usefull if the following sign belongs to the entry, which is not the case if there is a delimiter following, as in the MWE. This MWE works if unicode-math is not used, hyperref is not used or if xelatex is used instead of lualatex. Is there any way to make it work in lualatex with unicode-math and hyperref?

MWE:

% !TeX program = lualatex

\documentclass{scrartcl}

\usepackage{unicode-math} % Comment out to make it work correctly \usepackage{fontspec} \usepackage[colorlinks]{hyperref}

\usepackage[symbols]{glossaries-extra} % indices \makeglossaries % Glossar erstellen

\newglossaryentry{sym:I}{type = symbols, name = {\ensuremath{I}}, description = {intensity}}

\usepackage{lua-visual-debug} \begin{document} \printsymbols \begin{align} &I(\lambda)|\ &\gls{sym:I}[(]\lambda)|\ &\gls{sym:I}(\lambda)| \end{align} \end{document}

I found a similar question, that may be related, but did not lead me to a solution: Correct kerning of hyperlinks in math mode

Niklas
  • 642
  • 4
  • 13

1 Answers1

1

Kerning is the wrong word. Kerning is something that happens in text mode, not in math. The space you are missing here is the kern from the italic correction after the I. If you compile this

\documentclass{article}
\usepackage{unicode-math}   %
\begin{document}
\showoutput
$I(\lambda)$
\end{document}

and then look in the log you will see

....\mathon
....\TU/latinmodern-math.otf(1)/m/n/10 
....\kern0.85 (italic)
....\TU/latinmodern-math.otf(1)/m/n/10 (

XeTeX inserts this italic kern always, but luatex only if a char follows and so it get lost with all the color and link commands. One option to get around this is to insert a zero width char (U+200D):

\documentclass{scrartcl}

\usepackage{unicode-math} \usepackage{fontspec} \usepackage[colorlinks]{hyperref} \usepackage[symbols]{glossaries-extra} \makeglossaries \newglossaryentry{sym:I} {type = symbols, name = {\ensuremath{I^^^^200d}}, description = {intensity}}

\begin{document} \printsymbols \begin{align} &I(\lambda)|\ &\gls{sym:I}[(]\lambda)|\ &\gls{sym:I}(\lambda)| \end{align} \end{document}

enter image description here

Another (experimental!) option would be to switch to attribute based colors and links. lua-links can be found here: https://github.com/zauguin/lua-links

\DocumentMetadata{} %<-- required, changes also link colors
\documentclass{scrartcl}

\usepackage{unicode-math} \usepackage{fontspec}

\usepackage{luacolor} \usepackage[discard,tightH,tightV,unbox]{lua-links}

\usepackage[colorlinks]{hyperref} \usepackage[symbols]{glossaries-extra} \makeglossaries \newglossaryentry{sym:I} {type = symbols, name = {\ensuremath{I}}, description = {intensity}}

\begin{document} \printsymbols \begin{align} &I(\lambda)|\ &\gls{sym:I}[(]\lambda)|\ &\gls{sym:I}(\lambda)| \end{align} \end{document}

Ulrike Fischer
  • 327,261
  • Thanks Ulrike! If this is a fundamental problem, there is no (stable) automatic solution currently. Adding the zero width character does not help because sometimes, the italic correction is omitted, for example for subscripts. Then I need to manually do the decision to add the kern or not. – Niklas Dec 06 '23 at 12:08