lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to know the current page number from inside a regular markup (no


From: Jay Anderson
Subject: Re: how to know the current page number from inside a regular markup (not score/book header)
Date: Mon, 10 Sep 2012 08:28:21 -0700

On Sun, Sep 9, 2012 at 11:40 PM, Wilbert Berendsen <address@hidden> wrote:
> I use regular markups to display titles for hymns in a hymn book. The
> hymn number should align to the right on right pages but to the left on
> left pages.
>
> A hymn can start anywhere on a page.
>
> It seems I can't access the page:page-number-string property inside a
> markup function if it is not called in the context of a page header or
> footer.
>
> Is there any possibility for a regular (toplevel) \markup { } to know
> the page it is drawn on? (Or, at least, whether it is a right or left
> page?)

I was playing with this a while back to get the hymn numbers on the
outside of the page. David Nalesnik had a good idea (See here for more
info: http://lists.gnu.org/archive/html/lilypond-user/2012-03/msg00024.html).
Here was my final markup function:

#(define-markup-command (title-number-markup layout props) ()
  (let* ((title (chain-assoc-get 'header:title props))
         (label (string->symbol (chain-assoc-get 'header:number props)))
         (number-markup #{ \markup { \rounded-box \bold \fontsize #2 {
\fromproperty #'header:number } } #} )
         (title-markup #{ \markup {
                            \override #'(offset . 3)
                            \override #'(thickness . 3)
                            \bold \underline \fontsize #2
{\fromproperty #'header:title }
                          } #} )
         (even-markup #{ \markup { \fill-line { $number-markup
$title-markup } } #})
         (odd-markup #{ \markup { \fill-line { $title-markup
$number-markup } } #})
         (stencil (interpret-markup layout props odd-markup))
         (x-ext (ly:stencil-extent stencil X))
         (y-ext (ly:stencil-extent stencil Y)))
    (ly:make-stencil
     `(delay-stencil-evaluation
       ,(delay (ly:stencil-expr
                 (let* ((table (ly:output-def-lookup layout 'label-page-table))
                        (page-number (if (list? table)
                                         (assoc-get label table)
                                         #f)))
                   (interpret-markup layout props
                     (if (and page-number (even? page-number))
                         even-markup
                         odd-markup))))))
     x-ext
     y-ext)))

Then right before the score something like:
{ \label #(string->symbol (number->string hymn-num)) }

-----Jay Anderson



reply via email to

[Prev in Thread] Current Thread [Next in Thread]