Le 28/04/2015 10:03, ArnoldTheresius a écrit :
Hello,
if the first-page-number is different than 1, then the page-links in the PDF
(i.e. TOC, \page-link, \label & \page-ref) lead you to the wrong page.
E.g. first-page-number = 3; then a link to page 4 will lead you to the 4th
page, but this is page 6.
(done with Lilypond 2.18.2 on Windows, both Acrobat and SumatraPDF)


Here is what I do, thanks to Thomas Morley, and it works like a charm.

Cheers,
Jean-Charles
%%%%%%%%%%%%%%%%%%%%%
%% Correct page linking in pdf
%% Thanks Thomas Morley

#(define (book-first-page layout props)
   (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) 'first-page-number))

#(define-markup-command (with-link layout props label arg)
  (symbol? markup?)
  (let* ((arg-stencil (interpret-markup layout props arg))
         (x-ext (ly:stencil-extent arg-stencil X))
         (y-ext (ly:stencil-extent arg-stencil Y)))
    (ly:make-stencil
     `(delay-stencil-evaluation
       ,(delay (ly:stencil-expr
                (let* ((table (ly:output-def-lookup layout 'label-page-table))
                       (first-page-number (book-first-page layout props))
                       (orig-page-number (if (list? table)
                                        (assoc-get label table)
                                        #f))
                       (page-number (+ orig-page-number (+ 1 (* -1 
first-page-number) )))
                       (link-expr (list 'page-link page-number
                                        `(quote ,x-ext) `(quote ,y-ext))))
                  (ly:stencil-add (ly:make-stencil link-expr x-ext y-ext)
      arg-stencil)))))
           x-ext
           y-ext)))
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to