|||
Skip to current page in TOC

Running the preprocessor

The goal of Prequery is to avoid manual preparation of external resources before compiling your Typst document. The Prequery package alone can’t achieve that, since it sits inside Typst’s sandbox. This is where Prequery’s preprocessor enters the picture.

Configuring prequery

In the previous section, we have prepared our document to provide the necessary information, now we need to configure the preprocessor to use it. This is done inside the document’s typst.toml file:

[package]
name = "..."
version = "0.0.1"
entrypoint = "..."

[[tool.prequery.jobs]]
name = "download"
kind = "web-resource"

The [package] part of that file is not used by the preprocessor, but is required by Typst. Unless your document is part of a package, you can simply copy this part exactly as written, with ... and all. This requirement will hopefully be lifted in the future.

The [[tool.prequery.jobs]] part can appear multiple times; each one adds one job to the preprocessor, which is executed when running the prequery command. In this case, we’re running a web-resource job, which downloads files from the web. The files to download are the ones that were specified in the previous section, by using the image() function. We also give it a name, which is shown in the output for tracking the job’s progress.

Running prequery

Let’s now actually run the preprocessor:

prequery main.typ

If everything is in place, you should see some output like this:

[download] beginning job...
[download] Downloading to example.png: https://example.com/example.png...
[download] Downloading to example.png finished
[download] job finished

… and that’s it! The image required by your document is now present, and you can compile it:

typst compile main.typ

If you later add images, simply run the prequery command again.

Recap & Next steps

You have now seen how to automate the preparation of you document’s resources using Prequery:

You can take a look at the web-resource preprocessor’s documentation to see its more advanced features. For other use cases, the shell preprocessor offers early support for running arbitrary commands. If you need to do something and are not sure if it can be done with Prequery, let us know in an issue on the package or the CLI tool.