typst / typst/typst

Provide enum nesting depth to numbering function even without `full: true`

Open
#6,079 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

change request model
Dominant language
Rust
Stars
56.1k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
22

Description

Description
#set enum(
  numbering: (..numbers) => {
    let numbers = numbers.pos();
      if numbers.len() == 1 {
        return numbering("1.", numbers.at(0))
      }
      if numbers.len() == 2 {
        return numbering("a.", numbers.at(1))
      }
    },
  full: false
)

+ + Hello

#set enum(
  numbering: (..numbers) => {
    let numbers = numbers.pos();
      if numbers.len() == 1 {
        return numbering("1.", numbers.at(0))
      }
      if numbers.len() == 2 {
        return numbering("a.", numbers.at(1))
      }
    },
  full: true
)

+ + Hello

#set enum(numbering: "1.a.", full: false)

+ + Hello

#set enum(numbering: "1.a.", full: true)

+ + Hello

The output is:

Image

I intuitively expect

#set enum(numbering: s)

And

#set enum(numbering: nums => numbering(s, nums))

Should be equivalent. However that's not the case: when using a string argument, the indices of outer layers are considered (at least they are supplied as placeholders to trigger different numbering styles) even if full is set to false. When using a function argument, if full is set to false, the indices of outer layers are not passed to the function, resulting in the function not knowing which layer it is at.

I think all the indices of outer layers should be passed to the numbering function, since supplying a custom numbering function is an attempt to override the default behavior. Also the current behavior of full is very non-orthogonal: when using numbering strings, it doesn't behave by only considering the current single enum, contrast to when using numbering functions.

Reproduction URL

No response

Operating system

Linux

Typst version
  • I am using the latest version of Typst

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Typst reproduction in the issue and tracing the enum numbering implementation that handles custom numbering functions and the full setting. Done means outer enum indices are available to the function consistently with string numbering, while the shown nested-enum cases produce the expected equivalent results.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.