Allow `typst eval` to access `document.title` and similar fields
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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