%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% aligs.sty
% Ligatures 18.03.96
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\a@ident {aligs.sty} {3.04 compute ligatures} {18.03.96}

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

\def \aw@endligs #1#2*#3#4{% test for final ligatures
% c1 m1 * c2 c3
\ifcase \act@cls 
     \lam@lig #3#4% % 0 l
\or \test@in@list #1YyKL\a@E \a@y \a@Y >%	% 1 YntCbyp
	\ifin@list \yah@end #1#3#4\else
	\ifx #1E\yah@p@end #3#4\else
		\test@in@list #1nM\a@N \a@n >%
	\ifin@list \nun@end #1#3#4\else 
		\bah@end #1%
	\fi\fi\fi
\or \sin@lig #1#4%              		% 2 sxSD
\or \gim@lig #1#3#4%            		% 3 GHXJ
\or \global\@highfalse \set@mod@chr \put@tatwil % 4 cR
\or \kaf@end #3#4%              		% 5 kgM 
\or \fah@end #1%                		% 6 fqv
\or \sin@lig #1#4%              		% 7 VZ
\or \rah@end #1#2*#3#4%         		% 8 rzj \a@r \a@R
\or 	\ifx #1\a@n \nun@end #1#3#4\else	% 9 \a@t \a@n
	\ifx #1\a@N \nun@end #1#3#4\else \bah@end #1%
	\fi\fi
\else \global\@highfalse			% 10 ...
	\ifx #1\a@h \hah@urd #3%
	\else \set@mod@chr
		\ifx #1m\mim@end #2*#3#4\else
		\ifx #1d\gim@test #4\put@tatwil \else
		\ifx #1F\gim@test #4\put@tatwil \else \put@tatwil 
		\fi\fi\fi
	\fi
\fi }

%%%%%%%%%%%%%%%%%%%%%%% alif %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \alif@lig #1*#2#3*#4{% alif, test for ligature
% m * c m * c
\global\@highfalse
\ifx #2l\def \next {\lam@alif #1*#3*#4}\else
\gim@kaf@test #2#4%
\put@end #1*#2#3*#4<%
\fi \next }

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

\def \lam@alif #1*#2*#3#4*#5{% ligature lam-alif
% m * m * c m * c
\global\@highfalse \a@shift \test@chr #3\chr@fam #3%
\if@con \act@cd = \a@lam@alif@end \def \next {\aw@mid #3#4*#5}%
  \else \act@cd = \a@lam@alif@iso \def \next {\aw@end #3#4*#5}%
\fi
  \gim@kaf@test #3#5%
\a@lig #1*#2*% deposit the ligature ( -> awrite.sty )
\next }

%%%%%%%%%%%%%%%%%%%%%%% bah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \bah@end #1{% bah skeleton
% c1
\ifnum \act@cls = 1 % YntCbyp
   \act@cd = \a@bah@s
\else \act@cd = \a@bah@p 
\fi
\put@tatwil \set@mod@chr \global\@hightrue }

%%%%%%%%%%%%%%%%%%%%%%% gim %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \gim@lig #1#2#3{% gim, hhah, khah, tchah
% c1 c2 c3
   \test@in@list #1c\a@c \a@C \a@G >%
   \ifin@list \set@mod@chr \fi
   \test@end@char #3%
\ifend@char \gim@one #1#2#3\else \gim@more #1#2#3%
\fi }

\def \gim@one #1#2#3{% gim, hhah, khah, tchah
% and one char
% c1 c2 c3
%\ifligs
\ifcase \chr@cls            
    \act@gim #1\chr@tie = \a@lam@on@gim 	% 0 l
	\chr@cd = \a@space@spec
\or \act@gim #1\chr@tie = \a@g@to@bb 		% 1 YntCbyp
	\chr@cd = \a@space@spec 
\or \act@gim #1\chr@tie = \a@g@to@s 		% 2 sxSD
	\chr@sin #2\@raisetietrue
\or \act@gim #1%				% 3 GHXJ
\or % \act@gim #1%				% 4 cR
\or \act@gim #1%				% 5 kgM
\or \act@gim #1%				% 6 fqv
\else \ifx #2m\act@gim #1\chr@cd = \a@mim@spec \else \put@tatwil 
      \fi
%\fi
\fi }

\def \gim@more #1#2#3{% gim, hhah, khah, tchah
% and more than one char
% c1 c2 c3
\ifligs
\ifcase \chr@cls            
    \act@gim #1\chr@cd = \a@lam@spec@yah 	% 0 l
\or \act@gim #1\chr@tie = \a@g@to@mb 		% 1 YntCbyp
	\chr@cd = \a@bah@spec@yah
\or \act@gim #1\chr@tie = \a@g@to@s 		% 2 sxSD
	\chr@sin #2\@raisetietrue
\or % \act@gim #1%				% 3 GHXJ
\or % \act@gim #1%				% 4 cR
\or \act@gim #1%				% 5 kgM
\else \ifx #2m\ifx #3l\act@gim #1\chr@cd = \a@mim@lam@gim 
      \fi\fi
\fi
\fi }

%%%%%%%%%%%%%%%%%%%%%% sin %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \sin@lig #1#2{% sin, shin, ssad, ddad, ttah, tthah, \a@s
% c1 c3
\put@tatwil 
\ifx #1\a@S \set@mod@chr \else
\ifx #1\a@Z \set@mod@chr \else
\fi\fi
\ifnum \chr@cls = 1 % YntCbyp
       \test@end@char #2%
   \ifend@char \chr@cd = \a@bah@high \else
   \ifx #1s\chr@cd = \a@bah@high \else
   \ifx #1x\chr@cd = \a@bah@high \else
   \fi\fi\fi
\fi }

%%%%%%%%%%%%%%%%%%%%%% rah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \rah@end #1#2*#3#4{% final r, z, j 
% c1 m1 * c2 c3
\set@mod@chr
\ifcase \chr@cls \put@tatwil 			% 0 l
\or \test@end@char #4%				% 1 YntCbyp
    \ifend@char \else \chr@cd = \a@bah@spec \set@high@chr
    \fi
\or \chr@tie = \a@er@to@s \chr@sin #3%		% 2 sxSD
\or \put@tatwil 				% 3 GHXJ
\or \put@tatwil 				% 4 cR
\or \ifligs 					% 5 kgM
	\ifx #1r\test@updia #2*%
		\if@updia \put@tatwil \else \chr@kaf #3%
		\fi
	\else \put@tatwil 
	\fi
    \else \put@tatwil 
    \fi
\else \put@tatwil 
\fi }

%%%%%%%%%%%%%%%%%%%%%% fah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \fah@end #1{% fah family
% c1
\ifx #1\a@F \set@mod@chr \else
\ifx #1\a@Q \set@mod@chr \else
\ifx #1\a@V \set@mod@chr \else
\fi\fi\fi \global\@highfalse }

%%%%%%%%%%%%%%%%%%%%%% kaf %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \kaf@end #1#2{% kaf family
% c2 c3
\ifnum \act@cd = \a@kaf \gim@kaf@test #1#2%
\fi
\set@mod@chr }

%%%%%%%%%%%%%%%%%%%%%% lam %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \lam@lig #1#2{% lam family
% c2 c3
\global\@highfalse
\ifnum \act@cd = \a@lam@spec@low \else
\set@mod@chr \gim@kaf@test #1#2%
\ifnum \act@cd = \a@lam@spec@yah \@raisetrue
\fi\fi }

%%%%%%%%%%%%%%%%%%%%%% mim %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \mim@end #1*#2#3{% final mIm 
% m1 * c2 c3
\ifcase \chr@cls            		
    \act@cd = \a@mim@spec \test@end@char #3%	% 0 l
 	\ifend@char \else \chr@cd = \a@lam@spec@mim
	\fi
\or \act@cd = \a@mim@spec \test@end@char #3%	% 1 YntCbyp
	\ifend@char \chr@cd = \a@space@spec \chr@tie = \a@em@to@bb
	\else \chr@cd = \a@bah@end@mim
	\fi
\or \act@cd = \a@mim@spec 			% 2 sxSD
	\chr@tie = \a@em@to@s \chr@sin #2%
\or \act@cd = \a@mim@spec			% 3 GHXJ
\or \act@cd = \a@mim@spec			% 4 cR
\or \test@updia #1*% upper diacritic?		% 5 kgM
	\if@updia \put@tatwil 
	\else \act@cd = \a@mim@spec \chr@kaf #2%
	\fi
\or \act@cd = \a@mim@spec			% 6 fqv
\else	\ifx #2h\test@end@char #3%
		\ifend@char \act@cd = \a@mim@spec 
		\else \put@tatwil 
		\fi
	\else
	\ifx #2m\act@cd = \a@mim@spec \test@end@char #3%
		\ifend@char \chr@cd = \a@mim@spec
		\else \chr@cd = \a@mim@spec@high
		\fi
	\else \put@tatwil 
	\fi\fi
\fi }

%%%%%%%%%%%%%%%%%%%%%% nun %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \nun@end #1#2#3{% final nun
% c1 c2 c3
  \global\@highfalse
\ifx #1\a@n \else 
\ifx #1\a@N \else \set@mod@chr
\fi\fi
\ifnum \chr@cls = 1 \test@end@char #3%
	\ifend@char \else
	\chr@cd = \a@bah@spec \set@high@chr
	\fi
\else \put@tatwil 
\fi }

%%%%%%%%%%%%%%%%%%%%%% hah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \hah@end #1#2+#3*#4{% hah, test for ligature
% c2 m21 + m22 * c3
\set@mod@chr \global\@highfalse
\ifurd@ \act@cd = \a@hah@urd \test@end@char #1%
	\ifend@char \else \@raisetrue
	\fi
\else
\ifx #1l\ifx #4l%				% 0 l
	\ifnum #2 = \c@shadda \chr@cd = \a@lam@spec@low    
	% special short form of lam for the Name of God
	\else \put@tatwil 
	\fi                          
	\else \put@tatwil 
	\fi                          
\else 
\ifnum \chr@cls = 1 \chr@cd = \a@bah		% 1 YntCbyp
\else 
\ifnum \chr@cls = 3 				% 3 GHX
	\test@updia #2+#3*% upper diacritic
	\if@updia \chr@tie = \a@tatwil \else \put@tatwil 
	\fi
\else \gim@test #4\put@tatwil 
\fi\fi\fi\fi }

%%%%%%%%%%%%%%%%%%%%%% wavy hah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \hah@urd #1{% wavy hah
% c2 
\test@end@char #1%
  \ifend@char \act@cd = \a@hah
  \fi
\ifnum \chr@cls = 1 % YntCbyp
  \chr@cd = \a@bah
\fi }

%%%%%%%%%%%%%%%%%%%%%% yah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \yah@end #1#2#3{% yah or alif maqsoura
% y/Y/L c2 c3
\ifx #1y\ifyahd@ts \set@mod@chr \fi 
%\else \ifx #1\a@e \act@mod = 12 \fi 
\else \ifx #1\a@Ee \act@mod = 12 \fi 
	\set@mod@chr
\fi
\global\@highfalse \test@end@char #3%
\ifend@char \yah@one #2\else \yah@more #2%
\fi }

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

\def \yah@one #1{% yah or alif maqsoura
% and one char
% c2
\ifcase \chr@cls            % 0 l
   \act@yah \chr@cd = \a@lam@long 
\or                         % 1 YntCbyp
	\ifh@mza \act@yah \chr@cd = \a@bah@spec@yah \else
      	\ifk@fs \act@yah \chr@cd = \a@bah@spec@yah \else    	% ++++
	\ifx #1y\else
	\ifx #1Y\else
		\act@yah \chr@cd = \a@bah@spec@yah
	\fi\fi\fi\fi                                            % ++++
\or                         % 2 sxSD
   \act@yah \chr@tie = \a@em@to@s \chr@sin #1%
\or                         % 3 GHXJ
   \act@yah
\or                         % 4 cR
   \act@yah
