Open cderv opened 9 months ago
The problem here comes from the fact that the mermaid diagrams are emitted like so:
::::::{.cell layout-align="default"}
:::::{.cell-output-display}
::::{}
`<figure class=''>`{=html}
:::{}
![](8543_files/figure-typst/mermaid-figure-1.png){width="4.28in" height="0.52in"}
:::
`</figure>`{=html}
::::
:::::
::::::
Typst respects the requested size, which spills over the column.
This is the generated .typ:
#block[
#block[
#box(image("8543_files/figure-typst/mermaid-figure-2.png", height: 0.52in, width: 7.34in))
]
]
I keep going back and forth here.
This is, ultimately, another instance of Quarto's inability to tell default values from explicitly set values.
If a user had explicitly declared the desired width and height for the diagram, then we should respect it, independently of the column size. But for a plain mermaid declaration, there are two similarly bad choices:
I think this is also partly a problem with how Typst handles image sizing (which I know they've expressed interested in improving.) For example,
#box(image("8543_files/figure-typst/mermaid-figure-1.png", width: 8in), width: 100%, fill: gray)
This will create output like this:
Notice the gray line - that's the background for the box
. The box itself is 100%, but the image still spills over. So I don't think there's a currently a way in Typst to communicate "at least x inches, but not more than the width of the containing box".
Currently, the best workaround is to explicitly size the diagram from the mermaid
cell, like so:
```{mermaid}
%%| fig-width: 3in
graph LR
A---B---C---D---E---F
I think we'll sit on this until Typst makes a call on their sizing system.
Discussed in https://github.com/quarto-dev/quarto-cli/discussions/8542