%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% aboxes.sty
% ArabTeX
% deposit character into output box
% called in HMODE
% Version 28.05.2003
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Formale Methoden der Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\a@ident {aboxes.sty} {3.11 build output boxes} {28.05.2003}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dynamic definitions for Arabic
{\catcode `\^ 7 \catcode `\ =9 \catcode `\^^M=9 \catcode `\^^I=9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@arabaccent {% define accent macros for Arabic
\gdef \put@fatha     {\put@acc@hi {\char \a@fatha      }}
\gdef \put@damma     {\put@acc@hi {\char \a@damma      }}
\gdef \put@kasra     {\put@acc@lo {\char \a@kasra      }}
\gdef \put@shadda    {\put@acc@hi {\char \a@shadda     }}
\gdef \put@hamza     {\put@hi     {\char \a@hamza      }}
\gdef \put@hamzalo   {\put@lo     {\char \a@hamza      }}
\gdef \put@madda     {\put@hi     {\a@madda@up         }}
\gdef \put@sukun     {\put@acc@hi {\char \a@sukun      }}
\gdef \put@wasla     {\put@acc@hi {\char \a@wasla      }}
\gdef \put@fathatan  {\put@acc@hi {\char \a@fathatan   }}
\gdef \put@dammatan  {\put@acc@hi {\char \a@dammatan   }}
\gdef \put@kasratan  {\put@acc@lo {\char \a@kasratan   }}
\gdef \put@fathaspec {\put@acc@hi {\char \a@quran@alif }}
\gdef \put@kasraspec {\put@acc@lo {\char \a@quran@alif }}
\gdef \put@ammad     {\put@acc@hi {\char \a@ammad      }}
\gdef \put@zwarakay  {\put@acc@hi {\char \a@zwarakay   }}
\gdef \put@barslo    {\put@lo     {\char \a@bars       }}
\gdef \put@kh@hamza  {\put@hi     {\char \a@hamza      }}
\gdef \put@kl@hamza  {\put@lo     {\char \a@hamza      }}
\gdef \put@kh@hamz@s {\put@hi     {\char \a@hamz@s     }}
\gdef \put@kl@hamz@s {\put@lo     {\char \a@hamz@s     }}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}}% end of dynamic definitions for Arabic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newdimen \a@dp         \newdimen \a@ht        \newdimen \a@wd    
\newdimen \dia@dx       \newdimen \dia@dy      \newdimen \dia@ht
\newdimen \a@disp       \newdimen \a@ic         
\newbox   \ab@x         \newbox   \dia@box       

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%em# := 25.4dx#;        %ex# := 8dy#;

\def \a@kern {\kern.05em } \def \a@mkern {\kern-.05em }% Arabic kerning
\def \acc@hi {1.8ex }      \def \acc@lo {0.4ex }   % positions for .harakAt
\def \tat@ht {0.20ex }     \def \tat@wd {0.007em } % kashida dimensions
\def \tat@skip {0.014em plus 0.2fil }
\def \a@dsp {.5ex }         % shift for raised characters

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% global: \act@cd, \act@mod, \act@dia, \act@tie

\def \put@skel #1#2#3*{% deposit writing syllable	% f d m *
\put@act@box #1#2\put@mod #3*\dep@sitb@x 
\fix@act@box }

\def \put@lig@skel #1#2#3*#4*{% deposit 2char ligature  % f d m * m *
\put@act@box #1#2\global\a@wd .5\wd\ab@x 
\wd\ab@x \a@wd \dimen4 \a@ht \dimen6 \a@dp 
\global\setbox \ab@x \vbox {\box \ab@x }\put@mod #3*\dep@sitb@x 
\setbox0 \hbox to\a@wd {\hfill }\dp0 \dimen6 \ht0 \dimen4
\global\a@ht \dimen4 \global\a@dp \dimen6
\global\setbox \ab@x \vbox {\box0 }\put@mod #4*\dep@sitb@x 
\fix@act@box }

\def \put@act@box #1#2{% set tie and open character box
\ifnum \act@tie = 0 \else \advance\act@tie \a@f@mid \put@tie \fi
\advance\act@cd #2\xpa \dia@pos \act@dia #1\relax 
\put@b@x {\the\act@cd }\if@mod@act \put@d@t {\the\act@mod }\fi }

