aboutsummaryrefslogtreecommitdiff
path: root/src/guile/skribilo/package/slide.scm
blob: fbdf9124260fcf13f4f44088c0882e31826fb272 (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
282
283
284
285
286
287
288
289
290
291
292
293
;;; slide.scm  --  Overhead transparencies.
;;;
;;; Copyright 2003, 2004  Manuel Serrano
;;; Copyright 2006  Ludovic Court�s <ludovic.courtes@laas.fr>
;;;
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;; USA.


(define-module (skribilo package slide)
  :use-module (skribilo reader)
  :use-module (skribilo utils syntax)

  :use-module (skribilo lib)
  :use-module (skribilo ast)
  :use-module (skribilo engine)
  :use-module (skribilo evaluator) ;; `*load-options*'
  :use-module (skribilo package base)

  :autoload   (skribilo utils keywords) (the-options the-body)

  :use-module (srfi srfi-1)
  :use-module (ice-9 optargs))

(fluid-set! current-reader (make-reader 'skribe))



;*---------------------------------------------------------------------*/
;*    slide-options                                                    */
;*---------------------------------------------------------------------*/
(define-public &slide-load-options (*load-options*))


;*---------------------------------------------------------------------*/
;*    %slide-the-slides ...                                            */
;*---------------------------------------------------------------------*/
(define %slide-the-slides '())
(define %slide-the-counter 0)

;*---------------------------------------------------------------------*/
;*    slide ...                                                        */
;*---------------------------------------------------------------------*/
(define-markup (slide #!rest opt
		      #!key
		      (ident #f) (class #f)
		      (toc #t)
		      title (number #t)
		      (vspace #f) (vfill #f)
		      (transition #f)
		      (bg #f) (image #f))
   (let ((s (new container
	       (markup 'slide)
	       (ident (if (not ident)
			  (symbol->string (gensym "slide"))
			  ident))
	       (class class)
	       (required-options '(:title :number :toc))
	       (options `((:number
			   ,(cond
			       ((number? number)
				(set! %slide-the-counter number)
				number)
			       (number
				(set! %slide-the-counter
				      (+ 1 %slide-the-counter))
				%slide-the-counter)
			       (else
				#f)))
			  (:toc ,toc)
			  ,@(the-options opt :ident :class :vspace :toc)))
	       (body (if vspace
			 (list (slide-vspace vspace) (the-body opt))
			 (the-body opt))))))
      (set! %slide-the-slides (cons s %slide-the-slides))
      s))

;*---------------------------------------------------------------------*/
;*    ref ...                                                          */
;*---------------------------------------------------------------------*/
(define %slide-old-ref ref)

;; Extend the definition of `ref'.
;; FIXME: This technique breaks `ref' for some reason.
; (set! ref
;       (lambda args
; 	;; Filter out ARGS and look for a `:slide' keyword argument.
; 	(let loop ((slide #f)
; 		   (opt '())
; 		   (args args))
; 	  (if (null? args)
; 	      (set! opt (reverse! opt))
; 	      (let ((s? (eq? (car args) :slide)))
; 		(loop (if s? (cadr args) #f)
; 		      (if s? opt (cons (car args) opt))
; 		      (if s? (cddr args) (cdr args)))))

; 	  (format (current-error-port)
; 		  "slide.scm:ref: slide=~a opt=~a~%" slide opt)

; 	  (if (not slide)
; 	      (apply %slide-old-ref opt)
; 	      (new unresolved
; 		   (proc (lambda (n e env)
; 			   (cond
; 			    ((eq? slide 'next)
; 			     (let ((c (assq n %slide-the-slides)))
; 			       (if (pair? c)
; 				   (handle (cadr c))
; 				   #f)))
; 			    ((eq? slide 'prev)
; 			     (let ((c (assq n (reverse %slide-the-slides))))
; 			       (if (pair? c)
; 				   (handle (cadr c))
; 				   #f)))
; 			    ((number? slide)
; 			     (let loop ((s %slide-the-slides))
; 			       (cond
; 				((null? s)
; 				 #f)
; 				((= slide (markup-option
; 					   (car s) :number))
; 				 (handle (car s)))
; 				(else
; 				 (loop (cdr s))))))
; 			    (else
; 			     #f)))))))))


;*---------------------------------------------------------------------*/
;*    slide-pause ...                                                  */
;*---------------------------------------------------------------------*/
(define-markup (slide-pause)
   (new markup
      (markup 'slide-pause)))

;*---------------------------------------------------------------------*/
;*    slide-vspace ...                                                 */
;*---------------------------------------------------------------------*/
(define-markup (slide-vspace #!rest opt #!key (unit 'cm))
   (new markup
      (markup 'slide-vspace)
      (options `((:unit ,unit) ,@(the-options opt :unit)))
      (body (the-body opt))))

