# \include-ed variables in lilypond-book environments don't expand

I'm typesetting some music exercises using lilypond within TeX. Plain code seems to work fine, but I have a lot of code which is reused so I've tried to set up variables. The variables seem to get picked up but not expanded.

MWE:

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = LilyPond-Book
% !LILYPOND tex = xelatex
\documentclass{memoir}
\begin{document}
\begin{lilypond}
{
\include "lilypond-variables.ly"
\time 2/4
\grace { g''32 } g'4  \Ggrace a'4  \Ggrace b'4  \Ggrace c''4
\Ggrace d''4 \Ggrace e''4 \Ggrace f''4         g''4
a''2         g''4         f''4 \Ggrace e''4
\Ggrace d''4 \Ggrace c''4 \Ggrace b'4  \Ggrace a'4
\Ggrace g'4
\bar "||"
}
\end{lilypond}
\end{document}


Included file lilypond-variables.ly:

Ggrace = { \grace { g''32 } }


Output:

As you can see, the 'hard-coded' g grace note is fine, but the ones which should be produced by \Ggrace simply don't appear.

I've tried \include (with quotes as specified in the Lilypond documentation) and \input (quotes as above and braces), and before this I tried standard \newcommands within the TeX code but the result was the same.

As I have many, many grace note combinations this is quite a big problem. I had them all hard-coded originally, and thought I'd make future coding less painful and error prone.

Using macOS Sierra 10.12.5 (16F73) and TL 2016.

• @Bobyandbob Done. The original comment has been removed however so my response doesn't make much sense by itself, so I've removed it also. Jul 11 '17 at 21:25
• I think this is a pure Lilypond problem. Jul 11 '17 at 22:33
• @egreg You may be right. I'm now of the opinion that it's the lilypond-book python script which is to blame (I thought it might be related to the engine). The variables are recognized, but then not applied. Should we close this here? Jul 11 '17 at 23:22
• @K.G.Feuerherm I don't think we can do something on the TeX side about the problem. Jul 12 '17 at 7:49
• @egreg Well... If there was a way to force expansion of \newcommand{\Ggrace}{...} before lilypond-book gets invoked, it would work; but I don't know whether that's possible? Else, I agree. Jul 12 '17 at 13:22

It turns out that if the \include is moved outside the braces, the code works just fine, as follows:

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = LilyPond-Book
% !LILYPOND tex = xelatex
\documentclass{memoir}
\begin{document}
\begin{lilypond}
\include "lilypond-variables.ly"
{
\time 2/4
\grace { g''32 } g'4  \Ggrace a'4  \Ggrace b'4  \Ggrace c''4
\Ggrace d''4 \Ggrace e''4 \Ggrace f''4         g''4
a''2         g''4         f''4 \Ggrace e''4
\Ggrace d''4 \Ggrace c''4 \Ggrace b'4  \Ggrace a'4
\Ggrace g'4
\bar "||"
}
\end{lilypond}
\end{document}


Output:

So it was in fact a Lilypond issue as suggested by @egreg (with thanks, and to the colleague on the Lilypond list who pointed to the solution).