I like Typst a lot and am currently trying to convert one of my books from LaTeX. I ran into one problem that I can’t seem to make work: I need a way to spread a big image over two adjacent pages and starting on the left (even) page. In principle this code works:
trimmed-image is a function I found by googling, its exact content is not really important here I think. It works as expected and shows the left half of my image on the left page and the right half on the right page. (Maybe it would be possible to add trim as a parameter to the builtin image function?)
But this is not exactly what I want. The pages that come before the double-page image should still be filled with content but remains empty as soon as the pagebreak is hit. That’s what figures usually are for but I don’t seem to find a way to combine figures with pages directly.
Is there something comparable to LaTeX afterpage and/or hvfloat? I also tried defining a variable that tells me there is a double-page image “waiting” to be displayed but then I would need some kind of callback when the next even page starts and I don’t think there are any callback functions.
Replacing yourpage(…, image(…)) with a floating figure containing a big placeholder block might work.
// We'll need page.width and .height, so `context` is required.
#context {
// Enable floating for figures in this `{…}` block.
set figure(placement: top)
// Put the first image
figure({
// Compensate for the page's top margin
v(-5pt)
// Put a placeholder block of the same size as the page
// If you need to debug, you can add `fill: aqua` to the block.
block(width: page.width, height: page.height, {
// You have to scale the image properly.
// The specific approach depends on how trimmed-image is implemented.
trimmed-image("image.jpg", trim: (right: 50%))
})
})
// Put the second image (the same as above)
figure({
v(-5pt)
block(width: page.width, height: page.height, {
trimmed-image("image.jpg", trim: (left: 50%))
})
})
}
I recommend you manually adjust the number in v(-5pt), because the image should not start from the exact top edge of the page, or there will be problems when printing.
The only callback-like things I can think of are using page background, foreground, header or footer. In the sense that they “happen” on every page, so you can use them to draw on a specific page. But they can’t influence the page body, so there’s no way to use them to clear a page for a figure.