How can I import style settings from separate typ files within the workspace directory?

Can the style settings for the top typ be written to a separate file and then imported? Does import only seem to work for inserting functions? Is there an operation similar to macro substitution like C’s #include? When I use #include, it appears to fail when importing another file in the same working directory?

#set page(
  paper: "a4",
  header: align(right)[
    diffusion policy
  ],
  numbering: "1",
)


#show heading.where(
  level: 1
): it => block(width: 100%)[
  #set align(center)
  #set text(
    size: 20pt,
    weight: "bold",
    font: ("Noto Serif CJK SC"),
  )
  #smallcaps(it.body)
]

#show heading.where(
  level: 2
): it => block(width: 100%, below: 1.5em)[
  #set align(left)
  #set text(
    size: 18pt,
    weight: "bold",
    font: ("Noto Serif CJK SC"),
    fill: rgb("#045bac")
  )
  #counter(heading).display(it.numbering)
  #smallcaps(it.body)
]

#show heading.where(
  level: 3
): it => block(width: 100%, below: 1.2em, above: 2.0em)[
  #set align(left)
  #set text(
    size: 14pt,
    weight: "regular",
    font: ("Noto Serif CJK SC"),
    fill: rgb("#062f56")
  )
  #counter(heading).display(it.numbering)
  #smallcaps(it.body)
]

 
#set heading(numbering: (first, ..nums) => numbering("1.", ..nums))



#set text(
  font: ("Noto Serif CJK SC"),
  lang: "zh",
  region: "CH",
  size: 12pt
)

#set par(
  first-line-indent: (
    amount: 1.5em,
    all: true,
  ),
  spacing: 1.25em,
  leading: 1.00em,
  justify: true
)

#set enum(
  indent: 2.0em
)


xxxxxxxxxxxxx Content xxxxxxxxxxxxxxxxxx

Please refer to the tutorial on how to make a template as a separate file.

In short:

  • template.typ
#let project(body) = {
  set page(
    paper: "a4",
    header: align(right)[
      diffusion policy
    ],
    numbering: "1",
  )
  
  // And your other rules
  …

  body
}
  • main.typ
#import "template.typ": project
#show: project

xxxxxxxxxxxxx Content xxxxxxxxxxxxxxxxxx

import only seem to work for inserting functions?

Basically yes. Please refer to Modules – Scripting – Typst Documentation for details.

When I use #include, it appears to fail when importing another file in the same working directory?

It should work. Could you share more info?

1 Like