quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.77k stars 308 forks source link

Figure with empty caption and cross-ref label rendered to Typst crashes main.lua #9675

Closed iandol closed 4 months ago

iandol commented 4 months ago

Bug description

With this code:

---
title: "No Caption Figure Test"
author: Jane Doe
---

Text.

![](xkcd.png){#fig-xkcd}

Text.

I get this crashlog rendering to Typst:

▷ quarto render sf.qmd -t typst -o sf.pdf
pandoc -o sf.typ
  to: typst
  standalone: true
  default-image-extension: svg
  wrap: none
  citeproc: false

metadata
  title: No Caption Figure Test
  author: Jane Doe

Error running filter /Applications/quarto/share/filters/main.lua:
/Applications/quarto/share/filters/main.lua:22303: attempt to index a nil value (local 'caption')
stack traceback:
    /Applications/quarto/share/filters/main.lua:1211: in local 'filter_fn'
    /Applications/quarto/share/filters/main.lua:613: in function </Applications/quarto/share/filters/main.lua:603>
    (...tail calls...)
    [C]: in ?
    [C]: in method 'walk'
    /Applications/quarto/share/filters/main.lua:535: in function </Applications/quarto/share/filters/main.lua:524>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:1312: in local 'callback'
    /Applications/quarto/share/filters/main.lua:1330: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:1366: in function </Applications/quarto/share/filters/main.lua:1363>
stack traceback:
    /Applications/quarto/share/filters/main.lua:535: in function </Applications/quarto/share/filters/main.lua:524>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:1312: in local 'callback'
    /Applications/quarto/share/filters/main.lua:1330: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:1366: in function </Applications/quarto/share/filters/main.lua:1363>

I can stop the crash by removing the cross-ref label OR adding a caption text. Render to HTML or LaTeX and it works as is.

Steps to reproduce

No response

Expected behavior

Typst output doesn't crash main.lua

Actual behavior

No document is produced

Your environment

Quarto 1.5.35 on macOS 14.4.1

Quarto check output

▷ quarto check                           
Quarto 1.5.35
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.13: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.35
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.05
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/ian/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.1
      Path: /Users/ian/.pyenv/versions/3.12.1/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

      There is an unactivated Python environment in micromamba. Did you forget to activate it?

[✓] Checking R installation...........OK
      Version: 4.4.0
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
      knitr: (None)
      rmarkdown: (None)

      The knitr package is not available in this R installation.
      Install with install.packages("knitr")
      The rmarkdown package is not available in this R installation.
      Install with install.packages("rmarkdown")
mcanouil commented 4 months ago

Thanks for the report. The inline syntax does produce a crash.

Alternatively, the fenced div syntax works.

---
title: "No Caption Figure Test"
author: Jane Doe
format: typst
---

Text.

:::{#fig-xkcd}
![](xkcd.png)
:::

Text.
cscheid commented 4 months ago

Thanks for the report. (For our own sake, this is another side-effect of the Pandoc upstream fix that removed empty Plain nodes)

jbrick55 commented 2 months ago

I'm experiencing this same issue when rendering to HTML. I get a similar Lua error...

Error running filter /Applications/quarto/share/filters/main.lua:
/Applications/quarto/share/filters/main.lua:11765: attempt to index a nil value (field 'caption_long')
stack traceback:
    [C]: in ?
    [C]: in method 'walk'
    /Applications/quarto/share/filters/main.lua:557: in function </Applications/quarto/share/filters/main.lua:546>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:11762: in local 'filter_fn'
    /Applications/quarto/share/filters/main.lua:635: in function </Applications/quarto/share/filters/main.lua:625>
    (...tail calls...)
    [C]: in ?
    [C]: in method 'walk'
    /Applications/quarto/share/filters/main.lua:557: in function </Applications/quarto/share/filters/main.lua:546>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:1334: in local 'callback'
    /Applications/quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:1388: in function </Applications/quarto/share/filters/main.lua:1385>
stack traceback:
    /Applications/quarto/share/filters/main.lua:557: in function </Applications/quarto/share/filters/main.lua:546>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:11762: in local 'filter_fn'
    /Applications/quarto/share/filters/main.lua:635: in function </Applications/quarto/share/filters/main.lua:625>
    (...tail calls...)
    [C]: in ?
    [C]: in method 'walk'
    /Applications/quarto/share/filters/main.lua:557: in function </Applications/quarto/share/filters/main.lua:546>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:1334: in local 'callback'
    /Applications/quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:1388: in function </Applications/quarto/share/filters/main.lua:1385>
stack traceback:
    /Applications/quarto/share/filters/main.lua:557: in function </Applications/quarto/share/filters/main.lua:546>
    (...tail calls...)
    /Applications/quarto/share/filters/main.lua:1334: in local 'callback'
    /Applications/quarto/share/filters/main.lua:1352: in upvalue 'run_emulated_filter_chain'
    /Applications/quarto/share/filters/main.lua:1388: in function </Applications/quarto/share/filters/main.lua:1385>

Using...

knitr::knit_exit()

I was able to verify it was the images with no captions causing the issue. These are images that previously worked.

The fix offered by @mcanouil works.

This throws the error...

![ ](assets/STAT-415-SEC-1-15.svg){ #fig-STAT-415-SEC-1-15 .lightbox fig-alt="Natural logarithm graph" fig-align="center" width="50%"}

This fixes it...

:::{#fig-STAT-415-SEC-1-15}
![ ](assets/STAT-415-SEC-1-15.svg){.lightbox fig-alt="Natural logarithm graph" fig-align="center" width="50%"}
:::

So, my question is, do I need to fix every image in all documents so that I can render? I hope I provided enough information.

mcanouil commented 2 months ago

@jbrick55 This should have been fixed in 1.5. Are you using an older version? If so, please upgrade if you can.

jbrick55 commented 2 months ago

@mcanouil , here's what I'm currently using...

Quarto 1.5.53
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.53
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/jmh491/Library/TinyTeX/bin/universal-darwin
      Version: 2023

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.3
      Path: /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
      Jupyter: 5.7.2
      Kernels: sas, python3

(/) Checking Jupyter engine render....Traceback (most recent call last):
  File "/Applications/quarto/share/jupyter/jupyter.py", line 21, in <module>
    from notebook import notebook_execute, RestartKernel
  File "/Applications/quarto/share/jupyter/notebook.py", line 15, in <module>
    from yaml import safe_load as parse_string
ModuleNotFoundError: No module named 'yaml'
[✓] Checking Jupyter engine render....OK

Is there anything else I should try updating? Is there cache I should clear??

mcanouil commented 2 months ago

Could you open a new issue (linking to this one) with a small and fully reproducible example following the guidelines on the issue template?