reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
190 stars 51 forks source link

breaking font selection with LuaLaTeX and fontspec #650

Closed cabohah closed 3 months ago

cabohah commented 3 months ago

It seems, that polyglossia breaks fonts names with whitespaces when using LuaLaTeX and fontspec, e.g.:

\documentclass{report}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
\begin{document}
  \slshape
  This is a sentence.
\end{document}

results in:

luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: Font "TeX" not found.
./test.tex:6: Font \TU/TeXGyreTermes(0)/m/it/10=name:TeX not loadable: metric data not found or bad.
<to be read again> 
G
l.6   \slshape

So it seems, that the font name is TeX.

A workaround would be to load polyglossia after \setmainfont or to use TeXGyreTermes (without spaces) as font name.

There error does not occur with XeLaTeX instead of LuaLaTeX.

See also https://tex.stackexchange.com/q/721772/277964.

I'm not absolutely sure, that this is a polyglossia issue, but because the error does not occur without polyglossia or when using babel instead of polyglossia, I report it here.

cfr42 commented 3 months ago

It's an issue with the Harfbuzz renderer rather than polyglossia. You can reproduce without polyglossia:

\documentclass{book}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX,Renderer=Harfbuzz]{TeX Gyre Termes}

\begin{document}
\slshape 
This is a sentence.
\end{document}
amunn commented 3 months ago

The problem is caused by the fact that polyglossia uses the HarfBuzz renderer by default. So I'm not sure this is a polyglossia problem. It's really a fontspec problem:

\documentclass{book}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX,Renderer=HarfBuzz]{TeX Gyre Termes}

\begin{document}
This is a sentence.
\end{document}
Udi-Fogiel commented 3 months ago

You can change the default renderer with the luatexrenderer option of the package, FWIW.

cfr42 commented 3 months ago

It is not really class dependent, I don't think. The difference between article and book is probably in what they do at \begin{document}.

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX,Renderer=Harfbuzz]{TeX Gyre Termes}

\begin{document}
\slshape 
This is a sentence.
\end{document}

also reproduces.

cabohah commented 3 months ago

It's also class dependent, because this example works for me with article or report class.

Not if you add, e.g., \slshape into an example using article or report.

Udi-Fogiel commented 3 months ago

This is a bug in luaotfload, I've reported it in https://github.com/latex3/luaotfload/issues/285.

I'm closing this ticket, but feel free to reopen it if you think my analyze is wrong.