[Tex/LaTex] Typesetting Right-to-Left math

arabicequationsmath-moderight-to-left

UPDATE:

I've managed to produce something that is aesthetically correct, however with a lot of "hardcoding" and trial and error to manually measure my spaces. Not to mention that I have to write my equation "backwards" (e.g. "^2 b" instead of "b^2", and "0 = s" instead of "s = 0"). Is there a cleaner and more automatic way to do this ? The example then its minimal code follows:

Looks good

\documentclass{article}
\usepackage[leqno]{amsmath}
\usepackage{graphicx}
\newcommand{\asqrt}[1]{\reflectbox{\ensuremath{\sqrt{\reflectbox{\ensuremath{#1}}}}}}
\newcommand{\asum}[3]{\reflectbox{\ensuremath{\displaystyle\sum\limits_{\reflectbox{\ensuremath{#1}}}^{\reflectbox{\ensuremath{#2}}} \reflectbox{ \ensuremath{#3} }}}}

\usepackage{polyglossia}
\setdefaultlanguage[calendar=gregorian]{arabic}  % from polyglossia
\setmainfont[Script=Arabic,Scale=1.8,Mapping=arabicdigits]{Scheherazade}
\begin{document}
\begin{equation}
\asqrt{\frac{ ^{\raisebox{3pt}{\mbox{\tiny 2}}}\mbox{ف} } {\mbox{ب} \mbox{4}}}
\end{equation}
\begin{equation}
\asum{\mbox{\scriptsize 0 = س}}{\hspace{-9pt} \scriptsize \infty}{ ^{\mbox{\small 2}} \mbox{س}}
\end{equation}
\end{document}

Original question:


I am using XeLaTeX along with polyglossia package to typeset a mathematical article in Arabic. It is working very well for text but not for math.

The text is of course set Right-to-Left. However this is not the case for math, which is by default typeset the other way around. Unfortunately, this is not the only problem with it; I do as a matter of fact, need a "mirrored" version of the integration and summation symbols, and square roots.

1) Is there a ready package for that (I did search but didn't find any) ?

2) Is it possible to build such a package without losing existing features like the align environment of amsmath, or I will also have to re-implement that ?

In particular I wondering how bad is my situation if I try to approach implementing a complete solution for RTL math for Arabic.

EDIT:
I know there is the question How to typeset an Arabic paper with the equations in the usual Latin in Latex? but it is talking about Latin equation, not Arabic equations.

EDIT 2:

I can try some tricks like mirrorbox (like this \vec{x} but with arrow from right to left?) but still it doesn't work correctly.

There is several problems:

  1. If I do not put the Arabic
    characters inside a box (mbox) they
    do not appear nor reserve a vertical
    space at all.
  2. When using the "power" operator "^",
    I have to put the power before the
    base. Instead of x^2, I have to
    write it like ^2 x. However even so,
    it doesn't look raised because the size of the power mbox wasn't reduced (restricted space problem, it does look raised in the second example).
  3. Reversed order for numbers and
    characters. In the denominator of
    the attached photo, it should appear
    as "4 b" but rather rendered as "b
    4". To render it right I have to
    reverse the order in my source.

All these reversals will make the source incomprehensible for complex equations.

The example:

\asqrt{ \frac{ ^{\mbox{2}} \mbox{ف} } { \mbox{4 ب} } }

Where \asqrt is defined as :

\usepackage{graphicx}
\newcommand{\asqrt}[1]{\reflectbox{\ensuremath{\sqrt{\reflectbox{\ensuremath{#1}}}}}}

Example of incorrect behaviour

EDIT 3:

It gets hopeless with something like summation. The assignment below the summation should be reversed. Moreover, the need to use mbox makes the proportions very bad as well.

\newcommand{\asum}[3]{\reflectbox{\ensuremath{\sum\limits_{\reflectbox{\ensuremath{#1}}}^{\reflectbox{\ensuremath{#2}}} \reflectbox{ \ensuremath{#3} }}}}

\asum{\mbox{س = 0}}{\infty}{^{\mbox{2}} \mbox{س}}

Another bad example

Best Answer

As promised in the comment above, the new version of the XITS font has preliminary RTL support. There is a simple ConTeXt test file in the repository (you need a recent ConTeXt MkIV version) but it shouldn't be hard to port it to LuaLaTeX and unicode-math package.

It is work in progress, not all symbols have been mirrored and support for the proposed Arabic math symbols still lacking.

There is one caveat though, luatex reverses the direction of everything including numbers, so you either want to do something like {\textdir TLT 123} or try my experimental luadirections package (however it doesn't work in math mode yet, at least in ConTeXt, but I'm investigating that.)

mandatory sample :)

Related Question