]> git.donarmstrong.com Git - lilypond.git/blob - ly/toc-init.ly
c3fd5ab57d0ab3c236728d03350c65035e316bd3
[lilypond.git] / ly / toc-init.ly
1 \version "2.19.22"
2
3 %% defined later, in a closure
4 #(define-public (add-toc-item! markup-symbol text)
5   #f)
6 #(define-public (toc-items)
7   #f)
8
9 #(let ((toc-item-list (list)))
10    (call-after-session (lambda () (set! toc-item-list '())))
11    (set! add-toc-item!
12          (lambda (markup-symbol text)
13            (let ((label (gensym "toc")))
14              (set! toc-item-list
15                    (cons (list label markup-symbol text)
16                          toc-item-list))
17              (make-music 'EventChord
18                'page-marker #t
19                'page-label label
20                'elements (list (make-music 'LabelEvent
21                                  'page-label label))))))
22    (set! toc-items (lambda ()
23                      (reverse toc-item-list))))
24
25 \paper {
26   tocTitleMarkup = \markup \huge \column {
27     \fill-line { \null "Table of Contents" \null }
28     \null
29   }
30   tocItemMarkup = \markup \fill-line {
31     \fromproperty #'toc:text \fromproperty #'toc:page
32   }
33 }
34
35 tocItemWithDotsMarkup = \markup \fill-with-pattern #1 #RIGHT .
36   \fromproperty #'toc:text \fromproperty #'toc:page
37
38 #(define-markup-list-command (table-of-contents layout props) ()
39   ( _i "Outputs the table of contents, using the paper variable
40 @code{tocTitleMarkup} for its title, then the list of lines
41 built using the @code{tocItem} music function
42 Usage: @code{\\markuplist \\table-of-contents}" )
43   (cons (interpret-markup layout props
44                           (ly:output-def-lookup layout 'tocTitleMarkup))
45         (space-lines (chain-assoc-get 'baseline-skip props)
46                     (map (lambda (toc-item)
47                            (let ((label (car toc-item))
48                                  (toc-markup (cadr toc-item))
49                                  (text (caddr toc-item)))
50                              (interpret-markup
51                                layout
52                                (cons (list (cons 'toc:page
53                                             (markup #:with-link label #:page-ref label "XXX" "?"))
54                                            (cons 'toc:text (markup #:with-link label text))
55                                            (cons 'toc:label label))
56                                      props)
57                                (ly:output-def-lookup layout toc-markup))))
58                          (toc-items)))))
59
60 tocItem =
61 #(define-music-function (text) (markup?)
62    "Add a line to the table of content, using the @code{tocItemMarkup} paper
63 variable markup"
64    (add-toc-item! 'tocItemMarkup text))