typst

Override font of a template in a show rule


I have this MWE of a template (imported via typst.app) and my document (below). Is it possible to change the font of the #show call in this example without touching the original template?

// This is the imported part of the template
#let template(
  title: [The Title],
  body
) =  {
  set document(title: title)
  // Set text fonts and sizes
  set text(font: "Inter", size: 11pt)
  page(text(2em)[*#title*])
  body
}

and this is my document.

// This is my document
#show: template.with(
  title: [This is the Title]
)

= Headline
#lorem(50)

I'm still in the process of trying to figure out the syntax. Help much appreciated.


Solution

  • I've done additional research and, thanks to a hint on the Typst Discord, found this one-line solution:

    // This must be set *before* the #show call of the template
    #show page: set text(font: "Comic Neue")
    

    Possible exceptions: As far as I understand it, the specificity/strictness of #show page: is higher than of a general set text (as used in the template in my case). So this might fail if the template in question defines the font (or other values) for certain elements with higher strictness.

    In these cases, something even more strict like #show outline: set text(font: "Comic Neue") or #show bibliography: set text(font: "Comic Neue") may be necessary. But the line above was the closest I got to a global font change.