From 8d09a58857f18975524b1797300ef3a65569d0d8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 14 Sep 2024 10:12:07 -0700 Subject: [PATCH] LaTeX writer: avoid error on `refs` div with empty citations. If there are no citations, don't emit an empty CSLReferences environment. Closes #10185. --- src/Text/Pandoc/Writers/LaTeX.hs | 5 ++-- test/command/10185.md | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/command/10185.md diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 76d180d35085..04e0ab3db4cb 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -375,8 +375,9 @@ blockToLaTeX (Div (identifier,classes,kvs) bs) = do then modify $ \st -> st{ stIncremental = True } else when (beamer && "nonincremental" `elem` classes) $ modify $ \st -> st { stIncremental = False } - result <- if identifier == "refs" || -- <- for backwards compatibility - "csl-bib-body" `elem` classes + result <- if (identifier == "refs" || -- <- for backwards compatibility + "csl-bib-body" `elem` classes) && + (not (null bs)) then do modify $ \st -> st{ stHasCslRefs = True } inner <- blockListToLaTeX bs diff --git a/test/command/10185.md b/test/command/10185.md new file mode 100644 index 000000000000..27288a5a4b48 --- /dev/null +++ b/test/command/10185.md @@ -0,0 +1,44 @@ +``` +% pandoc -t latex --citeproc +Lorem ipsum + +# References + +::: #refs +::: +^D +Lorem ipsum + +\section{References}\label{references} +``` + +``` +% pandoc -t latex --citeproc +--- +references: +- id: foo + type: book + title: The Title + author: John Doe +... + +Lorem ipsum [@foo]. + +# References + +::: #refs +::: +^D +Lorem ipsum (John Doe, n.d.). + +\section{References}\label{references} + +\phantomsection\label{refs} +\begin{CSLReferences}{1}{0} +\bibitem[\citeproctext]{ref-foo} +John Doe. n.d. \emph{The Title}. + +\end{CSLReferences} + +``` +