[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-user
Subject:    Re: More complex preprocessing with scheme
From:       Jean Abou Samra <jean () abou-samra ! fr>
Date:       2021-09-28 18:17:13
Message-ID: 0c7f4b29-736c-ee03-871d-f18953674b27 () abou-samra ! fr
[Download RAW message or body]

Le 27/09/2021 à 17:05, Andrew Zah a écrit :
> Hi all,
> 
> Is it possible to do something like have lilypond evaluate a Scheme 
> file in order to do more complicated preprocessing of song files?
> 
> Ultimately I'd like to have a template and then include files like so, 
> based on some logic:
> 
> % ...
> \bookpart {
> \tocItem \markup "$SONG"
> \include "$FILE"
> % etc.
> }
> % ...
> 
> I know it's possible to achieve this with external tools, but I'd like 
> to be able to simply run `lilypond` with some flags to change the output.
> 
> Thanks,
> Andrew


Hi Andrew,

What you expect is not 100% clear to me.
This file structure can be achieved with
just variables, for example included1.ly
defining

   song = "LilyPond song"

and main.ly having

   \tocItem \markup \song

or any kind of Scheme code:

   \tocItem \markup #(string-upcase song)

To include a file of which the name is in
a variable, use

file = "/path/to/file.ly"

#(ly:parser-include-string
    (string-append "\\include \"" file "\""))

To read environement variables, use Guile's
getenv function.

https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Runtime-Environment.html#Runtime-Environment


In general, you can read parameters set from the
command line with the -e option. See

https://lilypond.org/doc/v2.22/Documentation/usage/command_002dline-usage#basic-command-line-options-for-lilypond


The typical way to construct or preprocess input would
be to define a syntax function as described at

https://lilypond.org/doc/v2.22/Documentation/extending/scheme-functions

With this approach, you're not compiling a central
.ly file anymore. You define the function in
included.ly as

   myFunc =
   #(define-scheme-function (...) (...)
      ...)

and you call it in an file you want:

   \include "included.ly"
   \myFunc ...

Best,
Jean


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic