Double figure captions in typst output
pandoc 3.2
Features: +server +lua
Scripting engine: Lua 5.4
typst 0.11.1
pandoc-crossref v0.3.17.1 git commit UNKNOWN (UNKNOWN) built with Pandoc v3.2, pandoc-types v1.23.1 and GHC 9.6.3
macOS Sonoma Version 14.4.1 (23E224)
When rendered with typst, figures are double captioned, often incorrectly if out of order. Example:
Raw typst:
= A title
<a-title>
Here is some content. Here is a figure (fig.~1). Here is another
(fig.~2)
#figure(image("figures/cen1_4.png"),
caption: [
Figure 1: nice figure
]
)
<fig:fig1>
#figure(image("figures/cen5_8.png"),
caption: [
Figure 2: nice figure
]
)
<fig:fig2>
This is with the input:
# A title
Here is some content.
Here is a figure (@fig:fig1).
Here is another (@fig:fig2)
{#fig:fig1}
{#fig:fig2}
running:
pandoc --output test.typ -t typst -F pandoc-crossref --citeproc test/test.md
The same error does not occur in latex or word output.
Cheers!
Hm figure didn't seem to attach:
I suspect this has to do with pandoc-crossref and how it interacts with pandoc. Pandoc's behavior here may have changed in recent releases. I'd contact the pandoc-crossref maintainer to diagnose the issue.
pandoc 3.3 output is different, but I suspect still not quite right:
= A title
<a-title>
Here is some content. Here is a figure
(#cite(<fig:fig1>, form: "prose");). Here is another
(#cite(<fig:fig2>, form: "prose");)
#figure(image("figures/cen1_4.png"),
caption: [
nice figure
]
)
<fig:fig1>
#figure(image("figures/cen5_8.png"),
caption: [
nice figure
]
)
<fig:fig2>
Trying to compile this yields an error:
error: the document does not contain a bibliography
┌─ toPdfViaTempFile61421-0.html:121:2
│
121 │ (#cite(<fig:fig1>, form: "prose");). Here is another
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the document does not contain a bibliography
┌─ toPdfViaTempFile61421-0.html:122:2
│
122 │ (#cite(<fig:fig2>, form: "prose");)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error producing PDF.
Please advise on what the right typst should be!
OK, I see that what we want is
(@fig:fig1). Here is another
(@fig:fig2).
Never mind: I forgot you were using pandoc-crossref.
OK, I think this is not a pandoc issue, but a pandoc-crossref issue.
pandoc-crossref seems to be adding the label Figure #, but typst adds this label automatically, so you get two. The solution is for pandoc-crossref to stop doing this if output is typst.