Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions scribble-lib/scriblib/bibtex.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,28 @@
(define (read-braced-value ip)
(read-char ip)
(let loop ()
(define first-part (read-until (λ (c) (or (char=? c #\{) (char=? c #\})))
(define first-part (read-until (λ (c) (or (char=? c #\{) (char=? c #\})
(char=? c #\\)))
ip))
(match (peek-char ip)
[#\{
(string-append first-part (read-value ip) (loop))]
(string-append first-part (read-braced-value ip) (loop))]
[#\}
(read-char ip)
first-part])))
first-part]
[#\\
(read-char ip)
(string-append first-part (read-maybe-bibtex-escape ip) (loop))])))

(define (read-maybe-bibtex-escape ip)
(match (peek-char ip)
[#\#
(read-char ip)
"#"]
[_
;; unknown escape; probably latex
"\\"]))


(define (read-value ip)
(slurp-whitespace ip)
Expand Down
5 changes: 5 additions & 0 deletions scribble-test/tests/scriblib/bibtex.escapes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bibliography

[1]A A\"uthor. Foo Bar $\Sigma$. fake, 2003. example.com#tag
[2]S. Hochreiter and J. Schmidhuber. Long Short-Term Memory. Neural
Computation 9(8), pp. 1735–1780, 1997.
8 changes: 7 additions & 1 deletion scribble-test/tests/scriblib/bibtex.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

(define-runtime-path normal-expected-path "bibtex.normal.txt")
(define-runtime-path number-expected-path "bibtex.number.txt")
(define-runtime-path escapes-expected-path "bibtex.escapes.txt")

(define-syntax-rule (test-render* definer expected-path body generate-bibliography-id)
(let ()
Expand Down Expand Up @@ -73,4 +74,9 @@
(λ (~cite-id citet-id)
(citet-id "salib:starkiller")
(citet-id "cryptoeprint:2000:067")
(citet-id "Tobin-Hochstadt:2011fk"))))
(citet-id "Tobin-Hochstadt:2011fk")))

(test-render escapes-expected-path (#:style number-style)
(λ (~cite-id citet-id)
(citet-id "escape1")
(citet-id "hochreiter_long_1997"))))
8 changes: 8 additions & 0 deletions scribble-test/tests/scriblib/example.bib
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,11 @@ @mastersthesis{salib:starkiller
month = "May",
year = 2004
}

@article{escape1,
author = {A A\"uthor},
title = "{Foo} {Bar} $\Sigma$",
year = 2003,
journal = "fake",
url = {example.com\#tag},
}