[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: \bookpart and variables
From: |
David Kastrup |
Subject: |
Re: \bookpart and variables |
Date: |
Mon, 09 Feb 2015 18:55:24 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Werner LEMBERG <address@hidden> writes:
>>> why are variable assignments not allowed in \bookpart? [...]
>>
>> Well, as far as I can see, assignments are also not allowed in
>> books.
>
> Hmm...
>
>> And the reason mostly would be that books and bookparts don't have
>> scope of their own (apart from book's \paper block). So even if it
>> were allowed, it would end up just the same as a global assignment
>> outside of the book/bookpart.
>
> OK. Even if \book and \bookpart don't provide `real' grouping (in the
> lilypond sense), they contain data between `{' and `}' – let's call
> this visual grouping. I consider it quite natural to put stuff into
> `\bookmark { ... } ' to indicate that it belongs together.
>
>> Do you have a particular use case in mind?
>
> Yes. I have the following structure for a collection of piano pieces
>
> file-a.ly: left = ...
> right = ...
>
> file-b.ly: left = ...
> right = ...
> ...
>
> and I would like to organize it as follows.
>
> \bookpart {
> \include "file-a.ly"
> \score { ... }
> }
>
> \bookpart {
> \include "file-b.ly"
> \score { ... }
> }
>
> ...
>
> Right now, I have to do this:
>
> \include "file-a.ly"
> \bookpart {
> \score { ... }
> }
>
> \include "file-b.ly"
> \bookpart {
> \score { ... }
> }
Well, yes. The former arrangement suggests a locality that is not
there. Here is an example (where I use the Scheme equivalent of
assignment):
\book {
\bookpart {
#(define notecolor blue)
\score {
{ \override NoteHead.color = #(lambda (grob) notecolor)
c1
}
}
}
\bookpart {
#(define notecolor red)
\score {
{ \override NoteHead.color = #(lambda (grob) notecolor)
c1
}
}
}
}
Now wouldn't you expect, assuming assignment were allowed where
#(define...) is not being used, that the bookparts would show different
colors for the noteheads?
Instead both of them have red noteheads because both use the same global
variable `notecolor' and reference it when \book starts iterating the
already assembled bookparts.
So as long as everything refers to global variables _and_ bookparts are
not iterated when they are encountered but only after the complete music
expressions in a book have been collected, we are just asking for
trouble by allowing assignment in places where the actual execution
happens at a different time than the assignments would.
--
David Kastrup