typst / typst

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

Export target elements #4174

Open tingerrr opened 2 weeks ago

tingerrr commented 2 weeks ago

Description

I propose adding document-like set-rule only elements for export targets to control target specific settings:

Use document either for only the common settings or as a convenient default for various settings from multiple targets.

Alongside this, a variable such as target should be added, which is set depending on the current export target. This allows code to act according to the export target, preventing incorrect output or panics when a target specific feature is used, such as Forms #2421 or OCGs #2613.

The newly added elements and variable could be put into an export module, i.e. set export.pdf(...), if export.target == export.pdf { ... }, as they should not require easy access for the majority of users.

While I thought about the target variable being the element of the active export target for nice looking checks (target == pdf), this comes with some downsides:

Using strings solves this more easily, as these sub-target checks could use string methods like target.starts-with("pdf") or even target.starts-with("pdf/a") for all versions of PDF/A.

Most of the sub-target specific settings will likely live on the "encompassing" element anyway (i.e. pdf for PDF/A).

Use Case

  1. Export target specific features which are likely to be more "low-level" than normal Typst features if they can't be easily generalized will likely need packages to be made usable for the average Typst user.

    Such packages need to be able to:

    • use export target specific features without panics (if they do when used on an unsupported target)
    • provide reasonable fallback behavior, when the target specific feature is not supported
      • this is especially important for preview of features which are not available for PNGs, such as forms
      • provide example images of target specific features without the need to take screenshots of PDF viewers to show of export target specific packages
  2. Export targets such as HTML #721 likely need more export target specific code, as it is fundamentally different from how Typst currently works.

emilyyyylime commented 2 weeks ago

target sounds like it'd fit inside the sys module, but I'm not too against export either