typst icon indicating copy to clipboard operation
typst copied to clipboard

Justification for Arabic

Open be5invis opened this issue 1 year ago • 4 comments

Justification of Arabic text is very unique. Usually, they do not add whitespace between words. Instead, Arabic text is justified using two ways:

  • Using more "compressed" or "stretchy" variant glyphs. OT have a tag called jalt to provide these alternatives.
  • Stretching the words by inserting Tatweel between letters.

Example of justified Arabic text from ref. Blue shows the swash Kaf, purple is used for the final elongated Alif, orange marks the Returning Yeh (Bari-Ye), and yellow highlights the use of Tatweels inserted. image

Exmaple of Tatweel insertion: image

Ref:

  • https://www.khtt.net/en/page/1821/the-big-kashida-secret
  • http://andreasmhallberg.github.io/stretchable-kashida/
  • https://quod.lib.umich.edu/j/jep/3336451.0023.104?view=text;rgn=main

be5invis avatar Mar 23 '23 07:03 be5invis

Potential issues with this :

  • Kashidas inserted between contextual alternatives (which are heavily used in Arabic fonts) break the shaping. Unless you intend to run the shaper afterwards.
  • The example given is ugly looking. Kashida shouldn't be used this heavily.
  • some Arabic fonts make use of justification alternates, which look better but are not widely supported. (only in indesign iirc). but even indesign just applies to EVERYTHING which looks as bad as the example photo.

The naive implementation for kashida insertion shouldn't be the default behavior (for line lengths this long it is almost always better to just stretch and shrink spaces). If it should exist at all it should be an opt-in toggle.

Here is a three-part essay about Arabic justification by Titus Nemeth: https://research.reading.ac.uk/typoarabic/on-arabic-justification-part-1/ which goes over the history and the issues. You'll find one of the historical findings is that native typesetters prefer to stretch spaces and use alternate shape forms rather than inserting kashidas everywhere. kashidas are at best used very sparingly.

Edit : OG post has been edited and my comment was on the pre-edit screenshot. the edit took in some of comments which is appreciated.

asibahi avatar Mar 23 '23 21:03 asibahi

I created a (n opinionated) crate to help with this: https://github.com/asibahi/kashida . Maybe you guys can find it useful. It has some custom rules for Arabic and Syriac, but also a generic function for other scripts like N'Ko and Adlam (using Unicode properties!)

While I believe using variable fonts to be the superior justification strategy, this is a useful fallback, before adjusting spaces.

asibahi avatar May 14 '24 18:05 asibahi

Thanks @asibahi!

laurmaedje avatar May 14 '24 18:05 laurmaedje

@asibahi that is awesome work!!

davelab6 avatar Jul 29 '24 15:07 davelab6