quarto-dev / quarto-cli

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

PDF fails with several output formats and SVG image #10883

Open zlatkig opened 4 days ago

zlatkig commented 4 days ago

Bug description

When generating HTML, PDF and DOCX formats from the same document which includes a SVG image, PDF generation fails. If generating only HTML and PDF, then all three outputs succeed.

Here is a minimal project which demonstrates the issue:

quazz.zip

The archive contains three files: a simple _quarto.yml, a SVG image and a simple document which references the image. If you run quarto render in the directory where you extract this archive, PDF generation will fail with the following error:

ERROR:
compilation failed- error
Unable to load picture or PDF file 'quazz_files/mediabag/piechart.pdf'.
<to be read again>
                   }
l.169 ...eight]{quazz_files/mediabag/piechart.pdf}

see /Users/igor/Gliwa/tmp/quazz/quazz.log for more information.
ERROR: Error
    at renderFiles (file:///Applications/quarto/bin/quarto.js:78081:29)
    at eventLoopTick (ext:core/01_core.js:153:7)
    at async renderProject (file:///Applications/quarto/bin/quarto.js:78479:25)
    at async Command.actionHandler (file:///Applications/quarto/bin/quarto.js:83077:32)
    at async Command.execute (file:///Applications/quarto/bin/quarto.js:8017:13)
    at async Command.parseCommand (file:///Applications/quarto/bin/quarto.js:7907:20)
    at async quarto (file:///Applications/quarto/bin/quarto.js:118224:9)
    at async file:///Applications/quarto/bin/quarto.js:118244:9
    at async mainRunner (file:///Applications/quarto/bin/quarto.js:118128:9)
    at async file:///Applications/quarto/bin/quarto.js:118235:5

If you now modify _quarto.yml and remove DOCX from output formats (remove or comment out the docx: {} line), PDF generation will succeed. I haven't tested them all, but I think you can use any format instead of docx to demonstrate the issue.

What I believe happens here is that Quarto (or Pandoc) use rsvg-convert to convert the SVG image to PDF. This succeeds and the resulting image is placed in quazz_files/mediabag/piechart.pdf. Pandoc generates a Tex file referencing that image. Now Quarto manages to delete that file (in fact it deletes the entire mediabag subdirectory) before Latex processes Pandoc's output. Latex then fails to find the referenced PDF image.

This only happens with SVG images. PNG images for example go fine. It also only happens if more than HTML and PDF output formats are listed in _quarto.yml.

Rendering to PDF on its own with quarto render --to pdf will succeed even if extra formats are specified in _quarto.yml. Ony rendering them all together with quarto render fails.

Am I doing something wrong?

Steps to reproduce

To reproduce this without the archive attached above, follow these steps:

This is a symbol of a pie chart in SVG:

Symbolic pie chart{width=20%}

That is it.

- Put this in `_quarto.yml`:
````yaml
project:
  title: "quazz"

format:
  html: {}
  pdf: {}
  docx: {}

Expected behavior

Expected is generation of three output documents as specified in _quarto.yml.

Actual behavior

PDF generation fails with an error.

Your environment

Quarto check output

Quarto 1.5.57
[✓] 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.57
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.09
      Chromium: 869685

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

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.6
      Path: /usr/local/opt/python@3.12/bin/python3.12
      Jupyter: (None)

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

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-x86_64/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 8 hours ago

Where did you see the following?

format:
  html: {}
  pdf: {}
  docx: {}

That is quite not pretty. You should use default which is clearer than {}.

This being said, I can reproduce using a simpler example. Thanks for the report.

---
title: "Quazz"
format:
  pdf: default
  docx: default
---

![Symbolic pie chart](piechart.svg)

Somehow, the temporary files seems to be wrongly deleted or at least not at the right time.

The following with docx as first format also works:

---
title: "Quazz"
format:
  docx: default
  pdf: default
---

![Symbolic pie chart](piechart.svg)