# arabxetex and footnote

I've had some problems with ^s when using arabxetex in footnotes. Transliteration and conversion to Arabic script work fine in the main text, but in footnotes they do not. All other letters seem to work fine.

\documentclass{article}

\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont[Numbers=OldStyle]{Brill}
\usepackage{arabxetex}

\begin{document}

Here it works: \textarab[trans]{^s}

Here it doesn't:
\footnote{\textarab[trans]{^s}}
\end{document}


The \textarab command changes category codes so it can't be used in the argument to another command.

There's a way out by using \scantokens. A quick redefinition can be obtained with the regexpatch command.

\documentclass{article}

\usepackage{fontspec}
\usepackage{arabxetex}
\usepackage{regexpatch}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Brill}

\makeatletter
\xpatchcmd*{\text@arab}{#2}{\scantokens{#2\noexpand}}{}{}
\makeatother

\setlength{\textheight}{2cm} % just to have a smaller picture
\begin{document}

Here it works: \textarab[trans]{^s}X\textarab{^s}X

Here too\footnote{\textarab[trans]{^s}X\textarab{^s}X}
\end{document}


The X's I added are just to ensure that no spurious space creeps in.

Here's the full redefinition in case you can't use regexpatch.

\documentclass{article}

\usepackage{fontspec}
\usepackage{arabxetex}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Brill}

\makeatletter
\renewcommand\text@arab[2][\ax@mode]{%
\edef\@tempa{#1}%
\def\ax@lang{arab}%
\ax@ismode@defined{\@tempa}%
\ifax@mode@defined
\ifx\@tempa\ax@mode@trans
\else
\ifx\@tempa\ax@mode@utf
\RL{\arabicfont\utf@fontfeature\scantokens{#2\noexpand}}%
\else
\fi
\fi
\else
\PackageWarning{arabxetex}{Mode \@tempa\ not defined, defaulting to \@ax@mode}%