commit cb442ffa94b3878ea6f1488703c563fcaf6b903b
parent 8f72339a18d3770ab71a0212525aa32760f7471f
Author: Jay McCarthy <jay@racket-lang.org>
Date: Mon, 25 Mar 2013 08:24:45 -0600
Support all define-cite options in define-bibtex-cite
original commit: 5bb51aff4c36253db680ff9bfa76801d7388b48b
Diffstat:
5 files changed, 51 insertions(+), 31 deletions(-)
diff --git a/collects/scriblib/bibtex.rkt b/collects/scriblib/bibtex.rkt
@@ -189,10 +189,10 @@
(define-syntax-rule
(define-bibtex-cite bib-pth
- ~cite-id citet-id generate-bibliography-id)
+ ~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)
+ (define-cite autobib-cite autobib-citet generate-bibliography-id . options)
(define ((make-citer citer) f . r)
(apply citer
(filter-map
diff --git a/collects/scriblib/scribblings/bibtex.scrbl b/collects/scriblib/scribblings/bibtex.scrbl
@@ -9,11 +9,11 @@
@defmodule[scriblib/bibtex]
-@defform[(define-bibtex-cite bib-pth ~cite-id citet-id generate-bibliography-id)]{
+@defform[(define-bibtex-cite bib-pth ~cite-id citet-id generate-bibliography-id . options)]{
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.
+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.
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.txt b/collects/tests/scriblib/bibtex.normal.txt
diff --git a/collects/tests/scriblib/bibtex.number.txt b/collects/tests/scriblib/bibtex.number.txt
@@ -0,0 +1,8 @@
+Bibliography
+
+[1]Ran Canetti. Universally Composable Security: A New Paradigm for
+ Cryptographic Protocols. 2000.
+[2]Michael Salib. Starkiller: A Static Type Inferencer and Compiler for
+ Python. Massachusetts Institute of Technology, 2004.
+[3]Sam Tobin-Hochstadt, Vincent St-Amour, Ryan Culpepper, Matthew Flatt,
+ and Matthias Felleisen. Languages as Libraries. In Proc. PLDI, 2011.
diff --git a/collects/tests/scriblib/bibtex.rkt b/collects/tests/scriblib/bibtex.rkt
@@ -2,12 +2,32 @@
(require racket/runtime-path
tests/eli-tester
scriblib/bibtex
+ scriblib/autobib
scribble/render
(prefix-in text: scribble/text-render))
(define-runtime-path example.bib "example.bib")
-(define-runtime-path expected-path "bibtex.txt")
+(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)
+ (let ()
+ (define-bibtex-cite example.bib
+ ~cite-id citet-id generate-bibliography-id . options)
+
+ (body ~cite-id citet-id)
+
+ (define actual-path
+ (make-temporary-file "~a-bibtex.txt"))
+
+ (render (list (generate-bibliography-id))
+ (list actual-path)
+ #:dest-dir (path-only actual-path)
+ #:render-mixin text:render-mixin)
+
+ (test
+ (file->string actual-path) => (file->string expected-path))))
(test
(let ()
@@ -19,30 +39,22 @@
(hash-ref (hash-ref raw "sweig42a") "month") => "1~mar"
(hash-ref (hash-ref raw "sweig42b") "month") => "1~march"
(hash-ref (hash-ref raw "sweig42c") "month") => "1~marcha"))
- (let ()
- (define-bibtex-cite example.bib
- ~cite-id citet-id generate-bibliography-id)
-
- (~cite-id "salib:starkiller")
- (~cite-id "cryptoeprint:2000:067")
- (~cite-id "Tobin-Hochstadt:2011fk")
- (~cite-id "cryptoeprint:2000:067" "Tobin-Hochstadt:2011fk")
- (~cite-id "cryptoeprint:2000:067 Tobin-Hochstadt:2011fk")
-
- (citet-id "salib:starkiller")
- (citet-id "cryptoeprint:2000:067")
- (citet-id "Tobin-Hochstadt:2011fk")
- (citet-id "Tobin-Hochstadt:2011fk" "Tobin-Hochstadt:2011fk")
- (citet-id "Tobin-Hochstadt:2011fk Tobin-Hochstadt:2011fk")
-
- (define actual-path
- (make-temporary-file "~a-bibtex.txt"))
-
- (render (list (generate-bibliography-id))
- (list actual-path)
- #:dest-dir (path-only actual-path)
- #:render-mixin text:render-mixin)
-
- (test
- (file->string actual-path) => (file->string expected-path))))
+ (test-render normal-expected-path ()
+ (λ (~cite-id citet-id)
+ (~cite-id "salib:starkiller")
+ (~cite-id "cryptoeprint:2000:067")
+ (~cite-id "Tobin-Hochstadt:2011fk")
+ (~cite-id "cryptoeprint:2000:067" "Tobin-Hochstadt:2011fk")
+ (~cite-id "cryptoeprint:2000:067 Tobin-Hochstadt:2011fk")
+
+ (citet-id "salib:starkiller")
+ (citet-id "cryptoeprint:2000:067")
+ (citet-id "Tobin-Hochstadt:2011fk")
+ (citet-id "Tobin-Hochstadt:2011fk" "Tobin-Hochstadt:2011fk")
+ (citet-id "Tobin-Hochstadt:2011fk Tobin-Hochstadt:2011fk")))
+ (test-render number-expected-path (#:style number-style)
+ (λ (~cite-id citet-id)
+ (citet-id "salib:starkiller")
+ (citet-id "cryptoeprint:2000:067")
+ (citet-id "Tobin-Hochstadt:2011fk"))))