typst

How to remove colon from appendix references while keeping custom numbering?


I have this:

#outline()

This is the body of my text. There is something cool I show in @first, but you
will have to read it to find out.

#heading("Appendices", numbering: none)

#set heading(
  offset: 1,
  numbering: (_, ..rest) => "Appendix " + numbering("A:", ..rest),
  supplement: []
)

= First <first>
Text of the first appendix.

= Second <second>
Text of the second appendix.

which allows me to write my appendices as level 1 headings, but show them as level 2 (i.e. indented in the table of contents, show them as level 2 under a level 1 Appendices, etc.).

current behavior

The issue is that the ":" still shows up when I reference an appendix in the text (which is not what happens for normal numbering: "A:". How can I fix this (while keeping all the other functionality)?


Solution

  • Here is a working solution that requires you to set heading.supplement and redefines the ref body for level 2 heading when it is an appendix:

    #show ref: it => {
      let el = it.element
      if el == none or el.func() != heading or el.level != 2 or el.supplement != [Appendix] {
        return it
      }
      let lvl = counter(heading).at(el.location()).at(1)
      let body = el.supplement + numbering(" A", lvl)
      link(el.location(), body)
    }
    
    #outline()
    
    This is the body of my text. There is something cool I show in @first, but you
    will have to read it to find out.
    
    #heading("Appendices", numbering: none)
    
    #set heading(
      offset: 1,
      numbering: (_, ..rest) => "Appendix " + numbering("A:", ..rest),
      supplement: [Appendix] // <- Important
    )
    
    = First <first>
    Text of the first appendix.
    
    = Second <second>
    Text of the second appendix.
    

    Inspired from this forum post.

    enter image description here