;*---------------------------------------------------------------------*/
;*    slide-embed ...                                                  */
;*---------------------------------------------------------------------*/
(define-markup (slide-embed #!rest opt
			    #!key
			    command
                            (arguments '())
			    (geometry-opt "-geometry")
			    (geometry #f) (rgeometry #f)
			    (transient #f) (transient-opt #f)
			    (alt #f)
			    &skribe-eval-location)
   (if (not (string? command))
       (skribe-error 'slide-embed
		     "No command provided"
		     command)
       (new markup
	  (markup 'slide-embed)
	  (loc &skribe-eval-location)
	  (required-options '(:alt))
	  (options `((:geometry-opt ,geometry-opt)
		     (:alt ,alt)
		     ,@(the-options opt :geometry-opt :alt)))
	  (body (the-body opt)))))

;*---------------------------------------------------------------------*/
;*    slide-record ...                                                 */
;*---------------------------------------------------------------------*/
(define-markup (slide-record #!rest opt #!key ident class tag (play #t))
   (if (not tag)
       (skribe-error 'slide-record "Tag missing" tag)
       (new markup
	  (markup 'slide-record)
	  (ident ident)
	  (class class)
	  (options `((:play ,play) ,@(the-options opt)))
	  (body (the-body opt)))))

;*---------------------------------------------------------------------*/
;*    slide-play ...                                                   */
;*---------------------------------------------------------------------*/
(define-markup (slide-play #!rest opt #!key ident class tag color)
   (if (not tag)
       (skribe-error 'slide-play "Tag missing" tag)
       (new markup
	  (markup 'slide-play)
	  (ident ident)
	  (class class)
	  (options `((:color ,(if color (skribe-use-color! color) #f))
		     ,@(the-options opt :color)))
	  (body (the-body opt)))))

;*---------------------------------------------------------------------*/
;*    slide-play* ...                                                  */
;*---------------------------------------------------------------------*/
(define-markup (slide-play* #!rest opt
			    #!key ident class color (scolor "#000000"))
   (let ((body (the-body opt)))
      (for-each (lambda (lbl)
		   (match-case lbl
		      ((?id ?col)
		       (skribe-use-color! col))))
		body)
      (new markup
	 (markup 'slide-play*)
	 (ident ident)
	 (class class)
	 (options `((:color ,(if color (skribe-use-color! color) #f))
		    (:scolor ,(if color (skribe-use-color! scolor) #f))
		    ,@(the-options opt :color :scolor)))
	 (body body))))



;*---------------------------------------------------------------------*/
;*    slide-number ...                                                 */
;*---------------------------------------------------------------------*/
(define-public (slide-number)
   (length (filter (lambda (n)
		      (and (is-markup? n 'slide)
			   (markup-option n :number)))
		   %slide-the-slides)))

;*---------------------------------------------------------------------*/
;*    slide-topic ...                                                  */
;*---------------------------------------------------------------------*/
(define-markup (slide-topic #!rest opt
			    #!key title (outline? #t)
                            (ident #f) (class #f))
   (new container
      (markup 'slide-topic)
      (required-options '(:title :outline?))
      (ident (or ident (symbol->string (gensym "slide-topic"))))
      (class class)
      (options `((:outline? ,outline?)
                 ,@(the-options opt :outline? :class)))
      (body (the-body opt))))

;*---------------------------------------------------------------------*/
;*    slide-subtopic ...                                               */
;*---------------------------------------------------------------------*/
(define-markup (slide-subtopic #!rest opt
			       #!key title (outline? #f)
                               (ident #f) (class #f))
   (new container
      (markup 'slide-subtopic)
      (required-options '(:title :outline?))
      (ident (or ident (symbol->string (gensym "slide-subtopic"))))
      (class class)
      (options `((:outline? ,outline?)
                 ,@(the-options opt :outline? :class)))
      (body (the-body opt))))



;;;
;;; Initialization.
;;;

(format (current-error-port) "Slides initializing...~%")

;; Register specific implementations for lazy loading.
(when-engine-class-is-loaded 'base
  (lambda ()
    (resolve-module '(skribilo package slide base))))
(when-engine-class-is-loaded 'latex
  (lambda ()
    (resolve-module '(skribilo package slide latex))))
(when-engine-class-is-loaded 'html
  (lambda ()
    (resolve-module '(skribilo package slide html))))
(when-engine-class-is-loaded 'lout
  (lambda ()
    (resolve-module '(skribilo package slide lout))))