[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cannot pass number variable to \markup.
From: |
Jean Abou Samra |
Subject: |
Re: Cannot pass number variable to \markup. |
Date: |
Sun, 07 May 2023 20:23:32 +0200 |
User-agent: |
Evolution 3.48.1 (3.48.1-1.fc38) |
Hi,
I'm adding back the list in CC. Please always keep it so that everyone can participate.
Le dimanche 07 mai 2023 à 10:45 -0400, dfro a écrit :
Jean,
Thank you, for the fast reply and the clear explanation! Perhaps, this insight could be put in the Learning Manual, 2.4.1 Organizing pieces with variables; or, somewhere else on using Scheme in Lilypond.
If I may also ask about the last example in that section of the manual:
<code start>
\version "2.24.1"
myWidth = 60 % a number to pass to a \paper variable
% (the unit is millimeter)
myName = "Wendy" % a string to pass to a markup
aFivePaper = \paper { #(set-paper-size "a5") }
\paper {
\aFivePaper
line-width = \myWidth
}
{
c4^\myName
}
<code end>
Why can the # symbol be left off of the myWidth variable and other \paper block variables,
Only \markup mode is special. In normal mode, a number is interpreted as a number. In markup mode, a number is not interpreted specially so that \markup { 42 is the answer } works.
and why must the aFivePaper variable be enclosed within '\paper { ... }'?
Unlike TeX macros if you are used to that, LilyPond variables don't just "insert something in the input" at the point they are used. A variable is variable in the true programming sense. It is associated with a value (which has a type). In this case, it does not work to do
aFivePaper = #(set-paper-size "a5")
because that calls set-paper-size immediately, not at the point where the variable is used, but at the point it is defined. This does nothing since set-paper-size doesn't have an effect outside of a \paper block. And since set-paper-size doesn't return a meaningful value, which in Guile means that it returns a dummy value called “*unspecified*”, your variable aFivePaper just ends up containing this dummy value.
With \paper, the variable contains a paper block, and LilyPond will merge it with the outer paper block if you reference the variable inside such a block.
Best,
Jean
signature.asc
Description: This is a digitally signed message part