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.


\newcommand{\Ggrace}{...}before lilypond-book gets invoked, it would work; but I don't know whether that's possible? Else, I agree. – K.G. Feuerherm Jul 12 '17 at 13:22lilypond-bookstrips off everything not in alilypondenvironment, typesets withlilypondthe music pieces and produces graphic files that are then included during the run of LaTeX. – egreg Jul 12 '17 at 13:28