latex3 / unicode-math

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

Cannot resolve font by name in xelatex #643

Open callegar opened 3 weeks ago

callegar commented 3 weeks ago

Description

In unicode engines it should be possible to resolve fonts both by name (e.g. "TeX Gyre Termes") or by filename (e.g. "latinmodern-math.otf).

Unfortunately, this is broken for math fonts when using unicode-math in combination with xelatex.

In the template for providing a minimal test case you say "filename only please", but selection by "preferred family name" should work too, and works just fine with LuaLaTeX.

Add info or delete as appropriate:

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Termes}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
$x$
\end{document}

In this case, when it comes to resolve TeX Gyre Termes Math, fontspec/unicode-math happily get something else (most likely TeX Gyre Termes), complaints that the font does not have the Math Script, and goes on typesetting math using Latin Modern Math.

However, on my system resolving TeX Gyre Termes Math is fine:

fc-match "TeX Gyre Termes Math"
texgyretermes-math.otf: "TeX Gyre Termes Math" "Regular"

The main issue here is not that the font is not found. It is that fontspec/unicode-math believe that they have found a font, yet getting the wrong one.

Unclear to me if the issue is with fontspec or unicode-math or xetex itself, though.

Further details

hvoss49 commented 3 weeks ago

XeTeX finds fonts by symbolic name only for system fonts and not the one from the TeX distribution. You can set a link from the system fonts to the TeX fonts, e.g. for macOS in ~/Library/Fonts

ln -s /usr/local/texlive/2024/texmf-dist/fonts/opentype/ ~/Library/Fonts/tl-opentype

with updating the font catalog with fc-cache -v -f it will find the font by symbolic name. LuaTeX is different, because it handles the font search by an own font list for system and TeX fonts.