commit e285bfb53b56cf0bc88d0ec8d8c3c964a4bc8450
parent 8f8f8315c538c145d326e81f1d5dae7b73b5bda4
Author: Matthew Flatt <mflatt@racket-lang.org>
Date: Tue, 31 Jul 2012 06:58:19 -0600
scriblib/figure: support references to multiple figures at once
original commit: 4a6bfacc27f81bb757001694dd5250eedbd728fd
Diffstat:
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/collects/scriblib/figure.rkt b/collects/scriblib/figure.rkt
@@ -75,7 +75,26 @@
(define figures (new-counter "figure"))
(define (Figure-target tag)
(counter-target figures tag "Figure"))
-(define (Figure-ref tag)
- (make-element #f (list (counter-ref figures tag "Figure"))))
-(define (figure-ref tag)
- (make-element #f (list (counter-ref figures tag "figure"))))
+
+(define (ref-proc initial)
+ (case-lambda
+ [(tag)
+ (make-element #f (list (counter-ref figures tag (string-append initial "igure"))))]
+ [(tag1 tag2)
+ (make-element #f (list (counter-ref figures tag1 (string-append initial "igures"))
+ " and "
+ (counter-ref figures tag2 #f)))]
+ [(tag . tags)
+ (make-element #f (cons (counter-ref figures tag (string-append initial "igures"))
+ (let loop ([tags tags])
+ (cond
+ [(null? (cdr tags))
+ (list ", and "
+ (counter-ref figures (car tags) #f))]
+ [else
+ (list* ", "
+ (counter-ref figures (car tags) #f)
+ (loop (cdr tags)))]))))]))
+
+(define Figure-ref (ref-proc "F"))
+(define figure-ref (ref-proc "f"))
diff --git a/collects/scriblib/scribblings/figure.scrbl b/collects/scriblib/scribblings/figure.scrbl
@@ -41,14 +41,14 @@ For a figure that demands left-aligned text, use @racket[left].
Implements a style for left-aligned figures.
}
-@defproc[(figure-ref [tag string?]) element?]{
+@defproc[(figure-ref [tag string?] ...+) element?]{
-Generates a reference to a figure, using a lowercase word ``figure''.}
+Generates a reference to one or more figures, using a lowercase word ``figure''.}
-@defproc[(Figure-ref [tag string?]) element?]{
+@defproc[(Figure-ref [tag string?] ...+) element?]{
-Generates a reference to a figure, capitalizing the word ``Figure''.}
+Generates a reference to one or more figures, capitalizing the word ``Figure''.}
@defproc[(Figure-target [tag string?]) element?]{