1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% awrite.sty
3% ArabTeX
4% basic contextual analysis
5% called in HMODE
6% Version 05.06.2003
7%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8% (c) Klaus Lagally
9%     Institut fuer Informatik
10%     Universitaet Stuttgart
11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13\a@ident {awrite.sty} {3.11 build output word } {05.06.2003}
14
15\UsePackage {xarbsymb}        % character definitions
16\UsePackage {arabskel}        % skeleton definitions
17\UsePackage {xarbskel}
18\UsePackage {aboxes}          % deposit output boxes
19
20\UsePackage {arabtoks}        % token definitions
21\UsePackage {arabchrs}        % character macros
22
23% ACT = 1. char
24\newcount \act@cd       \newcount \act@cls      \newcount \act@mod
25\newcount \act@con      \newcount \act@tie
26
27% CHR = 2. char
28\newcount \chr@cd       \newcount \chr@cls      \newcount \chr@mod
29\newcount \chr@con      \newcount \chr@tie
30
31% SKL = 3. char
32\newcount \skl@cd       \newcount \skl@cls      \newcount \skl@mod
33\newcount \skl@con
34
35\newcount \red@mod      \newcount \a@shp
36\newcount \a@max        \newcount \a@min
37
38\newif \if@con          \newif \if@mod@act      \newif \if@high@act
39\newif \if@mod@chr      \newif \if@tat          \newif \if@tatl
40\newif \if@updia        \newif \if@lodia	\newif \ifa@sk
41\newif \ifa@min         \newif \ifa@max
42
43\newdimen \a@min@dp     \newdimen \a@dx         \newdimen \a@dy
44
45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47\newif \ifa@@write      \a@@writetrue
48
49\def \a@@write #1>{% Arabic output
50\iftest@write \tracingmacros 1
51\iftest@parse \else \a@verb (#1 )>\fi\fi
52\a@write@hook
53\ifa@@write \arab@testfont \aw@beg #1>0+0*>0+0*>\fi
54\iftest@write \tracingmacros 0 \fi }
55
56\let \a@write \a@@write                \let \a@write@hook \relax
57
58%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59%em# := 25.4dx#;        %ex# := 8dy#;
60
61{\catcode `p=12 \catcode `t=12 % see TeXbook, Appendix D
62\csname expandafter\endcsname \gdef
63\csname getfactor\endcsname #1pt{#1}}
64
65\def \arab@testfont {% diagnose font, look for vowels and ayin
66\edef \next {\the\font }%
67\ifx \next \a@font \else
68\iftest@font \a@message{Arabic font \next selected.}\fi
69\global\let \a@font \next \a@testfont \fi }
70
71\def \a@testfont {% diagnose font, set params
72\xdef \a@slant {\xpa\getfactor \the\fontdimen1\font }%
73\dimen@ 128\fontdimen7\font % assumes \fontdimen7 < 128 pt
74\divide \dimen@ \fontdimen6\font \multiply \dimen@ 512
75\xdef \a@skew {\xpa\getfactor \the\dimen@}}
76
77\def \a@norm {% start a new character group
78\global\@highfalse \global\a@min@dp \z@ \global\a@min \z@
79\global\a@max \z@ \a@disp \z@ \@high@actfalse \global\a@sktrue }
80
81\def \aw@init {% start word, get font parameters
82\a@norm \leavevmode \a@dx .04em \a@dy .125ex }
83
84\def \a@skew {0}        \def \a@slant {0}
85
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88\def \aw@beg #1#2*#3#4*#5{% start output
89% c m * c m * c
90	\aw@init
91	\test@chr #1\def \next {\aw@end #1#2*#3#4*#5}%
92\ifx #1-\test@chr #3\chr@fam #3%
93	\def \next {\aw@mid #3#4*#5}%
94	\ifx #3>\ac@other #1#2*#3#4*#5<%
95	\fi \else
96\ifcat -\nxp #1\a@shift \test@chr #3%
97	\@confalse \ac@other #1#2*#3#4*#5<\else
98\fi\fi \next }
99
100\def \aw@beg #1#2*#3#4*#5{% start output
101% c m * c m * c
102\ifx #1>\let \next \relax \else
103	\aw@init
104	\test@chr #1\def \next {\aw@end #1#2*#3#4*#5}%
105\ifx #1-\test@chr #3\chr@fam #3%
106	\def \next {\aw@mid #3#4*#5}%
107	\ifx #3>\ac@other #1#2*#3#4*#5<%
108	\fi \else
109\ifcat -\nxp #1\a@shift \test@chr #3%
110	\@confalse \ac@other #1#2*#3#4*#5<\else
111\fi\fi\fi \next }
112
113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
115\def \aw@end #1#2*#3#4*#5{% character is not joined to the left
116% c m * c m * c
117% ACT, CHR defined
118\ifx #1>\let \next \relax \else
119\if \AND{\isx #3|}{\is@end@char #5}\def \next {\aw@end #1#2*#5}%
120\else \def \next {\aw@end #3#4*#5}%
121		\a@shift \test@chr #3%
122		\if \AND{\iscat -{\nxp #3}}%
123			{\NOT {\is@end@char #5}}\@contrue
124		\fi
125	\ifnum \act@cd = \a@alif \def \next {\alif@lig #2*#3#4*#5}\else
126	\ifcat \nxp ~\nxp #1\else
127	\ifx #1-\chr@fam #3\else
128%	\ifcat -\nxp #1\ac@other #1#2*#3#4*#5<\else
129	\ifcat -\nxp #1\@confalse \ac@other #1#2*#3#4*#5<\else
130		\ifnum \act@cd = \a@hamzc \@confalse \else
131		\ifnum \act@cd = \a@break \@confalse \else
132			\if@con \chr@fam #3%
133			\fi
134			\ifu@gh \@mod@acttrue
135				\ifnum \act@cd = \a@qaf \set@act\sk@q@s
136				\fi
137			\else	\aw@endligs #1#2*#3#4*#5%
138			\fi
139		\fi\fi
140        	\a@kern
141		\ifnum \act@cd  = \a@waw \under@cut #2*\else
142		\ifnum \act@cls = \rah@cls \under@cut #2*\else
143		\ifnum \act@cd  = \a@hah \a@kern
144		\fi\fi\fi
145		\put@end #2*#3#4*#5<%
146	\fi\fi\fi\fi
147\fi\fi \next }
148
149\def \alif@lig #1*#2#3*#4{% alif, test for ligature
150% m * c m * c
151\a@kern
152\chr@fam #2\global\@highfalse
153\ifx #2l\def \next {\lam@alif #1*#3*#4}\else
154	\gim@test #4%  closed gim?
155	\kaf@test #2%  kaf-alif ?
156	\aw@lower #4%
157        \put@end #1*#2#3*#4<%
158\fi \next }
159
160\def \lam@alif #1*#2*#3#4*#5{% ligature lam-alif
161% m * m * c m * c
162\global\@highfalse \a@shift \test@chr #3\chr@fam #3%
163\gim@test #5%  closed gim?
164\ifu@gh \else \kaf@test #3\fi %  kaf-lam ?
165\set@act\sk@l@a
166\if@con \lig@end #1*#2*\def \next {\aw@mid #3#4*#5}%
167  \else \lig@iso #1*#2*\def \next {\aw@end #3#4*#5}%
168\fi \next }
169
170\def \lig@iso #1*#2*{% isolated shape                        % m1 * m2 *
171\put@lig@skel 0\a@f@iso #1*#2*\a@norm }
172
173\def \lig@end #1*#2*{% final shape                           % m1 * m2 *
174\put@lig@skel 1\a@f@end #1*#2*}
175
176\def \aw@lower #1{% adjust vertical position
177% uses ACT, CHR, and #1
178\ifligs
179\ifnum \chr@cd = \a@hah
180	\ifx #1l\set@lowww@act \fi
181\fi
182\ifnum \chr@cls = 3 % gim etc
183	\a@test {#1}\xxpa \unp@ck@skl \skl@skel \relax
184%	\ifnum \skl@cls = 0 \set@lowww@act \fi
185	\ifnum \skl@cls = 1 \set@lowww@act \fi
186	\ifnum \skl@cls = 2 \set@lowww@act \fi
187	\ifnum \skl@cls = 5 \set@lowww@act \fi
188\fi\fi }
189
190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191
192\def \aw@mid #1#2*#3#4*#5{% character is joined to the left
193% c m * c m * c
194% ACT, CHR defined
195\ifx #1>\let \next \relax \else
196\if \AND{\isx #3|}{\is@end@char #5}\def \next {\aw@mid #1#2*#5}\else
197\ifx #1-\test@chr #3\chr@fam #3\def \next {\aw@mid #3#4*#5}\else
198	\a@shift \test@chr #3\chr@fam #3%
199\ifcat -\nxp #1\ac@other #1#2*#3#4*#5<%
200\else 	\if \AND{\iscat -{\nxp #3}}%
201		{\NOT {\is@end@char #5}}\@contrue
202	\fi
203	\ifu@gh \else
204        	\aw@midligs #1#2*#3#5%
205	\fi
206        \put@mid #2*#3#4*#5<%
207        \if@con \else % initial shape
208        \ifnum \act@cls = \kaf@cls % kaf etc.
209		\xpa\if \xpa\is@in@list \chr@skel \sk@a \sk@l >\a@kern
210		\else \unkern \a@mkern
211		\fi
212        \fi\fi
213\fi\fi\fi\fi \next }
214
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216
217\def \test@updia #1+#2*{% test for upper diacritic
218% m21 + m22 *
219\@updiafalse        \@lodiafalse
220\global\red@mod   #1 \relax
221\ifnum #1 > 9 \global\advance \red@mod -10 \fi
222\ifcase \red@mod
223   \relax\or      \@updiatrue\or \@updiatrue\or \@updiatrue\or
224   \@updiatrue\or \@lodiatrue\or
225\fi
226\ifcase #2\relax
227   \relax\or      \@updiatrue\or \@updiatrue\or \@lodiatrue\or
228   \@updiatrue\or \@updiatrue\or \@lodiatrue\or \@updiatrue\or
229   \@updiatrue\or \@updiatrue\or \@updiatrue\or \@lodiatrue\or
230   \@updiatrue\or
231\fi }
232
233\def \is@updia #1*{00% is there an upper diacritic ?
234\test@updia #1*\if@updia \else \xpa \setiffalse \fi }
235
236\def \is@lodia #1*{00% is there a lower diacritic ?
237\test@updia #1*\if@lodia \else \xpa \setiffalse \fi }
238
239\def \under@cut #1*{% if no upper diacritic                % m2 *
240\ifdim \a@dp > .5ex \else % \if\is@updia #1*\else
241\unkern \a@mkern \fi }
242
243%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244
245\def \put@end #1*#2<{% deposit non-joining character, set new state
246% m * c m * c <
247\if@con \ac@end #1*\def \next {\aw@mid #2}%
248 \else  \ac@iso #1*\def \next {\aw@end #2}%
249\fi }
250
251\def \put@mid #1*#2<{% deposit joining character, set new state
252% m * c m * c <
253\if@con \ac@mid #1*\def \next {\aw@mid #2}%
254 \else  \ac@beg #1*\def \next {\aw@end #2}%
255\fi }
256
257%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258
259\def \ac@high #1{\raise.5ex\hbox{#1}}
260\def \ac@high #1{% raise punctuation
261\ifu@gh #1\else \raise.5ex\hbox{#1}\fi }
262
263% define CS names for special punctuation
264
265{\catcode`\$ 12 \gdef \a@dlr {$}	% $
266\catcode `\# 12 \gdef \a@hsh {#}	% #
267\catcode `\% 12 \gdef \a@pct {%}}	% %
268{\catcode`\^ 12 \gdef \a@up  {^}	% ^
269\catcode `\_ 12 \gdef \a@dn  {_}	% _
270\catcode `\& 12 \gdef \a@amp {&}	% &
271\catcode `\A 12 \gdef \a@dq  {A}	% "
272\catcode `\B 12 \gdef \f@sila {B}	% ,
273\catcode `\C 12 \gdef \h@phen {C}	% -
274\catcode `\D 12 \gdef \a@bar {D}	% |
275\catcode `\E 12 \gdef \a@qt  {E}	% '
276\catcode `\F 12 \gdef \a@bsl {F}	% \
277\catcode `\G 12 \gdef \a@lbc {G}	% {
278\catcode `\H 12 \gdef \a@rbc {H}	% }
279\catcode `\I 12 \gdef \a@ell {I}	% ...
280\catcode `\J 12 \gdef \a@div {J}	% :-
281\catcode `\K 12 \gdef \a@lab {K}	% <
282\catcode `\L 12 \gdef \a@rab {L}	% >
283\catcode `\M 12 \gdef \a@end {M}	% --
284\catcode `\N 12 \gdef \a@emd {N}	% ---
285\catcode `\O 12 \gdef \a@lq  {O}	% `
286\catcode `\P 12 \gdef \a@rq  {P}	% '
287
288\gdef \ac@other #1#2*#3<{% special punctuation mark
289% c * c m * c
290\case #1\of
291{	){\ac@high {(}}
292	({\ac@high {)}}
293	]{\ac@high {[}}
294	[{\ac@high {]}}
295	`{\a@kern \ac@high {\char \a@lquotes }}
296	'{\ac@high {\char \a@rquotes }\a@kern }
297	^{{\tt ^}}
298	_{{\tt _}}
299	&{{\tt \char`\&}}
300	A{{\tt "}}
301	B{{\rm \bf ,}}
302	C{\ac@high {-}}
303	D{{\tt \char`\|}}
304	E{{\tt \char'015}}
305	F{{\tt \char`\\}}
306	G{{\tt \char`\}}}
307	H{{\tt \char`\{}}
308	I{{\bf $\cdots$}}
309	J{{\bf $\div$}}
310	K{{\tt \char`\>}}
311	L{{\tt \char`\<}}
312	M{{\rm \bf \char'173}}
313	N{{\rm \bf \char'174}}
314	O{{\rm \bf `}}
315	P{{\rm \bf '}}
316%	|{\char \a@break }
317	|{}
318	4{\ac@high {\iff@rsn \char \a@f@iv \else 4\fi }\a@kern }
319	5{\ac@high {\iff@rsn \char \a@f@v \else 5\fi }\a@kern }
320	6{\ac@high {\iff@rsn \char \a@f@vi \else 6\fi }\a@kern }
321\default {\ac@high {#1}\a@kern }
322}\endcase
323\if@con \def \next {\aw@mid #3}%
324 \else  \def \next {\aw@end #3}%
325\fi }
326%\def \next {\aw@end #3}}
327}% catcodes 12
328
329%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330
331\def \ac@iso #1*{% isolated shape                        % m *
332\put@skel 0\a@f@iso #1*\a@norm }
333
334\def \ac@end #1*{% final shape                           % m *
335\put@skel 1\a@f@end #1*}
336
337\def \ac@mid #1*{% medial shape                          % m *
338\put@skel 2\a@f@mid #1*}
339
340\def \ac@beg #1*{% initial shape                         % m *
341\put@skel 3\a@f@beg #1*\a@norm }
342
343%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344
345\def \a@shift {% go to next position
346% ACT := CHR
347\let \act@skel \chr@skel \act@mod \chr@mod \get@act
348\act@tie \chr@tie
349\let \if@mod@act \if@mod@chr \@mod@chrfalse }
350
351%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352
353\def \test@chr #1{% get attributes of next character
354% set CHR := SKL := <#1>
355\a@test #1\chr@tie 0
356\let \chr@skel \skl@skel \chr@mod \skl@mod \get@chr
357\ifnum \chr@con = 0 \@confalse \else \@contrue \fi }
358
359\def \a@test #1{% get character attributes
360% set SKL := <#1>
361\set@skl \sk@def \skl@mod 0
362\ifcat \nxp #1a%
363   \xpa \ifx \csname tc@\string #1\endcsname \relax
364        \else \unp@ck@tc {#1}%
365        \fi \else
366\if \nxp #1\relax \unp@ck@cs {#1}\else
367\ifx #1-\set@skl \sk@B \else
368\ifx #1|\set@skl \sk@spc \else
369\fi\fi\fi\fi }
370
371\def \a@test #1{% get character attributes
372% set SKL := <#1>
373	\skl@mod 0
374\ifcat \nxp #1a%
375   \xpa \ifx \csname tc@\string #1\endcsname \relax
376		\set@skl \sk@def
377        \else \unp@ck@tc {#1}%
378        \fi \else
379\if \nxp #1\relax \unp@ck@cs {#1}\else
380\ifx #1-\set@skl \sk@B \else
381\ifx #1|\set@skl \sk@spc \else
382	\set@skl \sk@def
383\fi\fi\fi\fi }
384
385\def \unp@ck@cs #1{% evaluate token routine
386\xpa\unp@ck@token #1\relax }
387
388\def \unp@ck@tc #1{% evaluate letter description
389\xxpa\unp@ck@token \csname tc@\string #1\endcsname \relax }
390
391\def \unp@ck@token #1,#2\relax {% unpack letter description
392\def \skl@skel {#1}\skl@mod #2}
393
394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395\endinput
396%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EOF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397
398