3

I want to color all the stanza numbers of many hymns with red. I would like to keep the color definition in a stylesheet and only pass "the number and dot" of the stanza as a parameter.

I was not able to make it work with \newcommand\mystanza[1]{}. The stylesheet from the user manual is confusing.

verseOne = \lyricmode {
    %... n1-> n20 -> number of stanzas.  I want to avoid defining the color 20 times
    %%6
    \set stanza = \markup { \with-color #red 6.} %<-- I want this in a stylesheet passing the number as parameter
    %\myestanza{6.} %does not work if defined as \newcommand\myestanza[1]{...}
    Et ju -- be me ve -- ni -- re ad te:
    Ut cum Sanc -- tis tu -- is lau -- dem te
    in sae -- cu -- la 
    sae -- cu -- lo -- rum.
    A _ _ _ men
}

...

\new Voice = "one" {
    \musicOne %defined elsewhere
}

\new Lyrics \lyricsto "one" {   
    \verseOne
}

2 Answers 2

2

After reading and rereading 4.7.3 Style sheets, I found the following solution

I saved these 4 lines code in an external file myscore.ily

mystanz = 
#(define-music-function
(string)
(string?)
#{ \set stanza = \markup \with-color "red" #string #})

Then in the music file I included the file

\include myscore.ily
...
verseOne = \lyricmode {
            \mystanz "8."
            Et ju -- be me ve -- ni -- re ad te:
}

Now I am able to change the color for all stanzas in a single place

1

Your self-answer is correct. In a document made with LuaLaTeX + lyLuaTeX, there are two different engines at play: LilyPond for the music, and LuaLaTeX for the text. These are completely separate. When you do \begin{lilypond}...\end{lilypond}, the part in the ... is interpreted by LilyPond. In spite of the superficial similarity of LilyPond syntax with TeX syntax, essentially the fact that commands are introduced by a backslash, there is no link from TeX to LilyPond. A backslash-prefixed command does not get interpreted by TeX but is literally passed, with the backslash, to LilyPond. So while you try to define \myestanza as a TeX macro, its invocation \myestanza{1.} does not get expanded by TeX but is just seen by LilyPond as "\myestanza{1.}", and LilyPond doesn't know about a command called \myestanza.

As you have found out, the solution is to write LilyPond functions and not TeX macros. (You will also notice that LilyPond is a much more structured and clean language than TeX.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.