git.iko.soy/typeable/pandoc
on master help sign in
BibTeX writer fixes. Closes #7067.

+ Require citeproc 0.3.0.7, which correctly titlecases when titles contain non-ASCII characters. + Correctly handle 'pages' (= 'page' in CSL). + Correctly handle BibLaTeX 'langid' (= 'language' in CSL). + In BibTeX output, protect foreign titles since there's no language field.

commitb239c89a82b66abc55bf7c08e37492938c817c56 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 1 Feb 2021, 08:43 (6 years ago) parent22faea1
4 files changed+108−9
pandoc.cabal+1−1 src/Text/Pandoc/Citeproc/BibTeX.hs+15−6 stack.yaml+2−2 test/command/7067.md+90
pandoc.cabal+1−1
@@ -410,7 +410,7 @@ library
410410 blaze-markup >= 0.8 && < 0.9,
411411 bytestring >= 0.9 && < 0.12,
412412 case-insensitive >= 1.2 && < 1.3,
413− citeproc >= 0.3.0.6 && < 0.4,
413+ citeproc >= 0.3.0.7 && < 0.4,
414414 commonmark >= 0.1.1.3 && < 0.2,
415415 commonmark-extensions >= 0.2.0.4 && < 0.3,
416416 commonmark-pandoc >= 0.2 && < 0.3,
src/Text/Pandoc/Citeproc/BibTeX.hs+15−6
@@ -115,7 +115,7 @@ writeBibtexString opts variant mblang ref =
115115 "motion_picture" | variant == Biblatex -> "movie"
116116 "review" | variant == Biblatex -> "review"
117117 _ -> "misc"
118−
118+
119119 mbSubtype =
120120 case referenceType ref of
121121 "article-magazine" -> Just "magazine"
@@ -149,7 +149,7 @@ writeBibtexString opts variant mblang ref =
149149 , "type"
150150 , "entrysubtype"
151151 , "note"
152− , "language"
152+ , "langid"
153153 , "abstract"
154154 , "keywords"
155155 ]
@@ -202,12 +202,19 @@ writeBibtexString opts variant mblang ref =
202202 [ (", " <>) <$> nameGiven name,
203203 nameDroppingParticle name ]
204204
205− titlecase = case mblang of
205+ mblang' = (parseLang <$> getVariableAsText "language") <|> mblang
206+
207+ titlecase = case mblang' of
206208 Just (Lang "en" _) -> titlecase'
207209 Nothing -> titlecase'
208− _ -> id
209−
210− titlecase' = addTextCase mblang TitleCase .
210+ _ ->
211+ case variant of
212+ Bibtex -> B.spanWith nullAttr
213+ -- BibTex lacks a language field, so we wrap non-English
214+ -- titles in {} to protect case.
215+ Biblatex -> id
216+
217+ titlecase' = addTextCase mblang' TitleCase .
211218 (\ils -> B.fromList
212219 (case B.toList ils of
213220 Str t : xs -> Str t : Walk.walk spanAroundCapitalizedWords xs
@@ -299,6 +306,8 @@ writeBibtexString opts variant mblang ref =
299306 getContentsFor "urldate" = getVariable "accessed" >>= toLaTeX . valToInlines
300307 getContentsFor "year" = getVariable "issued" >>= getYear
301308 getContentsFor "month" = getVariable "issued" >>= getMonth
309+ getContentsFor "pages" = getVariable "page" >>= toLaTeX . valToInlines
310+ getContentsFor "langid" = getVariable "language" >>= toLaTeX . valToInlines
302311 getContentsFor "number" = (getVariable "number"
303312 <|> getVariable "collection-number"
304313 <|> getVariable "issue") >>= toLaTeX . valToInlines
stack.yaml+2−2
@@ -19,10 +19,10 @@ extra-deps:
1919- doctemplates-0.9
2020- texmath-0.12.1
2121- tasty-bench-0.1
22−- citeproc-0.3.0.6
22+- citeproc-0.3.0.7
2323#- citeproc:
2424# git: https://github.com/jgm/citeproc.git
25−# commit: da1f9702fa70d7e1bad9a796f897e920e2d578f7
25+# commit: feb3b7580c6738eec3b23921f7c1739cfba611aa
2626ghc-options:
2727 "$locals": -fhide-source-paths -Wno-missing-home-modules
2828resolver: lts-16.23
test/command/7067.mdnew file+90
@@ -0,0 +1,90 @@
1+```
2+% pandoc -t biblatex
3+---
4+references:
5+- id: garaud
6+ author:
7+ - family: Garaud
8+ given: Marcel
9+ container-title: Bulletin de la Societé des antiquaires de l’Ouest
10+ collection-title: 4
11+ issued:
12+ - year: 1967
13+ language: fr-FR
14+ page: 11-27
15+ title: Recherches sur les défrichements dans la Gâtine poitevine aux XI^e^ et XII^e^ siècles
16+ type: article-journal
17+ volume: 9
18+...
19+^D
20+@article{garaud,
21+ author = {Garaud, Marcel},
22+ title = {Recherches sur les défrichements dans la Gâtine poitevine aux
23+XI\textsuperscript{e} et XII\textsuperscript{e} siècles},
24+ journal = {Bulletin de la Societé des antiquaires de l’Ouest},
25+ series = {4},
26+ volume = {9},
27+ pages = {11-27},
28+ date = {1967},
29+ langid = {fr-FR}
30+}
31+```
32+
33+```
34+% pandoc -t bibtex
35+---
36+references:
37+- id: garaud
38+ author:
39+ - family: Garaud
40+ given: Marcel
41+ container-title: Bulletin de la Société des antiquaires de l’Ouest
42+ collection-title: 4
43+ issued:
44+ - year: 1967
45+ language: fr-FR
46+ page: 11-27
47+ title: Recherches sur les défrichements dans la Gâtine poitevine aux XI^e^ et XII^e^ siècles
48+ type: article-journal
49+ volume: 9
50+...
51+^D
52+@article{garaud,
53+ author = {Garaud, Marcel},
54+ title = {{Recherches sur les défrichements dans la Gâtine poitevine aux
55+XI\textsuperscript{e} et XII\textsuperscript{e} siècles}},
56+ journal = {Bulletin de la Société des antiquaires de l’Ouest},
57+ series = {4},
58+ volume = {9},
59+ pages = {11-27},
60+ year = {1967}
61+}
62+```
63+
64+This tests the titlecasing of a word with an accented second letter:
65+```
66+% pandoc -t bibtex
67+---
68+references:
69+- id: garaud
70+ author:
71+ - family: Garaud
72+ given: Marcel
73+ container-title: English Journal
74+ issued:
75+ - year: 1967
76+ language: en-US
77+ title: Research on the défrichements in the Gâtine poitevine
78+ type: article-journal
79+ volume: 9
80+...
81+^D
82+@article{garaud,
83+ author = {Garaud, Marcel},
84+ title = {Research on the Défrichements in the {Gâtine} Poitevine},
85+ journal = {English Journal},
86+ volume = {9},
87+ year = {1967}
88+}
89+```
90+