blob: 198223764e058cb0af158951ea50246efdbf555c (
plain)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
;*=====================================================================*/
;* serrano/prgm/project/skribe/doc/skr/manual.skr */
;* ------------------------------------------------------------- */
;* Author : Manuel Serrano */
;* Creation : Mon Sep 1 11:24:19 2003 */
;* Last change : Mon Sep 13 19:18:48 2004 (serrano) */
;* Copyright : 2003-04 Manuel Serrano */
;* ------------------------------------------------------------- */
;* Skribe manuals and documentation pages style */
;*=====================================================================*/
;*---------------------------------------------------------------------*/
;* Base configuration */
;*---------------------------------------------------------------------*/
(let ((be (find-engine 'base)))
(markup-writer 'example be
:options '(:legend :number)
:action (lambda (n e)
(let ((ident (markup-ident n))
(number (markup-option n :number))
(legend (markup-option n :legend)))
(skribe-eval (mark ident) e)
(skribe-eval (center
(markup-body n)
(if number (bold (format "Ex. ~a: " number)))
legend)
e)))))
;*---------------------------------------------------------------------*/
;* html-browsing-extra ... */
;*---------------------------------------------------------------------*/
(define (html-browsing-extra n e)
(let ((i1 (let ((m (find-markup-ident "Index")))
(and (pair? m) (car m))))
(i2 (let ((m (find-markup-ident "markups-index")))
(and (pair? m) (car m)))))
(cond
((not i1)
(skribe-error 'left-margin "Can't find section" "Index"))
((not i2)
(skribe-error 'left-margin "Can't find chapter" "Standard Markups"))
(else
(table :width 100.
:border 0
:cellspacing 0 :cellpadding 0
(tr (td :align 'left :valign 'top (bold "index:"))
(td :align 'right (ref :handle (handle i1) :text "Global")))
(tr (td :align 'left :valign 'top (bold "markups:"))
(td :align 'right (ref :handle (handle i2) :text "Index")))
(tr (td :align 'left :valign 'top (bold "extensions:"))
(td :align 'right (ref :url *skribe-dir-doc-url*
:text "Directory"))))))))
;*---------------------------------------------------------------------*/
;* Html configuration */
;*---------------------------------------------------------------------*/
(let* ((he (find-engine 'html))
(bd (markup-writer-get 'bold he)))
(markup-writer 'bold he
:class 'api-proto-ident
:before "<font color=\"red\">"
:action (lambda (n e) (output n e bd))
:after "</font>")
(engine-custom-set! he 'web-book-main-browsing-extra html-browsing-extra)
(engine-custom-set! he 'favicon "lambda.gif"))
;*---------------------------------------------------------------------*/
;* LaTeX */
;*---------------------------------------------------------------------*/
(let* ((le (find-engine 'latex))
(opckg (engine-custom le 'usepackage))
(lpckg "\\usepackage{fullpage}\n\\usepackage{eurosym}\n")
(npckg (if (string? opckg)
(string-append lpckg opckg)
lpckg)))
(engine-custom-set! le 'documentclass "\\documentclass{book}")
(engine-custom-set! le 'usepackage npckg))
;*---------------------------------------------------------------------*/
;* prgm ... */
;*---------------------------------------------------------------------*/
(define-markup (prgm #!rest opts #!key (language skribe) (line #f) (file #f) (definition #f))
(let* ((c (cond
((eq? language skribe) *prgm-skribe-color*)
((eq? language xml) *prgm-xml-color*)
(else *prgm-default-color*)))
(sc (cond
((and file definition)
(source :language language :file file :definition definition))
(file
(source :language language :file file))
(else
(source :language language (the-body opts)))))
(pr (cond
(line
(prog :line line sc))
(else
(pre sc)))))
(center
(frame :margin 5 :border 0 :width *prgm-width*
(color :margin 5 :width 100. :bg c pr)))))
;*---------------------------------------------------------------------*/
;* disp ... */
;*---------------------------------------------------------------------*/
(define-markup (disp #!rest opts #!key (verb #f) (line #f) (bg *disp-color*))
(if (engine-format? "latex")
(if verb
(pre (the-body opts))
(the-body opts))
(center
(frame :margin 5 :border 0 :width *prgm-width*
(color :margin 5 :width 100. :bg bg
(if verb
(pre (the-body opts))
(the-body opts)))))))
;*---------------------------------------------------------------------*/
;* keyword ... */
;*---------------------------------------------------------------------*/
(define-markup (keyword arg)
(new markup
(markup '&source-key)
(body (cond
((keyword? arg)
(keyword->string arg))
((symbol? arg)
(string-append ":" (symbol->string arg)))
(else
arg)))))
;*---------------------------------------------------------------------*/
;* param ... */
;*---------------------------------------------------------------------*/
(define-markup (param arg)
(cond
((keyword? arg)
(keyword arg))
((symbol? arg)
(code (symbol->string arg)))
(else
arg)))
;*---------------------------------------------------------------------*/
;* example ... */
;*---------------------------------------------------------------------*/
(define-markup (example #!rest opts #!key legend class)
(new container
(markup 'example)
(ident (symbol->string (gensym 'example)))
(class class)
(required-options '(:legend :number))
(options `((:number
,(new unresolved
(proc (lambda (n e env)
(resolve-counter n env 'example #t)))))
,@(the-options opts :ident :class)))
(body (the-body opts))))
;*---------------------------------------------------------------------*/
;* example-produce ... */
;*---------------------------------------------------------------------*/
(define-markup (example-produce example . produce)
(list (it "Example:")
example
(if (pair? produce)
(list (paragraph "Produces:") (car produce)))))
;*---------------------------------------------------------------------*/
;* markup-ref ... */
;*---------------------------------------------------------------------*/
(define-markup (markup-ref mk)
(ref :mark mk :text (code mk)))
;*---------------------------------------------------------------------*/
;* &the-index ... */
;*---------------------------------------------------------------------*/
(markup-writer '&the-index
:class 'markup-index
:options '(:column)
:before (lambda (n e)
(output (markup-option n 'header) e))
:action (lambda (n e)
(define (make-mark-entry n fst)
(let ((l (tr :class 'index-mark-entry
(td :colspan 2 :align 'left
(bold (it (sf n)))))))
(if fst
(list l)
(list (tr (td :colspan 2)) l))))
(define (make-primary-entry n p)
(let* ((note (markup-option n :note))
(b (markup-body n)))
(when p
(markup-option-add! b :text
(list (markup-option b :text)
", p."))
(markup-option-add! b :page #t))
(tr :class 'index-primary-entry
(td :colspan 2 :valign 'top :align 'left b))))
(define (make-column ie p)
(let loop ((ie ie)
(f #t))
(cond
((null? ie)
'())
((not (pair? (car ie)))
(append (make-mark-entry (car ie) f)
(loop (cdr ie) #f)))
(else
(cons (make-primary-entry (caar ie) p)
(loop (cdr ie) #f))))))
(define (make-sub-tables ie nc p)
(define (split-list l num)
(let loop ((l l)
(i 0)
(acc '())
(res '()))
(cond
((null? l)
(reverse! (cons (reverse! acc) res)))
((= i num)
(loop l
0
'()
(cons (reverse! acc) res)))
(else
(loop (cdr l)
(+ i 1)
(cons (car l) acc)
res)))))
(let* ((l (length ie))
(w (/ 100. nc))
(iepc (let ((d (/ l nc)))
(if (integer? d)
(inexact->exact d)
(+ 1 (inexact->exact (truncate d))))))
(split (split-list ie iepc)))
(tr (map (lambda (ies)
(td :valign 'top :width w
(if (pair? ies)
(table :width 100. (make-column ies p))
"")))
split))))
(let* ((ie (markup-body n))
(nc (markup-option n :column))
(pref (eq? (engine-custom e 'index-page-ref) #t))
(loc (ast-loc n))
(t (cond
((null? ie)
"")
((or (not (integer? nc)) (= nc 1))
(table :width 100. :&skribe-eval-location loc
(make-column ie pref)))
(else
(table :width 100. :&skribe-eval-location loc
(make-sub-tables ie nc pref))))))
(output (skribe-eval t e) e))))
;*---------------------------------------------------------------------*/
;* compiler-command ... */
;*---------------------------------------------------------------------*/
(define-markup (compiler-command bin . opts)
(disp :verb #t
(color :fg "red" (bold bin))
(map (lambda (o)
(list " [" (it o) "]"))
opts)
"..."))
;*---------------------------------------------------------------------*/
;* compiler-options ... */
;*---------------------------------------------------------------------*/
(define-markup (compiler-options bin)
(skribe-message " [executing: ~a --options]\n" bin)
(let ((port (open-input-file (format "| ~a --options" bin))))
(let ((opts (read port)))
(close-input-port port)
(apply description (map (lambda (opt) (item :key (bold (car opt))
(cadr opt) "."))
opts)))))
|