Skip to content

Handle special characters in numbering patterns #1177

@edhebi

Description

@edhebi

Description

A number of characters are interpreted in numbering patterns (since that's the whole point). Because there's no escape hatch, this makes them impossible to use in the various prefix of suffix. I propose that a backslash character should stop the next character from being interpreted in this way. For example a patter of "Section 1.1 )" would be written "Sect\\ion 1.1 )"

I can see two limitations:

  • It's not obvious that you need a double backslash instead of of a single one to someone not familiar with escape sequences, and that makes an actual backslash be "\\\\" but I suspect that's not a common character at all to put in there.

  • It's added complexity for something that can currently be solved with numbering functions. I do think this makes a bunch of patterns nicer for the user on the long run tho.

I'd actually be willing to implement this if there's interested, that'd be a good way to get familiar with the codebase :p

Use Case

For more involved numbering patterns, it can get frustrating to work around interpreted characters, especially aAiI. For example, numbering("Section 1.1 )") doesn't produce the expected result because the i is a special character in a numbering pattern.

With this feature it would be numbering("Sect\\ion 1.1 )") instead.

// Before
#set heading(numbering: (..nums) => "Section " + numbering("1.1 )", ..nums.pos()))
// After
#set heading(numbering: "Sect\\ion 1.1 )")

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestscriptingAbout Typst's coding capabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions