The normal enum numbering function has the problem, that the suffixes and prefixes are global for all levels of nestedness, but often, I want for example the first level to be 1. but the second level a), one with a dot the other with a parenthesis. My current solution is:
#set enum(full: true, numbering: (..nums) => {
let numbers = nums.pos()
if numbers.len() == 1 {
numbering("I.", ..numbers)
} else if numbers.len() == 2 {
numbering("1.", numbers.at(1))
} else if numbers.len() == 3 {
numbering("a)", numbers.at(2))
} else if numbers.len() == 4 {
numbering("(1)", numbers.at(3))
}
})
But I feel like there could be a better solution using less ifs, and not the full: true. Is there a better way to do it, a best practice?
You are right! Oh, wow. Now I feel dumb. I got away from using numbly for the section numbering, because I wanted to have the possibility that my sections start from section 0, which I can achieve manually but not with numbly, so I didn’t think of using it for the enum-numbering, but instead adapted my section numbering to also work there. Thanks for the anwer!
If anyone is numbering, the full equivalent code is:
actually you can make numbly do this, just realize that numbly() is a function that returns a proper numbering function. So if you want to modify what numbers are put into numbly(...) you can write e.g. this:
This is great! I didn’t realize this. Actually I would like seeing this example in the numbly documentation. (Maybe I’ll do a pull request.) This makes the code so much cleaner and nicer. Thank you. :)
I. Introduction
II. Context
2.1 Sub-context 1
2.2 Sub-context 2
With the solution with numbly (numbly("{1:I}.", "{2:1.}", "{3:a})","({4})" )) I’m almost done, the problem is the Sub-context 1, which appears with 1. instead of 2.1, how I can fix this?