jperon / lyluatex

Alternative à lilypond-book pour lualatex
MIT License
58 stars 12 forks source link

\setmainfont causes problems #297

Closed tomaszgrabowskiop closed 2 years ago

tomaszgrabowskiop commented 2 years ago

After adding to a quite complicated preamble lyLuaTeX I received a bunch of errors. They are caused by \setmainfont{Minion Pro}. Scores are compiling correctly but the font is set to standard. The file compiles correctly with no lyLuaTeX and with no \setmainfont. But when both are in the file I have such error message:

...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}

? 
jperon commented 2 years ago

Is your font installed as a system font, or only locally in your project ? You should try to set pass-fonts to false:

\usepackage[pass-fonts=false]{lyluatex}
jperon commented 2 years ago

On my Linux system, after copying Minion Pro fonts into ~/.local/share/fonts, this MWE compiles properly, with the expected result:

\documentclass{article}

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

\begin{document}

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

\end{document}

test

tomaszgrabowskiop commented 2 years ago

Thank you for your replay. Your MWE works fine.

But adding \usepackage{polyglossia} is a source of trouble. Any ideas? I probably will have to switch back to babel.

\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) 
jperon commented 2 years ago

After a quick test, what I get is very weird: loading polyglossia before using \setmainfont raises the error, but loading it after does work. So this is working:

\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}
tomaszgrabowskiop commented 2 years ago

Yes, it does. But you have to remember to add fontspec package earlier. Polyglossia adds it two, so normally you don't need to repeat it (or in this case make it before polyglossia). Thanks a lot for your help.

jperon commented 2 years ago

@tomaszgrabowskiop May you please try with #298 ?