#Numbering by section

5 messages · Page 1 of 1 (latest)

primal crater
#

I want to number figures by section (level 2) and also make it dependent on the heading numbering (so figures in appendix start with A fx). I currently have the following code, but references don't work. Is there any way to fix it so references use the heading numbering at the position of the figure?

#

?render

#set heading(numbering: "1.1")

#show heading.where(level: 1).or(heading.where(level: 2)): it => {
  context counter(figure.where(kind: table)).update(0)
  context counter(figure.where(kind: image)).update(0)
  context counter(figure.where(kind: raw)).update(0)
  it
}

#set figure(numbering: (..num) => {
  numbering(
    heading.numbering,
    ..(..counter(heading).get(), 0, 0).flatten().slice(0, 2),
    ..num,
  )
})

- Top fig: #text(green)[@top]
- Sub fig: #text(green)[@sub]
- Subsub fig: #text(green)[@subsub]
- Appendix fig: #text(red)[@app]

#figure(
  rect[Test],
  caption: "Test",
) <top>

= Sec
#figure(
  rect[Test],
  caption: "Test",
)
== Subsec
#figure(
  rect[Test],
  caption: "Test",
) <sub>
=== Subsubsec
#figure(
  rect[Test],
  caption: "Test",
) <subsub>

#set heading(numbering: "A.1")
#counter(heading).update(0)

= Appendix
- Top fig: #text(red)[@top]
- Sub fig: #text(red)[@sub]
- Subsub fig: #text(red)[@subsub]
- Appendix fig: #text(green)[@app]

#figure(
  rect[Test],
  caption: "Test",
) <app>
primal crater
#

(red is wrong, green is right)

dusk nest
#

@primal crater I think what you've discovered is neatly discussed in https://forum.typst.app/t/how-to-counter-display-at-location-or-get-remote-context/5096

What the perfect solution is, is still under active discussion.

I assume you've already stumbled on these issues:

I've also submitted a proposal to add an optional level field to the figure element (see https://github.com/typst/typst/issues/6767 and https://github.com/typst/typst/pull/6768)

However, the right course forward is yet to be determined.

Of course, we'd love to invite you to the discussion and find a good approach for how to handle multi-level numberings in a clean and consistent manner ❤️

Cheerful regards,
Robin

GitHub

Description I suggested this change a while back on Discord. The idea is to have numbering patterns that depend on other counters, like equations being numbered per chapter (1.1), (1.2), (2.1), ......

GitHub

This adds a new hierarchical count() function which will both enable dependent counters and simplify the Rust code for counters at the same time.
I propose that this mechanism will replace the coun...

GitHub

Proposal This proposal seeks to address current limitations of how to handle multi-level numbering patterns for figures, such that the correct counter (and numbering pattern) is used for references...