Since this issue is so common, I wonder if we could add this feature to the 
lilypond code base? I thought the requirement is following:
1. The feature should be turned on by default with list of ascii punctuations, 
like ",.?{}()! :2. The list of punctuation can be override/customized with any 
unicode character list. 3. The feature can be turned off by override/set the 
punctuation list to empty.
Is it feasible? If it is ok,  I would like to help, but with my limited 
lilypond and Scheme knowledge, I wonder If I could make it.
ThanksJun
Date: Sun, 5 May 2013 06:24:26 -0700
From: tsan...@rogers.com
Subject: Re: Lyrics and Punctuations Alignment Issue?
To: david.nales...@gmail.com
CC: wj1...@hotmail.com; lilypond-user@gnu.org

David & Jun:
I complete the punctuation and parenthesis to the "align grob".  The following 
is the .ly UTF-8 file with test. I also attacha png file for your reference.
Thank you for your help,Ming
\version "2.17"

#(define (drop-punctuation-right str)
  (let ((punct-right '("." "," ";" ":" "?" "!" ")" "\"" "'" "。" "," ";" ":" "?" 
"!" ")" "]")))
    (let loop ((elt punct-right))
      (if (null? elt)
          #f
          (if (string-suffix? (car elt) str)
              (string-drop-right str (string-length (car elt)))
              (loop (cdr elt)))))))

#(define (drop-all-punctuation-right str)
  (let ((core (drop-punctuation-right str)))
    (if core
        (drop-all-punctuation-right core)
        str)))

#(define (drop-punctuation-left str)
  (let ((punct-left '("(" "\"" "'" "[" "(")))
    (let loop ((elt punct-left))
      (if (null? elt)
          #f
          (if (string-prefix? (car elt) str)
              (string-drop str (string-length (car elt)))
              (loop (cdr elt)))))))

#(define (drop-all-punctuation-left str)
  (let ((core (drop-punctuation-left str)))
    (if core
        (drop-all-punctuation-left core)
        str)))


#(define (align grob)
  (let* ((stil (ly:grob-property grob 'stencil))
         (stil-X (ly:stencil-extent stil X))
         (text (ly:grob-property grob 'text))
         ; determine X-extent of text stencil without punctuation at end
         (text-L (drop-all-punctuation-right text))
         (text-L-stil (grob-interpret-markup grob text-L))
         (text-L-stil-X (ly:stencil-extent text-L-stil X))
         (displacement (/ (- (cdr text-L-stil-X) (cdr stil-X)) 2))
         ; determine X-extent of text stencil without punctuation at start
         (text-R (drop-all-punctuation-left text))
         (text-R-stil (grob-interpret-markup grob text-R))
         (text-R-stil-X (ly:stencil-extent text-R-stil X))
         (displacement (+ displacement
                          (/ (- (cdr stil-X) (cdr text-R-stil-X)) 2))))

     (- (ly:self-alignment-interface::aligned-on-x-parent grob)
        displacement)))

\paper {
  ragged-right = ##f
}
\markup {" The following is lyric with  override LyricText ................"}
\relative c' {
  \time 3/4 e4 e4. e8
  d4 e d c d e
}

\addlyrics { \set stanza = "1. "
  \override LyricText #'X-offset = #align
  a "\"bb" ccc -- "dddd\"" eeeee f 'g h i'
}
%{
  \addlyrics { \set stanza = "2. "
  \override LyricText #'X-offset = #align
  "\"I" am so lone -- "ly,\"" said she
}
%}
\addlyrics { \set stanza = "3. "
  \override LyricText #'X-offset = #align
  [��  �O] (��  名) ��;  名。 啊:  明?  天!
}
\addlyrics { \set stanza = "4. "
  \override LyricText #'X-offset = #align
  "\"��"  "�O\"" (��  名) ��;  名. 啊:  明?  天!
}


\markup { " " }
\markup { " " }
\markup { " " }
\markup {"The following is normal lyric ie. no override LyricText 
.............."}
\relative c' {
  \time 3/4 e4 e4. e8
  d4 e d c d e
}

\addlyrics { \set stanza = "1. "
  a bb ccc dddd eeeee f 'g h' i
}
\addlyrics { \set stanza = "5. "
  [��  �O] (��  名) ��;  名。 啊:  明?  天!
}
\addlyrics { \set stanza = "6. "
  "\"��"  "�O\"" (��  名) ��;  名. 啊:  明?  天!
}
        From: MING TSANG <tsan...@rogers.com>
 To: David Nalesnik <david.nales...@gmail.com> 
Cc: Jun Wang <wj1...@hotmail.com>; "lilypond-user@gnu.org" 
<lilypond-user@gnu.org> 
 Sent: Saturday, May 4, 2013 6:01:13 PM
 Subject: Re: Lyrics and Punctuations Alignment Issue?
   
David, 
Yes, left and right  UTF-8 parenthese -
 UTF-8.
Thanks,Ming
        From: David Nalesnik <david.nales...@gmail.com>
 To: MING TSANG <tsan...@rogers.com> 
Cc: Jun Wang <wj1...@hotmail.com>; "lilypond-user@gnu.org" 
<lilypond-user@gnu.org> 
 Sent: Saturday, May 4, 2013 4:05:37 PM
 Subject: Re: Lyrics and Punctuations Alignment Issue?
   
Ming,


On Sat, May 4, 2013 at 11:16 AM, MING TSANG <tsan...@rogers.com> wrote:


Jun, Thank you.  I add a few punctuation to your code.

David,  I don't know scheme. That's why I did a lousy job. I add few more 
punctuation to the Jun's latest code.  It works.

Thank you both. I have been looking
 this for a long time.
Nice to hear!  By the way, did you mean to add the parentheses at "a" and :b" 
to your lists?
-David 


      

                                          
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to