latex3 / fontspec

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

With `fontspec` 2.9b, a font is wrongly claimed to be not found #510

Closed dbitouze closed 6 months ago

dbitouze commented 6 months ago

Description

With fontspec 2.9b, a font is wrongly claimed to be not found.

Check/indicate

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{fontspec}
\setmonofont{FiraCode-Regular.ttf}[ItalicFont= FiraCode-RegularItalic.otf]
\begin{document}
Foo
\end{document}

Further details

With fontspec:

BTW, with fontspec 2.9b, the following MCE:

\documentclass{article}
\usepackage{fontspec}
\setmonofont{FiraCode-Regular.ttf}
\begin{document}
Foo
\end{document}
u-fischer commented 6 months ago

Where did you get the fonts? There is no FiraCode-Regular.ttf in texlive, and at https://github.com/tonsky/FiraCode I only find ttf-files and no FiraCode-RegularItalic.otf

After I installed the firacode fonts (in my system), \setmonofont{FiraCode-Regular.ttf} worked fine for me with lualatex and xelatex.

dbitouze commented 6 months ago

Where did you get the fonts? There is no FiraCode-Regular.ttf in texlive, and at https://github.com/tonsky/FiraCode I only find ttf-files and no FiraCode-RegularItalic.otf

A friend gave them to me. But I guess they come from this repository.

After I installed the firacode fonts (in my system), \setmonofont{FiraCode-Regular.ttf} worked fine for me with lualatex and xelatex.

Strange! My system is GNU/Linux Mageia 9 with a vanilla install of TeX Live 2024. And:

$ fc-list | grep FiraCode-Regular
/usr/share/fonts/drakfont/Type1/FiraCode-Regular.pfb: Fira Code:style=Regular
/usr/share/fonts/drakfont/ttf/FiraCode-Regular.ttf: Fira Code:style=Regular
/usr/share/fonts/drakfont/otf/FiraCode-RegularItalic.otf: Fira Code:style=Regular Italic,Italic
wspr commented 6 months ago

I thought this might be a bug with mixing ttf and otf extensions in the same font family call, but this seems to work for me:

\documentclass{article}
\usepackage{fontspec}
\setmonofont{Ysabeau-Regular.otf}[ItalicFont=Lato-Regular.ttf]
\begin{document}
\ttfamily
Foo
\itshape
Foo
\end{document}

At the moment I am thinking this might not be a fontspec issue, so I'll close this issue now to avoid it lingering -- but let me know if you can find another example.

dbitouze commented 6 months ago

At the moment I am thinking this might not be a fontspec issue, so I'll close this issue now to avoid it lingering -- but let me know if you can find another example.

But isn't it a bug of fontspec that the following MCE doesn't compile with xelatex?

\documentclass{article}
\usepackage{fontspec}
\setmonofont{FiraCode-Regular.ttf}
\begin{document}
Foo
\end{document}
u-fischer commented 6 months ago

But isn't it a bug of fontspec that the following MCE doesn't compile with xelatex?

It compiles fine for me. But you can test if it is a problem with fontspec or your font installation by compiling without fontspec:

\documentclass{article}
\begin{document}
\font\test="[FiraCode-Regular.ttf]/OT:script=latn;language=dflt;" \test blub
\end{document}
dbitouze commented 6 months ago

@u-fischer Thanks for the useful hint. Indeed, this MCE:

! Font \test=[FiraCode-Regular.ttf]/OT:script=latn;language=dflt; not loadable:
 Metric (TFM) file or installed font not found.
<to be read again> 
                   \test 
l.3 ...r.ttf]/OT:script=latn;language=dflt;" \test
                                                   blub
