Can Typst perform a download action, allowing content to be downloaded from any source and saved locally?

Can Typst perform a download action, allowing content to be downloaded from any source and saved locally?

Natively, I think no. But maybe you can mount a network disk and use Typst to access it like a regular file.

1 Like

See Is it possible to make web request on compilation? - #2 by SillyFreak

If you have many remote resources and you really want this feature, then typst query might help you.

#let download(url, name) = if sys.inputs.at("mode", default: "compile") == "prepare" {
  [#metadata((url: url, name: name)) <download>]
} else {
  read("download-dir/" + name)
  // The above gives str.
  // You can replace `read` with `image` for an image, or `read(…, encoding: none)` for bytes.
}

#figure(
  download("https://example.com", "example.html"),
  caption: [Example]
)
# Step 1: Query what to download
$ typst query main.typ <download> --input mode=prepare --field value
[{"url":"https://example.com","name":"example.html"}]

# Step 2: Download them
$ let-llm-write-a-shell-or-python-script-for-you

# Step 3: Compile
$ typst compile main.typ

More complicated real usage: clreq/typ/show-example.typ at a98db2ddfca4a94b2d2456f51c98e7ee1e9cce48 · typst-doc-cn/clreq · GitHub

See also:

3 Likes