From b239c89a82b66abc55bf7c08e37492938c817c56 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 1 Feb 2021 08:43:26 -0800 Subject: [PATCH] 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. --- pandoc.cabal | 2 +- src/Text/Pandoc/Citeproc/BibTeX.hs | 19 +++++-- stack.yaml | 4 +- test/command/7067.md | 90 ++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 test/command/7067.md diff --git a/pandoc.cabal b/pandoc.cabal index 0890318e3..1bdd2a6b3 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -410,7 +410,7 @@ library blaze-markup >= 0.8 && < 0.9, bytestring >= 0.9 && < 0.12, case-insensitive >= 1.2 && < 1.3, - citeproc >= 0.3.0.6 && < 0.4, + citeproc >= 0.3.0.7 && < 0.4, commonmark >= 0.1.1.3 && < 0.2, commonmark-extensions >= 0.2.0.4 && < 0.3, commonmark-pandoc >= 0.2 && < 0.3, diff --git a/src/Text/Pandoc/Citeproc/BibTeX.hs b/src/Text/Pandoc/Citeproc/BibTeX.hs index 5b9068378..2b43fffb6 100644 --- a/src/Text/Pandoc/Citeproc/BibTeX.hs +++ b/src/Text/Pandoc/Citeproc/BibTeX.hs @@ -115,7 +115,7 @@ writeBibtexString opts variant mblang ref = "motion_picture" | variant == Biblatex -> "movie" "review" | variant == Biblatex -> "review" _ -> "misc" - + mbSubtype = case referenceType ref of "article-magazine" -> Just "magazine" @@ -149,7 +149,7 @@ writeBibtexString opts variant mblang ref = , "type" , "entrysubtype" , "note" - , "language" + , "langid" , "abstract" , "keywords" ] @@ -202,12 +202,19 @@ writeBibtexString opts variant mblang ref = [ (", " <>) <$> nameGiven name, nameDroppingParticle name ] - titlecase = case mblang of + mblang' = (parseLang <$> getVariableAsText "language") <|> mblang + + titlecase = case mblang' of Just (Lang "en" _) -> titlecase' Nothing -> titlecase' - _ -> id + _ -> + case variant of + Bibtex -> B.spanWith nullAttr + -- BibTex lacks a language field, so we wrap non-English + -- titles in {} to protect case. + Biblatex -> id - titlecase' = addTextCase mblang TitleCase . + titlecase' = addTextCase mblang' TitleCase . (\ils -> B.fromList (case B.toList ils of Str t : xs -> Str t : Walk.walk spanAroundCapitalizedWords xs @@ -299,6 +306,8 @@ writeBibtexString opts variant mblang ref = getContentsFor "urldate" = getVariable "accessed" >>= toLaTeX . valToInlines getContentsFor "year" = getVariable "issued" >>= getYear getContentsFor "month" = getVariable "issued" >>= getMonth + getContentsFor "pages" = getVariable "page" >>= toLaTeX . valToInlines + getContentsFor "langid" = getVariable "language" >>= toLaTeX . valToInlines getContentsFor "number" = (getVariable "number" <|> getVariable "collection-number" <|> getVariable "issue") >>= toLaTeX . valToInlines diff --git a/stack.yaml b/stack.yaml index 6c8c39fa7..dc6fa6517 100644 --- a/stack.yaml +++ b/stack.yaml @@ -19,10 +19,10 @@ extra-deps: - doctemplates-0.9 - texmath-0.12.1 - tasty-bench-0.1 -- citeproc-0.3.0.6 +- citeproc-0.3.0.7 #- citeproc: # git: https://github.com/jgm/citeproc.git -# commit: da1f9702fa70d7e1bad9a796f897e920e2d578f7 +# commit: feb3b7580c6738eec3b23921f7c1739cfba611aa ghc-options: "$locals": -fhide-source-paths -Wno-missing-home-modules resolver: lts-16.23 diff --git a/test/command/7067.md b/test/command/7067.md new file mode 100644 index 000000000..a66e3aa1f --- /dev/null +++ b/test/command/7067.md @@ -0,0 +1,90 @@ +``` +% pandoc -t biblatex +--- +references: +- id: garaud + author: + - family: Garaud + given: Marcel + container-title: Bulletin de la Societé des antiquaires de l’Ouest + collection-title: 4 + issued: + - year: 1967 + language: fr-FR + page: 11-27 + title: Recherches sur les défrichements dans la Gâtine poitevine aux XI^e^ et XII^e^ siècles + type: article-journal + volume: 9 +... +^D +@article{garaud, + author = {Garaud, Marcel}, + title = {Recherches sur les défrichements dans la Gâtine poitevine aux +XI\textsuperscript{e} et XII\textsuperscript{e} siècles}, + journal = {Bulletin de la Societé des antiquaires de l’Ouest}, + series = {4}, + volume = {9}, + pages = {11-27}, + date = {1967}, + langid = {fr-FR} +} +``` + +``` +% pandoc -t bibtex +--- +references: +- id: garaud + author: + - family: Garaud + given: Marcel + container-title: Bulletin de la Société des antiquaires de l’Ouest + collection-title: 4 + issued: + - year: 1967 + language: fr-FR + page: 11-27 + title: Recherches sur les défrichements dans la Gâtine poitevine aux XI^e^ et XII^e^ siècles + type: article-journal + volume: 9 +... +^D +@article{garaud, + author = {Garaud, Marcel}, + title = {{Recherches sur les défrichements dans la Gâtine poitevine aux +XI\textsuperscript{e} et XII\textsuperscript{e} siècles}}, + journal = {Bulletin de la Société des antiquaires de l’Ouest}, + series = {4}, + volume = {9}, + pages = {11-27}, + year = {1967} +} +``` + +This tests the titlecasing of a word with an accented second letter: +``` +% pandoc -t bibtex +--- +references: +- id: garaud + author: + - family: Garaud + given: Marcel + container-title: English Journal + issued: + - year: 1967 + language: en-US + title: Research on the défrichements in the Gâtine poitevine + type: article-journal + volume: 9 +... +^D +@article{garaud, + author = {Garaud, Marcel}, + title = {Research on the Défrichements in the {Gâtine} Poitevine}, + journal = {English Journal}, + volume = {9}, + year = {1967} +} +``` +