Skip to content

Commit

Permalink
LaTeX writer: avoid error on refs div with empty citations.
Browse files Browse the repository at this point in the history
If there are no citations, don't emit an empty CSLReferences
environment.

Closes #10185.
  • Loading branch information
jgm committed Sep 14, 2024
1 parent 8c14784 commit 8d09a58
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Text/Pandoc/Writers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions test/command/10185.md
Original file line number Diff line number Diff line change
@@ -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}
```

0 comments on commit 8d09a58

Please sign in to comment.