I use this snippet very frequently:

---------- Forwarded message ---------
From: Gabriel Ellsworth
Date: Thu, 30 Apr 2026
Subject: Re: Proposed snippet: center-on-vowels and center-on-first-vowel
To: Lilypond-User Mailing List <[email protected]>

This snippet is now on the Wiki:

Aligning lyrics based on vowels
<https://wiki.lilypond.community/wiki/Aligning_lyrics_based_on_vowels>

My thanks once again to Kieren!

---------- End of forwarded message ---------


But recently, I noticed that it fails if the lyrics are underlaid to a
NullVoice.


A minimal working example (MWE) is below.


Why does vowel centring fail with a NullVoice?


My best guess:

Per https://lilypond.org/doc/v2.27/Documentation/internals/nullvoice,

a NullVoice alters the X-extent of the NoteHead, compared to what it would
be in a normal Voice context. And (maybe) the callbacks for vowel alignment
need a normal NoteHead to work.


Here is why I am using NullVoice: In my real engraving project, which is
SATB, I want to use a NullVoice to contain all the rhythms that are needed
to attach lyrics.


*What I need:*

I want to align the vowel of a LyricText item with a note in the soprano
voice, even though (on the back end) my lyrics are aligned to a NullVoice.
Is there any way I can make this work?


Screenshot of problem (MWE):
[image: image.png]


%%%  SNIPPET BEGINS
\version "2.27.3"

%%%%% Alignment tweaks (automatic based on vowels) %%%%%
% View this snippet online:
% https://wiki.lilypond.community/wiki/Aligning_lyrics_based_on_vowels

% Define the set of characters that will be
% classified as vowels for these commands:
#(define vowel-set
   (list->char-set
    (string->list "AÁÀÃÂÆǼEÉÈÊIÍÌÎOÓÒÕÔŒU
        ÚÙÛYaáàãâæǽeéèêiíìîoóòõôœuúùûy")))

% This function returns the width of the
% grob (stencil) for a given piece of text.
#(define (width grob text)
   (let* ((X-extent
           (ly:stencil-extent (grob-interpret-markup grob text) X)))
     (if (interval-empty? X-extent)
         0
         (cdr X-extent))))

% This callback sets the alignment point of a LyricText grob
% to the centre of the first vowel that it contains.
#(define (center-on-first-vowel grob)
   (let* ((text (ly:grob-property-data grob 'text))
          (syllable (markup->string text))
          (vowel-position
           (if (string-index syllable vowel-set)
               (string-index syllable vowel-set)
               0))
          (vowel-end
           (if (string-index syllable vowel-set)
               (+ (string-index syllable vowel-set) 1)
               (string-length syllable)))
          (preword (substring syllable 0 vowel-position))
          (word (substring syllable vowel-position vowel-end))
          (preword-width (width grob preword))
          (word-width (width grob
                             (if (string-null? syllable) text word)))
          (note-column (ly:grob-parent grob X))
          (note-column-extent (ly:grob-extent
                               note-column note-column X))
          (note-column-width (interval-length note-column-extent))
          (self-X (ly:grob-property-data grob 'self-alignment-X)))
     (-
      (*
       (/ (- note-column-width word-width) 2)
       (1+ (if (procedure? self-X) (self-X grob) self-X)))
      preword-width)))

% This callback sets the alignment point of a LyricText grob
% to the point midway between its first and last vowels.
#(define (center-between-vowels grob)
   (let* ((text (ly:grob-property-data grob 'text))
          (syllable (markup->string text))
          (word-position
           (if (string-index syllable vowel-set)
               (string-index syllable vowel-set)
               0))
          (word-end
           (if (string-index-right syllable vowel-set)
               (+ (string-index-right syllable vowel-set) 1)
               (string-length syllable)))
          (preword (substring syllable 0 word-position))
          (word (substring syllable word-position word-end))
          (preword-width (width grob preword))
          (word-width (width grob
                             (if (string-null? syllable) text word)))
          (note-column (ly:grob-parent grob X))
          (note-column-extent (ly:grob-extent
                               note-column note-column X))
          (note-column-width (interval-length note-column-extent))
          (self-X (ly:grob-property-data grob 'self-alignment-X)))

     (-
      (*
       (/ (- note-column-width word-width) 2)
       (1+ (if (procedure? self-X) (self-X grob) self-X)))
      preword-width)))

% Helper functions that use the above code:
cvs = \once \override LyricText.X-offset = #center-between-vowels
cfv = \once \override LyricText.X-offset = #center-on-first-vowel
%%%%% End of “Aligning lyrics based on vowels” snippet from Wiki %%%%%

soprano = \fixed c' { a g f e | }

words = \lyricmode {
  Testttttt
  % aligned as expected



*  \cfv Testttttt  % fails, unless I use \lyricsto "soprano" below*
  \tweak LyricText.self-alignment-X #-0.65 Testttttt
  % aligned as expected

  X
}

<<
  \new Staff <<
    \new Voice = "soprano" \soprano

*    \new NullVoice = "aligner" \soprano*  >>
  \new Lyrics


*    % \lyricsto "soprano" \words % \cfv works with this    \lyricsto
"aligner" \words % \cfv does not work with this*>>
%%%  SNIPPET ENDS

>

Reply via email to