\def \put@tie {% deposit ties between characters
\setbox0 \hbox {\char \the\act@tie }%
\setbox2 \hbox {\char \the\act@tie \/}%
\ifdim \a@disp = \z@ \unhcopy0 
\else \raise\a@disp \hbox {\unhcopy0 }\fi 
\advance\a@disp \wd2 \advance\a@disp -\wd0 }

\def \set@high@act {% prepare raising of actual character
\advance \a@disp \a@dsp \@high@acttrue }

\def \set@low@act {% lower actual character
\advance \a@disp -.25ex }

\def \set@loww@act {% lower actual character
\advance \a@disp -.50ex }

\def \set@lowww@act {% lower actual character
\advance \a@disp -.75ex }

\def \fix@act@box {% fixup position and set tatwil
\if@high@act \advance\a@disp -\a@dsp \@high@actfalse \fi 
\advance\a@min@dp \a@ic \advance\a@disp \a@ic 
\if@tat \put@tat \@tatfalse \fi }

\def \put@tat {% deposit a keshide
\dimen@ \a@disp \advance\dimen@ \tat@ht \nobreak \hskip-\tat@wd
\leaders \hrule height\dimen@ depth-\a@disp \hskip\tat@skip \hskip-\tat@wd }

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

\def \put@b@x #1{% evaluate the argument
\edef \t@mp {\nxp\put@box {\char #1}}\t@mp }

\def \put@box #1{% pack and get dimensions, also ic and baseline skew 
\setbox0 \hbox {#1\/}\global\a@ic \wd0 
\global\setbox \ab@x \hbox{#1}% put into box
\global\a@ht \ht\ab@x \global\a@wd \wd\ab@x   
\global\a@dp \dp\ab@x \global\advance \a@ic -\a@wd 
\a@adj@lo \a@min@dp 
\ifnum \a@min > 0 \global\a@min@dp \a@dp \global\advance\a@min -1 
\else \global\a@min@dp \z@ \fi }
%\global\a@sk -\a@skew\a@wd 
%\ifa@sk \global\a@skfalse \else \global\a@sk -\a@sk \fi }

\def \dep@sitb@x {% put contents into output, unpack if possible
\ifhbox \ab@x \ifdim \a@disp = \z@  \unhbox \ab@x
              \else  \raise\a@disp \hbox {\unhbox\ab@x }%
              \fi
\else \global\advance \a@ht \a@disp \global\advance \a@dp -\a@disp
              \ht\ab@x \a@ht \dp\ab@x \a@dp  \box \ab@x
\fi }

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

\def \put@mod #1+#2*{% put modifier onto contents of "\ab@x" % m1 + m2 *
        \global\red@mod   0#1\relax
        \ifnum 0#1> 9 \global\advance \red@mod -10 \relax \fi
\ifnum 0#2= \c@kasra    \xpa\a@putkasra    \xpa{\the\red@mod }\else
\ifnum 0#2= \c@kasratan \xpa\a@putkasratan \xpa{\the\red@mod }\else
        \ifcase \red@mod 
        \relax     \or \put@shadda  \or 
        \put@hamza \or \put@hamza \put@shadda \or
        \put@madda \or \put@hamzalo \or
        \fi
        \put@voc 0#2*%
\fi \fi }

\def \a@putkasra #1{% modification at kasra                     % m1
\ifcase 0#1\put@kasra  \or \put@k@sra \put@shadda            \or
\put@ihamza \put@kasra \or \put@k@sra \put@hamza \put@shadda \or
\put@madda \put@kasra  \or \put@hamzalo \put@kasra           \or
\fi }

\def \a@putkasratan #1{% modification at kasratan               % m1
\ifcase 0#1\put@kasratan  \or \put@k@sratan \put@shadda \or
\put@ihamza \put@kasratan \or \put@k@sratan \put@hamza \put@shadda \or
\put@madda \put@kasratan  \or \put@hamzalo \put@kasratan           \or
\fi }

\def \put@k@sra {% high or low
\ifk@sra \put@kasra \else \put@fatha \fi }

