1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
;; $Id: dbautoc.dsl,v 1.1 2007/01/22 15:16:08 bjori Exp $
;;
;; This file is part of the Modular DocBook Stylesheet distribution.
;; See ../README or http://docbook.sourceforge.net/projects/dsssl/
;;
;; ========================== TABLE OF CONTENTS =========================
(define %toc-indent% 2pi)
(define %toc-spacing-factor% 0.4)
;; Returns the depth of auto TOC that should be made at the nd-level
(define (toc-depth nd)
(if (string=? (gi nd) (normalize "book"))
7
1))
(define (format-page-number)
(current-node-page-number-sosofo))
;; Prints the TOC title if first? is true, otherwise does nothing
(define (toc-title first?)
(let ((hsize (if (or (equal? (gi (current-node)) (normalize "article"))
(equal? (gi (current-node)) (normalize "part")))
(HSIZE 3)
(HSIZE 4))))
(if first?
(make paragraph
font-family-name: %title-font-family%
font-weight: 'bold
font-size: hsize
line-spacing: (* hsize %line-spacing-factor%)
space-before: (* hsize %head-before-factor%)
space-after: (* hsize %head-after-factor%)
start-indent: 0pt
first-line-start-indent: 0pt
quadding: %component-title-quadding%
heading-level: (if %generate-heading-level% 1 0)
keep-with-next?: #t
(literal (gentext-element-name (normalize "toc"))))
(empty-sosofo))))
;; Prints the TOC title if first? is true, otherwise does nothing
(define (lot-title first? lotgi)
(if first?
(make paragraph
font-family-name: %title-font-family%
font-weight: 'bold
font-size: (HSIZE 4)
line-spacing: (* (HSIZE 4) %line-spacing-factor%)
space-before: (* (HSIZE 4) %head-before-factor%)
space-after: (* (HSIZE 4) %head-after-factor%)
start-indent: 0pt
first-line-start-indent: 0pt
quadding: %component-title-quadding%
heading-level: (if %generate-heading-level% 1 0)
keep-with-next?: #t
(literal ($lot-title$ lotgi)))
(empty-sosofo)))
;; Print the TOC entry for tocentry
(define ($toc-entry$ tocentry level)
(make paragraph
start-indent: (+ %body-start-indent%
(* %toc-indent% level))
first-line-start-indent: (* -1 %toc-indent%)
font-weight: (if (= level 1) 'bold 'medium)
space-before: (if (= level 1) (* %toc-spacing-factor% 6pt) 0pt)
space-after: (if (= level 1) (* %toc-spacing-factor% 6pt) 0pt)
keep-with-next?: (if (= level 1) #t #f)
quadding: 'start
(make link
destination: (node-list-address tocentry)
(make sequence
(if (equal? (element-label tocentry) "")
(empty-sosofo)
(make sequence
(element-label-sosofo tocentry)
(literal (gentext-label-title-sep (gi tocentry)))))
(element-title-sosofo tocentry)))
(if (and (= level 1)
;; ??? %chapter-title-page-separate%
%page-number-restart%)
(empty-sosofo) ;; Don't need the leader etc then
(make sequence
(make leader (literal "."))
(make link
destination: (node-list-address tocentry)
(make sequence
(if %page-number-restart%
(literal
(string-append
(if (= level 1)
(element-label tocentry #t)
(substring (element-label tocentry #t)
0 (string-index (element-label tocentry #t) ".")))
(gentext-intra-label-sep "_pagenumber")))
(empty-sosofo))
(with-mode toc-page-number-mode
(process-node-list tocentry))))))))
;; Build a TOC starting at nd reaching down depth levels.
;; The optional arguments are used on recursive calls to build-toc
;; and shouldn't be set by the initial caller...
;;
(define (build-toc nd depth #!optional (first? #t) (level 1))
(let* ((toclist (toc-list-filter
(node-list-filter-by-gi (children nd)
(append (division-element-list)
(component-element-list)
(section-element-list))))))
(if (or (<= depth 0)
(node-list-empty? toclist))
(empty-sosofo)
(make sequence
(toc-title first?)
(let loop ((nl toclist))
(if (node-list-empty? nl)
(empty-sosofo)
(sosofo-append
($toc-entry$ (node-list-first nl) level)
(build-toc (node-list-first nl) (- depth 1) #f (+ level 1))
(loop (node-list-rest nl)))))))))
;; Print the LOT entry
(define ($lot-entry$ tocentry)
(make paragraph
start-indent: (+ %body-start-indent% %toc-indent%)
first-line-start-indent: (* -1 %toc-indent%)
font-weight: 'medium
space-before: 0pt
space-after: 0pt
quadding: 'start
(make link
destination: (node-list-address tocentry)
(make sequence
(if (equal? (element-label tocentry) "")
(empty-sosofo)
(make sequence
(element-label-sosofo tocentry #t)
(literal (gentext-label-title-sep (gi tocentry)))))
(element-title-sosofo tocentry)))
(make leader (literal "."))
(make link
destination: (node-list-address tocentry)
(make sequence
(if %page-number-restart%
(make sequence
(literal (substring (element-label tocentry #t)
0 (string-index (element-label tocentry #t) "-")))
(literal (gentext-intra-label-sep "_pagenumber")))
(empty-sosofo))
(with-mode toc-page-number-mode
(process-node-list tocentry))))))
;; Build a LOT starting at nd for all the lotgi's it contains.
;; The optional arguments are used on recursive calls to build-toc
;; and shouldn't be set by the initial caller...
;;
(define (build-lot nd lotgi #!optional (first? #t))
(let* ((lotlist (select-elements (descendants nd)
(normalize lotgi))))
(if (node-list-empty? lotlist)
(empty-sosofo)
(make sequence
(lot-title first? lotgi)
(let loop ((nl lotlist))
(if (node-list-empty? nl)
(empty-sosofo)
(make sequence
(if (string=? (gi (node-list-first nl)) lotgi)
($lot-entry$ (node-list-first nl))
(empty-sosofo))
(build-lot (node-list-first nl) lotgi #f)
(loop (node-list-rest nl)))))))))
(mode toc-page-number-mode
(default
(format-page-number)))
|