jperon / lyluatex

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

How to properly wrap \lily[raw-pdf] #169

Closed uliska closed 6 years ago

uliska commented 6 years ago

I'm at a loss with wrapping \lily[raw-pdf] in an includegraphics command.

When I do

\newcommand\mylily[1]{\lily[raw-pdf]{#1}}
\mylily{ c' }

it works and "correctly" prints the file name to the document.

But when I try

\newcommand\mylily[1]{\includegraphics{\lily[raw-pdf]{#1}}}
\mylily{ c' }

I get

! TeX capacity exceeded, sorry [input stack size=5000].
<argument> \@protected@testopt \lily 
                          \\lily {}[raw-pdf]{ c' }
l.17 \mylily{ c' }

before the Lilypond file is even compiled.

jperon commented 6 years ago

It seems \includegraphics doesn't like commands with optional argument. This MWE causes the same trouble:

\documentclass{scrartcl}
\usepackage{graphicx}

\begin{document}

\newcommand\abc[1][]{abc}
\includegraphics{\abc}

\end{document}

while this one doesn't:

\documentclass{scrartcl}
\usepackage{graphicx}

\begin{document}

\newcommand\abc[1]{abc}
\includegraphics{\abc{}}

\end{document}

I guess this comes from some expansion trick, but that's beyond my TeX skills… @rpspringuel Any idea ?

rpspringuel commented 6 years ago

If it is indeed an expansion issue then \expandafter\includegraphics{\abc} should do the trick. This tells LaTeX to expand \abc before attempting to expand \includegraphics (which is probably what you want, since \abc is meant to evaluate to the name of the file to be used as the argument for \includegraphics).

uliska commented 6 years ago

Unfortunately not:

\expandafter\includegraphics{\lily[raw-pdf]{ c' }}
=>
! TeX capacity exceeded, sorry [input stack size=5000].
<argument> \@protected@testopt \lily 
                          \\lily {}[raw-pdf]{ c' }
l.19 ...dafter\includegraphics{\lily[raw-pdf]{ c' }}

---

\expandafter\includegraphics{\lily{ c' }}
=>
! TeX capacity exceeded, sorry [input stack size=5000].
<argument> \@protected@testopt \lily 
                          \\lily {}{ c' }
l.19 \expandafter\includegraphics{\lily{ c' }}
uliska commented 6 years ago

https://tex.stackexchange.com/questions/418061/how-can-i-use-a-macro-as-the-main-argument-to-includegraphics

jperon commented 6 years ago

71651567dd4ed9c4feec8a9ba4201fc53658def9 should fix this. The syntax becomes:

\newcommand\mylily[1]{%
\lily[raw-pdf]{#1}%
\includegraphics{\lysystems}%
}

\mylily{ c' }
jperon commented 6 years ago

And sorry: I forgot to submit it as a PR.

uliska commented 6 years ago

Thank you. I've added some details (we don't want the "systems" output for inline scores) and changed my command to

\newcommand\mylily[2][]{%
\lily[raw-pdf,#1]{#2}%
\includegraphics{\lyscore}%
\let\lyscore\undefined%
}

\mylily{ c' }
\mylily[inline-staffsize=24]{ c' }

I'll create a proof-of-concept implementation in lilyglyphs ASAP.

jperon commented 6 years ago

I think we should undefine \lyscore ourselves; I'm going to do that.

jperon commented 6 years ago

Just changed it in cd04db912e7ee8da86257c7b1957d9dcc1ec87c0:

jperon commented 6 years ago

So here is what I eventually did:

That way:

jperon commented 6 years ago

Another change in 02f476c8a5e74319dce047dfdbc71231b3a7e801: all systems are now accessible from \lyscore, not only those specified in range.

uliska commented 6 years ago

Just to let you know that I've been off yesterday and won't be able to look into it during the day either.

uliska commented 6 years ago

OK, I've looked into it. I must admit I don't fully understand the behaviour yet. It would be nice if you could describe it in the manual.

But I could update the sample I made for myself did work, and I'm confident I can make the lilyglyphs sample command tomorrow.

jperon commented 6 years ago

I've no time just now for the doc, but here is a dirty example:

\documentclass{scrartcl}

\usepackage{lyluatex}
\usepackage{pgffor}

\begin{document}

\newcommand\mylily[2][]{%
\lily[insert=systems,raw-pdf,#1]{#2}%
\foreach \n in {1,...,\lyscore{nsystems}}{\noindent\includegraphics{\lyscore{\n}}\\}%
}

\mylily{ c' d' e' f' \break d' }
\mylily[staffsize=24]{ c' }

\end{document}