latex3 / fontspec

Font selection in LaTeX for XeTeX and LuaTeX
http://latex3.github.io/fontspec/
LaTeX Project Public License v1.3c
276 stars 33 forks source link

Cannot select font by family name and subfamily in xelatex #410

Closed callegar closed 4 years ago

callegar commented 4 years ago

Description

According to the documentation, fontspec should let fonts be specified both by family name and by filename, either on lualatex and xelatex. Apparently, specifying fonts by postscript name also works.

However, in xelatex there is an issue when a font is available in different subfamilies (e.g., bold, italic) in different files, as it is often the case, and you want to specify the font by family and subfamily name.

For instance, the following snippet works in lualatex, but not on xelatex:

\setmainfont{Linux Libertine O}[Ligatures=TeX,
  ItalicFont={TeX Gyre Pagella Italic}]

Apparently, there is no way to tell xelatex that you want the "Italic" version of Gyre Pagella if you prefer specifying the font by name. Setting ItalicFont={TeX Gyre Pagella} works but obviously does not give you an italic font.

Interestingly, specifying the font by postscript name as

\setmainfont{Linux Libertine O}[Ligatures=TeX,
  ItalicFont={TeXGyrePagella-Italic}]

works. Yet, it seems to me that the more "abstract" the naming the better for compatibility and portability reasons (e.g, when a font is to be instantiated in a class file to be used on different systems and setups).

Check/indicate

Minimal example demonstrating the issue

See above

Further details

Seen on Linux (kubuntu 19.10 with TexLive 2019 - the upstream one, not the ubuntu packaged one - kept up to date with tlmgr).

zauguin commented 4 years ago

Your observation that this "works" in LuaTeX is a bit misleading: LuaTeX is just very permissive when it comes to matching font names, so as far as LuaTeX (or actually luaotfload) is concerned, TeX Gyre Pagella Italic and TeXGyrePagella-Italic are exactly the same. Neither of these split the name into family and subfamily.

Also I think this is actually a font bug: Normally a font should contain a full font name which is supposed to be a combination of the fontfamily and the subfamily, so in your case "TeX Gyre Pagella Italic". This is the field used for matching a specific font but for TeX Gyre Pagella Italic this field just contains a copy of the postscript name "TeXGyrePagella-Italic".

Anyway, if you want to select a font by family name and choose the italic subfont, you can always use /I:

\setmainfont{Linux Libertine O}[Ligatures=TeX,
 ItalicFont={TeX Gyre Pagella/I}]
callegar commented 4 years ago

Ah, that was exactly what I was looking for!

callegar commented 4 years ago

Incidentally, where are the /I, etc. documented? I have also seen a /OT in a font trace and I cannot understand where it comes from and what it means.

wspr commented 4 years ago

From memory I believe xetexref.pdf and luaotfload.pdf (resp.) contain information about /I /B /OT and so on.