Autobib errors with no authors or dates on a bib entry. Test included.
This commit is contained in:
parent
d67997293d
commit
13e36fbec4
|
@ -34,6 +34,9 @@
|
||||||
(define-struct (author-element element) (names cite))
|
(define-struct (author-element element) (names cite))
|
||||||
(define-struct (other-author-element author-element) ())
|
(define-struct (other-author-element author-element) ())
|
||||||
|
|
||||||
|
(define (author-element-names* x)
|
||||||
|
(and x (author-element-names x)))
|
||||||
|
|
||||||
;; render the use of a citation.
|
;; render the use of a citation.
|
||||||
(define (add-cite group bib-entry which with-specific? disambiguation)
|
(define (add-cite group bib-entry which with-specific? disambiguation)
|
||||||
(let ([key (auto-bib-key bib-entry)])
|
(let ([key (auto-bib-key bib-entry)])
|
||||||
|
@ -95,9 +98,9 @@
|
||||||
(for ([i bib-entries])
|
(for ([i bib-entries])
|
||||||
(hash-set! (bib-group-ht group) (auto-bib-key i) i))
|
(hash-set! (bib-group-ht group) (auto-bib-key i) i))
|
||||||
(when (and (pair? (cdr bib-entries))
|
(when (and (pair? (cdr bib-entries))
|
||||||
(not (apply equal? (map (compose author-element-names auto-bib-author) bib-entries))))
|
(not (apply equal? (map (compose author-element-names* auto-bib-author) bib-entries))))
|
||||||
(error 'citet "citet must be used with identical authors, given ~a"
|
(error 'citet "citet must be used with identical authors, given ~a"
|
||||||
(map (compose author-element-names auto-bib-author) bib-entries)))
|
(map (compose author-element-names* auto-bib-author) bib-entries)))
|
||||||
(make-element
|
(make-element
|
||||||
#f
|
#f
|
||||||
(list (add-cite group (car bib-entries) 'autobib-author #f #f)
|
(list (add-cite group (car bib-entries) 'autobib-author #f #f)
|
||||||
|
@ -108,7 +111,7 @@
|
||||||
(define (add-cites group bib-entries sort? bib-date<? bib-date=?)
|
(define (add-cites group bib-entries sort? bib-date<? bib-date=?)
|
||||||
(define-values (groups keys)
|
(define-values (groups keys)
|
||||||
(for/fold ([h (hash)] [ks null]) ([b (reverse bib-entries)])
|
(for/fold ([h (hash)] [ks null]) ([b (reverse bib-entries)])
|
||||||
(let ([k (author-element-names (auto-bib-author b))])
|
(let ([k (author-element-names* (auto-bib-author b))])
|
||||||
(values (hash-update h k (lambda (cur) (cons b cur)) null)
|
(values (hash-update h k (lambda (cur) (cons b cur)) null)
|
||||||
(cons k (remove k ks))))))
|
(cons k (remove k ks))))))
|
||||||
(make-element
|
(make-element
|
||||||
|
@ -139,9 +142,11 @@
|
||||||
(define (default-render-date-cite date)
|
(define (default-render-date-cite date)
|
||||||
(make-element #f (list (number->string (date-year date)))))
|
(make-element #f (list (number->string (date-year date)))))
|
||||||
(define (default-date<? b0 b1)
|
(define (default-date<? b0 b1)
|
||||||
(< (date-year (auto-bib-date b0)) (date-year (auto-bib-date b1))))
|
(and (auto-bib-date b0) (auto-bib-date b1)
|
||||||
|
(< (date-year (auto-bib-date b0)) (date-year (auto-bib-date b1)))))
|
||||||
(define (default-date=? b0 b1)
|
(define (default-date=? b0 b1)
|
||||||
(= (date-year (auto-bib-date b0)) (date-year (auto-bib-date b1))))
|
(and (auto-bib-date b0) (auto-bib-date b1)
|
||||||
|
(= (date-year (auto-bib-date b0)) (date-year (auto-bib-date b1)))))
|
||||||
|
|
||||||
;; 0 -> a, 1 -> b, etc.
|
;; 0 -> a, 1 -> b, etc.
|
||||||
(define (default-disambiguation n)
|
(define (default-disambiguation n)
|
||||||
|
@ -186,9 +191,10 @@
|
||||||
#f
|
#f
|
||||||
(list (author-element-cite (extract-bib-author bib)))))
|
(list (author-element-cite (extract-bib-author bib)))))
|
||||||
;; store the date
|
;; store the date
|
||||||
(collect-put! ci
|
(when (auto-bib-date bib)
|
||||||
`(autobib-date ,(auto-bib-key bib)) ;; (list which key)
|
(collect-put! ci
|
||||||
(make-element #f (list (render-date-cite (auto-bib-date bib)))))
|
`(autobib-date ,(auto-bib-key bib)) ;; (list which key)
|
||||||
|
(make-element #f (list (render-date-cite (auto-bib-date bib))))))
|
||||||
;; store how to disambiguate it from other like citations.
|
;; store how to disambiguate it from other like citations.
|
||||||
(collect-put! ci
|
(collect-put! ci
|
||||||
`(autobib-disambiguation ,(auto-bib-key bib))
|
`(autobib-disambiguation ,(auto-bib-key bib))
|
||||||
|
|
20
collects/tests/scriblib/autobib.rkt
Normal file
20
collects/tests/scriblib/autobib.rkt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#lang racket/base
|
||||||
|
(require rackunit
|
||||||
|
scribble/render
|
||||||
|
scriblib/autobib)
|
||||||
|
|
||||||
|
(check-not-exn
|
||||||
|
(λ ()
|
||||||
|
(define-cite ~cite citet generate-bib)
|
||||||
|
|
||||||
|
(~cite (make-bib #:title "Test with nothing"))
|
||||||
|
(generate-bib)))
|
||||||
|
|
||||||
|
(check-not-exn
|
||||||
|
(λ ()
|
||||||
|
(define-cite ~cite citet generate-bib)
|
||||||
|
|
||||||
|
(~cite (make-bib #:title "Test with nothing"
|
||||||
|
#:author (author-name "Quick" "Checkerson")))
|
||||||
|
(render (list (generate-bib))
|
||||||
|
(list "test.scrbl"))))
|
Loading…
Reference in New Issue
Block a user