How to use indic language for page numbers?

I have started using typst recently. Coming from LaTeX, compilation speeds are unbelievable. As a long time LaTeX user, I find some things simple, and some not.

I am primarily interested in using typst to prepare some books in Kannada. Everything (almost) works fine. But I want to get the page numbers as kannada numerals, not arabic.

How do I get page numbers in kannada for the main matter? Curently, the frontmatter of the books has roman page numbers and mainmatter has it in arabic numerals.

In the numbering docs it lists these as built-in display options:

1, a, A, i, I, α, Α, , , , , , , א, , , *, ١, ۱, , , , , and

I’m not familiar enough with Kannada to know if one of these is correct.

To use one of these for the page number:

#set page(numbering: "1")//Change 1 to what you prefer

Also, I’ve changed the title of your post to better match the guidelines. Specifically:

Good titles are questions you would ask your friend about Typst.

That is the first thing I had tried. As it did not work, asked here. In fact, setting the numeral to devanagari works.

If there is a place I can raise a request for the language inclusion, I will do it.

EDIT: I have raised a feature request on github.

1 Like

In the meantime here is a way to use arbitrary numerals (assuming they function similarly to Arabic numerals):

#let custom-numerals(num, numerals) = {
  let num-as-string = str(num)
  let num-as-new = num-as-string
    .split("").slice(1,-1)
    .map(
      v => numerals
        .split("").slice(1, -1)
        .at(int(v))
    )
  return num-as-new.join("")
}

#let kannada(.., num, last) = custom-numerals(num, "೦೧೨೩೪೫೬೭೮೯")

#set page(numbering: kannada)

I’ve used .split("").slice(1, -1) a few times to convert a string into an array of characters.

2 Likes

The package numberingx has kannada styles: numberingx/styles.yaml at e95c71825791624b848abe9384dc306300aa0afc · edhebi/numberingx · GitHub so it could do this for you. The package should work, but has unfortunately not been updated since the first release (it needs updates to continue working in future Typst versions; a PR is posted but not merged.)

// The same numbering function can be use for lists as for page numbers

#import "@preview/numberingx:0.0.1"
#set enum(full: true, numbering: numberingx.formatter(
  "{kannada}"
))

+ 1
+ 2
+ 3
+ 4
+ 5

list

Since the numberingx package hasn’t been updated, if @gezepi’s function does the same thing, might as well use that one?

I am getting an error:

error: missing argument: last
   ┌─ vani-1986.typ:75:12
   │
75 │ #let kannada(.., num, last) = custom-numerals(num, "೦೧೨೩೪೫೬೭೮೯")
   │             ^^^^^^^^^^^^^^^

Thanks. Will try @gezepi’s method and see.

For page numbers, maybe you can fix it by using #let kannada(..num) = custom-numerals(num.pos().first(), "೦೧೨೩೪೫೬೭೮೯") as a quick fix.

Great, it worked :-) :grinning: Chapter numbers, section etc are remaining.

I have defined chapter like this:

#show heading.where(
  level: 1): it => [
  #pagebreak()
  #block(width: 100%, above: 0em, below: 1cm)
  #set align(center)
  #set text(15pt, weight: "bold", fill: amaranth)
  #counter(heading).step()
  #counter(heading).display().~#it.body
]

Using the function kannada, how can I make the counter(heading) to display kannada numerals?

You should set heading(numbering: function here), so use the numbering support on each element to configure numbering. The only change is that heading numbering is hierarchical while page numbering (normally) uses only one number.

A numbering function takes several arguments - the value from the counter - something like 1, 2, 3 and translates that to a number like 1.B.3 (using numerals and separators as defined by the numbering pattern or numbering function)

If you are modifying/stepping the heading counter yourself it’s already a bit more complicated than it should be, and maybe you need to continue adding custom code. But counter(heading).display() should pick up the heading.numbering setting automatically - at least you have that.

Thanks a lot. It worked. As you noted, step was causing a problem. Removing it solved it.

Noticed an issue. If I have,

#set page(numbering: "10")
#set page(numbering: kannada)

the page number should have started from 10 (೧೦). But, it starts from 1 (೧).

This directive sets the numbering pattern, not the number of the page. If you want to change the numbers, counter(page).update(9).

My bad. I had a reset statement, which I overlooked. It works!