\version "2.19.44" %% REMARK: %% Using instrument-names _and_ setting an invisible stanza with a certain %% extent at line-begin to avoid collisions %% Thanks to David Nalesnik %% http://lists.gnu.org/archive/html/lilypond-user/2016-07/msg00028.html #(define create-stanza-number-grob-engraver ;; puts out a StanzaNumber for every LyricText-grob (lambda (context) (let ((stanza (ly:context-property context 'stanza))) `((acknowledgers (lyric-syllable-interface . ,(lambda (engraver grob source-engraver) (let ((new-stanza-grob (ly:engraver-make-grob engraver 'StanzaNumber '()))) (ly:grob-set-property! new-stanza-grob 'text stanza))))))))) #(define (at-line-beginning? grob) (let* ((col (ly:item-get-column grob)) (ln (ly:grob-object col 'left-neighbor)) (col-to-check (if (ly:grob? ln) ln col))) (and (eq? #t (ly:grob-property col-to-check 'non-musical)) (= 1 (ly:item-break-dir col-to-check))))) #(define (keep-at-line-begin grob) (if (and (ly:item? grob) (not (at-line-beginning? grob))) (ly:grob-suicide! grob) grob)) keepLineStartStanzaNumbers = \layout { \context { \Lyrics \override StanzaNumber.after-line-breaking = #keep-at-line-begin } } numberLyrics = #(define-scheme-function (instr-name move)(number? number?) "Return a context-modification setting @code{stanza} and consisting @code{create-stanza-number-grob-engraver}, as well as @code{instrumentName} and @code{shortInstrumentName}. The latter prints the numbering using @var{instr-name}, the first is used to push the lyrics to the right, using @var{move}. " #{ \with { %stanza = \markup \italic #(format #f "~a." nmbr) stanza = \markup \combine \null \translate #(cons move 0) \null \consists #create-stanza-number-grob-engraver instrumentName = #(format #f "~a." instr-name) shortInstrumentName = #(format #f "~a." instr-name) } #}) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXAMPLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \score { << \new Staff { \key cis \major \repeat unfold 6 { c''4 d'' e'' } } \new Lyrics \with { \numberLyrics 1 3.5 } \lyricmode { \repeat unfold 6 { foo -- bar -- buzz } } \new Lyrics \with { \numberLyrics 2 3.5 } \lyricmode { \repeat unfold 6 { very-very-long-syllable bur -- buuuzz } } \new Lyrics \with { \numberLyrics 3 3.5 } \lyricmode { \repeat unfold 6 { fuu -- bla -- blibbb } } >> \layout { \keepLineStartStanzaNumbers \context { \Lyrics \override InstrumentName.X-offset = 2 } } }