Arabic & RTL

The font that reversed my surname in my CV's text layer

My Arabic CV showed my surname correctly, حسكي. Through pdftotext it came out حسيك: the last two letters swapped. That’s what a parser or a search box got from the PDF on my site.


The font

The CV uses IBM Plex Sans Arabic. As shipped, it has 241 pair ligatures under the rlig feature, and pdftotext reverses the letters inside them. So the glyphs on screen are right, and the text layer behind them isn’t.

Each fix was measured with pdftotext:

Tried What came out
XeLaTeX + polyglossia Every Arabic letter as a presentation form (U+FExx). Searching a plain word finds nothing
RawFeature=-liga No change. The pairs live in rlig, not liga
/ActualText on each word Whole words reversed
+rlig only on lam-alef words Presentation forms across the whole PDF
BoldFont=Regular with fake bold Presentation forms across the whole PDF

What worked was two changes together. LuaLaTeX with babel’s bidi=basic puts real Arabic codepoints in the text layer. Then a small script builds a copy of the font with rlig emptied. The letters come out in order everywhere, and لا still renders. The font is OFL, but “Plex” is a reserved name, so the modified copy has to be called something else. Mine is Career Sans Arabic.


What’s left

Bold Arabic still extracts as presentation forms, though in the right order, and NFKC normalization folds them back to plain Arabic. I accepted that. My name is in semibold at the top, and after normalization it reads حسكي. Normalization can’t fix حسيك, which is why the old PDF stayed wrong.

Parsers also disagree. pypdf returned the Arabic in visual order for every variant tested. I aimed for poppler-style extraction, which is what pdftotext uses, and viewer search.

The PDF on my site has been the fixed one since November 2026.