? H
I wasn't able to read the size data for this font,
so I will ignore the font specification.
[Wizards can fix TFM files using TFtoPL/PLtoTF.]
You might try inserting a different font spec;
e.g., type `I\font<same font id>=<substitute font name>'.

? 
Missing character: There is no b ("62) in font nullfont!
Missing character: There is no l ("6C) in font nullfont!
Missing character: There is no u ("75) in font nullfont!
Missing character: There is no b ("62) in font nullfont!
dbitouze commented 6 months ago

Another example:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}[
Extension      =.otf,
UprightFont    = *-Regular,
BoldFont       = *-Bold,
ItalicFont     = *-Italic,
BoldItalicFont = *-BoldItalic,
]
\begin{document}
Test
\end{document}

which:

! Package fontspec Error: (fontspec) The font "TeX Gyre Pagella-Regular" cannot be (fontspec) found; this may be but usually is not a fontspec (fontspec) bug. Either there is a typo in the font name/file, (fontspec) the font is not installed (correctly), or there is (fontspec) a bug in the underlying font loading engine (fontspec) (XeTeX/luaotfload).

In both case:

$ fc-list | rg Pagella | rg otf /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/tex-gyre/texgyrepagella-bolditalic.otf: TeX Gyre Pagella:style=Bold Italic /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/tex-gyre/texgyrepagella-italic.otf: TeX Gyre Pagella:style=Italic /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/newpx/TeXGyrePagellaX-Slanted.otf: TeX Gyre PagellaX:style=Slanted /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/newpx/TeXGyrePagellaX-Regular.otf: TeX Gyre PagellaX:style=Regular /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/newpx/TeXGyrePagellaX-BoldItalic.otf: TeX Gyre PagellaX:style=Bold Italic /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/newpx/TeXGyrePagellaX-Italic.otf: TeX Gyre PagellaX:style=Italic /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/newpx/TeXGyrePagellaX-BoldSlanted.otf: TeX Gyre PagellaX:style=BoldSlanted /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/newpx/TeXGyrePagellaX-Bold.otf: TeX Gyre PagellaX:style=Bold /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/aesupp/aepagella-italic.otf: AePagella:style=Italic /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/aesupp/aepagella-bolditalic.otf: AePagella:style=BoldItalic /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/tex-gyre/texgyrepagella-bold.otf: TeX Gyre Pagella:style=Bold /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/tex-gyre-math/texgyrepagella-math.otf: TeX Gyre Pagella Math:style=Regular /usr/local/texlive/2024/texmf-dist/fonts/opentype/public/tex-gyre/texgyrepagella-regular.otf: TeX Gyre Pagella:style=Regular

wspr commented 6 months ago

@dbitouze — I don't understand this example. The * notation is intended to copy the first argument into the subsequent arguments, and the Extension notation is to add .otf to them. So it seems correct that fontspec would be looking for:

And it also seems correct that it couldn't find these fonts using those filenames. How this ever worked I'm not too sure, but it was surely a mis-feature.

dbitouze commented 6 months ago

@wspr OK, thanks: removing the Extension = .otf option makes it work. Nevertheless, another example which used to work and that doesn't work anymore:

\documentclass{article}
\usepackage{fontspec}
\setmonofont{GoMono}[
UprightFont    = *-Regular,
BoldFont       = *-Bold,
ItalicFont     = *-Regular-Italic,
BoldItalicFont = *-Bold-Italic,
]
\begin{document}
\ttfamily
Test
\textbf{Test}
\textit{Test}
\textbf{\textit{Test}}
\end{document}

(“luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: Font "GoMono-Regular" not found.”), despite:

$ fc-list | rg GoMono | rg tf
/usr/local/texlive/2024/texmf-dist/fonts/truetype/bh/gofonts/GoMono-Regular.ttf: Go Mono:style=Regular
/usr/local/texlive/2024/texmf-dist/fonts/truetype/bh/gofonts/GoMono-Bold-Italic.ttf: Go Mono:style=Bold Italic
/usr/local/texlive/2024/texmf-dist/fonts/truetype/bh/gofonts/GoMono-Regular-Italic.ttf: Go Mono:style=Italic
/usr/local/texlive/2024/texmf-dist/fonts/truetype/bh/gofonts/GoMono-Bold.ttf: Go Mono:style=Bold

OK, the expected result is obtained with just \setmonofont{GoMono} (without the options specifying the UprightFont, BoldFont, ItalicFont, and BoldItalicFont).

wspr commented 6 months ago

@dbitouze — hmmm, this seems to be working for me in LuaTeX right now (albeit with a prerelease fontspec). But I think it's dangerous to ask for a file on disk without also giving an extension or specifying "Path" — otherwise you are relying on heuristics of the engine searching for the font name, failing to find it, then falling back to searching on disk.

dbitouze commented 6 months ago

hmmm, this seems to be working for me in LuaTeX right now (albeit with a prerelease fontspec). But I think it's dangerous to ask for a file on disk without also giving an extension or specifying "Path" — otherwise you are relying on heuristics of the engine searching for the font name, failing to find it, then falling back to searching on disk.

@wspr OK but still it was working before :wink:

But I'm a bit lost: could you please give the code that should be used for this GoMono font with the extension provided and the UprightFont, BoldFont, ItalicFont, BoldItalicFont specified?

wspr commented 6 months ago

@dbitouze — apologies for the inconvenience here! I am sorry that these changes have caused issues.

I prefer to load fonts by filename to avoid portability issues so I would recommend here:

\setmonofont{GoMono}[
Extension = .ttf,
UprightFont    = *-Regular,
BoldFont       = *-Bold,
ItalicFont     = *-Regular-Italic,
BoldItalicFont = *-Bold-Italic,
]
dbitouze commented 6 months ago

@wspr You're welcome! Many thanks to you for your answer, for fontspec and for your numerous other contributions!

dbitouze commented 5 months ago

For what it's worth, with fontspec v2.9d, the file of the OP:

\documentclass{article}
\usepackage{fontspec}
\setmonofont{FiraCode-Regular.ttf}[ItalicFont= FiraCode-RegularItalic.otf]
\begin{document}
Foo
\end{document}

For immediate help type H . ...

l.3 ...tf}[ItalicFont= FiraCode-RegularItalic.otf]

?

wspr commented 5 months ago

@dbitouze — thanks for letting me know... this was definitely supposed to be fixed! :(

khaledhosny commented 5 months ago

XeTeX does not load system fonts by file name, only TDS fonts, and vice versa. Luaotfload will load system fonts by file names (unless kpse: prefix is used).

dbitouze commented 5 months ago

XeTeX does not load system fonts by file name, only TDS fonts, and vice versa. Luaotfload will load system fonts by file names (unless kpse: prefix is used).

@khaledhosny Thanks! But, given that:

$ fc-list | rg -v wght | rg -v pfb | rg FiraCode | rg Italic
/usr/share/fonts/drakfont/otf/FiraCode-BoldItalic.otf: Fira Code:style=Bold Italic
/usr/share/fonts/drakfont/otf/FiraCode-RegularItalic.otf: Fira Code:style=Regular Italic,Italic

what would be with XeTeX the code to use in order to get the font provided by FiraCode-RegularItalic.otf (last line above) as ItalicFont?

khaledhosny commented 5 months ago

\setmonofont{Fira Code} should work, you don’t need to explicitly specify ItalicFont.

Bit if you want to load the fonts by file name, then the simplest solution is to copy them to the current directory.

wspr commented 5 months ago

Shouldn't it also work to write Path=/usr/share/fonts/drakfont/otf/ ?

khaledhosny commented 5 months ago

That would work too.