diff --git a/scribble-lib/scriblib/bibtex.rkt b/scribble-lib/scriblib/bibtex.rkt index 2b62393091..35c2375ba3 100644 --- a/scribble-lib/scriblib/bibtex.rkt +++ b/scribble-lib/scriblib/bibtex.rkt @@ -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) diff --git a/scribble-test/tests/scriblib/bibtex.escapes.txt b/scribble-test/tests/scriblib/bibtex.escapes.txt new file mode 100644 index 0000000000..ece211c9a1 --- /dev/null +++ b/scribble-test/tests/scriblib/bibtex.escapes.txt @@ -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. diff --git a/scribble-test/tests/scriblib/bibtex.rkt b/scribble-test/tests/scriblib/bibtex.rkt index a73089ef9a..4ec6d91c5b 100644 --- a/scribble-test/tests/scriblib/bibtex.rkt +++ b/scribble-test/tests/scriblib/bibtex.rkt @@ -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 () @@ -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")))) diff --git a/scribble-test/tests/scriblib/example.bib b/scribble-test/tests/scriblib/example.bib index 9d5d44b0e0..b29c720d69 100644 --- a/scribble-test/tests/scriblib/example.bib +++ b/scribble-test/tests/scriblib/example.bib @@ -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}, +} \ No newline at end of file