From b239c89a82b66abc55bf7c08e37492938c817c56 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 1 Feb 2021 08:43:26 -0800 Subject: 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. --- src/Text/Pandoc/Citeproc/BibTeX.hs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/Text') 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 - - titlecase' = addTextCase mblang TitleCase . + _ -> + 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 . (\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 -- cgit v1.2.3