Typst: cap images with a fixed width at the text width #15279
Replies: 1 comment
|
I'd lean towards leaving this as it is, and not making the cap the default. Relative widths already work in Typst. Pandoc's Typst writer passes the So when someone writes an absolute width, they've asked for that size, and I think Quarto should respect it. A silent cap would also change how existing documents render, and it would make For anyone who wants auto-shrink today, a Typst show rule does it in a few lines. It only scales images that are wider than their container and leaves the others alone: ---
format:
typst:
include-in-header:
- text: |
#show image: it => layout(size => {
let natural = measure(it)
if natural.width > size.width {
let r = size.width / natural.width * 100%
scale(x: r, y: r, reflow: true, it)
} else { it }
})
---The same rule also works from a If the cap does go in, I'd rather see it as an opt-in option for Typst only, and leave LaTeX as it is. |
Uh oh!
There was an error while loading. Please reload this page.
In Typst output, an image with an explicit size is placed at that size even when it is wider than the text area. LaTeX output behaves the same way.
The
.typkeeps#box(image("penrose.svg", width: 12in))on an 8.5in page, so most of the image runs off the page. Mermaid and Graphviz diagrams hit this often, because Quarto sizes them from their natural size in inches. In LaTeX output the same diagrams produce\includegraphics[width=17.61in,...].Proposal
Cap image width at the text width, the way HTML output does with
max-width: 100%. In Typst, one way to cap the width is to wrap the image inlayout(size => ...)and usecalc.min(width, size.width), scaling the height by the same factor.This changes how existing documents with oversized images render, so I'd like agreement before opening a PR:
All reactions