latex3 / unicode-math

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

problem with mode=base in math alphabets with ligatures #461

Open u-fischer opened 6 years ago

u-fischer commented 6 years ago

Description

luatex fails for some font/char combination when math alphabets are defined with mode=base with the error

! error:  (nodes): attempt to double-free math_char node 100245,

Check/indicate

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfontface\mathtestbase{STIX Two Text}[Renderer=Basic]
\setmathfontface\mathtestnode{STIX Two Text}% mode = node
\begin{document}
%fails with `! error:  (nodes): attempt to double-free math_char node 100245,`
 $\mathrm{fh^{-1}}$  %from siunitx \fento\barn
 $\mathtestbase{fh^{-1}}$ 

% works:
% $\mathtestbase{{fh}^{-1}}$
% $\mathtestnode{fh^{-1}}$

\end{document}

Further details

I came across this error from https://github.com/khaledhosny/libertinus/issues/166 and pulled it down to the example above. The error is triggered by the following conditions:

  1. a math alphabet is defined with mode=base
  2. a ligature (fh here)
  3. some math following the ligature inside the argument (\mathrm{fh\int} fails too).

The underlying problem is probably in the fontloader and I will ask on the context list. But for unicode-math the question is why the "automatically" defined math alphabets like \mathrm are setup with Renderer=Basic while \setmathfontface uses node mode.

wspr commented 6 years ago

Thanks Ulrike — the answer to your ultimate question is easy: a complete oversight. Things might have changed here since these defaults were first set up. Are you implying that removing the default of Renderer=Basic would be okay? (My original understanding was that mode=node wouldn't work for a maths font but I forget the reasons/context.) I could also load more than one maths font with the different mode setups if necessary.

u-fischer commented 6 years ago

Hans wrote on the context list that after an investigation he and Luigi "found a possible issue with the lig builder part". So probably the underlying problem will be gone someday.

I have no idea if a \mathXX font should better use mode=node or mode=basic (and if it matters). But I asked on the context list.

u-fischer commented 6 years ago

I found the reason why the mode matters: ligatures and kerning

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfontface\mathtestbase{STIX Two Text}[Renderer=Basic]
\setmathfontface\mathtestnode{STIX Two Text}% mode = node
\begin{document}

$\mathtestnode{VA fin}$   (node mode)

$\mathtestbase{VA fin}$   (base mode)

\end{document}

image

See also https://tex.stackexchange.com/questions/252493/ligatures-are-not-used-in-opentype-maths-families