3

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?

3
  • Have you tried embedding the fileC statement within a scheme expression? My thought is whether there's an issue of when (scheme) expressions are being evaluated: during compilation vs. at run-time.
    – Aaron
    May 28 at 2:21
  • Aaron, thanks, I tried that but it didn't work.
    – Ryan
    May 28 at 4:11
  • One other thought. How about changing fileA to be a scheme function called "number" that returns "3"?
    – Aaron
    May 28 at 4:29

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
    May 28 at 13:43
  • 1
  • 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
    May 28 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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