Skip to content

Apply out-width to Mermaid images - #15277

Open
faysou wants to merge 2 commits into
quarto-dev:mainfrom
faysou:fix/mermaid-out-width
Open

faysou wants to merge 2 commits into
quarto-dev:mainfrom
faysou:fix/mermaid-out-width

Conversation

@faysou

@faysou faysou commented Nov 3, 2026 •

Copy link
Copy Markdown

Description

Mermaid diagrams rendered as png or svg images ignore out-width. The Mermaid handler always writes the natural size in inches, such as {width="8.91in" height="3.02in"}, so in Typst and PDF output a wide diagram runs past the page and there is no way to fit it to the text width.

---
format:
  typst:
    mermaid-format: png
---

```{mermaid}
%%| out-width: 50%
flowchart LR
  A --> B
```

When out-width is set, the figure link now uses it as the image width and drops the height, so the image keeps its aspect ratio. 50% becomes width: 50.0% in Typst and 0.5\linewidth in LaTeX. Without out-width, the output does not change.

This is separate from #15192: out-width is relative to the text width, while mermaid-scale there is relative to each diagram's natural size.

Tests

tests/docs/smoke-all/2026/11/03/mermaid-out-width.qmd renders a diagram with out-width: 50% to Typst and LaTeX and checks the image width in the .typ and .tex. Both checks fail without the change.

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR

Mermaid diagrams rendered as png or svg images always got a width and
height in inches from their natural size, so out-width was ignored. In
Typst and LaTeX output, wide diagrams ran past the page with no way to
fit them to the text width.

When out-width is set, the figure link now uses it as the image width
and drops the height so the image keeps its aspect ratio. A percentage
such as 50% becomes 50% of the text width in Typst and 0.5\linewidth
in LaTeX.
@posit-snyk-bot

posit-snyk-bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants