[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Access header-modules from inside markup-command
From: |
Thomas Morley |
Subject: |
Access header-modules from inside markup-command |
Date: |
Mon, 27 Jun 2022 12:12:55 +0200 |
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" }
}
%}
Thanks,
Harm
- Access header-modules from inside markup-command,
Thomas Morley <=