Scale Mermaid diagrams by a percentage of their natural size (mermaid-scale)
#15069
faysou
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Description
What I want to achieve
When rendering to Typst or PDF with
mermaid-format: png, Quarto sizes each Mermaidimage at its natural size at 96 dpi. Mermaid's 16px text then prints at 12pt, which
is larger than body text in most documents, and wide diagrams run past the page.
Setting
fig-widthper diagram does not fix this consistently. A fixed width scaleseach diagram by a different factor, so text ends up a different size in every
diagram. Matching text size requires
fig-width= natural width x factor, and thenatural width is unknown until Mermaid renders the diagram.
What I need is one factor applied to every diagram's natural size, so all diagram
text prints at the same size (for example 75%, which gives 9pt text).
Proposal
A
mermaid-scaleoption next tomermaid-format, set for the whole document orfor one cell:
fig-widthorfig-heightstill wins, consistent with the point inTypst: Unable to fit mermaid diagram into columns #8543 that explicit sizes should be respected.
pngandsvgimage outputs, where Quarto computes the sizein
resolveSize. Withmermaid-format: js, mermaid.js sizes the diagram in thebrowser, so the option has no effect there.
This doesn't solve the column overflow in #8543 by itself, but it gives a uniform,
text-preserving way to shrink diagrams, which addresses the font-distortion concern
raised there.
Implementation
I have a working implementation on
faysou/quarto-cli@feature/mermaid-scale
(diff against
main).It validates the value in both the cell and front matter schemas, adds a changelog
entry, and includes a smoke test that compares a scaled diagram against the same
diagram at 100%, so it does not depend on font metrics.
Should I open a PR for it?
All reactions