Prequery

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 prequeryprequery

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.tomltypst.toml file:


                                
[package]

                                
name = "..."

                                
version = "0.0.1"

                                
entrypoint = "..."

                                


                                
[[tool.prequery.jobs]]

                                
name = "download"

                                
kind = "web-resource"

                                
[package]

                                
name = "..."

                                
version = "0.0.1"

                                
entrypoint = "..."

                                


                                
[[tool.prequery.jobs]]

                                
name = "download"

                                
kind = "web-resource"

                                
[package]

                                
name = "..."

                                
version = "0.0.1"

                                
entrypoint = "..."

                                


                                
[[tool.prequery.jobs]]

                                
name = "download"

                                
kind = "web-resource"

                                
[package]

                                
name = "..."

                                
version = "0.0.1"

                                
entrypoint = "..."

                                


                                
[[tool.prequery.jobs]]

                                
name = "download"

                                
kind = "web-resource"

The [package][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]][[tool.prequery.jobs]] part can appear multiple times; each one adds one job to the preprocessor, which is executed when running the prequeryprequery command. In this case, we're running a web-resourceweb-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()image() function. We also give it a name, which is shown in the output for tracking the job's progress.

Running prequeryprequery

Let's now actually run the preprocessor:


                                
prequery main.typ

                                
prequery main.typ

                                
prequery main.typ

                                
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

                                
[download] beginning job...

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

                                
[download] Downloading to example.png finished

                                
[download] job finished

                                
[download] beginning job...

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

                                
[download] Downloading to example.png finished

                                
[download] job finished

                                
[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

                                
typst compile main.typ

                                
typst compile main.typ

                                
typst compile main.typ

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

Recap & Next steps

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

  • Use the Prequery package to embed information about the required resources into your document.
  • Configure the prequeryprequery command line tool in typst.tomltypst.toml to tell it what kind of resources/processing is required.
  • Run the prequeryprequery command whenever your resources have changed.

You can take a look at the web-resourceweb-resource preprocessor's documentation to see its more advanced features. For other use cases, the shellshell 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.