
我正在 TeX 中使用 lilypond 排版一些音樂練習。純程式碼似乎工作正常,但我有很多重複使用的程式碼,所以我嘗試設定變數。變數似乎被拾取但沒有擴展。
微量元素:
% !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}
包含文件lilypond-variables.ly
:
Ggrace = { \grace { g''32 } }
輸出:
正如您所看到的,“硬編碼”g 裝飾音很好,但是應該由 產生的裝飾音\Ggrace
根本沒有出現。
我已經嘗試過\include
(使用 Lilypond 文件中指定的引號)和\input
(上面的引號和大括號),在此之前我嘗試了\newcommand
TeX 程式碼中的 standard s,但結果是相同的。
由於我有很多很多裝飾音組合,這是一個很大的問題。我最初將它們全部硬編碼,並認為我會讓未來的編碼變得不那麼痛苦和容易出錯。
使用 macOS Sierra 10.12.5 (16F73) 和 TL 2016。
答案1
事實證明,如果\include
將 移到大括號之外,程式碼就可以正常運作,如下所示:
% !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}
輸出:
因此,這實際上是 @egreg 所建議的 Lilypond 問題(感謝 Lilypond 清單中指出解決方案的同事)。