File: dbautoc.dsl

package info (click to toggle)
docbook-stylesheets 1.49-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,576 kB
  • ctags: 33
  • sloc: perl: 444; xml: 115; makefile: 98; sh: 27
file content (160 lines) | stat: -rw-r--r-- 5,207 bytes parent folder | download
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
;; $Id: dbautoc.dsl,v 1.8 1999/03/01 11:31:45 nwalsh Exp $
;;
;; This file is part of the Modular DocBook Stylesheet distribution.
;; See ../README or http://www.berkshire.net/~norm/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)
    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)))
    (make leader (literal "."))
    (make link
      destination: (node-list-address tocentry)
      (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)
      (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 (node-list-filter-by-gi (children nd)
					  (append (division-element-list)
						  (component-element-list)
						  (section-element-list)
						  (block-element-list)
						  (list (normalize "para"))))))
    (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)))