fontspec icon indicating copy to clipboard operation
fontspec copied to clipboard

Use of full file names (including extension) in .fontspec files

Open bgvoisin opened this issue 3 years ago • 0 comments
trafficstars

Back in 2014 I wrote (with help from Karl Berry) the .fontspec files for the Lucida OpenType fonts from TUG. The use of such files was in its infancy, the functionality was evolving, we had to experiment quite a bit to find a combination of .fontspec file content and .fontspec file name capitalization that seemed to work on several platforms (Mac, Unix).

We ended up with file name lucidabrightot.fontspec and file content

\defaultfontfeatures[LucidaBrightOT] { ExternalLocation, UprightFont = "LucidaBrightOT.otf", BoldFont = "LucidaBrightOT-Demi.otf", ItalicFont = "LucidaBrightOT-Italic.otf", BoldItalicFont = "LucidaBrightOT-DemiItalic.otf", }

So far things were working as intended: using \setmainfont{LucidaBrightOT} the .fonspec file was used, and using \setmainfont{LucidaBrightOT.otf} it wasn't used and the font file LucidaBrightOT.otf was loaded directly instead.

But just recently I encountered two situations where things didn't work any longer:

  • Use (on the Mac) of a TeX GUI (Texpad) that seems to rely on case-insensitive file calls. With TeXShop (the MacTeX default GUI), things are case-sensitive, fontspec interprets (as per its doc) \setmainfont{LucidaBrightOT.otf} as a call for LucidaBrightOT.fonspec, there's only lucidabrightot.fonspec whose case doesn't match, so it isn't used. With Texpad, the call for LucidaBrightOT.fonspec results in lucidabrightot.fonspec being used.

  • lucidabrightot.fontspec in TEXMFHOME and LucidaBrightOT.otf in TEXMFLOCAL. In that case, it seems that \setmainfont{LucidaBrightOT.otf} results in lucidabrightot.fontspec being found first and used.

In both circumstances, the use of lucidabrightot.fontspec with above content, when \setmainfont{LucidaBrightOT.otf} is called, gives an error. With XeLaTeX there's no detail, just

(/Users/brunovoisin/Library/texmf/tex/latex/lucidaot/LucidaBrightOT.fontspec) ./test-lucidaot.tex:7: Package fontspec Error: The font "LucidaBrightOT.otf" cannot be found.

LuaLaTeX's output is more helpful, telling in addition that

luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: File not found: "LucidaBrightOT.otf.otf".

So it seems that calling \setmainfont{LucidaBrightOT.otf} and having an associated .fontspec file containing UprightFont = "LucidaBrightOT.otf" results in LucidaBrightOT.otf.otf being looked for.

In TeX Live 2022, there are (last I looked) 45 built-in .fontspec files. They all specify separately the extension (.otf or .ttf), using Extension, and the file name without extension, using UprightFont etc. This would give here

\defaultfontfeatures[LucidaBrightOT] { Extension = .otf, UprightFont = LucidaBrightOT, BoldFont = LucidaBrightOT-Demi, ItalicFont = LucidaBrightOT-Italic, BoldItalicFont = LucidaBrightOT-DemiItalic, }

The same syntax is used in the example in §2.3 of the fontspec doc.

Does this mean that full file names including extension, like UprightFont = LucidaBrightOT.otf, cannot be used inside .fontspec files, to accomodate for the case when the user specifies a file name with extension, like \setmainfont{LucidaBrightOT.otf}?

Attached is a test archive with files test-algolrevived.tex (AlgolRevived being one of the fonts for which TeX Live includes a .fontspec file) and algolrevived.fontspec modified along the lines above (since Lucida, for which the problem was originally seen, is non-free).

Archive.zip

bgvoisin avatar Jun 21 '22 16:06 bgvoisin