What is the best practice for setting the enum numbering for every level individually?

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?

Isn’t using numbly as the solution (combined with full) also the answer here?

1 Like

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:

  #import "@preview/numbly:0.1.0": numbly

  #set enum(
     full:true, 
     numbering: numbly("{1:I}.", "{2:1.}", "{3:a})","({4})" )
  )

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:

#set heading(
  numbering: (fst, ..nums) => numbly("Top {1}:", "{1}.{2}.")(fst - 1, ..nums),
)

(I used the heading example from the other thread as zero-based roman numbering doesn’t make as much sense)

1 Like

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

1 Like