Hello Leo,

Here are two ways to do it, one by using \include and one directly parsing the 
contents of the file.

Cheers,
Valentin

Am Dienstag, 1. Februar 2022, 16:09:01 CET schrieb Leo Correia de Verdier:
> Dear list!
> 
> Is there a way to have an \include inside a function?
> In the attached file includeinfunction.ly the commented out line doesn’t
> work (probably for some very logical reason, but still unknown to me). Is
> there a way to work around that and have includes inside functions?
> 
> (The function in this case is indeed meaningless, in my real use case the
> function will hopefully construct midi files from the variables in the
> included files combined in different ways)
> 
> Thanks a lot!
> 
> /Leo
\version "2.23.3"

music = { b1 }
\version "2.23.3"

includeFunction = #(define-void-function (filename) (string?)
                     (ly:parser-parse-string (ly:parser-clone) (ly:gulp-file filename)))

%% or alternatively

includeFunctionB = #(define-void-function (filename) (string?)
                     (ly:parser-parse-string (ly:parser-clone) (format "\\include \"~a\"" filename)))

%\include "includetest.ily"

\includeFunction "includetest.ily"

\score { \music }

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to