\version "2.19.81" % Print table of contents entries to .toc % Based on % http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents % Pointed to by "Thomas Morley" #(define (oly:create-toc-file layout pages) (let* ((label-table (ly:output-def-lookup layout 'label-page-table)) (toc-items (toc-items))) (if (not (null? label-table)) (let* ( ;; We need a page-offset so entries are offset to begin with p.1 ;; (for use in \includepdf) (page-offset (- (ly:output-def-lookup layout 'first-page-number) 1)) (format-line (lambda (toc-item) (let* ((label (car toc-item)) (display text (caddr toc-item)) (page (- (assoc-ref label-table label) page-offset))) (format #f "~a,subsection,2,{~a},~a" page text label)))) (formatted-toc-items (map format-line toc-items)) (whole-string (string-join formatted-toc-items ",\n")) (output-name (ly:parser-output-name)) (outfilename (format "~a.toc" output-name)) (outfile (open-output-file outfilename))) (if (output-port? outfile) (display whole-string outfile) (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename)) (close-output-port outfile))))) \paper { first-page-number = 20 print-first-page-number = ##t #(define (page-post-process layout pages) (oly:create-toc-file layout pages)) } \bookpart { \tocItem \markup "A TOC entry" { c' } } \bookpart { \tocItem \markup "Another TOC entry" { d' e' } }