Parameters and Inputs
Parameters and Inputs
Section titled “Parameters and Inputs”Typst scripts declare their parameters in a frontmatter block at the very top
of the file, not through a getParameterDefinitions() function. This tutorial is
the reference for that block: its syntax, the parameter types, how values reach
the compile, and the nesting rules.
The frontmatter block
Section titled “The frontmatter block”The block is YAML wrapped in a Typst block comment with a magic opener:
/*javasculpt-params- name: heading type: text caption: Heading default: "Untitled"*/- It must be the very first thing in the file — the opener
/*javasculpt-paramshas to be at byte 0. Anything before it (even a blank line) means it is not recognised and the script is treated as having no params. - The body is a YAML list of parameter definitions.
- Because it is a genuine Typst block comment, the compiler ignores it — the editor strips it before compiling, but even an unstripped block leaves the file valid, compilable Typst.
- The block is optional: a file that doesn’t open with it just has no declared parameters.
How values reach the script
Section titled “How values reach the script”Each parameter surfaces as a control in the editor. On Run, the values are passed
to the compiler and read as sys.inputs.<name>:
= #sys.inputs.headingEverything in sys.inputs is a string. Values are passed on the typst compile command line (--input name=value), so there is no type information at
the boundary:
| Param type | Read as | Example value |
|---|---|---|
text, date, color, select |
string | "Untitled", "2026-07-01", "#1f3a5f" |
number, boolean |
string | "42", "true" |
object, array, json |
JSON string | "{\"a\":1}", "[1,2,3]" |
Convert as needed: int(sys.inputs.copies), float(sys.inputs.price), or
json(bytes(sys.inputs.rows)) for a structured value. Guard optional params with
sys.inputs.at("name", default: …) so a missing input doesn’t panic with a
“key not found” error.
Scalar parameter types
Section titled “Scalar parameter types”The scalar (leaf) types are text, number, date, color, boolean, and
select. Common fields:
/*javasculpt-params- name: title type: text caption: Document title default: "Report"- name: pages type: number default: 3 min: 1 max: 50- name: issued type: date default: "2026-01-01"- name: accent type: color default: "#2b6cb0"- name: draft type: boolean default: false- name: size type: select default: "a4" options: ["a4", "us-letter", "a5"]*/Structured types and the one-level nesting rule
Section titled “Structured types and the one-level nesting rule”For richer inputs there are three container types — object, array, and
group — plus a freeform json. Nesting is limited to one level deep
(MAX_PARAM_DEPTH = 1), enforced when the frontmatter is parsed:
-
object— a fixed set of namedfields. Each field must be a scalar.- name: sendertype: objectfields:- name: nametype: text- name: emailtype: text -
array— a repeatableitem. The item is either a scalar or an object of scalars (this is the one legal place an object appears as a child):- name: rowstype: arrayitem:name: linetype: objectfields:- name: labeltype: text- name: amounttype: number -
group— a purely visual grouping of controls; its childparamsmay be any top-level type (a group doesn’t count as a nesting level). -
json— an escape hatch for data deeper than one level. It has no declared children; the raw value is validated at input time and you decode it yourself.
If you exceed one level (e.g. an object field that is itself an object), the
frontmatter is rejected with an “invalid frontmatter” error — reach for a json
param instead.
Reading structured values
Section titled “Reading structured values”An object or array param arrives as a JSON string, so decode it — or, in a
document-generation script, read it from the data.custom bundle (see the
Generating documents tutorial):
#let sender = json(bytes(sys.inputs.at("sender", default: "{}")))#sender.at("name", default: "—")
#let rows = json(bytes(sys.inputs.at("rows", default: "[]")))#for r in rows [ #r.label: #r.amount #linebreak() ]Next steps
Section titled “Next steps”- Generating documents — how the Orders/Clients pipeline feeds a
datapayload and where your custom params land inside it. - The Letterhead example uses an
objectparam; Invoice and Contract use anarrayof objects.