Repository navigation
Description
I have:
- searched the issue tracker for similar issues
- installed the latest version of Quarto CLI
- formatted my issue following the Bug Reports guide
Bug description
Can't include mermaid diagrams as svg for beamer output, only as png
Steps to reproduce
Minimal example to reproduce:
---
format:
beamer:
mermaid-format: svg
mermaid: true
pdf:
mermaid-format: svg
mermaid: true
keep-tex: true
---
# Ola
```{mermaid}
flowchart
A["Amigo"]
```
Actual behavior
compilation failed- error
LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.109 <
script src="template_files/libs/quarto-diagram/mermaid-postprocess-shi...
With the script just being injected into the tex-file:
<...>
<script src="template_files/libs/quarto-diagram/mermaid-postprocess-shim.js"></script>
\KOMAoption{captions}{tableheading}
\makeatletter
<...>Expected behavior
no error
Your environment
- OS: Fedora42
Quarto check output
❯ quarto check
Quarto 1.8.25
[✓] Checking environment information...
Quarto cache location: /home/user/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.6.3: OK
Dart Sass version 1.87.0: OK
Deno version 2.3.1: OK
Typst version 0.13.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.8.25
Path: /opt/quarto-1.8.25/bin
[✓] Checking tools....................OK
Chromium: 869685
TinyTeX: (not installed)
[✓] Checking LaTeX....................OK
Using: Installation From Path
Path: /usr/bin
Version: 2023
[✓] Checking Chrome Headless....................OK
Using: Chrome found on system
Path: /usr/bin/chromium-browser
Source: PATH
[✓] Checking basic markdown render....OK
[✓] Checking Python 3 installation....OK
Version: 3.13.9
Path: /usr/bin/python3
Jupyter: 5.7.2
Kernels: .venv, myenv, python3, rust
(/) Checking Jupyter engine render....Traceback (most recent call last):
(-) Checking Jupyter engine render.... File "/opt/quarto-1.8.25/share/jupyter/jupyter.py", line 20, in
from notebook import notebook_execute, RestartKernel
File "/opt/quarto-1.8.25/share/jupyter/notebook.py", line 20, in
from nbclient import NotebookClient
ModuleNotFoundError: No module named 'nbclient'
WARN: Error encountered when rendering files
[✓] Checking Jupyter engine render....OK
Activity
mcanouil commentedon Nov 10, 2025
Thanks for the report I can repro on latest.
Side note Where did you see
mermaid: truewas a valid option?mermaidexpects an object, for instance the only current object inmermaidistheme: default/dark/forest/neutral.kusnezoff-alexander commentedon Nov 10, 2025
Thank you for looking into this :)
I forgot to exclude
mermaid: truefrom the copy-paste (sorry), I took it from here: https://paulrjohnson.net/blog/2022-09-17-rendering-mermaid-diagrams-using-quarto-and-hugo/cderv commentedon Nov 10, 2025
We should probably error differently, but this is expected to not being able to include svg in PDF.
Your document will also fail with PDF format.
PDF output will only support PNG format which is the default for them.
Or did you expect to have svg output be processed by
svgCTAN package that does use inskape CLI to transform to PDF ?I don't think the SVG from mermaid are self contained enough for that to work.
If PDF is better than PNG for LaTeX output, we could also try to screenshot to PDF ?
Overall, I am curious about why trying
mermaid-format: svgwith LaTeX outputs ?Thanks.
kusnezoff-alexander commentedon Nov 11, 2025
Exactly, that would be nice.
So people can copy&paste the text from the mermaid diagrams in my pdf slides (I am converting markdown->beamer->pdf) and partly due to better resolution (basically the advantages that svg have over png)
cderv commentedon Nov 12, 2025
I don't know if
svgpackage from CTAN is able to handle mermaid SVG. It also uses inkscape which needs to be setup for that to work. Did you have experience with a mermaid SVG diagram you added in a LaTeX document ?Sorry I don't understand that part. What will be copy pasted ? Diagram source code or the svg ?
It won't be SVG in the beamer PDF. It would be PDF, and I don't know if they are improved compare to PNG.
Anyhow, this is bigger feature request to support SVG from mermaid to be converted to PDF by inskcape as part of LaTeX processing. This require some research...
kusnezoff-alexander commentedon Nov 12, 2025
After your comment I tried to include a mermaid SVG diagram into a LaTeX document which didn't turn out to be very successful. Particularly there is the problem text not displaying inside the boxes when rendered to pdf. So I understand that this a bigger feature.
However I got it running by producing mermaid diagrams as pdfs with the following filter, maybe it helps:
Also here is what I tried to embed a mermaid svg into LaTeX, just for future reference:
%%{init: {"flowchart": {"useMaxWidth": false, "htmlLabels": false, "curve": "basis"}, "theme": "default"}}%% graph TD A[Start] --> B{Decision?} B -->|Yes| C[Do something] B -->|No| D[Do something else] C --> E[End] D --> E[End]test.md:
Then call:
Result:
mcanouil commentedon Nov 12, 2025
@kusnezoff-alexander Accessibility: To improve accessibility, please add alternative text to your screenshots. This helps all users, including those using screen readers, to understand the context of the images. A brief description can make a big difference! See Good Alt Text, Bad Alt Text — Making Your Content Perceivable.
cderv commentedon Nov 12, 2025
Yes
mmdcis mermaid-cli - we don't use that, but I have looked at it, and maybe this is better results.Without this, SVG using in LaTeX is processed by Quarto using
rsvg-convertCLI. This is not easily available though, especially on windows. Usinguse-rsvg-convert: falsewill make the svg pass to LaTeX and\includesvg{}will be used that requires inkscape.But yes supporting SVG in LaTeX output is not straightforward.
mcanouil commentedon Nov 12, 2025
FYI, The "diagram" extension uses the CLI for Mermaid: https://github.com/pandoc-ext/diagram
cderv commentedon Nov 12, 2025
Thanks for sharing. Good to know !
Add smoke test for mermaid-format:svg with Beamer/PDF (#13661)
mermaid-format: svgrenders raw HTML instead of image in PDF and Typst output #14016 as a duplicate of this issue