Le 27/06/2022 à 12:12, Thomas Morley a écrit :
Hi,

https://lsr.di.unimi.it/LSR/Item?id=467 provides a markup-command to
access header-entries for use in arbitrary markup.
Alas it's limited to $defaultheader.
Although there is a comment to add/access other headers like from
\score, \bookpar explicit \book, I found no way to do so.
I tried to look up '$current-book/'$current-bookpart in parser (and
apply ly:book-header on the result), but to no avail, the  book(part)
is not found.

How to do so?

Below some code to play with (I reformated, renamed the original
snippet, adding some condition etc):

\version "2.22.1"

%% LSR 467
#(define-markup-command (with-header layout props markup) (markup?)
   "Interpret the given markup with the header fields added to the props.
This way, one can re-use the same functions (using fromproperty
#'header:field) in the header block and as top-level markup."
;; TODO: If we are inside a score, add the score's local header block, too!
;; Currently, I only use the global header block, stored in $defaultheader
   (let ((scopes (list $defaultheader)))

(pretty-print
   (list
     (cons '$current-bookpart (ly:parser-lookup '$current-bookpart))
     (cons '$current-book (ly:parser-lookup '$current-book))
   )
)
     (if (every module? scopes)
         (let* ((alists (map ly:module->alist scopes))
                (prefixed-alist
                 (map
                   (lambda (alist)
                      (map
                        (lambda (entry)
                          (cons
                            (symbol-append 'header: (car entry))
                            (cdr entry)))
                        alist))
                   alists))
                (props
                  (append
                    prefixed-alist
                    props
                    (layout-extract-page-properties layout))))
           (interpret-markup layout props markup))
         (begin
           (ly:warning "No header-module found, returning point-stencil")
           point-stencil))))

%{
%% (1) \header and \markup at toplevel
%% works
\header { my-entry = "Whatever" }
\markup \with-header \with-color #red \fromproperty #'header:my-entry
%}

%{
%% (2) \header and \markup in explizit book
%% How to make it work?
\book {
   \header { my-entry = "Whatever" }
   \markup \with-header \with-color #red \fromproperty #'header:my-entry
}
%}

% {
%% (3) \header and \markup in \bookpart
%% %% How to make it work?
\bookpart {
   \header { my-entry = "Whatever" }
   \markup \with-header \with-color #red \fromproperty #'header:my-entry
}
%}

%{
%% (4) \header and \markup in toplevel \score
%% %% How to make it work?
\score {
   { b1-\markup \with-header \with-color #red \fromproperty #'header:my-entry }
   \header { my-entry = "Whatever" }
}
%}


I don't have the time to investigate much right now, but I
think it would be possible by changing the toplevel-score-handler
and such to set a property in the \layout to the \header, and later
use that property from the layout argument of the markup command.

This is likely to be a bit fragile, though. What is the use case?
There may be better ways to achieve what is wanted.

Jean

Reply via email to