[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Quick newbie help on coloring one letter at a time without space?
From: |
Jean Abou Samra |
Subject: |
Re: Quick newbie help on coloring one letter at a time without space? |
Date: |
Thu, 17 Jun 2021 23:15:04 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
Le 15/06/2021 à 16:52, darkijah@jesusgod-pope666.info a écrit :
I don't know why it would not have written to the forum, I thought I
did that - and not you.
%Rainbow Script:
#(define (color-list? x)
(and (list? x)
(every color? x)))
#(define-markup-command (rainbow layout props colors text)
(color-list? string?)
(let* ((chars (string->list text))
(atomic-strings (map string chars)))
(interpret-markup layout props
(make-concat-markup
(map make-with-color-markup
(apply circular-list colors)
atomic-strings)))))
%Rainbow end
This is what I am using at the moment.
---
\fontsize #-1 \rainbow #'("red" "orange" "yellow" "green" "lightblue"
"blue" "violet")
"Flojte sangbog til Bornene // Whistle song book to the Children"
}
But I would like to be able to have it work with special chars and
more defined colors like #(rgb-color 1 0 0) sorta thing :)
Dearly regards
- Darkijah
Here is how far I could get it:
\version "2.22.1"
#(use-modules (srfi srfi-26))
#(define (color-list? x)
(and (list? x)
(every color? x)))
#(define (unicode-aware-string->atomic-strings str)
(let* ((chars (string->list str)))
(map (cute apply string <>)
(let loop ((remaining-chars chars)
(new-chars '()))
(cond
((null? remaining-chars)
(reverse! new-chars))
((eqv? #\303 (car remaining-chars))
(loop (cddr remaining-chars)
(cons (list (car remaining-chars)
(cadr remaining-chars))
new-chars)))
(else
(loop (cdr remaining-chars)
(cons (list (car remaining-chars))
new-chars))))))))
#(define-markup-command (rainbow layout props colors text)
(color-list? string?)
(interpret-markup layout props
(make-concat-markup
(map make-with-color-markup
(apply circular-list colors)
(unicode-aware-string->atomic-strings text)))))
\markup \fontsize #-1 \rainbow #`(,(rgb-color 0.5 0.4 0.2) "orange"
"yellow" "green" "lightblue" "blue" "violet")
"ABC ÅØ"
This should have more reliable Unicode support.
Note the Scheme syntax to put RGB colors in the list. You have to
replace the ' (quote) with ` (backtick, introducing what is called a
quasiquote). Then you can prefix an expression in the middle with a ,
(comma).
Best,
Jean