\or                         % 5 kgM
%   \act@yah \chr@kaf #1%
   \act@yah 
%\chr@kaf #1%
\or                         % 6 fqv
   \act@yah
\else
%     \ifx #1h\act@yah \else
     \ifx #1m\act@yah \chr@cd = \a@mim@spec \else 
	\put@tatwil 
     \fi
%     \fi
\fi }

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

\def \yah@more #1{% yah or alif maqsoura
% and more than one char
% c2
\ifcase \chr@cls            % 0 l
   \act@yah \chr@cd = \a@lam@spec@yah 
\or                         % 1 YntCbyp
%\ifligs
\ifiz@fet \ifx #1y\else \ifx #1Y\else
            \act@yah \chr@cd = \a@bah@end@mim 
         \fi\fi
      \else \act@yah \chr@cd = \a@bah@end@mim
\fi
%\fi
\or                         % 2 sxSD
   \act@yah \chr@tie = \a@em@to@s \chr@sin #1%
\or                         % 3 GHXJ
   \act@yah 
\or                         % 4 cR
\put@tatwil 
\or                         % 5 kgM
   \act@yah \chr@kaf #1%
\else \put@tatwil 
\fi }

%%%%%%%%%%%%%%%%%%%%%% long yah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \yah@p@end #1#2{% long (Urdu) yah
% c2 c3
\global\@highfalse \test@end@char #2%
\ifend@char \yah@p@one #1\else \yah@p@more #1%
\fi }

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

\def \yah@p@one #1{% yah or alif maqsoura
% and one char
% c2
\ifcase \chr@cls            % 0 l
    \chr@cd = \a@lam@long %
\or                         % 1 YntCbyp
    \chr@cd = \a@bah@spec@yah
\or                         % 2 sxSD
    \chr@tie = \a@g@to@s \chr@sin #1\@raisetietrue
\else
     \ifx #1m\chr@cd = \a@mim@spec \else \put@tatwil 
     \fi
\fi }

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

\def \yah@p@more #1{% yah or alif maqsoura
% and more than one char c2 X
% c2
\ifcase \chr@cls            % 0 l
    \chr@cd = \a@lam@spec@yah
\or                         % 1 YntCbyp
    \chr@cd = \a@bah@spec@gim
\or                         % 2 sxSD
    \chr@tie = \a@g@to@s \chr@sin #1\@raisetietrue
\else
   \ifx #1m\chr@cd = \a@mim@spec@high \else
   \ifx #1h\chr@cd = \a@hah@spec@lam \else
	\put@tatwil 
   \fi\fi
\fi }

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


\def \aw@midligs #1#2*#3#4{% check for medial ligatures
% c1 m1 * c2 c3
\ifcase \act@cls \lam@lig #3#4% % 0 l
\or \bah@mid #2*#3#4%           	% 1 YntCbyp
\or \sin@lig #1#4%              	% 2 sxSD
\or \gim@lig #1#3#4%            	% 3 GHXJ
\or \global\@highfalse \put@tatwil  	% 4 cR
\or \global\@highfalse \put@tatwil 	% 5 kgM
\or \global\@highfalse \put@tatwil 	% 6 fqv
\or \sin@lig #1#4%              	% 7 VZ
\else \global\@highfalse
   \ifx #1m\mim@mid #2*#3#4\else
   \ifx #1h\hah@mid #1#3#4\else
	% two-eyed hah for Urdu
   \ifx #1\a@h\hah@urd@mid #1#3#4\else
	\put@tatwil 
   \fi\fi\fi
\fi }

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

\def \chr@fam #1{% put family
% c2
\if@con \@modtrue
\ifcase \chr@cls                 % 0 l
\or \chr@cd = \a@bah@s           % 1 YntCbyp
\or \ifx #1\a@s \chr@cd = \a@sin % 2 sxSD
    \fi
\or \ifnum \chr@cd = \a@hhah     % 3 GHXJ
    \else \@modfalse
    \fi
