Font selection by "family name" not working with unicode-math and xelatex
Description
A sentence or two describing the issue.
Trying to set the math font to "TeX Gyre Termes Math" with unicode math and xelatex does not work.
Fontspec/unicode-math end up finding a font, but pick the wrong one, then say the font has no Math script, and discard it. Most likely they end up with "TeX Gyre Termes", but I do not know how to see what the code does internally.
Check/indicate
- [X] Relevant for XeTeX
- [ ] Relevant for LuaTeX
- [X] Issue tracker has been searched for similar issues?
- [ ] Links to <tex.stackexchange.com> discussion if appropriate
Minimal example demonstrating the issue
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Termes}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
$x$
\end{document}
Further details
On my system the TeX Gyre Termes Math font gets resolved correctly by fc-match "TeX Gyre Termes Math" as texgyretermes-math.otf.
Lualatex has no issue either.
well xelatex finds TeXGyreTermesMath-Companion.otf in \fonts\opentype\public\context-companion-fonts
first (probably because it sets Preferred family: TeX Gyre Termes Math).
Imho there is not much fontspec can do. Use the filename instead. Or exclude that font from the search in fontconfig.
Thanks for looking into it. So "TeXGyreTermesMath-Companion.otf" is not a math font despite its name?
@u-fischer
(probably because it sets Preferred family: TeX Gyre Termes Math)
isn't that a bug in the font though?, all the other internal names are variants on TeX Gyre Termes Math Companion
@callegar if I hide /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/context-companion-fonts/TeXGyreTermesMath-Companion.otf then your document works with no warnings in xetex
All this looks a bit weird. My though was that TeXGyreTermesMath-Companion.otf was the same as texgyretermes-math.otf that had to be made available under a different name to make context happy. If it is not, then it should definitely get the "preferred family" to a different name, otherwise this is just looking for trouble. In addition to that, TeXLive should probably not make it part of the `collection-fontextra" if it is something for context only that shadows other packages.
No the font is obviously not a math font. You can also try \setmathfont{TeXGyreTermesMath-Regular}. That seems to find the right font. (It is odd that xetex finds the other one, but I doubt that someone will correct that).
This looks like incorrect font meta data, TeXGyreTermesMath-Companion.otf set name ID 16 (Typographic Family name) to “TeX Gyre Termes Math” and name ID 17 (Typographic Subfamily name) to “Regular”, so it is not unreasonable for XeTeX to pick it when the document asks for “TeX Gyre Termes Math” font.
Running fc-scan (from FontConfig) on the font, returns the following (including only naming relating info for brevity):
$ fc-scan TeXGyreTermesMath-Companion.otf
Pattern has 28 elts (size 32)
family: "TeX Gyre Termes Math"(s) "TeX Gyre Termes Math Companion"(s)
familylang: "en"(s) "en"(s)
style: "Regular"(s) "Companion"(s)
stylelang: "en"(s) "en"(s)
fullname: "TeXGyreTermesMath-Companion"(s)
fullnamelang: "en"(s)
postscriptname: "TeXGyreTermesMath-Companion"(s)
So FontConfig is giving also priority to the typographic family and subfamily (as it should), so it is likely if the font is installed system-wide many other applications might pick it for “TeX Gyre Termes Math”.
macOS is also confused by the font names. Using ftxinstalledfonts (from Apple Font Tool Suite), both fonts report the same family name and style (subfamily) name:
$ ftxinstalledfonts -f -M -s | grep TeX
680 TeXGyreTermesMath-Regular TeX Gyre Termes Math Regular
2012 TeXGyreTermesMath-Companion TeX Gyre Termes Math Regular
I've went back and tested and it looks like this issue has been present since around June 30th.
One solution that seems to fix this is blacklisting the companion fonts with fontconfig:
<!-- $TEXMFSYSVAR/fonts/conf/texlive-fontconfig.conf -->
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/usr/local/texlive/2024/texmf-dist/fonts/opentype</dir>
<dir>/usr/local/texlive/2024/texmf-dist/fonts/truetype</dir>
<dir>/usr/local/texlive/2024/texmf-dist/fonts/type1</dir>
<selectfont>
<rejectfont>
<pattern>
<patelt name="style">
<string>Companion</string>
</patelt>
</pattern>
</rejectfont>
</selectfont>
</fontconfig>
But if this is a problem with the fonts themselves, then we should probably get this fixed upstream (which I think is @mpsmath and @hanshagen). Even if the fonts are correct and it's XeTeX that is wrong, it's going to be much easier to change the fonts than to change XeTeX.
@gucci-on-fleek We were about to fix the lookup issue in Xe(La)TeX, but maybe changing a few names is less work.
Thanks everybody for looking into this so promptly, both here and in the texlive ml!
I’d keep name ID 1 as it is, change name ID 2 to Regular, and drop name IDs 16 and 17 as they are not needed at all.
I’d keep name ID 1 as it is, change name ID 2 to Regular, and drop name IDs 16 and 17 as they are not needed at all.
That is more or less what happened.
@mpsmath
I’d keep name ID 1 as it is, change name ID 2 to Regular, and drop name IDs 16 and 17 as they are not needed at all.
That is more or less what happened.
Ok, I uploaded the files from contextgarden/context-distribution-fonts@5131d698b6818332e0de75202789b0b13ee7286b in r72732, so it should make it in tomorrow's update. Hopefully those were the correct files since I didn't test it before I committed it.
(Long-term, it would probably be good for you/Hans/Mojca to add the files to CTAN so that the update process is slightly less manual, although it doesn't really matter too much either way if the updates are infrequent.)
@mpsmath
I’d keep name ID 1 as it is, change name ID 2 to Regular, and drop name IDs 16 and 17 as they are not needed at all.
That is more or less what happened.
Ok, I uploaded the files from contextgarden/context-distribution-fonts@5131d69 in
r72732, so it should make it in tomorrow's update. Hopefully those were the correct files since I didn't test it before I committed it.(Long-term, it would probably be good for you/Hans/Mojca to add the files to CTAN so that the update process is slightly less manual, although it doesn't really matter too much either way if the updates are infrequent.)
Well, the files now have slightly different names, so I'm afraid you will break ConTeXt in TL24 if the fonts are replaced without also changing configuration files.
@mpsmath
Well, the files now have slightly different names, so I'm afraid you will break ConTeXt in TL24 if the fonts are replaced without also changing configuration files.
Uhhhh, so should I rename those files to what they were called before, or should I pull in the .lfg goodie files from the current LMTX upstream?
(cc: @kberry)
@mpsmath
Well, the files now have slightly different names, so I'm afraid you will break ConTeXt in TL24 if the fonts are replaced without also changing configuration files.
Uhhhh, so should I rename those files to what they were called before, or should I pull in the
.lfggoodie files from the current LMTX upstream?(cc: @kberry)
I don't know what the procedures are for TeXLive, but I had sent an email to Karl explaining the situation. Maybe it is best to undo the upload and wait for Karl to wake up?
Since the problem will go away with TL25, my gut reaction is to revert back to the original companion fonts so ctx keeps working, and let xelatex people live with it. As I understood it, it is not that hard to use one of the other names that does not clash and still get Termes Math if desired. --thanks, karl.
Ok, I updated the font goodie files in TL to the versions from the LMTX upstream in r72745 and it seems to be working properly:
[...]
system > ConTeXt ver: 2024.02.27 09:18 LMTX fmt: 2024.6.29 int: english/english
[...]
fonts > 'fallback modern rm 12pt' is loaded
open source > level 2, order 4, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-texgyre.mkiv'
close source > level 2, order 4, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-texgyre.mkiv'
pages > flushing realpage 1, userpage 1, subpage 1
open source > level 2, order 5, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-dejavu.mkiv'
close source > level 2, order 5, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-dejavu.mkiv'
open source > level 2, order 6, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-libertinus.mkiv'
close source > level 2, order 6, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-libertinus.mkiv'
mathematics > tweak > 'LibertinusMath-Regular', size 7.20007, math size 3, version 'Version 7.051;RELEASE' found, version 'Version 7.040' expected
open source > level 2, order 7, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-plex.mkiv'
open source > level 3, order 8, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-texgyre.mkiv'
close source > level 3, order 8, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-texgyre.mkiv'
close source > level 2, order 8, name '/home/mseven/texlive/trunk/Master/texmf-dist/tex/context/fonts/mkiv/type-imp-plex.mkiv'
[...]
mkiv lua stats > loaded fonts: 84 files: ibmplexmono-italic.otf, ibmplexmono-medium.otf, ibmplexmono-mediumitalic.otf, ibmplexmon
o-regular.otf, ibmplexsans-italic.otf, ibmplexsans-medium.otf, ibmplexsans-mediumitalic.otf, ibmplexsans-regular.otf, ibmplexserif
-italic.otf, ibmplexserif-medium.otf, ibmplexserif-mediumitalic.otf, ibmplexserif-regular.otf, latinmodernmathcompanion-regular.ot
f, texgyrebonummathcompanion-regular.otf, texgyrepagellamathcompanion-regular.otf, texgyretermesmathcompanion-regular.otf, liberti
nusmath-regular.otf, libertinusmono-regular.otf, libertinussans-bold.otf, libertinussans-italic.otf, libertinussans-regular.otf, l
ibertinusserif-bold.otf, libertinusserif-bolditalic.otf, libertinusserif-italic.otf, libertinusserif-regular.otf, latinmodern-math
.otf, lmmono10-italic.otf, lmmono10-regular.otf, lmmonolt10-bold.otf, lmmonolt10-boldoblique.otf, lmroman10-bold.otf, lmroman10-bo
lditalic.otf, lmroman10-italic.otf, lmroman10-regular.otf, lmsans10-bold.otf, lmsans10-boldoblique.otf, lmsans10-oblique.otf, lmsa
ns10-regular.otf, texgyrebonum-math.otf, texgyredejavu-math.otf, texgyrepagella-math.otf, texgyreschola-math.otf, texgyretermes-ma
th.otf, texgyreadventor-bold.otf, texgyreadventor-bolditalic.otf, texgyreadventor-italic.otf, texgyreadventor-regular.otf, texgyre
bonum-bold.otf, texgyrebonum-bolditalic.otf, texgyrebonum-italic.otf, texgyrebonum-regular.otf, texgyrechorus-mediumitalic.otf, te
xgyrecursor-bold.otf, texgyrecursor-bolditalic.otf, texgyrecursor-italic.otf, texgyrecursor-regular.otf, texgyreheros-bold.otf, te
xgyreheros-bolditalic.otf, texgyreheros-italic.otf, texgyreheros-regular.otf, texgyrepagella-bold.otf, texgyrepagella-bolditalic.o
tf, texgyrepagella-italic.otf, texgyrepagella-regular.otf, texgyreschola-bold.otf, texgyreschola-bolditalic.otf, texgyreschola-ita
lic.otf, texgyreschola-regular.otf, texgyretermes-bold.otf, texgyretermes-bolditalic.otf, texgyretermes-italic.otf, texgyretermes-
regular.otf, dejavusans-bold.ttf, dejavusans-boldoblique.ttf, dejavusans-oblique.ttf, dejavusans.ttf, dejavusansmono-bold.ttf, dej
avusansmono-boldoblique.ttf, dejavusansmono-oblique.ttf, dejavusansmono.ttf, dejavuserif-bold.ttf, dejavuserif-bolditalic.ttf, dej
avuserif-italic.ttf, dejavuserif.ttf
mkiv lua stats > font engine: otf 3.140, afm 1.540, tfm 1.000, 171 instances, 74 shared in backend, 26 common vectors, 48 common
hashes, load time 1.602 seconds
mkiv lua stats > math tweaking time: 0.474 seconds, 116 math goodie tables
mkiv lua stats > font embedding time: 0.085 seconds, 81 fonts
[...]
I use the ConTeXt from TL24 for almost everything, so if something breaks I'll hopefully be the first to notice.
Sounds good to me. I trust you to keep an eye on it :). Thanks.