Skip to content

Dependent numberings #2652

@Marmare314

Description

@Marmare314

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), ....

One idea that was mentioned is to move numberings into the counter. I can't think of any problems this would cause
since there are no places where two numberings can be used for the same counter, except in figures.
But for figures, a second kind of figure can be created, so this should not be an issue.
However, this would allow the following syntax:

let a = counter("a", numbering: "{heading}.1.1")
let b = counter("b", numbering: "{heading}.{a}.i)")
let c = counter("c", numbering: "{figure.where(kind: "kind")}.1")
let d = counter("d", numbering: "{<label>}.a")

So the numbering is a formatting string that accepts any argument that counter does (except str).
The rest of the string is interpreted as a numbering string like they exist currently.
So to display a counter first the counter itself is displayed using the plain numbering string (ie removing all brackets)
while using placeholders for the missing arguments. Then all referenced counters are displayed using
their respective numberings and put into the right position. The use of {, } in numberings is probably rare enough that
just using \{, \} in those cases is fine. Also numbering can of course still be a function.

To make this flexible enough some modifiers for counters need to be provided. For example sometimes only
the first 2 levels of a counter should be used. For that a counters.slice(level-a, level-b) could be provided, maybe
even with a shorthand like counter[level-a : level-b]: {heading[1 : 2]}.1.

One thing to consider is when to reset dependent counters. I think it makes sense to treat them like levels
of counters. Consider a counter c with numbering {a}.1.{b}.1. When a is increased all levels of b and c should
be reset to 0. When b is increased all levels except level 1 should be reset on counter c. When c is increased all levels of b should be reset and all levels except level 1 of c should be reset.
However this might not always be the intended behavior. For example maybe b should not be reset when a or c change.
To allow for that there could be a function counter.ref() which only refers to the counter,
but does not reset in the way described above.

This syntax would also fit in nicely with the numbering strings provided by numberingx.

Use Case

This type of numbering seems to be really common. There are already some packages that implement this: i-figured, ctheorems, lemmify. However they only support a limited version of the requested features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestintrospectionRelated to the introspection categorymodelRelated to model category, which is all about structure and semantics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions