quarto-dev / quarto-cli

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

Mermaid rendering to PDF broken with `quarto install chromium` version #10961

Open sasja-san opened 1 month ago

sasja-san commented 1 month ago

Bug description

I'm not able to render this code to a PDF. The Mermaid code was taken from here: https://quarto.org/docs/authoring/diagrams.html#mermaid

---
title: Mermaid Test
format: pdf
---

# Hello!

```{mermaid}
sequenceDiagram
  participant Alice
  participant Bob
  Alice->>John: Hello John, how are you?
  loop Healthcheck
    John->>John: Fight against hypochondria
  end
  Note right of John: Rational thoughts <br/>prevail!
  John-->>Alice: Great!
  John->>Bob: How about you?
  Bob-->>John: Jolly good!

Here's the error I get:

$ quarto render mermaid-test.qmd ERROR: Internal Error: Couldn't find an svg element in svg string

This is a bug in quarto. We apologize for the inconvenience. Please consider reporting it at https://github.com/quarto-dev/quarto-cli. Thank you!

Stack trace: at resolveSize (file:///home/sasja/.quarto/quarto-cli/src/core/svg.ts:24:11) at eventLoopTick (ext:core/01_core.js:175:7) at async makePng (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/mermaid.ts:353:11) at async makeDefault (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/mermaid.ts:435:16) at async Object.cell (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/mermaid.ts:475:14) at async Promise.all (index 0) at async Object.document (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/base.ts:577:20) at async handleLanguageCells (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/base.ts:529:34) at async file:///home/sasja/.quarto/quarto-cli/src/command/render/render-files.ts:631:41 at async withTimingAsync (file:///home/sasja/.quarto/quarto-cli/src/core/timing.ts:50:20)


### Quarto check & version

I'm using the latest commit on `main` branch:

git show -s --format="%as %H" 2024-10-02 9d00acae2607c1d0fae479b0b8f830145454b207


From `quarto check`:

Quarto 99.9.9 [✓] Checking versions of quarto binary dependencies... Pandoc version 3.4.0: OK Dart Sass version 1.70.0: OK Deno version 1.46.3: OK Typst version 0.11.0: OK [✓] Checking versions of quarto dependencies......OK [✓] Checking Quarto installation......OK Version: 99.9.9 commit: 9d00acae2607c1d0fae479b0b8f830145454b207 Path: /home/sasja/.quarto/quarto-cli/package/dist/bin

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

[✓] Checking LaTeX....................OK Using: TinyTex Path: /home/sasja/.TinyTeX/bin/x86_64-linux Version: 2024

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

[✓] Checking Python 3 installation....OK Version: 3.12.5 Path: /usr/bin/python3 Jupyter: 5.7.2 Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........(None)

  Unable to locate an installed version of R.
  Install R from https://cloud.r-project.org/
cderv commented 1 month ago

Just to share on Windows this is rendering ok for me.

cscheid commented 1 month ago

I also can't repro myself, either on 1.6.18 or main, on macOS.

sasja-san commented 1 month ago

I'm using Manjaro Linux. Is there something I could do to test what might be going on? Maybe there are clues in the call stack?

mcanouil commented 1 month ago

@sasja-san See https://quarto.org/docs/troubleshooting/index.html

sasja-san commented 1 month ago

@sasja-san See https://quarto.org/docs/troubleshooting/index.html

The only thing that I did there (which was applicable to me, the env variable settings gave me nothing) was update my install of TinyTex from v2024.03.13 to v2024.10 - but the error remains.

I dug around a bit in the code trying to figure out what's wrong. I don't know any typescript so I don't really know what I'm doing. Anyway, in src/core/svg.ts i added some code at around line 23:

 const dom = (await getDomParser()).parseFromString(svg, "text/html");
  const svgEl = dom?.querySelector("svg");

  if (!svgEl) {
    throw new InternalError("Couldn't find an svg element in svg string"
                            + "\n\tdom   = " + dom
                            + "\n\tsvgEl = " + svgEl);
  }

which gave me this output:

ERROR: Internal Error: Couldn't find an svg element in svg string
    dom   = [object EventTarget]
    svgEl = null

I would try to make a long string with all the things in this dom object as well, but I don't really know how that's done. Basically what I want to do is something like

let s = "";
foreach e in dom {
    s += e;
}

If anyone could help me with this, then I can dig a little deeper.

github-actions[bot] commented 1 month ago

Thank you for using Quarto and reporting an issue!

Unfortunately, this issue is now considered stale because it has been opened since 14 days without providing a "working" reproducible example to help us investigate. If you are still facing the issue, please review the "Bug Reports" guide on how to provide a fully reproducible example as a self-contained Quarto document or a link to a Git repository. Without a reproducible example, it is unlikely that the issue will be addressed.

You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````).

````qmd
---
title: "Reproducible Quarto Document"
format: html
---

This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.

```{r}
plot(cars)

