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.
This commit is contained in:
John MacFarlane 2021-02-01 08:43:26 -08:00
parent 22faea15c2
commit b239c89a82
4 changed files with 107 additions and 8 deletions

View file

@ -410,7 +410,7 @@ library
blaze-markup >= 0.8 && < 0.9, blaze-markup >= 0.8 && < 0.9,
bytestring >= 0.9 && < 0.12, bytestring >= 0.9 && < 0.12,
case-insensitive >= 1.2 && < 1.3, 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 >= 0.1.1.3 && < 0.2,
commonmark-extensions >= 0.2.0.4 && < 0.3, commonmark-extensions >= 0.2.0.4 && < 0.3,
commonmark-pandoc >= 0.2 && < 0.3, commonmark-pandoc >= 0.2 && < 0.3,

View file

@ -115,7 +115,7 @@ writeBibtexString opts variant mblang ref =
"motion_picture" | variant == Biblatex -> "movie" "motion_picture" | variant == Biblatex -> "movie"
"review" | variant == Biblatex -> "review" "review" | variant == Biblatex -> "review"
_ -> "misc" _ -> "misc"
mbSubtype = mbSubtype =
case referenceType ref of case referenceType ref of
"article-magazine" -> Just "magazine" "article-magazine" -> Just "magazine"
@ -149,7 +149,7 @@ writeBibtexString opts variant mblang ref =
, "type" , "type"
, "entrysubtype" , "entrysubtype"
, "note" , "note"
, "language" , "langid"
, "abstract" , "abstract"
, "keywords" , "keywords"
] ]
@ -202,12 +202,19 @@ writeBibtexString opts variant mblang ref =
[ (", " <>) <$> nameGiven name, [ (", " <>) <$> nameGiven name,
nameDroppingParticle name ] nameDroppingParticle name ]
titlecase = case mblang of mblang' = (parseLang <$> getVariableAsText "language") <|> mblang
titlecase = case mblang' of
Just (Lang "en" _) -> titlecase' Just (Lang "en" _) -> titlecase'
Nothing -> 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 (\ils -> B.fromList
(case B.toList ils of (case B.toList ils of
Str t : xs -> Str t : Walk.walk spanAroundCapitalizedWords xs 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 "urldate" = getVariable "accessed" >>= toLaTeX . valToInlines
getContentsFor "year" = getVariable "issued" >>= getYear getContentsFor "year" = getVariable "issued" >>= getYear
getContentsFor "month" = getVariable "issued" >>= getMonth getContentsFor "month" = getVariable "issued" >>= getMonth
getContentsFor "pages" = getVariable "page" >>= toLaTeX . valToInlines
getContentsFor "langid" = getVariable "language" >>= toLaTeX . valToInlines
getContentsFor "number" = (getVariable "number" getContentsFor "number" = (getVariable "number"
<|> getVariable "collection-number" <|> getVariable "collection-number"
<|> getVariable "issue") >>= toLaTeX . valToInlines <|> getVariable "issue") >>= toLaTeX . valToInlines

View file

@ -19,10 +19,10 @@ extra-deps:
- doctemplates-0.9 - doctemplates-0.9
- texmath-0.12.1 - texmath-0.12.1
- tasty-bench-0.1 - tasty-bench-0.1
- citeproc-0.3.0.6 - citeproc-0.3.0.7
#- citeproc: #- citeproc:
# git: https://github.com/jgm/citeproc.git # git: https://github.com/jgm/citeproc.git
# commit: da1f9702fa70d7e1bad9a796f897e920e2d578f7 # commit: feb3b7580c6738eec3b23921f7c1739cfba611aa
ghc-options: ghc-options:
"$locals": -fhide-source-paths -Wno-missing-home-modules "$locals": -fhide-source-paths -Wno-missing-home-modules
resolver: lts-16.23 resolver: lts-16.23

90
test/command/7067.md Normal file
View file

@ -0,0 +1,90 @@
```
% pandoc -t biblatex
---
references:
- id: garaud
author:
- family: Garaud
given: Marcel
container-title: Bulletin de la Societé des antiquaires de lOuest
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 lOuest},
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 lOuest
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 lOuest},
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}
}
```