\or \chr@cd = \a@ain             % 4 cR
\or                              % 5 kgM
   \ifx #1g\ifpasht@ \chr@cd = \a@kaf@p@s
               \else \chr@cd = \a@gaf@s
           \fi \else
      \chr@cd = \a@kaf@s
   \fi
\or \chr@cd = \a@fah@s           % 6 fqv
\or                              % 7 VZ
\or                              % 8 rzj
\or \chr@cd = \a@bah@p           % 9 \a@t \a@n
\else
\fi\fi }

%%%%%%%%%%%%%%%%%%%%%%% bah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \bah@mid #1+#2*#3#4{% long form of bah etc.
% m11 + m12 * c2 c3
\put@tatwil 
\ifnum \act@cd = \a@bah@s % normal shape
   \set@mod@chr
   \if@high \ifnum #1 > 9 \act@cd = \a@bah@high \global\@highfalse
            \fi
   \else \global\@hightrue
   \fi
 \else
\ifnum \act@cd = \a@bah@high % higher shape
   \global\@highfalse
 \else
\ifnum \act@cd = \a@bah@spec@gim % before medial gim
   \@raisetrue \global\@highfalse
 \else
\ifnum \act@cd = \a@bah@spec@yah % before final yah
   \@raisetrue \global\@highfalse
 \else
\ifnum \act@cd = \a@bah@mid@mim % before medial mim
   \@raisetrue \global\@highfalse
 \else
\ifnum \act@cd = \a@bah@spec % before rah
   \gim@test #4%  closed gim ?
   \global\@highfalse
 \else
\fi\fi\fi\fi\fi\fi }

%%%%%%%%%%%%%%%%%%%%%% mim %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \mim@mid #1*#2#3{% medial mIm
% m1 * c2 c3
\ifnum \act@cd = \a@mim@spec@alif % s-m-a
	\ifnum \chr@cls = 2 \chr@sin #2%
	\fi
\else
\ifligs	\mim@mid@lig #1*#2#3%
\else \test@end@char #3%
\ifend@char \mim@mid@lig #1*#2#3%
\fi\fi\fi }

\def \mim@mid@lig #1*#2#3{% ligature for medial mIm
% m1 * c2 c3
\ifcase \chr@cls
    \test@end@char #3%				% 0 l
    \ifnum \act@cd = \a@mim@lam@gim \@raisetrue % l-m-^g
	\ifend@char \chr@cd = \a@lam@spec@hah
	\else \chr@cd = \a@lam@spec@yah
	\fi
	\test@updia #1*% upper diacritic?
	\if@updia \act@cd = \a@mim@spec@long
	\fi
    \else
    \ifend@char \act@mim@spec #1*\chr@cd = \a@lam@spec@mim
    \fi\fi
\or \act@mim@spec #1*\chr@cd = \a@bah@mid@mim	% 1 YntCbyp
\or \act@mim@spec #1*\chr@tie = \a@bah@mid@mim 	% 2 sxSD
	\@raisetietrue \chr@sin #2%
\or \act@cd = \a@mim@spec@high \gim@test #3%	% 3 GHXJ
\else	\ifnum 8 > \chr@cls \act@cd = \a@mim@spec@high \else
   	\ifx #2m\test@end@char #3%
	      \ifend@char \act@mim@spec #1*\chr@cd = \a@mim@spec@mim
	      \fi
   	\fi\fi
\fi
\ifnum \act@cd = \a@mim@spec \@raisetrue \else
\ifnum \act@cd = \a@mim@spec@long \@raisetrue \else
\ifnum \act@cd = \a@mim@spec@high \@raisetrue \else
\ifnum \act@cd = \a@mim@lam@gim \@raisetrue \else
\fi\fi\fi\fi }

%%%%%%%%%%%%%%%%%%%%%% hah %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \hah@mid #1#2#3{% medial hah, no ligature in Urdu
% c1 c2 c3
\ifcase \chr@cls
	\act@cd = \a@hah@spec@lam 		% 0 l
	\test@end@char #3%
	\ifend@char \chr@cd = \a@lam@spec@hah
	\else \chr@cd = \a@lam@spec@mim
	\fi
