3

This is likely a newb question, but I'm wondering how TeX automatically understands a language is RTL.

This is my test program:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\arabicfont}[Language=Default,Script=Arabic]{Cairo}
\begin{document}
\arabicfont العربية \par
\arabicfont ا ل ع ر ب ي ة \par
\end{document}

The output:

enter image description here

I didn't use a package such as bidi, and I didn't mention things like RTL anywhere in the code, but the letters are already displayed in the correct order when put together. Is it the font or the TeX engine that is doing the magic here? (The order of multiple words in a paragraph is wrong, but the order of letters within one word is correct.)

(I think the webpage also has some magic with code display. The letters in the source code are written in the LTR order, the same as the second line in the output.)

0

1 Answer 1

1

You did not mentioned which engine you are using, but I'm guessing you are using XeTeX.

XeTeX applies Unicode BiDi algorithm, but only per word (or for bigger chunks of text if \XeTeXinterwordspaceshaping is positive) when a modern font is used (see the last comment to this answer).

Consider the following code (to be compiled with XeTeX, not XeLaTeX, note that the \TeXXeTstate needs to be positive to use the \beginR and \endR primitives, which dictate the text direction):

\TeXXeTstate1

\beginR Hello World\endR

\bye

The output is unsurprisingly

enter image description here

But, remember that plain TeX loads cmr10 by default, which is not a modern font. By loading the opentype version of Latin Modern we will get

\font\test="Latin Modern Roman 10 Regular" at 10pt

\TeXXeTstate1

\beginR Hello World\endR

\bye

enter image description here

And as you can see, the text rendered as left to right, but only per word, since latin letters are considered as strong LTR bu the unicode BiDi algorithm.

By increasing \XeTeXinterwordspaceshaping you can also apply unicode BiDi algorithm for whole sentences

\font\test="Latin Modern Roman 10 Regular" at 10pt\test
\XeTeXinterwordspaceshaping=2
\TeXXeTstate=1

\beginR Hello World\endR

\bye

enter image description here

More interesting example with mixed english and herew text (sorry, I don't know any arabic) which renders correctly without the need of any directional nodes

\font\test="David CLM Medium" at 10pt\test
\XeTeXinterwordspaceshaping=2
\TeXXeTstate=1

Hello World שלום עולם, Just some text סתם קצת טקסט

\bye

enter image description here

but I don't think you can an RTL paragraph without the use of the directionality primitives.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .