I am writing a scientific paper with a lot of hi rez images, so the PDF grew to >100 MB.
This causes web UI to be very slow and even causes out of memory issues.
I was suggested to replace images with placeholders to speed things up during edits.
I am wondering if it’s possible to create a placeholder that would automatically take the geometry of an image it substitutes? Something like a rect with original filename inscribed.
Hi @Dmitriy, thanks for your question! I have split it off into a new topic, since the other topic is more a discussion about techniques for documents with large amounts of Typst content, while yours is more about large assets being included in your document. So your question is likely to have a different answer (and imo more likely to have one answer applying to most similar situations).
Feel free to message me if you think this does not reflect your intent. And of course feel free to change the post title I have used.
You can indeed automatically create placeholders with the original image dimensions. This will shrink the PDF size, but I’m not sure if it also improves performance and memory issues in the web app, as the images still have to be loaded to get their dimensions. It’s worth a try though :)
To get the dimensions of the image, just measure it while respecting the container’s (or page’s) size. You can do this for all images with a show rule:
#show image: it => layout(bounds => {
let size = measure(..bounds, it)
rect(..size, align(center + horizon)[#it.source])
})
However, I don’t quite get, how this should work. First, there is ..size that uses the binding before its creation. Second, if I leave just measure(it) the compiler complains that “label does not exist” for all images .
The ..size in the measure call should be ..bounds, sorry about that. I updated it in the above reply.
Regarding the label error: I’m not sure what happens there and I can’t reproduce that. You seem to reference something with a non-existent label. Where is that label supposed to be? Maybe you can give a (small) example that shows the error.
maybe you have #image(...) <label> in your document? the show rule here does not preserve the image and therefore also not the label (which is to be expected). You can change that, but the better fix would be to add labels to figures instead: #figure(image(...)) <label>.
No, the image is still there, it just looks different. Both the image and its label are in fact preserved, which is why I am confused about that error.