How to manage pages for ttb + rtl + dual books?

  • ttb: top to bottom
  • rtl: right to left
  • dual: view double pages at once

For a ttb+rtl language’s book, it’s natural to look from the right page to the left page, i.e. the page numbers are “2,1,4,3,6,5,…”.

How to do that in typst, or perhaps python pdf toolkit is a better choice?

Easiest would probably to use a custom numbering function to flip the even and odd numbers:

#set page(numbering: (first, second) => {
  let flipped-first = first - 1 + 2 * calc.rem(first, 2)
  // Change "1 / 1" to any numbering you wish
  numbering("1 / 1", flipped-first, second)
})

Full code
#set page(width: auto, height: auto, margin: 2em)
#set text(dir: rtl)
#set text(lang: "ar")

#set page(numbering: (first, second) => {
  let flipped-first = first - 1 + 2 * calc.rem(first, 2)
  numbering("1 / 1", flipped-first, second)
})

#range(6).map(n => "مرحبًا!").join(pagebreak())