#Custom counter

4 messages · Page 1 of 1 (latest)

plucky tusk
#

I want to make a custom counter that the first number is the heading number 1 level and after the dot is the counter itself.
And this counter should be restarted for each level 1 heading.
I want to make this for definition or theorem.
And how I cant implement calling them by the label? with the use of <example_definition> and later @example_definition

vast echo
# plucky tusk I want to make a custom counter that the first number is the heading number 1 le...

I want to make a custom counter that the first number is the heading number 1 level and after the dot is the counter itself.
And this counter should be restarted for each level 1 heading.

  1. define your counter with let def-counter = counter("definitions") for example
  2. one good option is to keep the heading counter separate from the def-counter, so you'd just reset the def counter for each heading:
#show heading.where(level: 1): it => {
  def-counter.update(0)
  it
}

and then, when displaying your definition, you'd display

#[Definition #context counter(heading).display();.#context def-counter.display()]
#

And how I cant implement calling them by the label? with the use of <example_definition> and later @example_definition

Well, you'll need a way to identify that a label belongs to a definition or theorem. For that, you may want to use figures with custom kinds (figure(kind: "definition")[stuff]), which requires def-counter above to be counter(figure.where(kind: "definition")) (for example).
That way, you'll be able to check whether the label points to a figure with the correct kind by checking if its associated element has func() == figure and kind == "definition".

Finally, you'd use this to customize ref as described in https://typst.app/docs/reference/model/ref/#customization - if your figure is referenced, display your custom counter, otherwise display whatever the ref would normally display.

vast echo