commit 3437fda407a5fd0c3a89be6400cf5cd533b37181
parent cb442ffa94b3878ea6f1488703c563fcaf6b903b
Author: Jay McCarthy <jay@racket-lang.org>
Date: Tue, 26 Mar 2013 05:58:20 -0600
Generalizing define-bibtex-cite
original commit: 875c20119d962c79ef3760a491bb24a57a2e51b5
Diffstat:
3 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/collects/scriblib/bibtex.rkt b/collects/scriblib/bibtex.rkt
@@ -191,8 +191,17 @@
(define-bibtex-cite bib-pth
~cite-id citet-id generate-bibliography-id . options)
(begin
- (define bibtex-db (path->bibdb bib-pth))
(define-cite autobib-cite autobib-citet generate-bibliography-id . options)
+ (define-bibtex-cite* bib-pth
+ autobib-cite autobib-citet
+ ~cite-id citet-id)))
+
+(define-syntax-rule
+ (define-bibtex-cite* bib-pth
+ autobib-cite autobib-citet
+ ~cite-id citet-id)
+ (begin
+ (define bibtex-db (path->bibdb bib-pth))
(define ((make-citer citer) f . r)
(apply citer
(filter-map
@@ -286,4 +295,5 @@
(provide (struct-out bibdb)
path->bibdb
bibtex-parse
- define-bibtex-cite)
+ define-bibtex-cite
+ define-bibtex-cite*)
diff --git a/collects/scriblib/scribblings/bibtex.scrbl b/collects/scriblib/scribblings/bibtex.scrbl
@@ -11,9 +11,20 @@
@defform[(define-bibtex-cite bib-pth ~cite-id citet-id generate-bibliography-id . options)]{
+This expands into:
+@racketblock[
+(begin
+ (define-cite autobib-cite autobib-citet generate-bibliography-id . options)
+ (define-bibtex-cite* bib-pth
+ autobib-cite autobib-citet
+ ~cite-id citet-id))]
+}
+
+@defform[(define-bibtex-cite* bib-pth autobib-cite autobib-citet ~cite-id citet-id)]{
+
Parses @racket[bib-pth] as a BibTeX database.
-Uses @racket[define-cite] from @racketmodname[scriblib/autobib], but augments the @racket[~cite-id] and @racket[citet-id] functions so that rather than accepting @racket[bib?] structures, they accept citation key strings. Any @racket[options] are given to @racket[define-cite] without interpretation.
+Augments @racket[autobib-cite] and @racket[autobib-citet] into @racket[~cite-id] and @racket[citet-id] functions so that rather than accepting @racket[bib?] structures, they accept citation key strings.
Each string is broken along spaces into citations keys that are looked up in the BibTeX database and turned into @racket[bib?] structures.
diff --git a/collects/tests/scriblib/bibtex.rkt b/collects/tests/scriblib/bibtex.rkt
@@ -11,12 +11,11 @@
(define-runtime-path normal-expected-path "bibtex.normal.txt")
(define-runtime-path number-expected-path "bibtex.number.txt")
-(define-syntax-rule (test-render expected-path options body)
+(define-syntax-rule (test-render* definer expected-path body generate-bibliography-id)
(let ()
- (define-bibtex-cite example.bib
- ~cite-id citet-id generate-bibliography-id . options)
+ definer
- (body ~cite-id citet-id)
+ body
(define actual-path
(make-temporary-file "~a-bibtex.txt"))
@@ -29,6 +28,23 @@
(test
(file->string actual-path) => (file->string expected-path))))
+(define-syntax-rule (test-render expected-path options body)
+ (begin
+ (test-render* (define-bibtex-cite example.bib
+ ~cite-id citet-id generate-bibliography-id . options)
+ expected-path
+ (body ~cite-id citet-id)
+ generate-bibliography-id)
+ (test-render* (begin
+ (define-cite autobib-cite autobib-citet
+ generate-bibliography-id . options)
+ (define-bibtex-cite* example.bib
+ autobib-cite autobib-citet
+ ~cite-id citet-id))
+ expected-path
+ (body ~cite-id citet-id)
+ generate-bibliography-id)))
+
(test
(let ()
(define example (path->bibdb example.bib))