### Configure `web-resource` Preprocessor Job in `typst.toml` Source: https://context7.com/typst-community/prequery/llms.txt Configures the `prequery` CLI to download web assets. Reads `` metadata and downloads URLs to local paths. Existing files are skipped by default. ```toml # typst.toml [package] name = "my-doc" version = "0.0.1" entrypoint = "main.typ" [[tool.prequery.jobs]] name = "download-images" kind = "web-resource" # Optional settings (shown with defaults): # query.selector = "" # query.field = "value" # overwrite = false # set true to re-download existing files # index = false # set true (or a filename) to track a resource index ``` -------------------------------- ### Import and Use Prequery Image Function Source: https://github.com/typst-community/prequery/blob/main/README.md Import the prequery package and use the `image` function to specify external image URLs for preprocessing. Optionally, enable fallback behavior. ```typ #import "@preview/prequery:0.2.0" // toggle this comment or pass `--input prequery-fallback=true` to enable fallback // #prequery.fallback.update(true) #prequery.image( "https://raw.githubusercontent.com/typst-community/prequery/refs/heads/main/test-assets/example-image.svg", "assets/example-image.svg") ``` -------------------------------- ### Download Web Resources with Python Helper Source: https://context7.com/typst-community/prequery/llms.txt Download web resources using a standalone Python script. The script takes the root directory and resource data as input, downloading files if they don't already exist. ```bash # Step 2: download with any tool, e.g. the bundled Python helper python download-web-resources.py . < resources.json # Output: # assets/img.png: downloading https://example.com/img.png # (or: assets/img.png: skipping — if it already exists) ``` -------------------------------- ### Use `prequery.image()` for Web Images Source: https://context7.com/typst-community/prequery/llms.txt A replacement for Typst's `image()` that adds web-resource metadata. Downloads from a URL and resolves file paths relative to the document. Fallback renders a frame icon. ```typst #import "@preview/prequery:0.2.0" // Basic usage — file is resolved relative to this document #prequery.image( "https://raw.githubusercontent.com/typst-community/prequery/refs/heads/main/test-assets/example-image.svg", "assets/example-image.svg") // With extra image() arguments (width, fit, etc.) #figure( prequery.image( "https://example.com/diagram.png", "assets/diagram.png", width: 80%, ), caption: [System diagram], ) // Query embedded metadata: // typst query --input prequery-fallback=true --field value main.typ '' // Output: // [{"url": "https://example.com/diagram.png", "path": "assets/diagram.png"}] ``` -------------------------------- ### Run Shell Commands with Prequery Source: https://context7.com/typst-community/prequery/llms.txt Execute arbitrary commands using the 'shell' job kind. Input is passed via stdin and output is captured from stdout. Configure stdin, stdout, and output formats. ```toml # typst.toml — run independent Python snippets [[tool.prequery.jobs]] name = "run-python" kind = "shell" query.selector = "" query.field = "value" command = "python" format.stdin = "plain" format.stdout = "plain" format.output = "plain" ``` -------------------------------- ### prequery() - Low-level prequery primitive Source: https://context7.com/typst-community/prequery/llms.txt The fundamental building block for all prequeries. Inserts a `metadata` element with a given label into the document (readable by `typst query`), and conditionally renders either the main `body` or the `fallback` content depending on the `fallback` state. The `body` may be a zero-argument function so that errors from missing files do not cause compilation failure when in fallback mode. ```APIDOC ## `prequery()` — Low-level prequery primitive The fundamental building block for all prequeries. Inserts a `metadata` element with a given label into the document (readable by `typst query`), and conditionally renders either the main `body` or the `fallback` content depending on the `fallback` state. The `body` may be a zero-argument function so that errors from missing files do not cause compilation failure when in fallback mode. ```typ #import "@preview/prequery:0.2.0" // Define a custom "python output" prequery #let python-result(out-path, code) = prequery.prequery( // metadata value embedded for the preprocessor to read (data: code.text, path: out-path), // label used to query this metadata , // body: a function (only called outside fallback mode) () => { raw(block: true, read(out-path)) }, // fallback: shown when prequery-fallback=true fallback: [```...```], ) // Usage in document #python-result("out.txt", ```py print("hello world") ```) // Query the metadata for the preprocessor: // typst query --input prequery-fallback=true --field value main.typ '' // Output: [{"data": "print(\"hello world\")\n", "path": "out.txt"}] ``` ``` -------------------------------- ### web-resource preprocessor job Source: https://context7.com/typst-community/prequery/llms.txt A `prequery` CLI job kind that reads `` metadata from the document and downloads each listed URL to its corresponding local path. Existing files are skipped by default. Configured in `typst.toml` under `[[tool.prequery.jobs]]`. ```APIDOC ## `web-resource` preprocessor job — Download web assets A `prequery` CLI job kind that reads `` metadata from the document and downloads each listed URL to its corresponding local path. Existing files are skipped by default. Configured in `typst.toml` under `[[tool.prequery.jobs]]`. ```toml # typst.toml [package] name = "my-doc" version = "0.0.1" entrypoint = "main.typ" [[tool.prequery.jobs]] name = "download-images" kind = "web-resource" # Optional settings (shown with defaults): # query.selector = "" # query.field = "value" # overwrite = false # set true to re-download existing files # index = false # set true (or a filename) to track a resource index ``` ```bash ``` -------------------------------- ### Run Joined Python Notebook with Prequery Source: https://context7.com/typst-community/prequery/llms.txt Execute a Python notebook where state is shared between snippets. The command can be a string or a list of strings. The Python script receives JSON input and returns JSON output. ```toml # typst.toml — run a joined Python notebook (shared state between snippets) [[tool.prequery.jobs]] name = "notebook" kind = "shell" query.selector = "" query.field = "value" command = ["python", "exec.py"] joined = true ``` -------------------------------- ### Configure Python Prequery with Shared Output Source: https://context7.com/typst-community/prequery/llms.txt Configure a Python prequery job to use a shared output file. The output path is stored in a state variable, and subsequent calls index into the JSON array of outputs. ```typ #import "@preview/prequery:0.2.0" // Store output path as arguments (preserves caller-relative resolution) #let python-out-path = state("python-out-path") #let configure-python(..args) = { [#metadata((path: args.pos().at(0)))] python-out-path.update(args) } #let python(code) = prequery.prequery( (data: code.text), , () => { let args = python-out-path.get() // index = number of preceding labels minus 1 (for configure-python) let index = query(selector().before(here())).len() - 2 let outputs = json(..args) raw(block: true, outputs.at(index)) }, fallback: [``` ... ```], ) // Configure once #configure-python("out.json") // Apply as a show rule — no explicit function call needed #show raw.where(block: true, lang: "pre-py"): set text(1em / 0.8) #show raw.where(block: true, lang: "pre-py"): python ```pre-py x = 1 print(x) ``` ```pre-py y = x + 1 print(y) ``` ``` -------------------------------- ### Query Image Metadata with Typst CLI Source: https://github.com/typst-community/prequery/blob/main/README.md Use the `typst query` command-line tool to extract metadata, specifically image URLs and their intended paths, from a Typst document. This requires enabling the prequery fallback input. ```sh typst query --input prequery-fallback=true --field value \ main.typ '' ``` -------------------------------- ### image() - Web image prequery Source: https://context7.com/typst-community/prequery/llms.txt A drop-in replacement for Typst's built-in `image()` that adds web-resource metadata under the `` label. The first argument is the URL to download from; the second (and subsequent) positional arguments are forwarded to the built-in `image()` — crucially, the file path is resolved relative to the calling document, not the package. Fallback renders the Unicode "Frame with Picture" character (🖼). ```APIDOC ## `image()` — Web image prequery A drop-in replacement for Typst's built-in `image()` that adds web-resource metadata under the `` label. The first argument is the URL to download from; the second (and subsequent) positional arguments are forwarded to the built-in `image()` — crucially, the file path is resolved relative to the calling document, not the package. Fallback renders the Unicode "Frame with Picture" character (🖼). ```typ #import "@preview/prequery:0.2.0" // Basic usage — file is resolved relative to this document #prequery.image( "https://raw.githubusercontent.com/typst-community/prequery/refs/heads/main/test-assets/example-image.svg", "assets/example-image.svg") // With extra image() arguments (width, fit, etc.) #figure( prequery.image( "https://example.com/diagram.png", "assets/diagram.png", width: 80%, ), caption: [System diagram], ) // Query embedded metadata: // typst query --input prequery-fallback=true --field value main.typ '' // Output: // [{"url": "https://example.com/diagram.png", "path": "assets/diagram.png"}] ``` ``` -------------------------------- ### Standalone Python Web Resource Downloader Source: https://context7.com/typst-community/prequery/llms.txt A minimal Python script for downloading web resources. It reads resource data from stdin and saves files to the specified root directory, skipping existing files. ```python # download-web-resources.py — minimal standalone downloader import json, os.path, sys, urllib.request data = json.load(sys.stdin) root = sys.argv[1] if len(sys.argv) == 2 else "." for item in data: url = item['url'] path = os.path.join(root, item['path']) if not os.path.isfile(path): print(f"{path}: downloading {url}") os.makedirs(os.path.dirname(path), exist_ok=True) urllib.request.urlretrieve(url, path) else: print(f"{path}: skipping") ``` -------------------------------- ### Define Custom Prequery with `prequery()` Source: https://context7.com/typst-community/prequery/llms.txt The fundamental building block for custom prequeries. Inserts metadata and conditionally renders body or fallback content. The body can be a zero-argument function to prevent errors in fallback mode. ```typst #import "@preview/prequery:0.2.0" // Define a custom "python output" prequery #let python-result(out-path, code) = prequery.prequery( // metadata value embedded for the preprocessor to read (data: code.text, path: out-path), // label used to query this metadata , // body: a function (only called outside fallback mode) () => { raw(block: true, read(out-path)) }, // fallback: shown when prequery-fallback=true fallback: [```...```], ) // Usage in document #python-result("out.txt", ```py print("hello world") ```) // Query the metadata for the preprocessor: // typst query --input prequery-fallback=true --field value main.typ '' // Output: [{"data": "print(\"hello world\")\n", "path": "out.txt"}] ``` -------------------------------- ### Extract Web Resource Metadata Source: https://context7.com/typst-community/prequery/llms.txt Extract web resource metadata from a Typst document using the `typst query` command. The output is a JSON file containing URLs and paths for resources. ```bash # Step 1: extract web-resource metadata from the document typst query --input prequery-fallback=true --field value main.typ '' \ > resources.json # resources.json: [{"url": "https://example.com/img.png", "path": "assets/img.png"}] ``` -------------------------------- ### Enable Fallback State in Typst Source: https://context7.com/typst-community/prequery/llms.txt Use this to render fallback content instead of failing compilation when preprocessed assets are missing. Can be toggled in-document or via command line. ```typst #import "@preview/prequery:0.2.0" // Option A: enable fallback in-document (useful while authoring) #prequery.fallback.update(true) // Option B: enable from the command line (useful for querying/CI) // typst compile --input prequery-fallback=true main.typ // With fallback enabled, images render as 🖼 instead of failing #prequery.image( "https://example.com/logo.png", "assets/logo.png") ``` -------------------------------- ### JSON Output of Image Metadata Query Source: https://github.com/typst-community/prequery/blob/main/README.md The output from `typst query` for web resources is a JSON array containing objects with 'url' and 'path' fields, indicating the source URL and the expected local path for each image. ```json [{"url": "https://raw.githubusercontent.com/typst-community/prequery/refs/heads/main/test-assets/example-image.svg", "path": "assets/example-image.svg"}] ``` -------------------------------- ### Embed Python Snippets as Metadata Source: https://context7.com/typst-community/prequery/llms.txt Embed individual Python snippets as metadata. Each snippet's output is written to a separate file. Requires the prequery package. ```typ #import "@preview/prequery:0.2.0" // Individual output file per snippet #prequery.prequery( (path: "out1.txt", data: "print('Hello from Prequery')"), , () => { raw(read("out1.txt")) }, fallback: [```...```], ) ``` -------------------------------- ### fallback - Global fallback state Source: https://context7.com/typst-community/prequery/llms.txt Controls whether the document renders fallback content instead of trying to load preprocessed assets. When true, all prequeries show their fallback content and compilation never fails due to missing files. Can be toggled in-document or passed on the command line. ```APIDOC ## `fallback` — Global fallback state A `state` that controls whether the document renders fallback content instead of trying to load preprocessed assets. When `true`, all prequeries show their fallback content and compilation never fails due to missing files. Can be toggled in-document or passed on the command line via `--input prequery-fallback=true`. ```typ #import "@preview/prequery:0.2.0" // Option A: enable fallback in-document (useful while authoring) #prequery.fallback.update(true) // Option B: enable from the command line (useful for querying/CI) // typst compile --input prequery-fallback=true main.typ // With fallback enabled, images render as 🖼 instead of failing #prequery.image( "https://example.com/logo.png", "assets/logo.png") ``` ``` -------------------------------- ### Python Script for Notebook Execution Source: https://context7.com/typst-community/prequery/llms.txt A Python script that executes code snippets, managing scope and capturing stdout. It parses JSON input and returns JSON output. ```python # exec.py — receives JSON array of code strings, returns JSON array of outputs import contextlib, io, json, sys def run(code, scope): with contextlib.redirect_stdout(io.StringIO()) as f: exec(code, scope) return f.getvalue() inputs = json.loads(sys.stdin.read()) scope = {} outputs = [run(code, scope) for code in inputs] sys.stdout.write(json.dumps(outputs)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.