reutenauer / polyglossia

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

Polyglossia does not allow lyLuaTeX pass-fonts option #569

Closed tomaszgrabowskiop closed 1 year ago

tomaszgrabowskiop commented 1 year ago

Using Polyglossia and LyLuaTeX package is not possible if you want to use fonts set in LaTeX document.

documentclass{article}
\usepackage{polyglossia}
  \setdefaultlanguage{polish}
   \setotherlanguage{latin} 
    \catcode`\^=7 % work-around for [Polyglossia \setotherlanguage after update of TeXLive conflicts with luatextra](https://tex.stackexchange.com/questions/663753/polyglossia-setotherlanguage-after-update-of-texlive-conflicts-with-luatextra) 
\usepackage[pass-fonts]{lyluatex}
\setmainfont{Minion Pro}
\begin{document}
\lily{
\fixed c'{c d e f}
\addlyrics{c d e f}
}
\end{document}

Such code reports error massage and will not pass fonts (either local or system installed).

Using only package fontspec causes no error and allows to pass fonts. I don't know where to report it. I ask @jperon (creator of lyLuaTeX) to look into it aswell.

Error massage:

...al/texlive/2022/texmf-dist/scripts/lyluatex/lyluatex.lua:1350: attempt to in
dex a nil value (field 'rawdata')
stack traceback:
    ...al/texlive/2022/texmf-dist/scripts/lyluatex/lyluatex.lua:1350: in function 
'lyluatex.lua.get_font_family'
    [\directlua]:1: in main chunk.
<argument> \directlua {ly.get_font_family(font.current())}

l.94 \end{lilypond}

? 
...al/texlive/2022/texmf-dist/scripts/lyluatex/lyluatex.lua:1350: attempt to in
dex a nil value (field 'rawdata')
stack traceback:
    ...al/texlive/2022/texmf-dist/scripts/lyluatex/lyluatex.lua:1350: in function 
'lyluatex.lua.get_font_family'
    ...al/texlive/2022/texmf-dist/scripts/lyluatex/lyluatex.lua:1364: in function 
'lyluatex.lua.set_fonts'
    [\directlua]:1: in main chunk.
\ly@currentfonts ..., \sffamilyid , \ttfamilyid )}
                                                  \endgroup 
l.94 \end{lilypond}

? 
jspitz commented 1 year ago

Is this probably related to #566 (and fixed by the commit that resolved that issue)?

tomaszgrabowskiop commented 1 year ago

I will try to check it out.

Important info (observed by jperon), "loading polyglossia before using \setmainfont raises the error, but loading it after does work."

It means you have to call package fontspec ealier too.

\documentclass{article}

\usepackage{fontspec}
\usepackage[pass-fonts]{lyluatex}
\setmainfont{Minion Pro}
\usepackage{polyglossia}

\begin{document}

\lily{
\fixed c'{c d e f}
\addlyrics{c d e f}
}

\end{document}
jperon commented 1 year ago

I don’t know whether it’s related to #566, but here are more details about this error. It seems that using \setmainfont after loading polyglossia alters fonts.hashes.identifiers. This MWE will show that:

\documentclass{minimal}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\directlua{without = type(font.getfont(font.current()).shared.rawdata)}

\usepackage{polyglossia}
\directlua{before = type(font.getfont(font.current()).shared.rawdata)}
\setmainfont{Linux Libertine O}
\directlua{after = type(font.getfont(font.current()).shared.rawdata)}

\begin{document}

Without polyglossia: \directlua{tex.sprint(without)}

Before setmainfont: \directlua{tex.sprint(before)}

After setmainfont: \directlua{tex.sprint(after)}

\end{document}

test-crop.pdf

jspitz commented 1 year ago

566 is only relevant for the catcode workaround in the original MWE.

What probably is the culprit here are the fontfamily patchings polyglossia makes. I have no idea how we could avoid that.

jperon commented 1 year ago

So far as lyluatex is concerned, if you know another way to get the font family name I get from font.getfont(font.current()).shared.rawdata.metadata['familyname'], I could fix this precise issue on my side.

jspitz commented 1 year ago

@dohyunkim is much more versed in things lua than I am. Thus inviting.

jperon commented 1 year ago

After searching a bit, I found that font.getfont(font.current()).fullname, which works with polyglossia, gives the info. I’ll go with it.

jspitz commented 1 year ago

Good.