% abjad.sty %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% defines the command \abjad {#1}
% to produce the `abjad' rendering of the argument,
% which must be a legal number between 1 and 1999
% This command works both inside and outside an Arabic environment.
% version 2
% 14.03.94
% no warranty whatsoever
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifx \abjatcode \undefined \else \expandafter \endinput 
\fi % load only once

\chardef \abjatcode = \catcode`\@  \catcode`\@ = 11

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \abj@d #1{% convert to abjad notation if possible
\ifnum #1>1999 #1 \else \ifnum #1=0 0 \else
\ifnum #1>999 \@bjad #1 \else \ifnum #1>099 \@bjad 0#1 \else
\ifnum #1>009 \@bjad 00#1 \else \@bjad 000#1
\fi\fi\fi\fi\fi }

\def \@bjad #1#2#3#4{% convert to abjad notation
\ifx #10\else .g\fi 
\ifcase #2 \or q\or r\or ^s\or t\or _t \or _h\or _d\or .d\or .z\fi
\ifcase #3 \or Y\or k\or l\or m\or n\or s\or `\or f\or .s\fi
%\ifcase #4 \or |A\or b\or ^g\or d\or h\or w\or z\or .h\or .t\fi }
\ifcase #4 \or |A\or .b\or .h-\or d\or h\or w\or z\or .h\or .t\fi }

\def \abjad #1{% inside a Roman environment
\ifshow \a@verb \abjad {#1} =>\fi
{\novocalize \setarab \transfalse
\edef \@bj@d {\abj@d {#1}}\expandafter \<\@bj@d >}%
\iftrans {\set@transfont \ \trans@text #1 \end }\fi }

\def \a@c@abjad #1{% inside an Arabic environment
\ifshow \a@verb \abjad {#1} =>\fi
\putwordb@x {\transfalse \showfalse \abjad {#1}}%
\ifshow \edef \@bj@d {\abj@d {#1}}\expandafter \a@verb \@bj@d >\fi
\iftrans {\set@transfont \trans@text #1 \end }\fi
\arab@tail }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode `\@ = \abjatcode

\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



