pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

Double figure captions in typst output

Open SwiftSeal opened this issue 1 year ago • 2 comments

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:

Uploading image.png…

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)

![nice figure](figures/cen1_4.png){#fig:fig1}

![nice figure](figures/cen5_8.png){#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!

SwiftSeal avatar Jun 18 '24 09:06 SwiftSeal

Hm figure didn't seem to attach:

image

SwiftSeal avatar Jun 18 '24 09:06 SwiftSeal

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.

jgm avatar Jun 18 '24 19:06 jgm

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!

jgm avatar Sep 05 '24 17:09 jgm

OK, I see that what we want is

(@fig:fig1). Here is another
(@fig:fig2).

jgm avatar Sep 05 '24 17:09 jgm

Never mind: I forgot you were using pandoc-crossref.

jgm avatar Sep 05 '24 17:09 jgm

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.

jgm avatar Sep 05 '24 17:09 jgm