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

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

Closed bgvoisin closed 4 months ago

bgvoisin commented 2 years ago

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:

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

wspr commented 5 months ago

Sorry for the slow response. I have made some changes to this code recently and will release to CTAN shortly. When that happens would you be able to re-test?

bgvoisin commented 5 months ago

Hi Will,

Glad to see you back, and kicking! Yes, of course I'll test.

I must say I had completely forgotten about the issue. Looking back at it, I can't even understand my own prose. As usual, things exposed in the most convoluted possible way! I'll look closer, to see what was the matter.

Bruno

On 27 Apr 2024, at 10:45, Will Robertson @.***> wrote:

Sorry for the slow response. I have made some changes to this code recently and will release to CTAN shortly. When that happens would you be able to re-test?

— Reply to this email directly, view it on GitHub https://github.com/latex3/fontspec/issues/472#issuecomment-2080419347, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQBADYUWCW4FEAZN7K44E3Y7NQS7AVCNFSM5ZM52W22U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBYGA2DCOJTGQ3Q. You are receiving this because you authored the thread.

wspr commented 5 months ago

@bgvoisin — and I'm very happy to hear from you in return! Academic life is still keeping me overly busy... it's a bit of a long story but all in all things are going well enough down here.

I've just uploaded an update to CTAN, should see it in a couple days I expect...

bgvoisin commented 5 months ago

The update (2.9b) seems to solve the issue, at leat on the Mac.

Namely, having a file lucidabrightot.fontspec say containing

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

and then calling the font with either of

\setmainfont{LucidaBrightOT}
\setmainfont{LucidaBrightOT.otf}

works just the same: the font LucidaBrightOT.otf is used successfully. Previously, the second form, \setmainfont{LucidaBrightOT.otf}, resulted in a call for LucidaBrightOT.otf.otf hence a fail.

Thanks!

wspr commented 4 months ago

I'll close this one for now but aware that there are / might be other potential bugs that have resulted from the changes made!