How to import a custom counter in multiple files correctly?

Hi,

I have defined a custom counter sin my main.typ file as follows:


#let c = counter("theorem")
#let theorem(it) = block[
  #c.step()
  *Theorem #context c.display():*
  #it
]

#let d = counter("definition")
#let definition(it) = block[
  #d.step()
  *Definition #context d.display():*
  #it
]

#include "vector_spaces.typ"

#include "linear_span.typ"

I now have want to use the counter in my vector_spaces.typ and linear_span.typ file in a consistent way so that the number increments correctly across the files.

How can I do so?

I tried importing from my main file to each section file, but that did not work.

Any guidance would be much appreciated!

Actually I figured it out - I just extracted the functions to a separate utils file and imported it into all the included files.

Hey @ziggy, welcome to the forum! I’ve changed your question post’s title to better fit our guidelines: How to post in the Questions category

For future posts, please make sure your title is a question you’d ask to a friend about Typst. :wink:

1 Like