How do I use states in between different files?

Suppose I have the following file structure:

.
├── main.typ
├── properties.typ
├── lib
│   ├── colors.typ
│   ├── functions.typ
│   └── template.typ
└── sections
    ├── abstract.typ
    ├── introduction.typ
    ├── first_section.typ
    └── appendix.typ

I want to set a theme state in main.typ than can be used both in template.typ – which contains the styling functions responsible for margins, page counter, etc – and functions.typ, which contains elements that have to react to the color theme.

For instance, in functions.typ:

// this is how I tried to do
#import "../properties.typ" : *
#let theme = properties.at("theme")

#let title(string, colour) = {
  set line(stroke: colour)

  grid(
    columns: (1fr, auto, 1fr),
    align: horizon + center,
    line(start: (-8pt, 0pt), end: (56pt, 0pt)),
    box(stroke: colour, inset: 0pt, outset: 10pt, smallcaps(string)),
    line(start: (12pt, 0pt), end: (80pt, 0pt)),
  )

  v(1.5em, weak: false)
}

// this doesn't work, however it demonstrates how I would want it to work
#show title.with(colour: theme)

so that every time I import functions.typ with a different theme attribute set in properties I get something like this:

This styling should affect every function, in whatever document they are. I have tried using states but didn’t manage to get it working.

So far main.typ looks like this:


#import "lib/template.typ": *
#import "lib/functions.typ": *
#import "properties.typ": *

#show: document.with(..properties)

#include "sections/abstract.typ"
#include "sections/introduction.typ"
#include "sections/first_section.typ"
#include "sections/appendix.typ"

while properties:

#let properties = (
  title: "Title",
  authors: (),
  theme: "blue",
)

Hi @VictuarVi, thanks for your question! Could you maybe try to revise your post’s title so others can find it easier in the future? The question guidelines recommend a complete question:

Good titles are questions you would ask your friend about Typst.

I think the questions under the templates tag could be interesting to you (and that may be a good tag for your question too). Without completely thinking through your situation, this in particular sounds promising: