jperon / lyluatex

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

Strange problem parsing the LilyPond code #51

Closed uliska closed 6 years ago

uliska commented 6 years ago

The following document

\documentclass{scrartcl}
\usepackage{lyluatex}
\begin{document}

\begin{ly}
{
  \repeat unfold 3 { c1 }
}
\end{ly}

\end{document}

triggers a strange error:

! Extra }, or forgotten \endgroup.
<argument> { \relative c' { \repeat unfold 3 { c1 } }
                                           } 
l.12 \end{ly}

?

Obviously it chokes about something in this input. The behaviour is the same with the ly environment or the \lily command.

If the document contains \tuplet 3/2 { c' d' e' } instead there is no problem.

jperon commented 6 years ago

I don't know why this error occurs. As a workaround for now, putting \def\repeat{} before the ly environment makes it work. I guess this has something to do with robust and fragile LaTeX commands, but this is a pure guess… @rpspringuel, would you have an idea about that, please ?

rpspringuel commented 6 years ago

The error is a LaTeX one, which implies that LaTeX is attempting to parse the contents of the environment, which is decidedly not what it should be doing. It should grab the environment contents as they are and pass them on to LilyPond. It's doing it at least partially, since \relative and \repeat are coming back as undefined commands. My best guess is that there's something in how \NewEnviron sets things up so that the body of the environment gets stored in \BODY (before handing it off to lua).

uliska commented 6 years ago

Yes, I also think that LaTeX somehow tries to process the content, which it shouldn't do. Some more experiments with different contents of the ly environment:

{ \set Staff.instrumentName = "Hallo" c' }

correctly works

{ \sffamily Staff.instrumentName = "Hallo" c' }

works for LaTeX but gives the expected LilyPond failure

\relative { \set Staff.instrumentName = "Hallo" c' }

compiles correctly

{ \repeat Staff.instrumentName = "Hallo" c' }

does not produce a LilyPond failure but the LaTeX error.

{ \r Staff.instrumentName = "Hallo" c' }

does produce the expected LilyPond failure but not a LaTeX error as does

{ \repea Staff.instrumentName = "Hallo" c' }

Interestingly

```lilypond
{ \\repeat Staff.instrumentName = "Hallo" c' }

does produce the LilyPond error and no LaTeX one.

{ 
  \set Staff.instrumentName = "Hallo"
  \repeat unfold 4  c'
}

also lets LaTeX fail with the usual error

So it seems specifically related to the \repeat and neither to the fact there is a backslash command at the beginning nor to the combination \r. Of course there may be other triggers for this error, and maybe looking into the sourece code of environ may give some insight. Could it be that \repeat is some kind of magic keyword in that package?

jperon commented 6 years ago

Yes, \repeat seems very special ; I didn't see anything about it in the source of environ, but it seems to be a plain TeX command to do a loop. LaTeX says it is undefined, but a \providecommand in the sty doesn't solve the problem… As it seems (for now) that it is the only one to raise such a problem, I suggest merging #53 (after #52, on which it is based), that solves it. If we encounter other such problems, it will be time to open a specific issue.