]> git.donarmstrong.com Git - lilypond.git/blob - ly/toc-init.ly
Issue 5148/1: Various chain-assoc-get -> #:properties
[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   #:properties ((baseline-skip))
40   ( _i "Outputs the table of contents, using the paper variable
41 @code{tocTitleMarkup} for its title, then the list of lines
42 built using the @code{tocItem} music function
43 Usage: @code{\\markuplist \\table-of-contents}" )
44   (cons (interpret-markup layout props
45                           (ly:output-def-lookup layout 'tocTitleMarkup))
46         (space-lines baseline-skip
47                     (map (lambda (toc-item)
48                            (let ((label (car toc-item))
49                                  (toc-markup (cadr toc-item))
50                                  (text (caddr toc-item)))
51                              (interpret-markup
52                                layout
53                                (cons (list (cons 'toc:page
54                                             (markup #:with-link label #:page-ref label "XXX" "?"))
55                                            (cons 'toc:text (markup #:with-link label text))
56                                            (cons 'toc:label label))
57                                      props)
58                                (ly:output-def-lookup layout toc-markup))))
59                          (toc-items)))))
60
61 tocItem =
62 #(define-music-function (text) (markup?)
63    "Add a line to the table of content, using the @code{tocItemMarkup} paper
64 variable markup"
65    (add-toc-item! 'tocItemMarkup text))