git.iko.soy/typeable/pandoc
on master help sign in
Handle 'nocite' better with --biblatex and --natbib.

Previously the nocite metadata field was ignored with these formats. Now it populates a `nocite-ids` template variable and causes a `\nocite` command to be issued. Closes #4585.

commit3622097da360ab83112eb26b4f6231488d747a95 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 14 Mar 2021, 00:09 (6 years ago) parentc55a73b
2 files changed+13−2
data/templates/default.latex+3 src/Text/Pandoc/Writers/LaTeX.hs+10−2
data/templates/default.latex+3
@@ -372,6 +372,9 @@ $for(bibliography)$
372372\addbibresource{$bibliography$}
373373$endfor$
374374$endif$
375+$if(nocite-ids)$
376+\nocite{$for(nocite-ids)$$it$$sep$, $endfor$}
377+$endif$
375378$if(csl-refs)$
376379\newlength{\cslhangindent}
377380\setlength{\cslhangindent}{1.5em}
src/Text/Pandoc/Writers/LaTeX.hs+10−2
@@ -1,4 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE TupleSections #-}
34{-# LANGUAGE PatternGuards #-}
45{-# LANGUAGE ScopedTypeVariables #-}
@@ -145,6 +146,11 @@ pandocToLaTeX options (Pandoc meta blocks) = do
145146
146147 let dirs = query (extract "dir") blocks
147148
149+ let nociteIds = query (\case
150+ Cite cs _ -> map citationId cs
151+ _ -> [])
152+ $ lookupMetaInlines "nocite" meta
153+
148154 let context = defField "toc" (writerTableOfContents options) $
149155 defField "toc-depth" (tshow
150156 (writerTOCDepth options -
@@ -177,9 +183,11 @@ pandocToLaTeX options (Pandoc meta blocks) = do
177183 else id) $
178184 (case writerCiteMethod options of
179185 Natbib -> defField "biblio-title" biblioTitle .
180− defField "natbib" True
186+ defField "natbib" True .
187+ defField "nocite-ids" nociteIds
181188 Biblatex -> defField "biblio-title" biblioTitle .
182− defField "biblatex" True
189+ defField "biblatex" True .
190+ defField "nocite-ids" nociteIds
183191 _ -> id) $
184192 defField "colorlinks" (any hasStringValue
185193 ["citecolor", "urlcolor", "linkcolor", "toccolor",