Using Prequery in documents
Let's say you have a document with many images in them, and these images are available on the web. Instead of manually downloading these images, you'd like to load these images from their respective URLs, something like this:
Of course, this doesn't work; Typst doesn't allow you to access the internet. You get an error like "file not found (searched at …/https:/example.com/example.png)."
While writing your document, the Prequery package helps you embed the necessary metadata (here, image URLs) into your document:
Here, image()
image()
is not Typst's built-in function, but Prequery's (you can still use the original by writing std.image()
std.image()
, or not import the function directly and instead write prequery.image()
prequery.image()
). This function takes a URL first and a filename second, so that an outside tool can know what to download and where to.
Before the image was downloaded, your document won't compile. If you still want to preview your document without the image, the code snippet above indicates what you can do: activate the "fallback" option in code, or pass it on the command line:
(assuming your document is in a file main.typ
main.typ
)
At this point, you don't have your image inside your document yet – for that, you'll need to run the prequery
prequery
CLI tool.