\or 	\ifurd@ \else
\act@hah \chr@cd = \a@bah@end@hah		% 1 YntCbyp
	\fi
\or 	\ifurd@ \else
\act@hah \chr@tie = \a@mh@to@s \chr@sin #2%	% 2 sxSD
	\fi
\else 	\ifnum \chr@cls = 9 			% \a@t \a@n
	\ifurd@ \else \act@hah \chr@cd = \a@bah@end@hah
	\fi \else \put@tatwil 
	\fi
\fi
\ifnum \act@cd = \a@hah@spec@lam \@raisetrue
\fi }

\def \hah@urd@mid #1#2#3{% medial (wavy) hah 
% c1 c2 c3
\ifcase \chr@cls
	\act@cd = \a@hah@spec@lam 		% 0 l
	\test@end@char #3%
	\ifend@char \chr@cd = \a@lam@spec@hah
	\else \chr@cd = \a@lam@spec@mim
	\fi
\or \act@hah \chr@cd = \a@bah@end@hah		% 1 YntCbyp
\or \act@hah \chr@tie = \a@mh@to@s \chr@sin #2%	% 2 sxSD
\else 	\ifnum \chr@cls = 9 			% \a@t \a@n
	\act@hah \chr@cd = \a@bah@end@hah
	\else \put@tatwil 
	\fi
\fi
\ifnum \act@cd = \a@hah@spec@lam \@raisetrue
\fi }

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

\def \gim@kaf@test #1#2{% lam,alif,kaf etc.
% c2 c3
\gim@test #2\kaf@test #1%  kaf-lam ?
}

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

\def \gim@test #1{% closed gim ?
% c3
\ifnum \chr@cls = \gim@cls % GHXJ
   \test@end@char #1%
\ifend@char \chr@cd = \a@gim@close \@modtrue \global\@highfalse
\fi\fi }

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

\def \kaf@test #1{% short kaf ?
\ifnum \chr@cls = \kaf@cls % k g M \a@kp
\chr@kaf #1\global\@highfalse
\else \put@tatwil
\fi }

%%%%%%%%%%%%%%%%%%%%%% change chr@cd %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \chr@sin #1{% shape without tooth
% c
  \ifx #1x\chr@cd = \a@shin@spec \else
  \ifx #1S\chr@cd = \a@sad@spec  \else
  \ifx #1D\chr@cd = \a@dad@spec  \else
          \chr@cd = \a@sin@spec
\fi\fi\fi }

\def \chr@kaf #1{% put ligature
% c
\ifx #1g\ifpasht@\chr@cd = \a@kaf@p@spec
           \else \chr@cd = \a@gaf@spec
        \fi
\else \chr@cd = \a@kaf@spec \@modtrue
\fi }

%%%%%%%%%%%%%%%%%%%%%% change act@cd %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \act@yah {% short yah
\ifnum \act@cd = \a@yah \act@cd = \a@yah@spec \else
\ifnum \act@cd = \a@yah@h \act@cd = \a@yah@h@spec
\fi\fi }

\def \act@hah {% short hah
\ifurd@ \else
\ifnum \act@cd = \a@hah \act@cd = \a@hah@spec
\fi\fi }

\def \act@gim #1{% Ligatur setzen
% c
  \act@cd = \a@hhah@spec \@raisetrue
\ifx #1c\set@mod@chr \else
\ifx #1\a@c\set@mod@chr \else
   \act@mod = 0
\ifx #1G\act@cd = \a@gim@spec  \else
\ifx #1H\act@cd = \a@hhah@spec \else
\ifx #1X\act@cd = \a@khah@spec \else
\ifx #1J\act@cd = \a@tsah@spec \else
\fi\fi\fi\fi
\fi\fi }

\def \act@mim@spec #1*{% lam-mim etc.
\test@updia #1*% upper diacritic
\if@updia \act@cd = \a@mim@spec@long
\else \act@cd = \a@mim@spec % no diacritic
\fi }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% keshide %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \put@tatwil {% deposit keshide 
\ifspread \if@con \@tattrue
\fi\fi }

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