reutenauer / polyglossia

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

\symbol inserts wrong glyph when using polyglossia #579

Closed fpom closed 1 year ago

fpom commented 1 year ago

When I load polyglossia, using \symbol to insert glyphs from a TTF font results in the wrong glyphs being inserted. For instance, with this document:

\documentclass{article}
  \usepackage{fontspec}
  \usepackage{polyglossia}
\begin{document}
  {\fontspec{Material Design Icons}\symbol{"F0A27}}
\end{document}

In the screenshot below, the resulting PDF is displayed at the bottom, while the expected result is displayed above and has been obtained by just removing \usepackage{polyglossia}.

screenshot

I'd be happy with a workaround if no fix is possible.

jspitz commented 1 year ago

Apparently, this font does not work well with the Harfbuzz (LuaTeX) renderer that is used by polyglossia by default since this one supports some (non-Latin) scripts better. Use either

\documentclass{article}
\usepackage[luatexrenderer=none]{polyglossia}
\begin{document}
    {\fontspec{Material Design Icons}\symbol{"F0A27}}
\end{document}

or

\documentclass{article}
\usepackage{polyglossia}
\begin{document}
    {\fontspec[Renderer=Node]{Material Design Icons}\symbol{"F0A27}}
\end{document}

or

\documentclass{article}
\usepackage{polyglossia}
\newfontfamily{\mdi}{Material Design Icons}[Renderer=Node]
\begin{document}
    {\mdi\symbol{"F0A27}}
\end{document}

All three solutions will work. The first one will reset the renderer globally to the default (Node), the second one only for the given use of \fontspec (a command which is actually discouraged for real documents, see fontspec manual), the third for the here defined \mdi font family. Personally, I would suggest the third method.

Hope this helps.

Edit: remove loading of fontspec, as this is done by polyglossia anyway.

jspitz commented 1 year ago

BTW, you might want to report this to the luaotfload guys as well. It might be a bug in this very font, or a problem of the renderer with the Supplementary Private Use Area-A where the respective glyph is located. In any case, the colleagues might be interested. Here is a MWE without polyglossia (I use a different variant of the font as this is the one I found on the net):

% !TeX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\mdih}{Material Design Icons Desktop}[Renderer=HarfBuzz]
\newfontfamily{\mdin}{Material Design Icons Desktop}[Renderer=Node]
\begin{document}
    {\mdih\symbol{"F0A27}}{\mdin\symbol{"F0A27}}
\end{document}
fpom commented 1 year ago

Thanks so much for your quick answer, and yes, it helps a lot. I'll also report it to luaotfload as you suggest.