lilypond-user
[Top][All Lists]
Advanced

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

Re: problem to code page-numbers


From: Thomas Morley
Subject: Re: problem to code page-numbers
Date: Sat, 15 Aug 2015 00:02:16 +0200

2015-08-14 12:21 GMT+02:00 Thomas Morley <address@hidden>:
> 2015-08-14 12:11 GMT+02:00 David Kastrup <address@hidden>:
>> Thomas Morley <address@hidden> writes:
>>
>>> Hi,
>>>
>>> I'm trying to put out a \book, affecting the page-numbers in a certain way.
>>> Ofcourse this should happen under certain conditions.
>>>
>>> Look at the minimal example below.
>>> All I try to affect is the `counter', if the page is the last of the 
>>> bookpart.
>>> I had expected that the counter would get up to 3 (starting at 1 and
>>> two bookparts having a last page)
>>> Instead it goes up to 9.
>>>
>>> No idea why it's called nine times.
>>
>> It can be called any number of times.  LilyPond does not guarantee you
>> that it gets the pages laid out perfect at first try.
>>
>> So you better not depend on any particular order or number of header
>> field calls.
>>
>> What is it that you are trying to do?
>>
>> --
>> David Kastrup
>
> Will need to be a bit more verbose then.
> Though, I have to run, will do in the evening.
>
>
> Thanks,
>   Harm

Finally I want to be able to set every bookparts first-page-numbers
indepent and solve the request here:
http://lists.gnu.org/archive/html/lilypond-user/2015-08/msg00237.html

As far as I know, we have no mechnism for it implemented.

Though, I recently made a snippet for the german forum, which
recalculates the page-numbers in a mannor that every bookpart starts
with page-number 1.
I thought it might be possible to extend it, to get arbitrary
page-numbers for every bookpart.
Obviously one needs to know when a new bookpart starts. Additionally
the correct entry from a list containing those arbitrary numbers needs
to be found.

Meanwhile I've found the coding below. It does the job, but needs to
refer to a list defined toplevel. And all in all I have the impression
it's very fragile.

Any hints to get rid of that toplevel list and to make it all more
robust are highly appreciated.

I'll attach the code as well, in case some mail-client will destroy
the indentation/linebreaks. Several comments inline.


\version "2.19.25"

#(define ls (list))

#(define (reset-part-first-page layout props arg)
  (let* ((actual-book-page (chain-assoc-get 'page:page-number props -1))
         (actual-part-first-page
           (ly:output-def-lookup layout 'first-page-number 1))
         (reset-part-first-page-number
           (ly:output-def-lookup layout 'reset-part-first-page-number #f))
         (new-props
           (if reset-part-first-page-number
               (prepend-alist-chain
                 'page:page-number-string
                 (number->string
                   ;; In case `reset-part-first-page-number' was set #t, do some
                   ;; calculation to put out every bookpart starting with
                   ;; page-number 1, increasing the follow page-numbers
                   ;;
                   ;; Otherwise we try to find a list of page-settings, probably
                   ;; stored in `reset-part-first-page-number'.
                   ;; If found, we choose the appropiate entry and do some
                   ;; calculations to put out this entry as the new
                   ;; bookparts-first-page-number, with incresing follow ups.
                   (if (boolean? reset-part-first-page-number)
                       (- actual-book-page (1- actual-part-first-page))
                       (begin
                         ;; `ls' is defined in \paper
                         ;; accumulate there every part-first-page, if not
                         ;; already present.
                         (if (or (null? ls)
                                 (not (= (car ls) actual-part-first-page)))
                             (set! ls (cons actual-part-first-page ls)))
                         ;; (length ls) shows us how many bookparts are present
                         ;; at the state of current compilation.
                         ;; Therefore we can use (length ls) to choose which
                         ;; element of `reset-part-first-page-number' should be
                         ;; taken for the new book-part-first-page-number.
                         ;; list-ref starts with 0, therefore we do 1-
                         ;; As a fall-back, put out the real `actual-book-page'
                         (if (or (< (length reset-part-first-page-number)
                                    (length ls))
                                 (null? ls))
                             actual-book-page
                             (let ((bookpart-new-first-page
                                     (list-ref
                                       reset-part-first-page-number
                                       (1- (length ls)))))
                              ;; Put out `actual-book-page', if a boolean was
                              ;; catched from `reset-part-first-page-number'
                              (if (boolean? bookpart-new-first-page)
                                  actual-book-page
                                  (+ (- actual-book-page actual-part-first-page)
                                     bookpart-new-first-page)))))))
                 props)
               props)))
    (interpret-markup layout new-props arg)))

\paper {
  %% This list may contain booleans, to get default page-counting for a certain
  %% bookpart
  reset-part-first-page-number = #'(1 60 17 613 41)
  oddHeaderMarkup = \markup
  \fill-line {
    " "
    \on-the-fly #print-page-number-check-first
      \on-the-fly #reset-part-first-page
      \fromproperty #'page:page-number-string
  }

  evenHeaderMarkup = \markup
  \fill-line {
    \on-the-fly #print-page-number-check-first
      \on-the-fly #reset-part-first-page
      \fromproperty #'page:page-number-string
    " "
  }
}

%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%

#(set-default-paper-size "a6")

\book {
  \markuplist \table-of-contents
  \pageBreak
  \markup "Prolog"

  \bookpart {
    \markup "first bookpart"
    \tocItem "first bookpart"
    \repeat unfold 3 { c''1 \pageBreak }
  }
  \bookpart {
    \markup "second bookpart"
    \tocItem "second bookpart"
    \repeat unfold 2 { d''1 \pageBreak }
  }
  \bookpart {
    \markup "third bookpart"
    \tocItem "third bookpart"
    \repeat unfold 4 { e''1 \pageBreak }
  }
  \bookpart {
    \markup "fourth bookpart"
    \tocItem "fourth bookpart"
    \repeat unfold 5 { f''1 \pageBreak }
  }
}



Thanks,
  Harm

Attachment: reset-every-bookpart-first-page-number-01.ly
Description: Text Data


reply via email to

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