How to customize numbering for nested enum items?

I managed to style the numbers of the enumeration in blue:

  // Configure Enums:
  set enum(
    numbering: n => (text(fill:blue)[#n.]),
  )

When I now have a enum like this:

+ ABC
   + DEF

I want that the DEF is colored in gray. How to reach that? Any thoughts?

Set full: true on the enum, then it receives all levels of numbers in the callback, then it can be customized by level (and also create multilevel type numbering like “1.b” if wanted)

To complete @bluss’s answer, if you set full: true to your enum, the numbering function will receive all numbers corresponding to the enum.items. That is, the first item will send (1,), the nested item will send (1, 1).

You can receive these arguments using arguments as such:

#let nb = (..n) => { ... }

Then, n will be of type arguments. The easiest here is to convert it directly to an array and look at its length and slice for each level. A full example below. You do need to be careful to either define a default behaviour, or not use any levels with no customization.

// Configure Enums:
  #set enum(
    numbering: (..n) => {
      n = n.pos()
      let level = n.len()
      if level == 1 {
        text(blue, numbering("1.", ..n))
      } else if level == 2 {
        text(gray, numbering("a.", ..n.slice(1)))
      } else {
        // panic("Enum level not set")
        // or
        numbering("1.", ..n)
      }
    },
    full: true,
  )

+ ABC
   + DEF
   + DEF
     + DEF
2 Likes