Heading numbering style does not work in 0.14.0

Hi All

My heading style worked well in 0.13.1. However, it does not work for 0.14.0

 ALL TESTS  (heading 1)
   EASY TESTS  (heading 2)
      Test 1. something (heading 3)
      Test 2. something more (heading 3)
   INTERMEDIATE TESTS (heading 2)
      Test 3. Another test name (heading 3)
   HARD TESTS (heading 2)
      Test 4. Yet another test name (heading 3)
  • Numbering is none for level 1 and 2
  • Simple numbering for level 3, with prefix “Tests”
  • Level 3 numbers remain consecutive even if a higher-level heading occurs

The code is:

#let third-heading-counter = counter("third-heading-level")
#show selector.or(heading.where(level: 1), heading.where(level: 2)): it => {
  it

  // Revert level 3+ resets
  context {
    let new-numbers = third-heading-counter.get()
    counter(heading).update(if it.level == 1 {
       (one, ..n) => (one, 0, ..new-numbers)
    } else {
       (one, two, ..n) => (one, two, ..new-numbers)
    })
  }
}

/* This part makes it so test number continues accross higer headers */
#show heading: it => {
  if it.level >= 3 {
    third-heading-counter.step(level: it.level - 2)
    text(1.1em, it)
  } else  if it.level >= 3{ 
     text(red, 1em, it)
  }else{
  it
  }
}

#show heading.where(level: 1): set heading(numbering: none)
#show heading.where(level: 2): set heading(numbering: none)
// For level 3+: ignore first two numbers
#set heading(numbering: (first, second, ..n) => numbering("Test 1.", ..n))

The problem happens in the last line, where it complains about missing argument.

What would be the correct statement now?

1 Like

Hi, welcome to the forum!

I guess the cause is the same as Why the heading number can be zero in v0.14.0-rc.2?, that the numbering function gets additional mysterious ghost call in v0.14.0. The specific reason is still unclear, though.

You can mitigate it by changing the rule to the following, making it happy for all kinds of inputs.

#set heading(numbering: (..nums) => if nums.pos().len() >= 2 {
  numbering("Test 1.", ..nums.pos().slice(2))
})