hi lilypond,

i found the following code in
https://mail.gnu.org/archive/html/lilypond-user/2011-01/msg00408.html

#(define-markup-command (verse layout props lyrics) (ly:music?)
"Transform a \\lyricmode lyric into a \\markup \\line"
  (interpret-markup layout props
    (make-line-markup (reduce-hyphens (flatten-nonmarkup-list
(lyrics->list lyrics))))))

#(define (lyrics->list lyrics)
"Return only syllables and hyphens from  @code{lyrics}."
         (if (ly:music? lyrics)
             (if (memq (ly:music-property lyrics 'name) '(LyricEvent
HyphenEvent))
                 (begin (if (eq? (ly:music-property lyrics 'name) 'LyricEvent)
                            (list (ly:music-property lyrics 'text))
                            (list "--")))
                 (let ((elt (ly:music-property lyrics 'element))
                       (elts (ly:music-property lyrics 'elements)))
                   (if (ly:music? elt)
                       (lyrics->list elt)
                       (if (null? elts)
                           '()
                           (map (lambda(x)
                                   (lyrics->list x))
                            elts)))))
             '()))

#(define (flatten-nonmarkup-list x)
  "Unnest list, but don't flatten markup constructs!"
  (cond ((null? x) '())
        ((not (pair? x)) (list x))
        (else (append (if (markup? (car x))
                          (list (car x))
                          (flatten-nonmarkup-list (car x)))
                      (flatten-nonmarkup-list (cdr x))))))

#(define (reduce-hyphens text)
         (let eat ((wd (car text)) (wds (cdr text)))
                 (cond
                   ((null? wds) (list wd))
                   ((and (equal? "--" (car wds)) (not (null? (cdr wds))))
                    (eat (markup #:concat (wd (cadr wds)))
                         (cddr wds)))
                   (else (cons wd (eat (car wds) (cdr wds)))))))



i used the code on  this sample:

\version "2.24.3"

wordsOne = \lyricmode { This is my ex --  \markup { \italic am }  -- ple text. }
wordsTwo = \lyricmode { Here goes the se -- cond line then. }
melody = \relative c' { c4 d e f | g a c2 }

\new Voice { \melody \melody }
\addlyrics { \wordsOne \wordsTwo }

\markup \column{ \verse #wordsOne \verse #wordsTwo }


the following image shows the result:

[image: Untitled1.png]



note that there are still spaces in between syllables:

"ex am ple" instead of "example"

"se cond" instead of "second"


kindly seeking your help to fix this. thank you ;)


Dennis Noel G. de Lara

Reply via email to