4

I'm running into an issue trying to pass a variable between three files. For example:

  • in fileA.ily I have the variable number = "3"
  • in fileB.ly I have the statement \include "fileA.ily" and \include "fileC.ily"
  • in fileC.ily I have the statement {c'4 \mark \markup { \number }.

And this works fine. When I compile fileB, the variable number gets picked up. The problem I'm running into, though, is when I use a more complicated scheme-style \include statement in fileB. For example:

#(define subdir "somefolder")
#(define subdir2 "somefolder2")
\include #(string-append "firstDir/" subdir "/filename" ".ily")
\include #(string-append "firstDir/" subdir2 "/filename" ".ily")

When I use these kinds of includes, then when I compile fileB, it performs the includes correctly but doesn't find the number variable like it did in the first example. Any advice?

0

1 Answer 1

4

I’m rather surprised that the first version works for you. Basically the problem is that \number is already defined as a markup command. During parsing of markup statements Lilypond will first try to evaluate a command \abc as markup command and then (if no such command exists) try to scope it. This means that in your example Lilypond should always try to call the \number ... markup command, and fail due to no argument being passed. This behaviour can be seen in this example:

\markup "Default:"
\markup \draw-hline

\markup "Overriding \draw-hline:"
draw-hline = "abc"
\markup \draw-hline

\markup "Using \draw-hlineb instead:"
draw-hlineb = "abc"
\markup \draw-hlineb

You’ll see that overriding the markup command draw-hline will not in fact affect the output.

There are multiple things you can do to circumvent this: Instead of doing number = "3" you could redefine the markup command like this #(define-markup-command (number layout props) () (interpret-markup layout props "3")), although it is arguable whether this is really a good way to do it. You could also change the name of the variable to something that is not a markup command, like NUMBER. Then you could also explicitely force the parser to scope the number variable. This can be done by not using \number, but #number, which explicitely tells the parser to evaluate the scheme expression number, which then scopes for a binding to number. So instead of {c'4 \mark \markup { \number }} you’d do {c'4 \mark \markup { #number }}.

3
  • When I left my comments for the OP, I looked to see if \number was predefined, but didn't find it. What is it for?
    – Aaron
    Commented May 28, 2022 at 13:43
  • 1
    Look in lilypond.org/doc/v2.23/Documentation/notation/…. Commented May 28, 2022 at 14:28
  • 1
    @Aaron As can be seen in the docs linked by Jean \number ... is used to switch the font style for the argument to Lilypond’s special number style, used for Time Signatures, Fingerings &c.
    – Lazy
    Commented May 28, 2022 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.