Jump to content

Separating footers with a horizontal line

From LilyPond wiki
Revision as of 11:43, 26 February 2026 by SimonAlbrecht (talk | contribs) (New snippet: Separating footers with a horizontal line)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Separating footers from the main content of the page using a horizontal line can be done by altering the oddFooterMarkup paper variable (and evenFooterMarkup, if they should be different). However, this requires printing the horizontal line only if any footer is shown on that page; this snippet demonstrates how to program such a condition.

\version "2.24"

#(define (separator-condition layout props arg)
   (if (or (and (chain-assoc-get 'header:copyright props)
                ;on-first-page-of-part copied from ly/titling-init.ly
                (= (chain-assoc-get 'page:page-number props -1)
                   (ly:output-def-lookup layout 'first-page-number)))
           (and (chain-assoc-get 'header:tagline props)
                ;on-last-page
                (chain-assoc-get 'page:is-bookpart-last-page props #f)
                (chain-assoc-get 'page:is-last-bookpart props #f)))
       (interpret-markup layout props arg)
       empty-stencil))

\header {
  tagline = "Special tagline"
}

\paper {
  #(set-paper-size "a9landscape")
  oddFooterMarkup = \markup \center-column {
    %% how to make the following horizontal line conditional on whether the
    %% following header fields aren’t empty?
    \on-the-fly \separator-condition \with-color #grey \override #'(span-factor . 1/3) \draw-hline
    %% Copyright header field only on first page in each bookpart.
    \if \on-first-page-of-part \fill-line {
      \fromproperty #'header:copyright
    }
    %% Tagline only on last page in each book.
    \if \on-last-page \fill-line {
      \fromproperty #'header:tagline
    }
  }
}

\bookpart {
  \markup "(Public Domain content)"
}
\bookpart {
  \header { copyright = "©" }
  \markup "(Copyright content)"
  \pageBreak
  \markup \column { "(no Copyright statement""on subsequent page)" }
}
\bookpart {
  \markup "(final page with tagline)"
}