Hello,
thanks a lot for your thoughts, David.
Am 25.03.2015 um 16:33 schrieb David Nalesnik:
Hi Simon,
I can't judge whether this is getting closer to you want, but maybe my
observations can help.
On Wed, Mar 25, 2015 at 9:17 AM, Simon Albrecht
<simon.albre...@mail.de <mailto:simon.albre...@mail.de>> wrote:
Hello,
I’m experimenting with an implementation of automatic tagline
language selection and currently have two problems with the void
function \language that I adapted from music-functions-init.ly
<http://music-functions-init.ly>:
– I can’t get the first, optional argument to work; it needs to be
explicitly given or Lily will take the string as first argument –
although it’s required to be a symbol.
I haven't succeeded in making this work with the optional argument in
the first position. I moved it last.
From the design point of view I think it’s necessary to have it first:
it’s much more intuitive to write \language output "deutsch" than
\language "deutsch" output.
I don’t quite get why having the optional argument first doesn’t work:
after all, this is commonly used in music functions and scheme
functions. But apparently define-void-function is implemented differently.
This would then mean that one has to always specify the first argument,
which is not the most elegant form. I’ll probably switch to using three
distinct functions \language, \inputLanguage and \outputLanguage (with
the names being subject to discussion of course).
However, the last argument either must be specified with a symbol or
with \default. Otherwise, the following expression will be taken as
the argument and an error will be raised: in my rewrite that is
'#(newline)'.
– The define in the second clause to cond doesn’t work: there are
two errors due to output-language being an unbound variable.
You need to define output-language as a global variable. Then you can
set it within the music function. In your version, output-language
only exists within the music function's scope, and so it is
inaccessible to your format call, for example.
Note:
I don't think the cond expression within the definition of 'language'
is what you want. Once we hit a true value, we leave the cond
expression entirely. It appears that you want _both_ clauses to be
evaluated, so I used two if expressions.
Right you are.
I attach another state of work, which now works fine. It will have to be
extended by solutions for tocTitleMarkup and eventually tocItemMarkup
and then perhaps I’ll even make a patch myself. We’ll see :-)
Yours,
Simon
\version "2.19.16"
#(define output-language 'english)
inputLanguage =
#(define-void-function (parser location language) (string?)
(_i "Set note names for language @var{language}.")
(note-names-language parser language))
outputLanguage =
#(define-void-function (parser location language) (string?)
(_i "Define language for output (i.e. display tagline and table of contents in @var{language})")
(set! output-language (string->symbol language))
)
language =
#(define-void-function (parser location language) (string?)
(_i "Define languages for input (i.e. set note names for @var{language}) and
output (i.e. display tagline and table of contents in @var{language})")
(note-names-language parser language)
(set! output-language (string->symbol language))
)
%\language "deutsch"
\inputLanguage "deutsch"
\outputLanguage "catalan"
#(format #t "Output language has been defined as ~a" output-language)
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 {
\pad-to-box #'(0 . 0) #'(0 . 3)
{
\with-url #"http://lilypond.org/";
$text
}
}
#}))
tagline =
\markup \format-tagline
#(let
((tagl (assoc-get output-language taglines)))
(if tagl
tagl
(begin
(ly:warning (format #f "Tagline for ~a not defined, using the english one."
(symbol->string output-language)))
(assoc-get 'english taglines))))
\header {
}
{ h'1 }
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user