Hi,
On Wed, May 20, 2020 at 8:35 AM Fr. Samuel Springuel
<[email protected]> wrote:
>
> > On 20 May, 2020, at 2:41 AM, Witold Uchman <[email protected]> wrote:
> >
> > Hello!
> >
> > I am looking for a way to simplify input in a book of psalms, namely to be
> > able to simply put an * in lyrics and make the character in red.
> >
>
Well, this might be monstrous overkill, but I remember something I
wrote a long long time ago (2012) which could be used:
https://www.mail-archive.com/[email protected]/msg68357.html
The initial problem was to replace many specific Unicode characters
within words with colored versions.
I'm not going to bother making the code more elegant, but I got it to
handle your text. Note you have to put any character your text
includes in the definition of "all-characters".= or that character
won't appear. I put in the characters with accents that your text
uses.
For the fun of it, you can add other characters to the definition of
"characters-to-color".
For what it's worth, probably the answer given by Fr. Samuel Springuel
is better for your use case :)
Best,
David Nalesnik
\version "2.20.0"
\language "deutsch"
#(define all-characters
;; this contains every character that the text might use, including ones to be colored red
;; make sure there are no duplicates (they will appear doubled in the transformed text...)
'(" " "!" "\"" "$" "%" "'" "(" ")" "*" "+" "," "-" "." "/"
"0" "1" "2" "3" "4" "5" "6" "7" "8" "9" ":" ";" "<" "=" ">" "?" "@"
"A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
"[" "\\" "]" "^" "_" "`"
"a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "ó" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "ż"
"{" "|" "}" "~"))
#(define characters-to-color "*")
#(define (find-pos-length-pair str symb)
;; for the specified character --> '((position . length) (position . length) ...)
(let ((result '())
(counter 0))
(define (helper str)
(let ((pos (string-contains str symb)))
(if pos
(let ((dpos (+ pos (string-length symb))))
(set! result (append result (cons (cons (+ pos counter) (string-length symb)) '())))
(set! counter (+ counter dpos))
(helper (string-drop str dpos))))))
(helper str)
result))
#(define (create-pos-length-alist str)
;; join alists of character data
(let ((result '()))
(for-each
(lambda (sym)
(let ((pos-length (find-pos-length-pair str sym)))
(if (pair? pos-length)
(set! result (append result pos-length)))))
all-characters)
result))
#(define (sort-alist alist)
;; sort alist by keys
(sort alist (lambda (p q) (< (car p) (car q)))))
#(define convert-alist-to-markup
(lambda (grob)
(let* ((text (ly:grob-property grob 'text))
(char-alist (sort-alist (create-pos-length-alist text))) ; position/length data for each character in text
(result '()))
(for-each (lambda (x)
;; convert each substring into a markup
;; if it is in the list characters-to-color, make it red
(let* ((left (car x))
(right (+ (car x) (cdr x)))
(substr (substring text left right)))
(if (string-contains characters-to-color substr)
(set! result (append result (list (markup #:with-color red substr))))
(set! result (append result (list (markup substr)))))))
char-alist)
(set! result (make-concat-markup result))
(set! (ly:grob-property grob 'text) result))))
colorSymbols =
#(define-music-function
(parser location) ()
#{
\override Lyrics . LyricText #'before-line-breaking = #convert-alist-to-markup
#})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
transpozycja = c'
akordy = {
\chordmode{
}
}
melodia = {
\key d \minor
f8 g[ a] a\breve b8 a g a4\bar "|"
a\breve g8 f g[ a] g[( f e] d4)\bar "|."
}
tekst = {
\lyricmode {
\override LyricSpace #'minimum-distance = #1.0
\override LyricText #'font-size = #3
\colorSymbols
Bo -- że, "mój Boże," szu -- kam Cie -- "bie *"
"i pragnie Ciebie" mo -- ja du -- sza._*
}
}
\score {
\transpose c' \transpozycja
<<
\chords { \akordy }
\relative c' {
\cadenzaOn \autoBeamOff \melodia
}
\addlyrics {
\set stanza = "1."
\tekst
}
>>
}
\layout {
\context {
\Lyrics
\override LyricText.self-alignment-X = #-1
\override StanzaNumber.font-series = #'medium
\override StanzaNumber.color = #(rgb-color 0.894 0.207 0.172)
\override StanzaNumber.font-size = #+1
}
\context {
\ChordNames
\germanChords
chordNameLowercaseMinor = ##t
}
\context {
\Lyrics \consists "Bar_engraver"
\consists "Separating_line_group_engraver"
\hide BarLine
}
}