\ProvidesPackage{arabicnumbers}
        [2010/03/18 v0.2 %
         Formatting of Arabic and Farsi digits and of Arabic abjad numerals]

\def\arabicdigits#1{\expandafter\@arabic@digits #1@}
\def\@arabic@digits#1{%
  \ifx @#1% then terminate
  \else
    \ifx0#1٠\else\ifx1#1١\else\ifx2#1٢\else\ifx3#1٣\else\ifx4#1٤\else\ifx5#1٥\else\ifx6#1٦\else\ifx7#1٧\else\ifx8#1٨\else\ifx9#1٩\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@arabic@digits
  \fi
}

\def\farsidigits#1{\expandafter\@farsi@digits #1@}
\def\@farsi@digits#1{%
  \ifx @#1% then terminate
  \else
    \ifx0#1۰\else\ifx1#1۱\else\ifx2#1۲\else\ifx3#1۳\else\ifx4#1۴\else\ifx5#1۵\else\ifx6#1۶\else\ifx7#1۷\else\ifx8#1۸\else\ifx9#1۹\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@farsi@digits
  \fi
}

\newif\ifabjad@jim@notail
\abjad@jim@notailfalse

\def\abjad#1{%
\ifnum#1>1999\xpg@ill@value{#1}{abjad numeral}%
\else
\ifnum#1<\z@\space\xpg@ill@value{#1}{abjad numeral}%
  \else
    \ifnum#1<10\expandafter\abj@num@i@iso\number#1%
    \else
      \ifnum#1<100\expandafter\abj@num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\abj@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\abj@num@iv\number#1%since #1<2000, we must have 1000
          \fi
        \fi
      \fi
    \fi
  \fi
\fi
}
\def\abjad@zero{}
\def\abjad@one{ا}
\def\abjad@three{ج\ifabjad@jim@notail\Uchar"200D\fi}
\def\abj@num@i@iso#1{%
  \ifcase#1\abjad@zero\or \abjad@one\or ب\or\abjad@three\or د%
           \or ه\Uchar"200D\or و\or ز\or ح\or ط\fi}
\def\abj@num@i#1{%
  \ifcase#1\abjad@zero\or\abjad@one\or ب\or\abjad@three\or د%
           \or ه\or و\or ز\or ح\or ط\fi}
\def\abj@num@ii#1{%
  \ifcase#1\or ي\or ك\or ل\or م\or ن%
           \or س\or ع\or ف\or ص\fi 
  \abj@num@i}
\def\abj@num@iii#1{%
  \ifcase#1\or ق\or ر\or ش\or ت\or ث%
            \or خ\or ذ\or ض\or ظ\fi
  \abj@num@ii}
\def\abj@num@iv#1{%
  \ifcase#1\or غ\fi
  \abj@num@iii}
\endinput
