2

I would like use math superscript ^ instead of \sp in mathematical formulae in an Arabic environment when using arabxetex. Unfortunately it doesn't work, see the below example. Is there a way to solve this problem? Similarly for _ and \sb.

\documentclass{article}
\usepackage{arabxetex}

\begin{document}

$a^2$ 
$a\sp{2}$
$a\sb{2}$

\begin{farsi}
$a^2$
$a\sp{2}$
$a\sb{2}$
\end{farsi}

\end{document}
2
+50

See section 3.2.1 of the manual:

3.2.1 Contextual analysis of hamza
As with ArabTeX, a contextual analysis of the input encoding is performed (at the font-mapping level) to automatically determine the carrier of the hamza, as illustrated by the following examples:

\begin{arab}
'amruN, 'ibiluN, 'u_htuN, '"u_ht"uN, '"Uql"Id"Is, ra'suN, 'ar'asu,
sa'ala, qara'a, bu'suN, 'ab'usuN, ra'ufa, ru'asA'u, bi'ruN, 'as'ilaTuN,
ka'iba, qA'imuN, ri'AsaTuN, su'ila, samA'uN, barI'uN, sU'uN, bad'uN,
^say'uN, ^say'iN, ^say'aN, sA'ala, mas'alaTuN, saw'aTuN, _ha.tI'aTuN,
...

So ^ and _ lose their meaning for math mode in the arab, farsi or urdu environments.

You can make ^ and _ math active; their behavior will be the desired one in transliterated text, returning to the usual one in math mode. The code

\begingroup\lccode`~=`^ \lowercase{\endgroup\let~}\sp
\begingroup\lccode`~=`_ \lowercase{\endgroup\let~}\sb
\AtBeginDocument{\mathcode`^=\string"8000 \mathcode`_=\string"8000 }

is what you need. Here's a complete example.

\documentclass{article}
\usepackage{arabxetex}

\begingroup\lccode`~=`^ \lowercase{\endgroup\let~}\sp
\begingroup\lccode`~=`_ \lowercase{\endgroup\let~}\sb
\AtBeginDocument{\mathcode`^=\string"8000 \mathcode`_=\string"8000 }

\begin{document}

\begin{farsi}
\relax ^say'uN _ha.tI'aTuN

$a^2$
$a\sp{2}$
$a\sb{2}$
\end{farsi}

\end{document}

enter image description here

The \relax is needed if ^ or _ are the first characters.

A better implementation, which fixes some problems with control sequence in math mode is as follows

\documentclass{article}
\usepackage{arabxetex}

% define ^ and _ to do the right thing in math mode
\begingroup\lccode`~=`^ \lowercase{\endgroup\let~}\sp
\begingroup\lccode`~=`_ \lowercase{\endgroup\let~}\sb
\AtBeginDocument{\mathcode`^=\string"8000 \mathcode`_=\string"8000 }
\makeatletter
% redefine the codes used in the environments for Arab script
\def\arabtex@codes{%
  \catcode`^=12 \lccode`^=`^
  \catcode`_=12 \lccode`_=`_
}
\makeatother


\begin{document}

\begin{farsi}
\relax ^say'uN _ha.tI'aTuN

$a^2$ $\tau_2$
$a\sp{2}$
$a\sb{2}$
\end{farsi}

\end{document}

You should make the maintainers aware of this better definition of \arabtex@codes. Characters with category code 11 or 12 are equivalent when hyphenation is concerned, so long as their \lccode is non zero.

  • Is it possible to modify you code in order to be compatible with math Greek letters? in fact writing something like $\tau_2$ in the environment \begin{farsi} \end{farsi} produce the error `ERROR: Undefined control sequence'. On the other hand writing ${\tau}_2$ seems to correctly work. – Name Dec 10 '14 at 9:17
  • @Name I don't know why arabxetex makes _ and ^ into letters; I would have made them into “other characters”, but perhaps the authors have their reasons. You have to type \tau _{2} (the braces are optional but recommended). And maybe file a bug report. – egreg Dec 10 '14 at 9:23
  • strangely {\tau}_2 works but not \tau_{2}. – Name Dec 10 '14 at 9:31
  • @Name I've added a better workaround. – egreg Dec 10 '14 at 13:11
  • Perfect, thank you for your great contributions. – Name Dec 10 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.