Le 20/03/2022 à 17:43, Richard Shann a écrit :
I wonder if someone could suggest how to get LilyPond to emit various
bits of information about the score it is typesetting. Specifically can
it be persuaded to display the number of pages in the output PDF and
the total number of systems?
The idea would be to guide the user as to suitable values for

\paper {
   system-count = xx
   page-count = yy
}

without having to count up the number of systems (pages is not really a
problem of course).

Richard Shann

Not sure if there's a more elegant way, but you could try

\version "2.22.2"

markWithPageInfo =
  %% Must not get called before line breaking
  \tweak X-extent #'(0 . 0)
  \tweak Y-extent #'(0 . 0)
  \tweak horizontal-skylines
    #(ly:make-unpure-pure-container 
ly:grob::simple-horizontal-skylines-from-extents)
  \tweak vertical-skylines
    #(ly:make-unpure-pure-container 
ly:grob::simple-vertical-skylines-from-extents)
  \tweak stencil
    #(lambda (grob)
       (let* ((sys (ly:grob-system grob))
              ;; No broken pieces for systems ...
              (alignment (ly:grob-object sys 'vertical-alignment))
              (all-alignments (ly:spanner-broken-into (ly:grob-original 
alignment)))
              (all-systems (map ly:grob-system all-alignments))
              (n-systems (length all-systems))
              (all-pages (map (lambda (s) (ly:grob-property s 'page-number))
                              all-systems))
              (n-pages (1+ (- (apply max all-pages)
                              (apply min all-pages))))
              (layout (ly:grob-layout grob))
              (defs (append `((n-systems . ,(number->string n-systems))
                              (n-pages . ,(number->string n-pages)))
                            (ly:output-def-lookup layout 'text-font-defaults)))
              (props (ly:grob-alist-chain grob defs))
              (text (ly:grob-property grob 'text)))
         (interpret-markup layout props text)))
  \mark \etc

{
  \markWithPageInfo \markup { Have \fromproperty #'n-systems systems on 
\fromproperty #'n-pages pages }
  \repeat unfold 20 { 1 1 \break }
}
Jean



Reply via email to