How to use words as heading numbers

I know you can customize the heading to have some roman numbers or letters:

#set heading(numbering: "I.1.a.")

= Bla bla bla 1
= Bla bla bla 2
= Bla bla bla 3

Which will render as:

I. Bla bla bla 1

II. Bla bla bla 2

III. Bla bla bla 3

Now, say I want “First part”, “Second Part”, “Third Part”, Instead of the roman “I”, “II”, “III”, how can I do this?

First Part - Bla bla bla 1

Second Part - Bla bla bla 2

Third Part - Bla Bla Bla 3

I currently have this workaround but it feels janky… (or maybe it’s the best solution?)

#let numless(it) = {set heading(numbering: none); it }
#numless[= #underline[First Part] - Bla bla bla 1)]

You can define your own numbering function to do what you need, for example

  #set heading(numbering: (..n) => {
    let index = n.pos().at(0)
    // extend me
    let first = ("First", "Second", "Third").at(index - 1, default: str(index) + "th")
    // what about the rest
    let rest = numbering("1.a", ..n.pos().slice(1, none))
    if rest.len() > 0 { rest = " " + rest }
    [#first -#rest]
  })
  = Bla
  = Bla Bla
  == Sub
  === Sub

1 Like

This doesn’t look readable to me.

#let nth(ordinal-num) = (
  "First",
  "Second",
  "Third",
  "Fourth",
  "Fifth",
  "Sixth",
  "Seventh",
  "Eighth",
  "Ninth",
  "Tenth",
).at(ordinal-num - 1)


#set heading(numbering: (..n) => {
  let (a, ..b) = n.pos()
  [#nth(a) Part] + numbering(".1.a —", ..b)
})

= Heading
== Heading
=== Heading
= Heading
== Heading
=== Heading
= Heading
== Heading
=== Heading

Hello @oiseauidiot, did @bluss’s response solve your problem? If so, can you please mark it as a solution with the :white_check_mark: button? Otherwise, please tell us how can we help you further. Thanks! :slight_smile:

1 Like

This is what I wanted ! Thanks a lot

2 Likes