typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
29.68k stars 809 forks source link

Cyrillic numbering (Russian) #1595

Open Andrew15-5 opened 12 months ago

Andrew15-5 commented 12 months ago

Description

I thought, that adding #set enum(numbering: "а)" | "А)" | "а." |"А.") numbering patterns would be perfect. But it's only for Cyrillic (which is my main issue). Maybe adding custom numbering — string (where each char is indexed enum label) or list of strings — would be a more flexible and universal solution.

Note: in Cyrillic enum list, next letters are de facto excluded: ё, й, ъ, ы, ь (source).

Use Case

Everyone would be able to easily create new numbering styles (emoji, Cyrillic, Japanese etc.).

Enivex commented 12 months ago

You can already provide an arbitrary function to that argument

Andrew15-5 commented 12 months ago

Nice. Thank you!

Here is my MWE:

#let ru_alph(pattern: "а)") = {
  let alphabet = "абвгдежзиклмнопрстуфхцчшщэюя".split("")
  let f(i) = {
    let letter = alphabet.at(i)
    let str = ""
    for char in pattern {
      if char == "а" {
        str += letter
      }
      else if char == "А" {
        str += upper(letter)
      }
      else {
        str += char
      }
    }
    str
  }
  f
}
#set enum(numbering: ru_alph()) // or
#set enum(numbering: ru_alph(pattern: "А."))
MDLC01 commented 12 months ago

I think the original issue is still relevant, though. There should be a cyrillic numbering kind.

Andrew15-5 commented 12 months ago

I mean, for convenience — yes. But is it the only one which should be added — probably not. Although I don't know if every language uses its own alphabet/syllabary in enumerated lists.

syroezhkin commented 6 months ago

The search for a solution to the same problem brought me here. If numbering patterns should support several alphabets (except English, Japanese, etc.), then it would be great for me to see support for Cyrillic alphabet out of the box as well. Otherwise, we are back to the fundamental problems of LaTeX.

Anyway, Typst is great!

Andrew15-5 commented 6 months ago

@syroezhkin, I think I haven't opened an issue asking for all numbering styles (not only Russian ones) because I have found this package: https://github.com/typst/packages/tree/main/packages/preview/numberingx/0.0.1 https://github.com/edhebi/numberingx

Which implements all the "predefined counter styles" listed here: https://www.w3.org/TR/predefined-counter-styles/. So I tried it and it works. Here is a MWE that covers all use cases (in a form of 2 examples) for Russian (case, excluded letters, [.)] suffix):

#import "@preview/numberingx:0.0.1"
#columns(2, {
  set enum(numbering: numberingx.formatter("{lower-russian})"))
  enum(..range(28).map(it => enum.item[]))
  colbreak()
  set enum(numbering: numberingx.formatter("{upper-russian-full})"))
  enum(..range(33).map(it => enum.item[]))
})
output

![image](https://github.com/typst/typst/assets/37143421/27b6ac74-b0d1-42da-bc4e-775abe6f0b74)

Although I never really had to use it in my documents. Nevertheless, it would be nice if not only Russian, but all the standard counter styles were to be added directly into Typst. You can open an issue about it, if it doesn't exist yet.

Andrew15-5 commented 2 months ago

I'll re-open this issue, because the provided solutions are more of a workaround, than what I described/wanted.

There is already support for English, Japanese and Chinese, IIUC (https://typst.app/docs/reference/model/numbering/#parameters-numbering):

Counting symbols are 1, a, A, i, I, 一, 壹, あ, い, ア, イ, א, 가, ㄱ, and *. They are replaced by the number in the sequence, in the given case.

Since the most common set is the non-full one, I think it's better to include it, instead of the full one.