typst / typst/typst

Allow `typst eval` to access `document.title` and similar fields

Open
#8,291 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

change request cli
Dominant language
Rust
Stars
56.1k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
22

Description

Description

A rule like set document(title: ...) is scoped like any other set rule, and expressions evaluated through typst eval are not contained in that scope. That means that evaluating e.g. document.title returns null/none (see Discord for an experiment).

Since document properties are "global" (at least when not exporting a bundle), this may be unexpected – you're "querying the document" after all.

A workaround could be to add #context [#metadata(document.title)<title>] to the document but 1) this need explicit support from the document in question and 2) is limited to queries that were envisioned in advance. Trying to extract that from the document has the same scope problems (see same Discord thread).

Use Case

Scripts could use this to e.g. determine a suitable output file name before compiling:

OUT_NAME=$(typst eval ... 'document.title')
typst compile ... "$OUT_NAME.pdf"

There are many more ways integrations could want to use document metadata, e.g. to index for search, although reading that metadata from the output file after compilation could often be a workaround.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the typst eval command and investigate how its evaluation scope handles document properties such as document.title, compared with normal document evaluation. Done means an expression like document.title can access the document's global metadata without requiring explicit support from the document.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.