[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

automatic tables of contents

From: Nicolas Sceaux
Subject: automatic tables of contents
Date: Sat, 16 Jun 2007 11:47:15 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)


I have some code working for automatically building table of
contents, and would like some comments.

Below is the code where commands related to this feature are

 - markups used for building the table of contents (its title, the
 text/page-number lines) are defined as \paper variables, like the
 titling markups;

 - A music function is defined to place a label and push a (label
 paper-markup-variable text-markup) element to a list of toc items;

 - a \table-of-contents markup list command reads this toc items list to
 generate the table of contents.

My questions:

 - should we define more levels for the toc item markups? Here, only one
   level is defined: \addToToc adds a toc item using the tocItemMarkup
   style, but there could be several styles.

 - is it OK to let all this code in a ly/ file?


\version "2.11.26"

%% defined later, in a closure
#(define-public (add-toc-item! markup-symbol text)
#(define-public (toc-items)

#(let ((toc-item-list (list)))
   (set! add-toc-item!
         (lambda (markup-symbol text)
           (let ((label (gensym "toc")))
             (set! toc-item-list
                   (cons (list label markup-symbol text)
             (make-music 'EventChord
               'page-marker #t
               'page-label label
               'elements (list (make-music 'LabelEvent
                                 'page-label label))))))
   (set! toc-items (lambda ()
                     (reverse toc-item-list))))

#(define-markup-command (toc-page-ref layout props symbol-prop) (symbol?)
  (let ((label (chain-assoc-get symbol-prop props)))
    (interpret-markup layout props
                      (if (symbol? label)
                          (markup #:page-ref label "XXX" "?")

\paper {
  tocTitleMarkup = \markup \huge \column {
    \fill-line { \null "Table of Contents" \null }
    \hspace #1
  tocItemMarkup = \markup \fill-line { 
    \fromproperty #'toc:text 
    \toc-page-ref #'toc:label

#(define-markup-list-command (table-of-contents layout props) ()
  (cons (interpret-markup layout props
                          (ly:output-def-lookup layout 'tocTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
                    (map (lambda (toc-item)
                           (let ((label (car toc-item))
                                 (toc-markup (cadr toc-item))
                                 (text (caddr toc-item)))
                               (cons (list (cons 'toc:label label)
                                           (cons 'toc:text text))
                               (ly:output-def-lookup layout toc-markup))))

addToToc = 
#(define-music-function (parser location text) (markup?)
   (add-toc-item! 'tocItemMarkup text))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]