typst / webapp-issues

Issue tracker for Typst's web app.
https://typst.app
13 stars 0 forks source link

Pass file name to system inputs to allow control flow of imports. #316

Open fizykz opened 7 months ago

fizykz commented 7 months ago

Description

When rendering a file, pass a variable to the --input of Typst with the file name (and it's directory) so that it may be accessed with sys.inputs in the code.

One line change:

typst --input main=fileToBeRendered.typ       . . .

Use Case

This simple change allows control flow based on the file being rendered. This is especially useful for large projects, which may be split into several chapters but that you may wish to have more control over while simultaneously saving performance in such a situation. Thanks to sillyfreak on Discord for coming up with this solution.

if sys.inputs == "main.typ" {
  // Yay control flow!
}
TheJanzap commented 3 weeks ago

Please re-file this issue in the https://github.com/typst/typst repo, as it's a complier feature request, not specifically a web app one