What Are Best Practices for Allowing Users to Modify Constants in Typst Packages?

The idiomatic way, so far at least until we get custom elements and types, is to make all these variables (not constants) parameters of your template function which the user would apply with #show: template.with(...).

You could still keep your template-defined values in constant.typ by utilizing named parameters, like so:

#import constant.typ: *
#let my-template(
  title-font: _Title-font,
  title-spacing: _Title-spacing,
  ..., // and so on
  body
) = {
  // Your show and set rules.
  body
}

That way the user can either choose to override these values with #show: my-template.with(title-font: "Comic Sans") or leave them as-is by not providing the named parameter, see also Making a Template – Typst Documentation.

1 Like