latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
124 stars 34 forks source link

Allow manually inserted tatweel to stretch with Arabic kashida #243

Open amarakon opened 1 year ago

amarakon commented 1 year ago

The kashida feature allows the use of tatweel to achieve justification instead of stretching the width of spaces. I think that manually inserted tatweel should also be stretchable. But there should also be an option to toggle this feature. In the image below, you will see tatweel with dagger alifs above them, but they are not stretched because they are manually inserted.

import-2023-05-14_00:20:10

jbezos commented 1 year ago

Please, provide a MWE. Very likely it can be already done by defining a new rule, but I’m not sure.

amarakon commented 1 year ago

MWE:

\documentclass{article}

\usepackage{multicol}
\usepackage[bidi = basic]{babel}

\babelprovide[
    main,
    import,
    mapdigits,
    justification = kashida,
    transforms = kashida.plain
]{arabic}

\babelfont[arabic]{rm}{Scheherazade New}

\newcommand{\ayah}{^^^^06dd}

\begin{document}

\begin{multicols}{3}
    بِسْمِ ٱللَّهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ~\ayah1
    ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَـٰلَمِينَ~\ayah2
    ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ~\ayah3
    مَـٰلِكِ يَوْمِ ٱلدِّينِ~\ayah4
    إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ~\ayah5
    ٱهْدِنَا ٱلصِّرَ^^^^2009ٰطَ ٱلْمُسْتَقِيمَ~\ayah6
    صِرَ^^^^2009ٰطَ ٱلَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ ٱلْمَغْضُوبِ عَلَيْهِمْ وَلَا ٱلضَّآلِّينَ~\ayah7
\end{multicols}

\end{document}

import-2023-05-14_17:13:20

You can see, for example that the manually inserted tatweel in the word “ٱلرَّحْمَـٰنِ” (last word on the first line of the first column from the right) is not stretched.

jbezos commented 1 year ago

First attempt:

\babelprehyphenation{arabic}{ {0640} }{ kashida=500 }

However, there are now too many tatweels: image

amarakon commented 1 year ago

Ideally, there should be the same amount of tatweel before and after the manually inserted tatweel. This way, the dagger alif is in the middle. Also, the kashida should be just as long as every other kashida. Is your example above a fixed length?

jbezos commented 1 year ago

there should be the same amount of tatweel before and after the manually inserted tatweel.

Which means there must be an odd number of tatweel, right? That’s not very difficult. But if there is an even number then the diacritic must be shifted horizontally, which is more complicated.

amarakon commented 1 year ago

Oh, I thought that the tatweel could be any arbitrary length. I did not know that it has to be an integer number of tatweels. Does that mean that even when the justify factor is set to 1, some space-stretching might have to be used to achieve justification?

I think there are two good options of there is an even number:

  1. One more tatweel to the right of the manually inserted tatweel with the diacritic above it than to the left of it; then shift the diacritic to the right by half the width of the tatweel character.
  2. Simply add one more tatweel to the right of the manually inserted tatweel than to the left of it. It will appear mostly centered, but not exactly.

Option 1 seems better, but I don't know if it it could cause problems. Otherwise, option 2 is also fine.

jbezos commented 1 year ago

I’m working on it, but I’m stuck with the vertical placement of diacritics. Well, there is a trick (which I’ve already used in the tentative code for the elongated forms), but I’d like investigate other options before.

jbezos commented 1 year ago

Update. It seems there is a bug in the default renderer (but I’m not yet sure), which misplaces all diacritics if they are ‘marked’ internally to keep track of them. With Harfbuzz it works as expected. So, this feature has to wait a little bit.