\def \put@k@sratan {% high or low
\ifk@sra \put@kasratan \else \put@fathatan \fi }

\def \put@voc #1*{% put .harakAt                                % m2
\ifcase 0#1\relax \or \put@sukun    \or \put@fatha     \or \put@kasra     \or
\put@damma        \or \put@fathatan \or \put@kasratan  \or \put@dammatan  \or
\put@zwarakay     \or \put@wasla    \or \put@fathaspec \or \put@kasraspec \or
\put@ammad \or \put@fatha\put@kasra \or \put@barslo    \or \put@kh@hamza  \or
\put@kl@hamza     \or\put@kh@hamz@s \or \put@kl@hamz@s \or
\fi }

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

\def \put@ihamza {% hamza at <i> depending on carrier
\ifnum \act@cd = \a@alif@iso     \put@hamzalo \else
\ifnum \act@cd = \a@alif@end     \put@hamzalo \else
\ifnum \act@cd = \a@lam@alif@iso \put@hamzalo \else
\ifnum \act@cd = \a@lam@alif@end \put@hamzalo \else
   \put@hamza
\fi\fi\fi\fi }

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

\def \a@one@up {\char \a@one@dot@up }

\def \a@two@up {\char \a@two@dots@up }

\def \a@twov@up {\setbox0 \hbox {\char \a@one@dot@up }%
\setbox2 \hbox {\char \a@one@dot@up }\dimen@ .6\ht2 
\advance \dimen@ -.4\dp0 \ht2 \dimen@ \advance \dimen@ \dp0
\vbox {\moveright \a@slant\dimen@ \box0 \nointerlineskip \box2 }}

\def \a@three@up {\char \a@three@dots@up }

\def \a@threev@up {\setbox0 \hbox {\char \a@three@dots@down }%
\ht0 \dp0 \dp0 .5\dp0 \box0 }

\def \a@four@up {\setbox0 \hbox {\char \a@two@dots@up }%
\setbox2 \hbox {\char \a@two@dots@up }\dimen@ .6\ht2 
\advance \dimen@ -.4\dp0 \ht2 \dimen@ \advance \dimen@ \dp0
\vbox {\moveright \a@slant\dimen@ \box0 \nointerlineskip \box2 }}

\def \a@hamza@up {\setbox0 \hbox {\char \a@hamza }%
\dp0 -\ht0 \box0 }

\def \a@alif@up {\char \a@quran@alif }

\def \a@ttah@up {\char \a@ttah@dia }

\def \a@bow@up {\char\a@bow@dia }

\def \a@madda@up {\setbox0 \hbox {\char \a@madda \kern .02em}\box0 }

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

\def \a@one@down {\char \a@one@dot@down }

\def \a@two@down {\char \a@two@dots@down }

\def \a@twov@down {\setbox2 \hbox {\char \a@one@dot@down }%
\setbox0 \hbox {\char \a@two@dots@down }\dimen@ .6\dp0 
\setbox0 \hbox {\char \a@one@dot@down }% correct depth
\advance \dimen@ -.4\ht2 \dp0 \dimen@ \advance \dimen@ \ht2
\vbox {\moveright \a@slant\dimen@ \box0 \nointerlineskip \box2 }}

\def \a@three@down {\setbox0 \hbox {\char \a@three@dots@down }%
\dp0 .7\dp0 \box0 }

\def \a@four@down {\setbox0 \hbox {\char \a@two@dots@down }%
\setbox2 \hbox {\char \a@two@dots@down }\dimen@ .6\dp0 
\advance \dimen@ -.4\ht2 \dp0 \dimen@ \advance \dimen@ \ht2
\vbox {\moveright \a@slant\dimen@ \box0 \nointerlineskip \box2 }}

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

\def \put@d@t #1{% evaluate the argument
\edef \t@mp {\nxp\put@dot {#1}}\t@mp }

\def \put@dot #1{% modify character skeleton
\ifcase 0#1%
\relax                  \or                           %  0
%     .       ..      ^       
%  1 ---   2 ---   3 ---   4 ---   5 ---   6 ---
%                             .       ..      v
\put@hi {\a@one@up     }\or                           %  1
\put@hi {\a@two@up     }\or                           %  2
\put@hi {\a@three@up   }\or                           %  3
\put@lo {\a@one@down   }\or                           %  4
\put@lo {\a@two@down   }\or                           %  5
\put@lo {\a@three@down }\or                           %  6
%     c       b               .               u
%  7 ---   8 ---   9 ---  10 ---  11 ---  12 ---
%                     :       .       6   
\put@hi {\a@hamza@up   }\or                           %  7
\put@hi {\a@ttah@up    }\or                           %  8
\put@lo {\a@twov@down  }\or                           %  9
\put@hi {\a@one@up     }\put@lo {\a@one@down }\or     % 10
\put@lo {\char\a@h@dia }\or                           % 11
\put@hi {\a@bow@up     }\or                           % 12
%             u       :       v       ::
% 13 ---  14 ---  15 ---  16 ---  17 ---  18 ---
%     u       ..                              ::
\put@lo {\a@bow@up     }\or                           % 13
\put@lo {\a@two@down   }\put@hi {\a@bow@up }\or       % 14
\put@hi {\a@twov@up    }\or                           % 15
\put@hi {\a@threev@up  }\or                           % 16
\put@hi {\a@four@up    }\or                           % 17
\put@lo {\a@four@down  }\or                           % 18
%     9       |       b       ^       .       ^
% 19 ---  20 ---  21 ---  22 ---  23 ---  24 ---
%                     .       v       v       .
\put@hi {\char\a@damma }\or                           % 19
\put@hi {\a@alif@up    }\or                           % 20
\put@hi {\a@ttah@up    }\put@lo {\a@one@down   }\or   % 21
\put@hi {\a@three@up   }\put@lo {\a@three@down }\or   % 22
\put@hi {\a@one@up     }\put@lo {\a@three@down }\or   % 23
\put@hi {\a@three@up   }\put@lo {\a@one@down   }\or   % 24
%     ^               C                        
% 25 ---  26 ---  27 ---  28 ---  29 ---  30 ---
%             H               C              
%
\put@hi {\char\a@roof  }\or                           % 25
\put@lo {\char\a@bars  }\or                           % 26
\put@hi {\char\a@hamz@s}\or                           % 27
\put@lo {\char\a@hamz@s}\or                           % 28
      \put@hi {\char 2 }\or                           % illegal
\else \put@hi {\char 2 }\or                           % illegal
\fi}

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

\def \put@hi #1{% deposit upper modifier, slanted
\setbox\dia@box \hbox to \z@ {\hss #1\hss }%
\dia@dy \a@ht \hi@dia \put@upper }

\def \put@acc@hi #1{% deposit upper accent
\ifacc@hi \a@adj@hi \acc@hi \fi 
\setbox\dia@box \hbox to \z@ {\hss #1\hss }%
\dia@dy \a@ht \a@ubox@u \put@upper }

\def \put@lo #1{% deposit lower modifier, slanted
\setbox\dia@box \hbox to \z@ {\hss #1\hss }%
\a@adj@lo \a@min@dp \dia@dy \a@dp \lo@dia \put@lower }

\def \put@acc@lo #1{% deposit lower accent
\ifacc@hi \a@adj@lo \acc@lo \fi 
\setbox\dia@box \hbox to \z@ {\hss #1\hss }%
\dia@dy \a@dp \a@lbox@d \put@lower }

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

\def \hi@dia {% position of upper diacritic
\ifcase \dia@mod \relax 
\a@ubox@u \or \a@ubox@d \or \a@ubox@u \or 
\a@ubox@d \or \a@ubox@u \or \a@ubox@d \or
\a@ubox@c \or \a@ubox@c \or \a@ubox@c \or
\fi }

\def \lo@dia {% position of lower diacritic
\ifcase \dia@mod \relax 
\a@lbox@d \or \a@lbox@d \or \a@lbox@u \or 
\a@lbox@u \or \a@lbox@c \or \a@lbox@c \or
\a@lbox@d \or \a@lbox@u \or \a@lbox@c \fi }

\def \a@adj@hi #1{% adjustment of box height
\dimen@ #1\advance\dimen@ -\a@disp
\ifdim \dimen@ > \a@ht \advance\dimen@ -\a@ht 
  \global\advance\a@ht \dimen@ \global\setbox\ab@x \vbox 
  {\kern\dimen@ \nointerlineskip
  \ifvbox\ab@x \unvbox\ab@x \else \box\ab@x \fi }\fi }

\def \a@adj@lo #1{% adjustment of box depth
\dimen@ #1\advance\dimen@ \a@disp
\ifdim \dimen@ > \a@dp \advance\dimen@ -\a@dp 
  \global\advance\a@dp \dimen@ \global\setbox\ab@x \vbox
  {\ifvbox\ab@x \unvbox\ab@x \else \box\ab@x \fi
  \nointerlineskip \kern\dimen@ }\fi }

\def \a@ubox@u {% upper box above
\dimen@ \ht\dia@box \advance\dimen@ \dp\dia@box 
\advance\dia@dy .5\dimen@ \global\advance \a@ht \dimen@ }

\def \a@ubox@d {% upper box lowered
\dimen@ \ht\dia@box \advance\dimen@ \dp\dia@box 
\advance\dia@dy -.5\dimen@ \dp\dia@box -\ht\dia@box }

\def \a@ubox@c {% upper box centered
\dimen@ .5\ht\dia@box \advance\dimen@ .5\dp\dia@box 
\global\advance \a@ht  \dimen@
\advance\dimen@ -\ht\dia@box \dp\dia@box \dimen@ }

\def \a@lbox@d {% lower box below
\dimen@ \ht\dia@box \advance\dimen@ \dp\dia@box 
\advance \dia@dy .5\dimen@ \global\advance \a@dp \dimen@ }

\def \a@lbox@u {% lower box raised
\dimen@ \ht\dia@box \advance\dimen@ \dp\dia@box
\advance \dia@dy -.5\dimen@ \ht\dia@box -\dp\dia@box }

\def \a@lbox@c {% lower box centered
\dimen@ \ht\dia@box \advance\dimen@ \dp\dia@box
\advance \dia@dy -.5\dimen@ \advance \dia@dy -.75\a@dp
\advance\dimen@ -2\ht\dia@box \advance\dimen@ 1.5\a@dp
\dp\dia@box .4\dimen@ \ht\dia@box -\dp\dia@box }

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

\def \put@upper {\dia@dx \a@slant\dia@dy \advance\dia@dx .5\a@wd 
\advance\dia@dx \dia@hadj\a@dx \global\setbox\ab@x \vbox 
{\moveright\dia@dx \box\dia@box \nointerlineskip
\ifvbox\ab@x \unvbox\ab@x \else \box\ab@x \fi }\wd\ab@x \a@wd }

\def \put@lower {\dia@dx -\a@slant\dia@dy \advance\dia@dx .5\a@wd 
\advance\dia@dx \dia@hadj\a@dx \global\setbox \ab@x \vbox 
{\ifvbox\ab@x \unvbox\ab@x \else \box\ab@x \fi 
\nointerlineskip \moveright\dia@dx \box\dia@box }\wd\ab@x \a@wd }

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

\iffalse 					% cf. aparse.sty
\chardef \c@shadda    = 1    \chardef \c@hamza    = 2
\chardef \c@hamzalow  = 3    \chardef \c@madda    = 4
\chardef \c@high      = 10

\chardef \c@sukun     = 1    \chardef \c@fatha     = 2
\chardef \c@kasra     = 3    \chardef \c@damma     = 4
\chardef \c@fathatan  = 5    \chardef \c@kasratan  = 6
\chardef \c@dammatan  = 7    \chardef \c@zwarakay  = 8
\chardef \c@wasla     = 9    \chardef \c@fathaspec = 10
\chardef \c@kasraspec = 11   \chardef \c@ammad     = 12
\chardef \c@kas@fath  = 13   \chardef \c@bars      = 14
\chardef \c@kh@hamza  = 15   \chardef \c@kl@hamza  = 16
\chardef \c@kh@hamzl  = 17   \chardef \c@kl@hamzl  = 18
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EOF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

