commit a04afeb855e3ebac18ce294a662b5af53aa9b494
parent d6ff9dd6fa9be58540b1ce098eeb07a2a1517177
Author: Sam Tobin-Hochstadt <samth@racket-lang.org>
Date: Fri, 11 Jun 2010 16:52:27 -0400
Support multiple arguments to `citet', provided that all authors are equal?
- Also refactors indexing to separately index date and author
original commit: c9459277768aee67ab6f430d2f7b7970b223ea57
Diffstat:
2 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/collects/scriblib/autobib.rkt b/collects/scriblib/autobib.rkt
@@ -1,4 +1,4 @@
-#lang at-exp scheme/base
+#lang at-exp racket/base
(require scribble/manual
scribble/core
scribble/decode
@@ -41,6 +41,25 @@
(lambda () "(???)")
(lambda () "(???)")))
+(define (add-inline-cite group bib-entries)
+ (for ([i bib-entries]) (hash-set! (bib-group-ht group) i #t))
+ (when (and (pair? (cdr bib-entries)) (not (apply equal? (map auto-bib-author bib-entries))))
+ (error 'citet "citet must be used with identical authors, given ~a" (map auto-bib-author bib-entries)))
+ (make-element
+ #f
+ (list (add-cite group (car bib-entries) 'autobib-author)
+ 'nbsp
+ "("
+ (let loop ([keys bib-entries])
+ (if (null? (cdr keys))
+ (add-cite group (car keys) 'autobib-date)
+ (make-element
+ #f
+ (list (loop (list (car keys)))
+ "; "
+ (loop (cdr keys))))))
+ ")")))
+
(define (add-cites group bib-entries)
(make-element
#f
@@ -48,7 +67,12 @@
"("
(let loop ([keys bib-entries])
(if (null? (cdr keys))
- (add-cite group (car keys) 'autobib-cite)
+ (make-element
+ #f
+ (list
+ (add-cite group (car keys) 'autobib-author)
+ " "
+ (add-cite group (car keys) 'autobib-date)))
(make-element
#f
(list (loop (list (car keys)))
@@ -87,23 +111,17 @@
`(autobib ,(auto-bib-key k))))
(lambda (ci)
(collect-put! ci
- `(autobib-cite ,(auto-bib-key k))
+ `(autobib-author ,(auto-bib-key k))
(make-element
#f
(list
- (author-element-cite (auto-bib-author k))
- " "
- (auto-bib-date k))))
+ (author-element-cite (auto-bib-author k)))))
(collect-put! ci
- `(autobib-inline ,(auto-bib-key k))
+ `(autobib-date ,(auto-bib-key k))
(make-element
#f
(list
- (author-element-cite (auto-bib-author k))
- 'nbsp
- "("
- (auto-bib-date k)
- ")")))))))))
+ (auto-bib-date k))))))))))
bibs)))
null)))
@@ -112,8 +130,8 @@
(define group (make-bib-group (make-hasheq)))
(define (~cite bib-entry . bib-entries)
(add-cites group (cons bib-entry bib-entries)))
- (define (citet bib-entry)
- (add-cite group bib-entry 'autobib-inline))
+ (define (citet bib-entry . bib-entries)
+ (add-inline-cite group (cons bib-entry bib-entries)))
(define (generate-bibliography #:tag [tag "doc-bibliography"])
(gen-bib tag group))))
diff --git a/collects/scriblib/scribblings/autobib.scrbl b/collects/scriblib/scribblings/autobib.scrbl
@@ -31,11 +31,11 @@ space. It has the contract
]
The function bound to @scheme[citet-id] generates an element suitable
-for use as a noun---referring to a document or its author---for a
-single bibliography entry. It has the contract
+for use as a noun---referring to a document or its author---for one
+or more bibliography entries which share an author. It has the contract
@schemeblock[
-(bib? . -> . element?)
+((bib?) () (listof bib?) . ->* . element?)
]
The function bound to @scheme[generate-bibliography-id] generates the