Skip to content

Query external typst document #5218

Open

Description

@aaeberharter

Description

Add an optional argument to query e.g. of the form external_file: none. If the argument is set to a valid typst file, e.g. file.typ, query returns elements found in that file.

Use Case

Currently a single typst compile call can only generate a single PDF document (?), e.g. A.typ produces A.pdf. If we are dealing with several documents, e.g we have B.typ -> B.pdf, we would like to create correct references in B.pdf which refer to A.pdf and vice versa.

A possible workaround is performing a pre-compile step using an external script e.g. python which calls typst query and dumps info into a file structure which is later read by the typst compile step. This however is cumbersome and does not make use of the already strong feature set available for intra-document introspection.

A possible difficulty arises from convergence issues of inter-dependent documents, this however is also the case for intra-document query.

An alternative could be a feature to reset the current state, so that multiple documents are exported into a single PDF file which is then split up by an external tool.

Activity

  1. added
    feature request
    on Oct 16, 2024
  2. added
    introspection
    on Oct 17, 2024
  3. sijow commented on Mar 17, 2025

    @sijow
    Contributor

    Another use case is querying to include content (rather than make references). For example, I have a document where exercises are interspersed with theory. I want to produce another document with just the exercises. It would be nice if I could write

    #let exercises = figure.where(kind: "exercise")
    #context query(exercises, document: "document.typ").join()

    In simple cases something similar can be achieved with #include and show rules for hiding other content, but it's hacky and quickly runs into additional complexity for example to deal with interference between headings in both documents.

    I guess a proper way to hide "everything but" together with a solution for #1841 would go a long way in addressing this use case.

    A special case of this use case is wanting to include the content of the whole frozen document as in #3723.

  4. benrob0329 commented on Apr 17, 2026

    @benrob0329
    Sponsor

    Types of more technical writing (like TTRPGs or other games) would greatly benefit from this, as it's very common to reference or include sections from multiple reference/source documents.

    This can even go as far as to include a subsection in one place, and the surrounding section in another (e.g. one relevant rule vs the whole group of rules with context), which is made trivial via section tagging but quite difficult otherwise.

    There's also the (currently quite difficult) use for generated glossary documents, which can prove most useful if you have a breadth of options or mechanics.

    Not having this has resulted in needing to either make writing exceptionally more difficult by converting an ordinary document into a hierarchal data structure (not fun to make or work with for writers), or by using hacky functions to include but not display another document so that pieces of it can be included (will break and doesn't solve page references).

  5. Andonome commented on Apr 19, 2026

    @Andonome

    I make heavy use of cross referencing for an RPG book.

    As an extreme example, the footnotes here in italics reference another book and pull the sentence from it, so that rule-adjustments update across all other books.

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestintrospection

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions