typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
32.69k stars 877 forks source link

Simultaneous query & compile #3015

Open ntjess opened 9 months ago

ntjess commented 9 months ago

Description

I have a large document that I would like to compile and see the results of some labeled content. Currently, I query and compile separately for 2 total calls to typst. It would be ideal to allow querying during compilation and print the query result to stdout while exporting files as usual.

Use Case

Any documents where both metadata and outputs are equally desirable. A common use case is slideshows. In one compilation, the svg slides can be generated and their metadata for transitions, speaker notes, etc. will also be available.

SillyFreak commented 3 months ago

I think there are many generalizations that are worth considering from the start:

I think the last one may be attainable, but may also have the fewest legitimate use cases and/or it might be an anti-pattern to structure one's workflow in a way where this saves a lot of work.

There has been some discussion on Discord in this direction: https://discord.com/channels/1054443721975922748/1245821833308012614

One of the suggestions was the option to start Typst as a agent and access it using an ID:

id=$(typst agent diagrams.typ)
typst query --id "$id" --field value metadata
typst c --id "$id"
typst c --id "$id" 'diagram{n}.svg'
typst agent --kill "$id"

this would allow the first three scenarios in a natural way.