lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Markup functions and punctuation in lyrics


From: Jean Abou Samra
Subject: Re: Markup functions and punctuation in lyrics
Date: Mon, 18 Oct 2021 23:23:38 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2

Le 18/10/2021 à 21:22, R. Padraic Springuel a écrit :
I’m using some functions to allow me to select words in the lyrics of some 
hymns in a systematic way so that the same hymn can be used referring to one or 
more persons (and in some cases, either a man or a woman).  These functions 
work just fine when they appear in the lyrics by themselves, but when there is 
punctuation immediately after one of these functions, the punctuation gets 
shifted to its own syllable.  Is there a way to have the function interact with 
punctuation more intelligently?  I’m thinking I need to use \concat somehow, 
but how do I write the function so that it only does the concatenation when the 
next character is punctuation?

Attached is an example showing one of my simple word selection functions 
followed by a comma.


It's slightly tricky. What you may want is a
function recognizing the comma as its argument,
but not taking any argument if the next input
element is not punctuation. This is not possible
because optional function arguments in last position
can only omitted with \default, not implicitly.
However, you can make a function that takes the
next element in all cases, and inserts it back
in the input, either together with your lyric
event as a single event, or separately in a second
event as you got it. The only disadvantage is that
putting \man at the end of an expression
(\lyricmode { ... \man }) will not work since \man
will be expecting an argument. As long as you're
not doing that (I assume you would want a period
at the end anyway), all should be fine.


\version "2.22.1"

#(use-modules (srfi srfi-11)
              (ice-9 regex))

#(define punctuation (make-regexp "^[.,;:?!]+$"))

gender = #'other

man =
#(define-music-function (next) (ly:music?)
   (let-values
     (((text)
       (case gender
         ((male) "man")
         ((plural) "men")
         (else "man/men")))
      ((next-is-punctuation punctuation-text)
       (if (music-is-of-type? next 'lyric-event)
           (let ((other-text (ly:music-property next 'text)))
             (if (and (string? other-text)
                      (regexp-match? (regexp-exec punctuation other-text)))
                 (values #t other-text)
                 (values #f #f)))
           (values #f #f))))
     (case gender
       ((male plural)
        (if next-is-punctuation
            #{ \lyricmode { #(string-append text punctuation-text) } #}
            #{ \lyricmode { #text #next } #}))
       (else
        (if next-is-punctuation
            #{ \lyricmode { \markup \concat { \italic #text #punctuation-text } } #}
            #{ \lyricmode { \markup \italic #text #next } #})))))


music = { c' c' c' c' c' c' c' c' c' c' c' }

verseI = \lyricmode {
  In glad re -- mem -- brance of this ho -- ly \man, \skip 4
  Who sought to fol -- low you in faith and love.
}

\new Staff <<
    \new Voice = "mel" { \music \music }
    \new Lyrics \lyricsto "mel" { \verseI }
>>



Note the use of symbols, which are better suited
for discrete values than strings (comparison is
cheaper at least in theory, and you get nice
specific idioms like case).

Best,
Jean



reply via email to

[Prev in Thread] Current Thread [Next in Thread]