#Using state for heading numbering

7 messages · Page 1 of 1 (latest)

lunar plaza
#

I would like to change the way I number headings with the use of a state variable, such that I can simply update that state to change the numbering at any point. I am using this approach for changing the supplement, which can take content however, the numbering argument requires a string and the locate function returns content even though the state has been set with a string value

#let appendix = state("appendix", false)
#let heading-numbering-fmt = state("heading-numbering-fmt", "I.A.1.")
#let heading-supplement = state("heading-supplement", "Section")

#let start-appendix() = {
  appendix.update(true)
  heading-numbering-fmt.update("A:")
  heading-supplement.update("Appendix")
}

#set heading(
  numbering: locate(loc => {heading-numbering-fmt.at(loc)}),
  supplement: locate(loc => {
    heading-supplement.at(loc)
  })
)

= Not in the appendix
<a0>
@a0

#start-appendix()

= In the appendix
<a1>
@a1
frigid gate
#

but honestly, i think you're overcomplicating this

#

you can just reset the heading counter

#

place counter(heading).update(0) in the document and the magic is done

#

the solution to your immediate problem, however, would be to (..numbers) => locate(...) instead of just locate

lunar plaza
#

I suppose you're right, but I would like to have it package neatly as a single function call like this, then later on I can pack other functionality or styling into it.