Thanks for elaborating, Harm. That’s some elegant coding with which I
couldn’t have come up :-)
Am 15.03.2015 um 19:22 schrieb Thomas Morley:
[snip]
\version "2.19.16"
%% Please note, \language has to be declared before 'used-language'
%% is done or included, (if stored elsewhere)
\language "deutsch"
%\language "english"
%% if no tagline for a language is defined, default-english will be
printed
%\language "catalan"
%% TODO: find better method to detect which language is actually used
#(define used-language
(car
(find
(lambda (e) (eq? (cdr e) (ly:parser-lookup parser 'pitchnames)))
language-pitch-names)))
I imagine that a generic solution worth being included in the code base
would require this definition to be made through the \language command
itself.
englishTaglineText = #(format #f
"Music typeset using LilyPond
~a~awww.lilypond.org <http://awww.lilypond.org>"
(lilypond-version)
(ly:wide-char->utf-8 #x2014) ;; 2014 = em dash.
)
germanTaglineText = #(format #f
"Noten gesetzt mit LilyPond ~a ~a
www.lilypond.org <http://www.lilypond.org>"
(lilypond-version)
(ly:wide-char->utf-8 #x2013) ;;2013 = en dash.
)
#(define taglines
`(
(deutsch . ,germanTaglineText)
(english . ,englishTaglineText)
))
#(define-markup-command (format-tagline layout props text) (markup?)
(interpret-markup layout props
#{
\markup {
\italic
\pad-to-box #'(0 . 0) #'(0 . 3)
{
\with-url #"http://lilypond.org/"
$text
}
}
#}))
#(define used-tagline
(markup #:format-tagline
(let ((tagl (assoc-get used-language taglines)))
(if tagl
tagl
(assoc-get 'english taglines)))))
\header {
tagline = #used-tagline
}
In the attachment, I made an additional function, getTagline, to have
the user select a tagline (somehow, it didn’t work with define in line
57, only if tagline was already defined and then set! applied – why?).
(There’s certainly room for improvements in the coding.)
Thanks
Simon
\version "2.19.16"
%% Please note, \language has to be declared before 'used-language'
%% is done or included, (if stored elsewhere)
\language "deutsch"
%\language "english"
%% if no tagline for a language is defined, default-english will be printed
%\language "catalan"
%% TODO: find better method to detect which language is actually used
#(define used-language
(car
(find
(lambda (e) (eq? (cdr e) (ly:parser-lookup parser 'pitchnames)))
language-pitch-names)))
englishTaglineText = #(format #f
"Music typeset using LilyPond ~a~awww.lilypond.org"
(lilypond-version)
(ly:wide-char->utf-8 #x2014) ;; 2014 = em dash.
)
germanTaglineText = #(format #f
"Noten gesetzt mit LilyPond ~a ~a www.lilypond.org"
(lilypond-version)
(ly:wide-char->utf-8 #x2013) ;;2013 = en dash.
)
#(define taglines
`(
(deutsch . ,germanTaglineText)
(english . ,englishTaglineText)
))
#(define-markup-command (format-tagline layout props text) (markup?)
(interpret-markup layout props
#{
\markup {
\italic
\pad-to-box #'(0 . 0) #'(0 . 3)
{
\with-url #"http://lilypond.org/"
$text
}
}
#}))
#(define used-tagline
(markup #:format-tagline
(let ((tagl (assoc-get used-language taglines)))
(if tagl
tagl
(assoc-get 'english taglines)))))
tagline = #used-tagline
getTagline = #(define-void-function
(parser location lang) (string?)
(set! tagline
(markup #:format-tagline
(let ((tagl (assoc-get (string->symbol lang) taglines)))
(if tagl
tagl
(begin
(ly:warning (format #f "Tagline for ~a not supported, using English." lang))
(assoc-get 'english taglines))))))
;(display tagline)
)
\header {
\getTagline "deutsch"
}
{ c''1 }_______________________________________________
bug-lilypond mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-lilypond