The end.

cderv commented 1 month ago

@sasja-san can you try with Quarto v1.5 and latest Quarto v1.6 ? Though we are facing #11135 if you have recent build of chrome :(

cscheid commented 1 month ago

Yeah, I think this is "just" a duplicate of #11135

sasja-san commented 4 weeks ago

Sorry I missed this. The tab was active on a virtual desktop I didn't look at for a while, so I cleared the notification without noticing.

I installed and tested with both 1.5.57 and 1.6.31.

Verson 1.6 gave me the same error but version 1.5 gave me a pdf.

Image

As I said previously, I don't know any typescript. But if any of you have suggestions for some code I could use to proceed with poking around I'd gladly try it out.

cderv commented 4 weeks ago

Is this still with the same example shared above in https://github.com/quarto-dev/quarto-cli/issues/10961#issue-2564104122 ?

I still can't reproduce. What is your chrome version on your system ?

To debug further, you can activate Debug logging (https://quarto.org/docs/troubleshooting/#verbose-mode) and see if anything else is helping.

The thing I would if I was able to reproduce would be to try interactively debug dev version inside VSCODE. We don't have a step by step guide for that yet, so one would need to be confortable with VSCODE debugging and quarto dev.

Hopefully, we'll manage to find a reproducible environment for that. Which OS are you on ?

sasja-san commented 4 weeks ago

Is this still with the same example shared above in https://github.com/quarto-dev/quarto-cli/issues/10961#issue-2564104122 ?

Yes.

What is your chrome version on your system ?

From quarto check.

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

To the best of my knowledge I have no other instances of chromium installed. Except maybe bundled ones, if that's what Electron is doing. Do you have some command for me which I could run to check that I don't have some fishy stuff on my system?

so one would need to be confortable with VSCODE debugging and quarto dev.

I'm cool with this. I even wrote a tutorial (rendered using Quarto) about debugging in VS Code: https://github.com/sasja-san/vscode-remote-debug-example

I have pretty much zero experience of TypeScript, though. But that's subject to change ;)

Which OS are you on ?

Image

(though the image there lies, as I have now installed a 65W CPU in my nine years old powerhouse of a computer XD)

mcanouil commented 4 weeks ago

To the best of my knowledge I have no other instances of chromium installed. Except maybe bundled ones, if that's what Electron is doing. Do you have some command for me which I could run to check that I don't have some fishy stuff on my system?

To be accurate, it's chromium-based. If you have Chrome or Edge, they will be used.

cderv commented 4 weeks ago

Can you run with 1.6.32 in verbose mode ? https://quarto.org/docs/troubleshooting/#verbose-mode

This will tell us which chrome version is found and used for mermaid graph processing. I want to rule out chrome before looking into this further.

I don't know if this could come from Manjaro linux distribution or not, I'll try to check if I can have such environment available. How did you install Quarto there BTW ?

sasja-san commented 3 weeks ago

If you have Chrome or Edge, they will be used.

I have Vivaldi and Brave installed, both Chromium based. Vivaldi set as my default browser. I also have a quite old version of Edge installed (117.0.2045.47) but I highly doubt that that is being detected, as it's a flatpak.

Can you run with 1.6.32 in verbose mode ?

Image

How did you install Quarto there BTW ?

I just extracted the x86_64 tarball into a subdir in ~/.quarto/ Normally I run the latest master branch of quarto-cli as I have a link to that binary in my PATH. If you look in the image above you see that I make a call that is very explicit to the version you asked for.

cderv commented 3 weeks ago

Ok so chromium not found on OS known location means that the internal chromium installed with quarto install chromium is probably what is used (I should make that more clear in debug log...)

So maybe this version which is old have an issue with this specific document. I'll look at this scenario to reproduce

mcanouil commented 3 weeks ago

@sasja-san since you are using the pre-release, could you try setting the environment variable QUARTO_CHROMIUM=/path/to/brave and try to render again? (This is a new feature to allow any chromium-based browser, for instance, I am using it to use Brave as I don't use Quarto chromium or Chrome/Edge)

sasja-san commented 3 weeks ago

This rendered well. It also worked with vivaldi.

$ QUARTO_LOG_LEVEL=DEBUG QUARTO_CHROMIUM=/usr/bin/brave quarto render merm.qmd
Quarto version: 99.9.9
[CHROMIUM] Using path specified in QUARTO_CHROMIUM
[CHROMIUM] Found at /usr/bin/brave, and will be used.
Loaded deno-dom-native
-- Searching for R binary --
Looking for 'Rscript' in QUARTO_R: undefined
Looking for 'Rscript' in R_HOME: undefined
Looking for 'Rscript' in PATH.
[execProcess] which Rscript
[execProcess] Success: false, code: 1
Quarto did no found Rscript and will try to use it directly.
pandoc --verbose --trace
  to: latex
  output-file: merm.tex
  standalone: true
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf

metadata
  documentclass: scrartcl
  classoption:
    - DIV=11
    - numbers=noendperiod
  papersize: letter
  header-includes:
    - \KOMAoption{captions}{tableheading}
  block-headings: true
  title: Mermaid Test

[execProcess] /home/sasja/.quarto/quarto-cli/package/dist/bin/tools/x86_64/pandoc +RTS -K512m -RTS --defaults /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/quarto-defaults694f38cbf2aaf347.yml /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/quarto-inputeb2a63d1736a0843.md --metadata-file /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/quarto-metadata8ddcf61a432a4ce9.yml --verbose --trace --data-dir /home/sasja/.quarto/quarto-cli/src/resources/pandoc/datadir
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/template.patched from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/template.patched
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/doc-class.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/doc-class.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/pandoc.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/pandoc.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/tightlist.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/tightlist.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/tables.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/tables.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/graphics.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/graphics.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/citations.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/citations.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/before-title.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/before-title.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/title.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/title.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/before-body.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/before-body.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/toc.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/toc.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/before-bib.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/before-bib.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/biblio.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/biblio.tex
[INFO] Loaded /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/after-body.tex from /tmp/quarto-sessionadf76223d29a40c9/eb57584a9a64343f/27d4522467bfd6d5/after-body.tex
[trace] Parsed [Plain [Str "DIV=11"]] at line 1
[trace] Parsed [Plain [Str "numbers=noendperiod"]] at line 1
[trace] Parsed [Plain [Str "scrartcl"]] at line 1
[trace] Parsed [Plain [Str "blue"]] at line 1
[trace] Parsed [Plain [Str "letter"]] at line 1
[trace] Parsed [Plain [Str "Mermaid",Space,Str "Test"]] at line 1
[trace] Parsed [Plain [Str "Table",Space,Str "of",Space,Str "contents"]] at line 1
[trace] Parsed [] at line 7
[trace] Parsed [Header 1 ("hello",[],[]) [Str "Hello!"]] at line 13
[trace] Parsed [] at line 15
[trace] Parsed [] at line 17
[trace] Parsed [Para [RawInline (Format "html") "<figure class=''>"]] at line 20
[trace] Parsed [] at line 22
[trace] Parsed [Para [Image ("",[],[("width","7.81in"),("height","5.94in"), at line 23
[trace] Parsed [Div ("",[],[]) [Para [Image ("",[],[("width","7.81in"),("he at line 24
[trace] Parsed [Para [RawInline (Format "html") "</figure>"]] at line 25
[trace] Parsed [Div ("",[],[]) [Para [RawInline (Format "html") "<figure cl at line 26
[trace] Parsed [Div ("",["cell-output-display"],[]) [Div ("",[],[]) [Para [ at line 27
[trace] Parsed [Div ("",["cell"],[("layout-align","default")]) [Div ("",["c at line 30
[INFO] Running filter /home/sasja/.quarto/quarto-cli/src/resources/filters/main.lua
[INFO] Completed filter /home/sasja/.quarto/quarto-cli/src/resources/filters/main.lua in 74 ms
[INFO] Not rendering RawInline (Format "html") "<figure class=''>"
[INFO] Not rendering RawInline (Format "html") "</figure>"
[execProcess] Success: true, code: 0

Rendering PDF
running xelatex - 1
[execProcess] tlmgr --version
[execProcess] /home/sasja/.TinyTeX/bin/x86_64-linux/xelatex -interaction=batchmode -halt-on-error merm.tex
[execProcess] Success: true, code: 0
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

running xelatex - 2
[execProcess] /home/sasja/.TinyTeX/bin/x86_64-linux/xelatex -interaction=batchmode -halt-on-error merm.tex
[execProcess] Success: true, code: 0
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

[NotebookContext]: Starting Cleanup
Output created: merm.pdf
mcanouil commented 3 weeks ago

Thanks for the quick test! So there might be an issue with the version of chromium that Quarto installs.

github-actions[bot] commented 1 week ago

Thank you for using Quarto and reporting an issue!

Unfortunately, this issue is now considered stale because it has been opened since 14 days without providing a "working" reproducible example to help us investigate. If you are still facing the issue, please review the "Bug Reports" guide on how to provide a fully reproducible example as a self-contained Quarto document or a link to a Git repository. Without a reproducible example, it is unlikely that the issue will be addressed.

You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````).

````qmd
---
title: "Reproducible Quarto Document"
format: html
---

This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.

```{r}
plot(cars)

The end.