Skip to content

specify compiler options via in-file metadata header #7225

@gasche

Description

@gasche

Description

Many options that affect the build of a Typst document can be passed via command-line options to typst compile or typst watch. For example: --root <root>, --ppi <PPI>, --features <feature>. But sometimes it would be much easier, in particular for tooling support, to be able to specify those options directly in the file, in some header metadata:

#document-header(
  root: "..",
  features: ["html", "ally"],
)

(rest of the document)

The document-header comment must be placed first in the file (with optional comments before and inside), so that it can be located without interpreting the whole file. (A bespoke lexical syntax for metadata could also be designed, see Pandoc metadata block.)

If options are provided via both the command-line and the document header, then the file header settings take precedence.

Use Case

My Emacs typst-ts-watch mode fails on the following error for a given file:

error: failed to load file (access denied)
    ┌─ slides.typ:652:14
    │
652 │ #bibliography("../suspended.bib", title: none, style: "./gasche-author-date.csl")
    │               ^^^^^^^^^^^^^^^^^^
    │
    = hint: cannot read file outside of project root
    = hint: you can adjust the project root with the --root argument

Unfortunately typst-ts-watch does not currently provide support for specifying the --root parameter when it invokes typst watch. I will of course request such support in that particular tool, but there are dozens of tools out there (editor modes, linters, build system integrations, etc.) that will each need to be extended to support specific command-line options for the typst CLI, while these options could be passed once and for all in the file itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions