From 6dae03f719b4b809a38ff7cc361be3b46447b87d Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 30 Jul 2025 11:24:18 +0200 Subject: Typst writer: add native Typst support for `nocite`. The `nocite` metadata field can now be used to supply additional citations that don't appear in the text, just as with citeproc and LaTeX's bibtex and natbib. Closes: #10680 --- data/templates/default.typst | 5 ++++- src/Text/Pandoc/Writers/Typst.hs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/data/templates/default.typst b/data/templates/default.typst index 00e1ec557..4c75fd0f4 100644 --- a/data/templates/default.typst +++ b/data/templates/default.typst @@ -132,6 +132,9 @@ $endif$ $body$ $if(citations)$ +$for(nocite-ids)$ +#cite(label("${it}"), form: none) +$endfor$ $if(csl)$ #set bibliography(style: "$csl$") @@ -141,7 +144,7 @@ $elseif(bibliographystyle)$ $endif$ $if(bibliography)$ -#bibliography($for(bibliography)$"$bibliography$"$sep$,$endfor$) +#bibliography($for(bibliography)$"$bibliography$"$sep$,$endfor$$if(full-bibliography)$, full: true$endif$) $endif$ $endif$ $for(include-after)$ diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 9e71ea513..7fd7e1cf6 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -28,10 +28,12 @@ import Data.Bifunctor (first, second) import Network.URI (unEscapeString) import qualified Data.Text as T import Control.Monad.State ( StateT, evalStateT, gets, modify ) -import Text.Pandoc.Writers.Shared ( metaToContext, defField, resetField, - setupTranslations, lookupMetaString ) +import Text.Pandoc.Writers.Shared ( lookupMetaInlines, lookupMetaString, + metaToContext, defField, resetField, + setupTranslations ) import Text.Pandoc.Shared (isTightList, orderedListMarkers, tshow) import Text.Pandoc.Translations (Term(Abstract), translateTerm) +import Text.Pandoc.Walk (query) import Text.Pandoc.Writers.Math (convertMath) import qualified Text.TeXMath as TM import Text.DocLayout @@ -75,10 +77,17 @@ pandocToTypst options (Pandoc meta blocks) = do let toPosition :: CaptionPosition -> Text toPosition CaptionAbove = "top" toPosition CaptionBelow = "bottom" + let nociteIds = query (\inln -> case inln of + Cite cs _ -> map citationId cs + _ -> []) + $ lookupMetaInlines "nocite" meta + let context = defField "body" main $ defField "toc" (writerTableOfContents options) $ (if isEnabled Ext_citations options then defField "citations" True + . defField "nocite-ids" (filter (/= "*") nociteIds) + . defField "full-bibliography" ("*" `elem` nociteIds) else id) $ (case lookupMetaString "lang" meta of "" -> id -- cgit v1.2.3