[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Basic Scheme Markdown Function
From: |
David Kastrup |
Subject: |
Re: Basic Scheme Markdown Function |
Date: |
Fri, 06 Dec 2024 23:17:31 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Mark Knoop <mark@opus11.net> writes:
> At 14:40 on 06 Dec 2024, Steph Phillips wrote:
>> Hi all, this one's probably a simple solution, but I'm a
>> little fuzzy on how to implement custom Scheme functions
>> still.
>
>> I'm working on a musical theater score, and there are lots
>> of instrument changes formatted like this:
>
>> changeBbClar = ^\markup {
>> \general-align #X #-0.7
>> \bold
>> \override #'(box-padding . 0.5) \box
>> "Bb Clarinet"
>> }
>
>> My end goal is a function where I can define the name of
>> the instrument and the x-alignment - something like
>
>> \InstrumentChange "Bb Clarinet" #-0.7
>
> This will do what you want.
>
> InstrumentChange =
> #(define-music-function
> (mkp align) (markup? number?)
> #{
> <>^\markup
> \general-align #X #align
> \bold
> \override #'(box-padding . 0.5)
> \box #mkp
> #})
>
> For more details about writing music functions, see this excellent
> guide put together by Jean:
>
> https://extending-lilypond.gitlab.io/en/extending/index.html
It would make more sense to have the markup as last argument because it
makes stacking functions on markup a lot more readable. And there may
be a point in making the number an optional argument and providing a
default. So that would end up more like
InstrumentChange =
#(define-music-function
(align mkp) ((number? LEFT) markup?)
#{
<>^\markup
\general-align #X #align
\bold
\override #'(box-padding . 0.5)
\box #mkp
#})
Of course the original example would not work until changing it to
\InstrumentChange #-0.7 "Bb Clarinet"
--
David Kastrup