Le 27/02/2021 à 02:16, Ken Ledeen a écrit :

I am struggling to understand the restrictions on substitution functions.

For example:

1) can a function include "\score { ...}"  or can it only be invoked INSIDE a \score?

2) is it possible to include \header { ...}  inside a substitution function?  It fails when I try, but I don't understand why.

I assume I am missing some basic concepts regarding their use.

Thanks!


Hello,

Music functions must return music objects; \score blocks are not music but general containers that enclose music as well as other objects such as \header and \layout blocks.

However, replacing define-music-function with define-scheme-function, you can define more versatile functions that are allowed to return any kind of object for interpretation. For example:

\version "2.23.1"

failingFunction =
#(define-music-function () ()
   #{
     \score {
       \header {
         piece = "Piece A"
       }
       { c' }
     }
   #})

% \failingFunction

succeedingFunction =
#(define-scheme-function () ()
   #{
     \score {
       \header {
         piece = "Piece B"
       }
       { c' }
     }
   #})

\succeedingFunction


Hope that helps,
Jean


Reply via email to