Am Mittwoch, 21. Mai 2008 schrieben Sie:
> Le 21 mai 08 à 18:21, Reinhold Kainhofer a écrit :
> > [...] how can I access the header fields from a top-level markup?
>
> Book and score title are dealt with in a special way: when they
> are interpreted, the header variables are added to the properties
> provided to the command, which can then retrieve the header
> variables.
Ah, thanks for the thorough explanation and the implicit hint to RTFC...
> This is not the case of other markups. You may work around that
> by using variables defined in the paper block, and then retreiving
> them using the command layout argument.
The alternative is to implement a \markupWithHeader, which does exactly this:
Add the variables defined in the header block to the props (i.e. mimicking
the mark-up-title command) before interpreting the markup.
My attempt for this is attached and works quite well. The PDF is too large for
the mailing list, so I uploaded it to our server:
http://www.fam.tuwien.ac.at/~reinhold/temp/using_header_fields_in_arbitrary_markup.pdf
The only problem I'm experiencing is that I can only pass markups stored in a
variable, but not explicit markups. I.e. while
testMarkup = \markup {Title: \fromproperty #'header:title }
\markup \markupWithHeader \testMarkup
works, the following does not work
\markup \markupWithHeader \markup {Title: \fromproperty #'header:title }
What's the difference of the two?
The other thing I'm missing is a way to retrieve the local header module if
the markup is placed inside a score (see the score in the attached example).
In particular, how can I get the score, so I can call ly:score-header on it?
Currently, I'm only using the global header block...
Also, I suppose there is no way to get rid of the first \markup and simply use
\markupWithHeader instead, since the parser checks for \markup explicitly and
does a lot of stuff on it, right?
Cheers,
Reinhold
--
------------------------------------------------------------------
Reinhold Kainhofer, Vienna University of Technology, Austria
email: [EMAIL PROTECTED], http://reinhold.kainhofer.com/
* Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.at/
* K Desktop Environment, http://www.kde.org, KOrganizer maintainer
* Chorvereinigung "Jung-Wien", http://www.jung-wien.at/
\version "2.11.46"
% This function is originally copied from mark-up-title (file scm/titling.scm),
% which is lilypond's internal function to handle the title markups. I needed
% to replace the scopes and manually add the $defaultheader (which is internally
% done in paper-book.cc before calling mark-up-title. Also, I don't extract the
% markup from the header block, but use the given markup.
%
% I'm not sure if I really need the page properties in props, too... But I
% suppose it does not hurt, either.
#(define-markup-command (markupWithHeader 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."
(let* (
; 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
(scopes (list $defaultheader))
(alists (map ly:module->alist scopes))
(prefixed-alist
(map (lambda (alist)
(map (lambda (entry)
(cons
(string->symbol (string-append "header:" (symbol->string (car entry))))
(cdr entry)))
alist))
alists))
(props (append prefixed-alist
props
(layout-extract-page-properties layout)))
)
(interpret-markup layout props markup)
)
)
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% test markup containing references to header fields:
testMarkup = \markup {
\justify {
This is a text inserted using the new \typewriter{"\\markupWithHeader"}
command to allow using header fields
(via \concat{"\fromproperty #'header:fieldname").} For example, the title field
is \fontsize #+3 \fromproperty #'header:title and
the composer is \fontsize #+3 \fromproperty #'header:composer
}
}
\header {
title="My own title"
composer="Someone"
piece = "Global piece name"
}
% Print out the markups. The \fromproperty #'header:field are now properly
% interpreted.
\markup\markupWithHeader \testMarkup
% Unfortunatly, I'm not able to directly pass a markup to the function????
%
% \markup\markupWithHeader \markup {
% \wordwrap {
% This is a long text, which is now able to use the header fields
% (via "\fromproperty #'header:fieldname"). For example, the title field
% of this score is: \fromproperty #'header:title and the composer is:
% \fromproperty #'header:composer
% }
% }
% FIXME: How can I get the score object for markups inside a score, so that I
% can add the local header block to the properties, too?
scoreTestMarkup = \markup {Piece: \fontsize #+2 \fromproperty #'header:piece }
\score {
\relative c'' { c1^\markup\markupWithHeader\scoreTestMarkup}
\header { piece = "Local piece name" }
}_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user