Am Fr., 26. Sept. 2025 um 13:31 Uhr schrieb William Rehwinkel via
LilyPond user discussion <[email protected]>:
>
> Dear David,
>
> After returning to this problem, I think the attached file may achieve
> what you were hoping for. Let me know if this misses the mark.
>
> Thanks,
> -William
>
> On 9/25/25 12:16 PM, William Rehwinkel via LilyPond user discussion wrote:
> > Dear David,
> >
> > First of all, the following answer may be completely off the mark, so I
> > welcome anyone who corrects me.
> >
> > I believe that this is due to the interesting way that Lilypond handles
> > checking for stanzas.
> >
> > When you use "\set stanza = "1"", the "stanza" variable is continually
> > set. Lilypond makes sure to not print the stanza before every single
> > lyric by using a "last-stanza" variable and checking that they are not
> > the same using the scheme "eq?" procedure.
> >
> > See: https://github.com/lilypond/lilypond/
> > blob/9f9243b9948ffaee93ff0551bbb3e36577139d8e/lily/stanza-number-
> > engraver.cc#L61
> >
> > Now, consider the following code:
> >
> > % ------
> > \version "2.24.0"
> > #(define verse-number "1")
> > #(define verse-number2 "1")
> > #(display (eq? verse-number verse-number))
> > #(display (eq? verse-number verse-number2))
> > % ------
> >
> > The scheme eq? procedure has very interesting logic about what things
> > are equal to each other, basically whether or not they are the same
> > object instead of being an equal value (scheme programmers are told to
> > use "equal?" instead).
> >
> > I think that this is an intentional choice by the Lilypond devs, because
> > it allows us to set the stanza number at the beginning of each line
> > without having to change it.
> >
> > However, I believe that your code is setting the stanza to the same
> > variable, which means that Lilypond does not recognize it as a different
> > value.
> >
> > I'm not sure what I can offer as an alternative to avoid this, I will
> > think on this further.
> >
> > -William
> >
> > On 9/23/25 3:28 PM, David Poon wrote:
> >> Hi,
> >>
> >> I have no problems displaying stanza numbers on multiple systems,
> >> except when I try to wrap the \set stanzacommand in a variable, it
> >> only displays the first one.
> >>
> >> In the MWE below, only the first stanza number is printed; but if you
> >> uncomment
> >>
> >> \set stanza = #"1"
> >>
> >> the second one appears as I expected.
> >>
> >> Why is this? (To be clear, I would /like/ to be able to display stanza
> >> numbers on multiple (specific) systems.)
> >>
> >> Thanks!
> >> -David
> >>
> >>
> >> \version "2.24.0"
> >>
> >> verse = \set stanza = #"1"
> >>
> >> text = \lyricmode {
> >> \verse
> >> One two
> >> \verse
> >> % \set stanza = #"1"
> >> three
> >> }
> >>
> >> notes = { c' d' \break e' }
> >>
> >> \score {
> >> <<
> >> \new Voice = "tune" { \notes }
> >> \new Lyrics { \lyricsto "tune" \text }
> >> >>
> >> }
> >
> >
@ William
I think your code works, due to the way a music-function is called and when.
The function itself may be simplified:
verse = #(define-music-function () () #{ \set stanza = #"1" #})
It's a no-brainer to make this function take an argument.
@ David
You may be interested in:
https://gitlab.com/lilypond/lilypond/-/issues/4913#note_1871525118
Follow the links given there.
Cheers,
Harm