From 65a309c41e9f18befa34328a60efab9132e402c9 Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Wed, 15 Oct 2014 22:13:03 +0200 Subject: [PATCH] Roman numerals may be used for page numbers This patch builds on the number-format function used for string numbers and enables it for page numbers, through a new 'page-number-type paper property. Previously, a custom markup function had to be used as demonstrated in the bookparts.ly regtest, which has now been rewritten to make use of the new property. --- Documentation/changes.tely | 4 ++++ Documentation/notation/spacing.itely | 8 ++++++++ input/regression/bookparts.ly | 17 +++++++++++------ ly/paper-defaults-init.ly | 1 + scm/define-markup-commands.scm | 15 +++++++++++---- scm/titling.scm | 3 ++- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Documentation/changes.tely b/Documentation/changes.tely index 1dd439dfb0..467f5a30ca 100644 --- a/Documentation/changes.tely +++ b/Documentation/changes.tely @@ -61,6 +61,10 @@ which scares away people. @end ignore +@item +Page numbers may now be printed in roman numerals, by setting the +@code{page-number-type} paper variable. + @item It is now possible to use @code{\time} and @code{\partial} together to change the time signature in mid measure. diff --git a/Documentation/notation/spacing.itely b/Documentation/notation/spacing.itely index e90d71a45f..1cded7566a 100644 --- a/Documentation/notation/spacing.itely +++ b/Documentation/notation/spacing.itely @@ -991,6 +991,14 @@ If set to true, a page number is printed on the first page. If set to false, page numbers are not printed. +@cindex page numbers in roman numerals +@item page-number-type +@funindex page-number-type + +The type of numerals used for page numbers. Choices include +@code{roman-lower}, @code{roman-upper} and @code{arabic}. +Default: @code{'arabic}. + @end table @seealso diff --git a/input/regression/bookparts.ly b/input/regression/bookparts.ly index 52660c9312..7ee4cf1683 100644 --- a/input/regression/bookparts.ly +++ b/input/regression/bookparts.ly @@ -10,10 +10,6 @@ Page labels are also collected into the top-level paper." #(set-default-paper-size "a6") -#(define-markup-command (roman-page-number layout props) () - (let ((page-number (chain-assoc-get 'page:page-number props))) - (interpret-markup layout props (format #f "~@r" page-number)))) - \book { \tocItem \markup "First part" \header { title = "Book with several parts" } @@ -25,8 +21,17 @@ Page labels are also collected into the top-level paper." left-margin = 20\mm right-margin = 20\mm line-width = 65\mm - evenHeaderMarkup = \markup \fill-line { \roman-page-number "SECOND PART" \null } - oddHeaderMarkup = \markup \fill-line { \null "SECOND PART" \roman-page-number } + page-number-type = #'roman-upper + evenHeaderMarkup = \markup \fill-line { + \fromproperty #'page:page-number-string + "SECOND PART" + \null + } + oddHeaderMarkup = \markup \fill-line { + \null + "SECOND PART" + \fromproperty #'page:page-number-string + } } \tocItem \markup "Second part" \markup \justify { Second part, with different margins and page header. } diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly index ef74193122..398b5ac941 100644 --- a/ly/paper-defaults-init.ly +++ b/ly/paper-defaults-init.ly @@ -119,6 +119,7 @@ first-page-number = #1 print-first-page-number = ##f print-page-number = ##t + page-number-type = #'arabic %% %% Headers, footers, and titles diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index 467ccba7e1..20990a7385 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -1374,8 +1374,8 @@ equivalent to @code{\"fi\"}. "Perform simple wordwrap, return stencil of each line." (define space (if justify ;; justify only stretches lines. - (* 0.7 base-space) - base-space)) + (* 0.7 base-space) + base-space)) (define (stencil-len s) (interval-end (ly:stencil-extent s X))) (define (maybe-shift line) @@ -4231,7 +4231,11 @@ a column containing several lines of text. Reference to a page number. @var{label} is the label set on the referenced page (using the @code{\\label} command), @var{gauge} a markup used to estimate the maximum width of the page number, and @var{default} the value to display -when @var{label} is not found." +when @var{label} is not found. + +(If the current book or bookpart is set to use roman numerals for page numbers, +the reference will be formatted accordingly -- in which case the @var{gauge}'s +width may require additional tweaking.)" (let* ((gauge-stencil (interpret-markup layout props gauge)) (x-ext (ly:stencil-extent gauge-stencil X)) (y-ext (ly:stencil-extent gauge-stencil Y))) @@ -4244,7 +4248,10 @@ when @var{label} is not found." (page-number (if (list? table) (assoc-get label table) #f)) - (page-markup (if page-number (format #f "~a" page-number) default)) + (number-type (ly:output-def-lookup layout 'page-number-type)) + (page-markup (if page-number + (number-format number-type page-number) + default)) (page-stencil (interpret-markup layout props page-markup)) (gap (- (interval-length x-ext) (interval-length (ly:stencil-extent page-stencil X))))) diff --git a/scm/titling.scm b/scm/titling.scm index 41a32dd467..a29bdd25b6 100644 --- a/scm/titling.scm +++ b/scm/titling.scm @@ -48,6 +48,7 @@ variables set in @var{scopes} and @code{page:is-bookpart-last-page}, (cdr entry))) alist)) alists)) + (number-type (get 'page-number-type)) (pgnum-alist (list (cons 'header:tagline @@ -56,7 +57,7 @@ variables set in @var{scopes} and @code{page:is-bookpart-last-page}, (cons 'page:is-last-bookpart is-last-bookpart) (cons 'page:is-bookpart-last-page is-bookpart-last-page) (cons 'page:page-number-string - (number->string page-number)) + (number-format number-type page-number)) (cons 'page:page-number page-number))) (props (append (list pgnum-alist) -- 2.39.2