Am Di., 10. Juni 2025 um 06:47 Uhr schrieb Dennis Noel de Lara < [email protected]>:
> 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 > > > > > > Use the code from the LSR snippet, as already linked, not an outdated version from the web. The LSR is maintained! If you obseve a not working as expected snippet notify us here or on the bug-mailing-list and someone will take a look (it may take some time though). In the current use case snippet 744 works fine. -Harm
