Skip to content

PDF fails with several output formats and SVG image #10883

Closed as not planned
Closed as not planned

Description

@zlatkig

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:

  • Create a Quarto project with default type using quarto create project default . quazz --no-open. This will generate two files in the current directory named _quarto.yml and quazz.qmd.
  • Find any SVG image and save it as piechart.svg.
  • Put this in quazz.qmd:
---
title: "quazz"
---

This is a symbol of a pie chart in SVG:

![Symbolic pie chart](/piechart.svg "A SVG Picture"){width=20%}

That is it.
  • Put this in _quarto.yml:
project:
  title: "quazz"

format:
  html: {}
  pdf: {}
  docx: {}
  • Run quarto render

Expected behavior

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

Actual behavior

PDF generation fails with an error.

Your environment

  • IDE: VIM, but not relevant. Any text editor will do.
  • OS: macOS Sequoia 15.0

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/[email protected]/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")

Activity

  1. added
    bug
    on Sep 25, 2024
  2. mcanouil commented on Sep 29, 2024

    @mcanouil
    Collaborator

    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)
    • quarto render index.qmd --to all leads to an error.
    • remove docx: default (or change the order) and quarto render index.qmd --to all works.

    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)
  3. added
    docx
    latex
    on Sep 29, 2024
  4. zlatkig commented on Oct 1, 2024

    @zlatkig
    Author

    Sorry for the ugly curlies {}. That was me in attempt to satisfy data type requirements in this particular example and not thinking in the process. In production I have actual options there overriding the defaults or adding to them.

    Changing the order and putting pdf format last leads to a working construct. That confirms that I didn't think far enough. I really should have been able to come up with that workaround on my own. This workaround solves my particular use case.

    Nevertheless, this led me to investigate the typst format. I found that typst and pdf cannot be generated at the same time and that doesn't seem to be by design.

    The use case for that would be migration from LaTeX to Typst for PDF generation. Potentially complex LaTeX templates cannot be reused, new ones must be created from scratch. It would help to have both outputs available during transition to compare them.

    The formats typst and pdf have the same output file by default and one of them must be renamed. I attempted to do this using output-ext option. This leads to errors which are not observable without this option. Is that generally a wrong way and if not, would this be a topic for a separate issue report? I fail to find an issue already dealing with this and that is often a sign for me doing something wrong (or not searching deep enough).

  5. mcanouil commented on Oct 1, 2024

    @mcanouil
    Collaborator

    Your last comment is unrelated to this thread in most parts.

    Use output-file to have different file names.
    (There are several discussions about this, as revealjs/html also have the same issue of sharing the same file extension).

  6. cderv commented on Oct 1, 2024

    @cderv
    Member

    I believe this issue is similar to others on mediabag cleaning happening to soon in the rendering process when multiple format.

    This is a direct duplicate of:

    and probably others, so I'll close this one and will follow up in the other.

    Workaround for now. change the order. Doing docx before pdf will work.

    format:
      docx: default
      pdf: default
  7. cderv commented on Oct 1, 2024

    @cderv
    Member

    Duplicate of #8373

  8. added
    duplicate
    on Oct 1, 2024
  9. modified the milestone: v1.6 on Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocxduplicatelatexprojects

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions