%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% awrite.sty
% ArabTeX
% Ausgabe 14.07.94
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\version = {3.02}  		\datum = {14.07.94}
\message {\the\version }	\message {(\the\datum )}

\edef \arabtexconfig {\arabtexconfig 
awrite.sty \the\version \space (\the\datum) }

\input arabsymb.sty 	     % character definitions

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dynamic definitions for Arabic
{\catcode `\ =9 \catcode `\^^M=9 \catcode `\^^I=9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@arabskel {% define Arabic character skeletons
\globaldefs 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def \sk@a   {\chr@cls 10 \chr@cd \a@alif  \@confalse }	% alif
\def \sk@b   {\chr@cls  1 \chr@cd \a@bah }      	% bah without dot
\def \sk@b@p {\chr@cls  9 \chr@cd \a@bah@p }      	% bah with loop
\def \sk@d   {\chr@cls 10 \chr@cd \a@dal   \@confalse }	% dal
\def \sk@d@p {\chr@cls 10 \chr@cd \a@dal@p \@confalse }	% dal with loop
\def \sk@dd  {\chr@cls  2 \chr@cd \a@dad }		% ddad
\def \sk@f   {\chr@cls  6 \chr@cd \a@fah }      	% fah 
\def \sk@f@s {\chr@cls  6 \chr@cd \a@fah@s }    	% fah without dot
\def \sk@g@p {\chr@cls  5 \chr@cd \a@kaf@p@s }  	% gaf with loop
\def \sk@g@s {\chr@cls  5 \chr@cd \a@gaf@s }    	% gaf with bar
\def \sk@h   {\chr@cls 10 \chr@cd \a@hah }      	% hah
\def \sk@h@s {\chr@cls 10 \chr@cd \a@hah@spec }		% urdu hah
\def \sk@hh  {\chr@cls  3 \chr@cd \a@hhah }		% hhah
\def \sk@j   {\chr@cls  3 \chr@cd \a@gim }		% gim
\def \sk@k   {\chr@cls  5 \chr@cd \a@kaf }      	% kaf
\def \sk@k@s {\chr@cls  5 \chr@cd \a@kaf@s }    	% kaf without mark
\def \sk@kh  {\chr@cls  3 \chr@cd \a@khah }		% khah
\def \sk@l   {\chr@cls  0 \chr@cd \a@lam }      	% lam
\def \sk@m   {\chr@cls 10 \chr@cd \a@mim }      	% mim
\def \sk@n   {\chr@cls  1 \chr@cd \a@nun }      	% nun without dot
\def \sk@n@p {\chr@cls  9 \chr@cd \a@nun@p }		% nun with loop
\def \sk@q   {\chr@cls  6 \chr@cd \a@qaf } 		% qaf
\def \sk@r   {\chr@cls  8 \chr@cd \a@rah   \@confalse }	% rah
\def \sk@r@p {\chr@cls  8 \chr@cd \a@rah@p \@confalse }	% rah with loop
\def \sk@r@s {\chr@cls  8 \chr@cd \a@rah@s \@confalse }	% rah with two dots
\def \sk@s   {\chr@cls  2 \chr@cd \a@sin }      	% sin
\def \sk@s@p {\chr@cls  2 \chr@cd \a@sin@p }      	% sin with two dots
\def \sk@sh  {\chr@cls  2 \chr@cd \a@shin }     	% shin
\def \sk@ss  {\chr@cls  2 \chr@cd \a@sad }		% ssad
\def \sk@ts  {\chr@cls  3 \chr@cd \a@tsah }		% tchah
\def \sk@tt  {\chr@cls  7 \chr@cd \a@ttah }		% ttah
\def \sk@v   {\chr@cls  6 \chr@cd \a@vah }		% vah
\def \sk@w   {\chr@cls 10 \chr@cd \a@waw   \@confalse }	% waw
\def \sk@y   {\chr@cls  1 \chr@cd \a@yah } 		% yah
\def \sk@y@h {\chr@cls  1 \chr@cd \a@yah@h }  		% yah with stroke
\def \sk@y@p {\chr@cls  1 \chr@cd \a@yah@p } 		% yah bari
\def \sk@z   {\chr@cls  8 \chr@cd \a@zay   \@confalse }	% zay
\def \sk@zh  {\chr@cls  8 \chr@cd \a@zhah  \@confalse }	% zhah
\def \sk@zz  {\chr@cls  7 \chr@cd \a@zzah }		% zzah

\def \sk@B   {\chr@cls 10 \chr@cd \a@tatwil }		% tatwil
\def \sk@P   {\chr@cls  4 \chr@cd \a@ain }		% `ain
\def \sk@Q   {\chr@cls 10 \chr@cd \a@hamza@iso \@confalse}% hamza
\def \sk@W   {\chr@cls 10 \chr@cd \a@break \@confalse }	% small space

\def \sk@@   {\chr@cls 10 \chr@cd `* }			% star
\globaldefs 0 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@arabchars {% define character macros for Arabic
\globaldefs 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def \tc@a {\sk@a }			% alif
\def \tc@b {\sk@b 	\chr@mod    4 }	% bah
\def \tc@c {\sk@hh 	\chr@mod    7 }	% gim with hamza
\def \tc@d {\sk@d }    			% dal
\def \tc@f {\sk@f 	\chr@mod    1 }	% fah
\def \tc@g {\sk@g@s }			% gaf with bar
\def \tc@h {\sk@h }                 	% hah
\def \tc@j {\sk@zh }    		% zhah
\def \tc@k {\sk@k }			% kaf
\def \tc@l {\sk@l }                 	% lam
\def \tc@m {\sk@m }                 	% mim
\def \tc@n {\sk@n 	\chr@mod    1 }	% nun
\def \tc@p {\sk@b 	\chr@mod    6 } % pah
\def \tc@q {\sk@q	\chr@mod    2 }	% qaf
\def \tc@r {\sk@r }    			% rah
\def \tc@s {\sk@s }                 	% sin
\def \tc@t {\sk@b 	\chr@mod    2 } % tah
\def \tc@v {\sk@v	\chr@mod    3 }	% vah
\def \tc@w {\sk@w }    			% waw
\def \tc@x {\sk@sh }                	% shin
\def \tc@y {\sk@y 	\chr@mod    5 } % yah
\def \tc@z {\sk@z }    			% zay

\def \tc@A {\sk@a }			% alif also
\def \tc@B {\sk@B }              	% tatwil
\def \tc@C {\sk@b 	\chr@mod    3 }	% thah
\def \tc@D {\sk@dd }                 	% ddad
\def \tc@E {\sk@y@p	\chr@mod    5 }	% yah bari
\def \tc@F {\sk@d 	\chr@mod    1 }	% dhal
\def \tc@G {\sk@j 	\chr@mod    4 }	% gim
\def \tc@H {\sk@hh }  			% hhah
\def \tc@J {\sk@ts 	\chr@mod    6 } % tchah
\def \tc@K {\sk@k@s 	\chr@mod    3 } % kaf-i-nun
\def \tc@L {\sk@y@h }  			% yah with stroke
\def \tc@P {\sk@P }			% `ain
\def \tc@Q {\sk@Q }			% hamza
\def \tc@R {\sk@P 	\chr@mod    1 }	% ghain
\def \tc@S {\sk@ss }                 	% ssad
\def \tc@T {\sk@h 	\chr@mod    2 }	% tah marbuta
\def \tc@V {\sk@tt }                	% ttah
\def \tc@W {\sk@W }    			% small space
\def \tc@X {\sk@kh 	\chr@mod    1 } % khah
\def \tc@Y {\sk@y }  			% alif maqsura
\def \tc@Z {\sk@zz }                	% zzah

\tc@def \a@b {\sk@b }			% bah without dot
\tc@def \a@c {\sk@hh	\chr@mod    3 }	% gim with three dots
\tc@def \a@d {\sk@d	\chr@mod    8 }	% dal with ttah
\tc@def \a@e {\sk@d@p }			% dal with loop
\tc@def \a@f {\sk@f@s }			% fah without dot
\tc@def \a@g {\sk@g@p }		  	% gaf with loop
\tc@def \a@h {\sk@h@s	\chr@mod   11 } % urdu hah
\tc@def \a@k {\sk@k@s }			% kaf without mark
\tc@def \a@l {\sk@l 	\chr@mod   12 }	% kurdish lam
\tc@def \a@m {\sk@k }			% kaf
\tc@def \a@n {\sk@n	\chr@mod    1 }	% nun without dot
\tc@def \a@p {\sk@P	\chr@mod    3 }	% `ain with three dots
\tc@def \a@q {\sk@r@p }			% rah with loop
\tc@def \a@r {\sk@r	\chr@mod    8 }	% rah with ttah
\tc@def \a@s {\sk@s@p	\chr@mod   10 }	% sin with two dots
\tc@def \a@t {\sk@b 	\chr@mod    8 }	% tah with ttah
\tc@def \a@v {\sk@b@p 	\chr@mod    2 }	% tah with loop
\tc@def \a@y {\sk@y	\chr@mod    6 }	% yah with three dots below
\tc@def \a@z {\sk@r@s }       		% rah with two dots

\tc@def \a@C {\sk@hh 	\chr@mod    2 }	% hhah with two dots above
\tc@def \a@D {\sk@d	\chr@mod    4 }	% dal with dot below
\tc@def \a@E {\sk@y	\chr@mod   14 }	% kurdish yah
\tc@def \a@F {\sk@f@s 	\chr@mod    4 }	% fah with dot below
\tc@def \a@G {\sk@hh 	\chr@mod    5 }	% hhah with two dots below
\tc@def \a@H {\sk@h \@confalse }	% hah marbuta !
\tc@def \a@J {\sk@P 	\chr@mod    1 }	% ghain
\tc@def \a@K {\sk@k@s	\chr@mod    1 }	% kaf with dot
\tc@def \a@L {\sk@k }			% kaf
\tc@def \a@M {\sk@k }			% kaf
\tc@def \a@N {\sk@n@p 	\chr@mod    1 }	% nun with loop
\tc@def \a@Q {\sk@f@s 	\chr@mod    1 }	% fah with one dot above
\tc@def \a@R {\sk@r	\chr@mod   13 }	% kurdish rah
\tc@def \a@S {\sk@s	\chr@mod    2 }	% sin with two dots
\tc@def \a@T {\sk@b	\chr@mod   15 }	% tah with two vert. dots above
\tc@def \a@V {\sk@f@s 	\chr@mod    6 }	% fah with three dots below
\tc@def \a@W {\sk@w	\chr@mod   12 }	% kurdish waw
\tc@def \a@Y {\sk@y 	\chr@mod    9 } % yah with two vert. dots below
\tc@def \a@Z {\sk@s	\chr@mod   15 }	% sin with two dots vertical

\iffalse
\def \tc@e {\sk@@ }	\def \tc@N {\sk@@ }	% reserved
\def \tc@i {\sk@@ }	\def \tc@I {\sk@@ }	% reserved
\def \tc@o {\sk@@ }	\def \tc@O {\sk@@ }	% reserved
\def \tc@u {\sk@@ }	\def \tc@U {\sk@@ }	% reserved

\tc@def \a@a {\sk@@ }	\tc@def \a@i {\sk@@ }	% reserved
\tc@def \a@o {\sk@@ }	\tc@def \a@u {\sk@@ }	% reserved
\tc@def \a@A {\sk@@ }	\tc@def \a@I {\sk@@ }	% reserved
\tc@def \a@O {\sk@@ }	\tc@def \a@U {\sk@@ }	% reserved
\fi
\globaldefs 0 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@arabaccent {% define accent macros for Arabic
\globaldefs 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def \put@accent ##1+##2*{% put modifier onto contents of "\ab@x"
% m1 + m2 *
  \global\red@mod   ##1 \relax
  \ifnum ##1 > 9 \global\advance \red@mod -10 \fi
\relax
\ifnum ##2 = \c@kasra    \a@putkasra    \red@mod \else
\ifnum ##2 = \c@kasratan \a@putkasratan \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 ##2*%
\fi \fi }

\def \put@fatha     {\put@acc@hi {\char \a@fatha     }}
\def \put@damma     {\put@acc@hi {\char \a@damma     }}
\def \put@kasra     {\put@acc@lo {\char \a@kasra     }}
\def \put@shadda    {\put@hi     {\char \a@shadda    }}
\def \put@hamza     {\put@hi     {\char \a@hamza     }}
\def \put@hamzalo   {\put@lo     {\char \a@hamza     }}
\def \put@sukun     {\put@acc@hi {\char \a@sukun     }}
\def \put@madda     {\put@acc@hi {\char \a@madda     }}
\def \put@wasla     {\put@acc@hi {\char \a@wasla     }}
\def \put@fathatan  {\put@acc@hi {\char \a@fathatan  }}
\def \put@dammatan  {\put@acc@hi {\char \a@dammatan  }}
\def \put@kasratan  {\put@acc@lo {\char \a@kasratan  }}
\def \put@fathaspec {\put@acc@hi {\char \a@quran@alif}}
\def \put@kasraspec {\put@acc@lo {\char \a@quran@alif}}
\def \put@ammad     {\put@acc@hi {\char \a@ammad     }}
\def \put@zwarakay  {\put@acc@hi {\char \a@zwarakay  }}
\globaldefs 0 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}% end of dynamic definitions for Arabic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif \if@con        	\newif \if@mod        	\newif \if@raise   
\newif \if@tie        	\newif \if@raisetie   	\newif \if@tat
\newif \if@uptie      	\newif \if@high@chr   	\newif \if@tatl
\newif \ifa@kern	\newif \ifa@@write  	\a@@writetrue

\newcount \chr@cd     \newcount \act@cd     \newcount \chr@tie
\newcount \act@tie    \newcount \chr@mod    \newcount \act@mod
\newcount \chr@cls    \newcount \act@cls    \newcount \red@mod
\newcount \old@cls

\newdimen \a@dp       \newdimen \a@ht       \newdimen \a@wd    
\newdimen \a@disp     \newdimen \a@dim      \newdimen \a@acc
\newdimen \a@tat@ht

\newbox \ab@x         \newbox \lig@box       

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

% Arabic kerning
\def \a@kern   {\kern 0.05em }	\def \a@mkern  {\kern -0.05em }

% shift for raised characters
\def \a@dsp    {.5ex }

% fixed positions for .harakAt
\def \acc@hi   {1.8ex }		\def \acc@lo   {0.4ex }

% kashida dimensions
\def \tat@ht   {0.20ex }	\def \tat@wd   {0.02ex }
\def \tat@skip {0.04ex plus .5ex }

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

\def \a@@write #1>{% Arabic output
\iftest@write \iftest@parse \else
\a@verb (#1 )>\fi
\tracingmacros   1 \fi
\a@write@hook
\ifa@@write \aw@beg #1>0+0*>0+0*>\fi
\iftest@write \tracingmacros   0 \fi }

\let \a@write \a@@write		\let \a@write@hook \relax

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

\def \aw@beg #1#2*#3#4*#5{% start output
% c m * c m * c
   \global\@highfalse \@raisefalse \@tiefalse \a@norm \leavevmode
   \test@chr #1\def \next {\aw@end #1#2*#3#4*#5}%
\ifx #1-\test@chr #3\chr@fam #3%
   \def \next {\aw@mid #3#4*#5}%
   \ifx #3>\ac@other #1#3%
\fi\fi \next }

\def \aw@end #1#2*#3#4*#5{% character is not joined to the left
% c m * c m * c
\ifx #1>\let \next \relax \else
\ifx #1-\test@chr #3\chr@fam #3%
   \def \next {\aw@end #3#4*#5}%
\else \a@shift \test@chr #3%
   \ifcat #1-\ac@other #1#3\def \next {\aw@end #3#4*#5}%
   \else \a@kern
      \ifx #1Q\@confalse \fi
      \ifx #1W\@confalse \fi
      \chr@fam #3%
      \ifx #1a\def \next {\alif@lig #2*#3#4*#5}%
      \else \ifx #1h\hah@end #3#4*#5\else
            \ifx #1T\hah@end #3#4*#5\else
               \aw@endligs #1#2*#3#5%
            \fi\fi
            \ifx #1w\under@cut #2*\else
            \ifnum \act@cls = \rah@cls \under@cut #2*\else % rzj
            \ifnum \act@cd = \a@hah \a@kern               	% ++++
            \fi\fi\fi
         \put@end #2*#3#4*#5<%
      \fi
   \fi
\fi\fi \next }

\def \aw@mid #1#2*#3#4*#5{% character is joined to the left
% c m * c m * c
\ifx #1>\let \next \relax \else
\ifx #1-\test@chr #3\chr@fam #3%
   \def \next {\aw@mid #3#4*#5}%
\else
   \a@shift \old@cls   \act@cls \test@chr #3%
      \chr@fam #3%
          \aw@midligs #1#2*#3#5%
   \put@mid #2*#3#4*#5<%
   \if@con \else % initial shape
      \ifnum \old@cls = \kaf@cls % kaf etc.
      \ifx #3a\else \ifx #3l\else
         \unkern \a@mkern
      \fi\fi\fi
   \fi
\fi\fi \next }

\def \under@cut #1+#2*{% if no upper diacritic		% m21 + m22 *
\ifdim \a@dp > .5ex \a@kernfalse 
\else \a@kerntrue \global\red@mod   #1 \relax
    \ifnum #1 > 9 \global\advance \red@mod -10 \fi
  \ifnum \red@mod = 0 \else \ifnum \red@mod = 5 \else \a@kernfalse 
  \fi\fi
  \ifnum #2 = 0 \else \ifnum #2 = 3 \else
  \ifnum #2 = 6 \else \ifnum #2 = 11 \else \a@kernfalse 
  \fi\fi\fi\fi
\fi \ifa@kern \unkern \a@mkern \fi }

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

\def \put@end #1*#2<{% deposit non-joining character, set new state
% m * c m * c <
\if@con \ac@end #1*\def \next {\aw@mid #2}%
 \else  \ac@iso #1*\def \next {\aw@end #2}%
\fi }

\def \put@mid #1*#2<{% deposit joining character, set new state
% m * c m * c <
\if@con \ac@mid #1*\def \next {\aw@mid #2}%
 \else  \ac@beg #1*\def \next {\aw@end #2}%
\fi }

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

\def \ac@other #1#2{% punctuation mark			% c1 c2
\ifx #1)(\else \ifx #1][\else 
\ifx #1`\char \a@lquotes \else 
\ifx #1()\else \ifx #1[]\else
\ifx #1'\char \a@rquotes \else
#1%
\fi\fi\fi\fi\fi\fi 
\ifx #2>\else \arab@space % at the end of the word
\fi }

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

\def \ac@iso #1*{% isolated shape			% m *
\put@chr \put@mod #1*\a@norm } % Grundstellung

\def \ac@beg #1*{% initial shape			% m *
\advance \act@cd \a@f@beg \put@chr \put@mod #1*\a@norm }

\def \ac@mid #1*{% medial shape				% m *
\advance \act@cd \a@f@mid \put@chr \put@mod #1*}

\def \ac@end #1*{% final shape  			% m *
\advance \act@cd \a@f@end \put@chr \put@mod #1*}

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

\def \put@mod #1*{% deposit character, modifiers and ties	% m *
\if@tie \put@tie \@tiefalse \fi
\put@accent #1*\dep@sitb@x
\if@high@chr \advance \a@disp -\a@dsp \@high@chrfalse \fi
\a@ital {\act@cd }\@raisefalse
\if@tat \put@tat \@tatfalse \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@tie {% ties between characters
\ifdim \a@disp = \z@ \char \the\act@tie
\else \raise \a@disp \hbox {\char \the\act@tie }%
\fi \a@ital {\act@tie }}

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

\def \a@norm {% start a new character group
\a@disp   \z@ \@high@chrfalse }

\def \a@ital #1{% shifting char: displace \a@disp by italcorr
\setbox0 \hbox {\char \the #1\/}\advance \a@disp \wd0
\setbox0 \hbox {\char \the #1}\advance \a@disp -\wd0 }

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

\def \a@putkasra #1{% modification at kasra			% m1
\ifcase #1\put@kasra	\or \put@fatha \put@shadda 		\or
\put@ihamza \put@kasra	\or \put@fatha \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 #1\put@kasratan	  \or \put@fathatan \put@shadda  	   \or
\put@ihamza \put@kasratan \or \put@fathatan \put@hamza \put@shadda \or
\put@madda \put@kasratan  \or \put@hamzalo \put@kasratan 	   \or
\fi }

\def \put@voc #1*{% put .harakAt				% m2
\ifcase #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
\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 \put@dot #1{% modify character skeleton
\ifcase #1%
\relax				   \or	 %  0
\put@hi {\char \a@one@dot@up      }\or   %  1
\put@hi {\char \a@two@dots@up     }\or   %  2
\put@hi {\char \a@three@dots@up   }\or   %  3
\put@lo {\char \a@one@dot@down    }\or   %  4
\put@lo {\char \a@two@dots@down   }\or   %  5
\put@lo {\char \a@three@dots@down }\or   %  6
\put@hi {\char \a@hamza           }\or   %  7
\put@hi {\char \a@ttah@dia        }\or   %  8
\put@lo {\char \a@one@dot@down }%
  \put@lo {\char \a@one@dot@down  }\or   %  9
\put@hi {\char \a@one@dot@up }%
  \put@lo {\char \a@one@dot@down  }\or   % 10
\put@lo {\char \a@h@dia           }\or   % 11
\put@hi {\char \a@bow@dia         }\or   % 12
\put@lo {\char \a@bow@dia         }\or   % 13
\put@lo {\char \a@two@dots@down }%
  \put@hi {\char \a@bow@dia       }\or   % 14
\put@hi {\char \a@one@dot@down }%
  \put@hi {\char \a@one@dot@down  }\or   % 15
\fi}

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

\def \put@box #1{\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 }

\def \put@acc@hi {% upper accent
\ifacc@hi \a@acc \acc@hi \advance \a@acc -\a@disp
\ifdim \a@acc > \a@ht
  \advance \a@acc -\a@ht \global\advance \a@ht \a@acc
  \global\setbox \ab@x   \vbox {\kern \a@acc \nointerlineskip
  \ifvbox \ab@x \unvbox \ab@x \else \box \ab@x \fi }%
\fi\fi \put@hi }

\def \put@acc@lo {% lower accent
\ifacc@hi \a@acc \acc@lo \advance \a@acc \a@disp
\ifdim \a@acc > \a@dp
  \advance \a@acc -\a@dp \global\advance \a@dp \a@acc
  \global\setbox \ab@x   \vbox
  {\ifvbox \ab@x \unvbox \ab@x \else \box \ab@x \fi
  \nointerlineskip \kern \a@acc }%
\fi\fi \put@lo }

\def \put@hi #1{% upper modifier
\setbox0 \hbox to\a@wd {\hss #1\hss }%
\global\advance \a@ht \ht0 \global\advance \a@ht \dp0 
\global\setbox \ab@x   \vbox {\box0 \nointerlineskip
\ifvbox \ab@x \unvbox \ab@x \else \box \ab@x \fi }}

\def \put@lo #1{% lower modifier
\setbox0 \hbox to\a@wd {\hss #1\hss }%
\global\advance \a@dp \ht0 \global\advance \a@dp \dp0 
\global\setbox \ab@x   \vbox 
{\ifvbox \ab@x \unvbox \ab@x \else \box \ab@x \fi 
\nointerlineskip \box0 }}

\def \a@lig #1*#2*{% deposit a ligature
% m * m *
\setbox \lig@box \hbox {\char \the\act@cd }%
\global\a@wd   \wd \lig@box  \global\divide \a@wd 2   
\let \if@tatl \if@tat \@tatfalse
\global\setbox \ab@x   \vbox {\hbox to\a@wd {\unhcopy \lig@box \hss }}%
\global\a@ht   \ht \lig@box  \global\a@dp   \dp \lig@box \put@mod #1*%
\let \if@tat \if@tatl
\global\setbox \ab@x   \vbox {\hbox to\a@wd {\hss \unhcopy \lig@box }}%
\global\a@ht   \ht \lig@box  \global\a@dp   \dp \lig@box \put@mod #2*}

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

\def \a@shift {% go to next position
\act@cd \chr@cd \act@mod \chr@mod \act@cls \chr@cls \act@tie \chr@tie
  \if@raisetie \@uptietrue \@raisetiefalse \else \@uptiefalse \fi
\ifnum \act@tie = 0 \@tiefalse
\else \advance \act@tie \a@f@mid \@tietrue
\fi
\if@mod \@modfalse % deposit character from family
      \def \put@chr
      {\put@box {\char \the\act@cd }\put@dot \act@mod \global\@highfalse }%
\else \def \put@chr {\put@box {\char \the\act@cd }}% 
\fi }

\def \set@high@chr {% raise actual character
\advance \a@disp \a@dsp \@high@chrtrue }

\def \set@mod@chr {% aktuelles Zeichen aus Familie setzen
 \def \put@chr {\put@box {\char \the\act@cd }\put@dot \act@mod }}

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

\def \test@chr #1{% get character attributes
    \chr@mod   0 \chr@cls   \other@cls \chr@tie   0 \@confalse
\ifx #1-\chr@cd   \a@tatwil \@contrue \else
\ifx #1|\chr@cd   \a@space@spec \@contrue \else
\if \nxp #1\relax \a@test #1\else
\ifcat #1a\a@test #1%
\fi\fi\fi\fi }

\def \a@test #1{% switch to character routine
\xpa \ifx \csname tc@\string #1\endcsname \relax
    \chr@cls   \other@cls \chr@cd   \a@block
\else \@contrue \csname tc@\string #1\endcsname \relax % numbers!
\fi }

\def \tc@def #1#2{% define \tc@#1 as {#2}
\xpa \gdef \csname tc@\string #1\endcsname {#2}}

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

\chardef \bah@cls   1	\chardef \gim@cls   3	\chardef \kaf@cls   5  
\chardef \rah@cls   8  	\chardef \other@cls   10

\chardef \a@zwarakay   \a@e@dia

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