Skip to content

Change heading numbering within function? #778

Answered by PgBiel
Holt59 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the clarification., That solution is far form ideal and I would barely usable...

Worry not - Typst has exactly what you need:

#let appendices(body) = {
  pagebreak()
  counter(heading).update(0)
  counter("appendices").update(1)

  set heading(
    numbering: (..nums) => {
      let vals = nums.pos()
      let value = "ABCDEFGHIJ".at(vals.at(0) - 1)
      if vals.len() == 1 {
        return "APPENDIX " + value + ": "
      }
      else {
        return value + "." + nums.pos().slice(1).map(str).join(".")
      }
    }
  );
  
  [#body]
}

#show: appendices

= First
... text ...
= Second
... text ...
= Third
... text ...

Using #show: function will wrap the whole document after…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@arj0019
Comment options

@arj0019
Comment options

@arj0019
Comment options

Comment options

You must be logged in to vote
4 replies
@Holt59
Comment options

@PgBiel
Comment options

Answer selected by Holt59
@Holt59
Comment options

@PgBiel
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants