lilypond-user
[Top][All Lists]
Advanced

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

Re: Custom footers


From: Thomas Morley
Subject: Re: Custom footers
Date: Wed, 20 Mar 2013 03:45:01 +0100

2013/3/19 Jérôme Plût <address@hidden>:
> Decimo quinto Kalendas Apriles MMXIII scripsit james :
>> they come from the header.
>
> That's what I figured from the documentation about footer markup. But
> this does not answer my question: is there a way to put in there, for
> example, a counter that gets incremented at each page and reset at
> each bookpart (or some more complicated stuff such as total page count
> for the book or bookpart)? This is possible for example in TeX as the footer
> markup is actually evaluated on each page. Is there a way to do it in
> Lilypond?
>
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user

Hi Jérôme,

in the code below you'll see increasing page-numbers throughout the
book as usual.
Additionally every bookpart has increasing page-numbers starting with "page 1"
Though, I didn't manage to code "(1/3)" for consecutive bookparts,
because I didn't understand how to get or calculate the
bookpart-last-page-number.

It's quite easy to get the bookpart-first-page-number via
(ly:output-def-lookup layout 'first-page-number).
And there is a testing about bookpart-last-page-number:
(chain-assoc-get 'page:is-bookpart-last-page props #f)
If there is a test, the values to compare must be somewhere, but I
couldn't find them.

Nevertheless here's the code:

\version "2.16.2"

#(define (looking-up layout props symbol)
   (define (ancestor layout)
     "Return the topmost layout ancestor"
     (let ((parent (ly:output-def-parent layout)))
       (if (not (ly:output-def? parent))
           layout
           (ancestor parent))))
   (ly:output-def-lookup (ancestor layout) symbol))

#(define (book-second-page? layout props)
   "Return #t iff the current page number, got from @code{props}, is the
    book second one."
   (= (chain-assoc-get 'page:page-number props -1)
      (+ (looking-up layout props 'first-page-number) 1)))

#(define (not-second-page layout props arg)
   (if (not (book-second-page? layout props))
       (interpret-markup layout props arg)
       empty-stencil))

#(define (print-bookpart-numbers layout props arg)
   (let* ((book-page-number
            (chain-assoc-get 'page:page-number props -1))
          (bookpart-first-page-number
            (ly:output-def-lookup layout 'first-page-number))
          (book-part-numbers
            (number->string (- book-page-number bookpart-first-page-number -1)))
          (book-part-number-markup
            (markup book-part-numbers)))
      (interpret-markup layout props book-part-number-markup)))


\paper {
  %% works with different settings of `first-page-number´
  %% currently the default is set
  first-page-number = 1

  %% For now page-header are set #f
  oddHeaderMarkup = ##f
  evenHeaderMarkup = ##f

  oddFooterMarkup = \markup {
    %% Don't print on first and second book-page
    \on-the-fly #not-first-page
    \on-the-fly #not-second-page
    \column {
      \fill-line {
        \fromproperty #'header:title
        \fontsize #2 \italic \fromproperty #'header:instrument
        %% \parenthesize or \bracket. Choose one.
        \parenthesize
        %\bracket
        \concat {
                \fromproperty #'header:instrument
                "-part, page "
                %% "" needs to be here! because
                %% \on-the-fly expects _two_ arguments.
                \on-the-fly #print-bookpart-numbers ""
        }
      }
      \fill-line {
              \concat {
                      "- page "
                      \fromproperty #'page:page-number-string
                      " -"
              }
      }
    }
  }
}

\book {
  \bookpart {
          \markup \column {
                \vspace #8
               \fill-line { \fontsize #12 "Music" }
               \vspace #30
               \fill-line { \override #'(span-factor . 1/3) \draw-hline }
               \vspace #4
               \fill-line {
                       \fontsize #1
                       \center-column {
                               "edited"
                               "by"
                               "me"
                       }
               }
          }
  }
  \bookpart {
          \markuplist \table-of-contents
  }
  \bookpart {
          \tocItem \markup "First Piece"
          %% header on bookpart-top-level.
          %% Otherwise instrument-setting isn't recognized
          %% by page-headers/footers
          \header {
                  title = "First Piece"
                  instrument = "Trombone"
          }
          \score {
            \new Staff {
                  \repeat unfold 3 { c''1 \pageBreak }
            }
          }
  }
  \bookpart {
          \tocItem \markup "Second Piece"
          \header {
                  title = "Second Piece"
                  instrument = "Saxophone"
          }
          \score {
            \new Staff {
                  \repeat unfold 3 { cis''1 \pageBreak }
            }
          }
  }
}



HTH,
  Harm



reply via email to

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