%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hewrite.sty
% ArabTeX
% Modifications for Hebrew mode
% 10.03.1995
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\a@ident {hewrite.sty} {3.03} {10.03.95}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dynamic definitions for Hebrew
{\catcode `\ =9 \catcode `\^^M=9 \catcode `\^^I=9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@hebskel {% define font encoding for Hebrew
\globaldefs=1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chardef \sk@B  45 	% maqqeph
\chardef \sk@a  96 	% aleph
\chardef \sk@b  97 	% beth
\chardef \sk@j 	98	% gimel
\chardef \sk@d	99 	% daleth
\chardef \sk@h  100 	% he
\chardef \sk@w 	101 	% waw
\chardef \sk@z 	102 	% zayin
\chardef \sk@hh 103 	% chet
\chardef \sk@tt 104 	% ttet
\chardef \sk@y 	105 	% yod
\chardef \sk@kf	106 	% kaph, final
\chardef \sk@k  107 	% kaph
\chardef \sk@l 	108 	% lamed
\chardef \sk@mf 109 	% mem, final
\chardef \sk@m  110 	% mem
\chardef \sk@nf	111 	% nun, final
\chardef \sk@n 	112 	% nun
\chardef \sk@s  113 	% samech
\chardef \sk@P  114 	% ayin
\chardef \sk@ff	115 	% pe, final
\chardef \sk@f 	116 	% pe, f
\chardef \sk@sf 117 	% ssade, final
\chardef \sk@ss 118 	% ssade
\chardef \sk@q	119 	% qoph
\chardef \sk@r	120 	% resh
\chardef \sk@si 121 	% ssin
\chardef \sk@t  122 	% taw
\chardef \sk@Pv 123 	% vowel ayin
\globaldefs=0
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@hebchars {% define character macros for Hebrew
\globaldefs=1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def \tc@a {\act@cd \sk@a }				% aleph
%\def \tc@b {\act@cd \sk@b  	\global\@dageshtrue }	% beth
\def \tc@b {\act@cd \sk@b  }				% beth
%\def \tc@d {\act@cd \sk@d  	\global\@dageshtrue }	% daleth
\def \tc@d {\act@cd \sk@d  }				% daleth
\def \tc@f {\act@cd \sk@f 	\global\@finaltrue }	% pe
\def \tc@g {\act@cd \sk@j 	\global\@dageshtrue }	% gimel
\def \tc@h {\act@cd \sk@h }				% he
%\def \tc@k {\act@cd \sk@k \global\@finaltrue \global\@dageshtrue }	% kaph
\def \tc@k {\act@cd \sk@k \global\@finaltrue }		% kaph
\def \tc@l {\act@cd \sk@l }				% lamed
\def \tc@m {\act@cd \sk@m 	\global\@finaltrue }	% mem
\def \tc@n {\act@cd \sk@n 	\global\@finaltrue }	% nun
\def \tc@p {\act@cd \sk@f \global\@finaltrue \global\@dageshtrue }	% pe
\def \tc@q {\act@cd \sk@q }				% qoph
\def \tc@r {\act@cd \sk@r }				% resh
\def \tc@s {\act@cd \sk@s }				% samekh
%\def \tc@t {\act@cd \sk@t 	\global\@dageshtrue }	% taw
\def \tc@t {\act@cd \sk@t }				% taw
\def \tc@v {\act@cd \sk@b }				% beth
\def \tc@w {\act@cd \sk@w }				% waw
\def \tc@x {\act@cd \sk@si 	\act@mod \shind@t }	% shin with dot
\def \tc@y {\act@cd \sk@y }				% yod
\def \tc@z {\act@cd \sk@z }				% zayin

\def \tc@A {\act@cd \sk@a }				% aleph again
\def \tc@B {\act@cd \sk@B }				% maqqeph
\def \tc@C {\act@cd \sk@t }				% taw
\def \tc@D {\act@cd \sk@d  	\global\@dageshtrue }	% daleth
\def \tc@F {\act@cd \sk@d }				% daleth
\def \tc@G {\act@cd \sk@j }				% gimel
%\def \tc@H {\act@cd \sk@h 	\global\@dageshtrue }	% he
\def \tc@H {\act@cd \sk@h }				% he
\def \tc@N {\act@cd \sk@n 	\global\@finaltrue }	% nun
\def \tc@P {\act@cd \sk@P }				% ayin
\def \tc@Q {\act@cd \sk@a }				% aleph again
\def \tc@R {\act@cd \sk@k 	\global\@finaltrue }	% kaph
\def \tc@S {\act@cd \sk@ss 	\global\@finaltrue }	% sade
\def \tc@T {\act@cd \sk@h 	\global\@dageshtrue }	% he
\def \tc@V {\act@cd \sk@tt }				% tet
%\def \tc@X {\act@cd \sk@hh 	\global\@dageshtrue }	% chet
\def \tc@X {\act@cd \sk@hh }				% chet
\def \tc@Y {\act@cd \sk@y }				% yod

\tc@def \a@s {\act@cd \sk@si 	\act@mod \sind@t }	% sin with dot
\tc@def \a@H {\act@cd \sk@h }				% silent he 
\tc@def \a@S {\act@cd \sk@si }				% sin without dot
\globaldefs=0 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \def@hebaccent {% define accent macros for Hebrew
%\put@box {\hebfont \char \sk@a}\h@ht \ht\ab@x	% height of aleph
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\globaldefs=1

\def \put@accent ##1+##2*{% put modifier onto contents of "\ab@x"
% m1 + m2 *
\global\let \h@vowel \h@putvowel	\global\red@mod = ##1 \relax
\ifnum \red@mod > 9 \global\advance \red@mod -10 \relax\fi
\ifnum \red@mod > 3 \global\advance \red@mod -4 
	\global\let \h@vowel \h@meteg \fi
\ifnum \red@mod > 1 \global\advance \red@mod -2 \relax \h@cholem \fi
\ifnum \red@mod > 0 \global\advance \red@mod -1 \global\@dageshtrue \fi
\ifcase ##2\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 \fi }

\def \put@fatha     {\h@vowel {\char 1 }}	% patach
\def \put@fathaspec {\h@vowel {\char 2 }}	% qames 
\def \put@zwarakay  {\h@vowel {\char 3 }}	% segol
\def \put@damma     {\h@vowel {\char 4 }}	% qibbus
\def \put@kasra     {\h@vowel {\char 5 }}	% chireq
\def \put@ammad     {\h@vowel {\char 6 }}	% qames chatuph
\def \put@sukun     {\h@vowel {\char 7 }}	% shwa
\def \put@kasraspec {\h@vowel {\char 9 }}	% sere
\def \put@fathatan {\h@vowel {\char 1 \char 7 }}% chateph patach 
\def \put@kasratan {\h@vowel {\char 3 \char 7 }}% chateph segol
\def \put@dammatan {\h@vowel {\char 6 \char 7 }}% chateph qames
\def \put@wasla     {\h@ldot }			% cholem breve
\globaldefs=0 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}% end of dynamic definitions for Hebrew
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% static definitions for Hebrew
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\chardef \sind@t  1	\chardef \shind@t 2
\chardef \illch@r 33	\chardef \m@qqeph 45

\newdimen \h@ht
\newif \if@dagesh	\newif \if@final	\newif \ifhv@wel
\newif \ifhcl@s

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

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

\def \heb@testfont {% look for vowels and ayin
\setbox0 \hbox {\char \sk@a }\h@ht \ht0 % height of aleph
\def \v@adj {0}%
\setbox0 \hbox {\tracinglostchars 0 \char 125 }% is there punctuation
\ifdim \wd0 = \z@ \hcl@strue \else \heb@punct \fi
\setbox0 \hbox {\tracinglostchars 0 \char 1 }% are there vowel marks? 
\ifdim \wd0 = \z@ \hv@welfalse \else \hv@weltrue 
\setbox0 \hbox {\tracinglostchars 0 \char 127 }% dclass2?
%\ifdim \wd0 = \z@ \else \def \v@adj {0}\chardef \sk@Pv 127 \fi
% test does not work on 10.03.1995
\fi }

\def \heb@punct {% there is punctuation
\hcl@sfalse \def \v@adj {-.2}\chardef \sk@Pv 114 }

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

\def \heb@beg #1#2*#3{% start output			% c m * c 
\heb@testfont
\h@test@chr #1\def \next {\heb@end #1#2*#3}%
\ifx #1W\h@test@chr #3\def \next {\heb@mid #3}%
\ifx #3>\h@put@spec #1#2*#3<%
\fi\fi \next }

\def \heb@end #1#2*#3{% final character 		% c m * c 
\ifx #1>\let \next \relax \else
\ifx #1W\h@test@chr #3\def \next {\heb@end #3}\else 
\ifcat #1-\h@put@spec #1#2*#3<\else \h@put@end #1#2*#3<%
\fi\fi\fi \next }

\def \heb@mid #1#2*#3{% non-final character 		% c m * c 
\ifx #1>\let \next \relax \else
\ifx #1W\h@test@chr #3\def \next {\heb@end #3}\else
\ifcat #1-\h@put@spec #1#2*#3<\else \h@put@mid #1#2*#3<%
\fi\fi\fi \next }

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

\def \h@put@end {% final position
\if@final \advance \act@cd -1 \fi \h@put@mid }

\def \h@put@mid #1#2+#3*#4<{% deposit character		% c m1 + m2 * c <
\def \next {\heb@mid #4}%
\put@box {\char \the\act@cd }%
\ifhv@wel \put@accent #2+#3*%
\ifcase \act@mod \or \h@sindot \or \h@shindot 
\fi \if@dagesh \h@putdagesh \fi
\fi 
\ifnum \act@cd = \m@qqeph \def \next {\heb@end #4}%
\ifhcl@s \else 
\put@box {\raise .6ex \hbox {\kern.05em\unhbox \ab@x \kern.05em}}%
\fi\fi \unhbox \ab@x \h@test@chr #4}

\def \h@put@spec #1#2*#3<{% special character		% c m * c <
\ifx #1|\else \ifx #1--\else
\ifx #1!#1\else \ifx #1,#1\else \ifx #1.#1\else \ifx #1:#1\else
{\ifhcl@s \rm \bf \fi
\ifx #1][\else \ifx #1[]\else
#1%
\fi\fi}%
%\fi\fi\fi\fi \kern 1pt%
\fi\fi\fi\fi \kern 5pt%
\fi\fi 
\h@test@chr #3% % special handling of apostrophe
\ifx #1'\def \next {\heb@mid #3}\else \def \next {\heb@end #3}\fi }

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

\def \h@test@chr #1{% get character attributes
\global\@dageshfalse	\global\@finalfalse	
\act@mod 0 	\act@cd \illch@r
\if \nxp #1\relax \h@@test #1\else
\ifcat #1a\h@@test #1%
\fi\fi }

\def \h@@test #1{% switch on character
\csname tc@\string #1\endcsname }

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

\def \h@putdagesh {\def \vadj {.45}\def \hadj {0}% default
\ifnum \act@cd = \sk@j 	\def \hadj {-.2}\fi % gimel
\ifnum \act@cd = \sk@w 	\def \hadj {-.4}\fi % waw
\ifnum \act@cd = \sk@z 	\def \hadj {-.4}\fi % zayin
\ifnum \act@cd = \sk@tt \def \hadj  {.1}\fi % tet
\ifnum \act@cd = \sk@y 	\def \hadj {-.5}\def \vadj {.7}\fi % yod
\ifnum \act@cd = \sk@l 	\def \hadj {-.1}\def \vadj {.3}\fi % lamed
\ifnum \act@cd = \sk@n 	\def \hadj {-.2}\fi % nun
\ifnum \act@cd = \sk@f 	\def \hadj {.12}\fi % pe
\ifnum \act@cd = \sk@ss \def \hadj  {.1}\fi % sade
\ifnum \act@cd = \sk@si	\def \hadj  {.05}\fi % shin
\rlap {\kern \hadj\a@wd \kern .5\a@wd \raise \vadj\a@ht \hbox {\char 0}}}

\def \h@put@dot #1{% as I said
\rlap {\kern #1\a@wd \raise 1.2\h@ht \hbox {\char 0}}}

\def \h@shindot {\h@put@dot {.8}}	% right dot for shin
\def \h@sindot  {\h@put@dot {.2}}	% left dot for sin
\def \h@rdot  	{\h@put@dot {.5}}	% right dot for waw, cholem breve
\def \h@ldot    {% left dot for cholem breve
\ifnum \act@cd = \sk@l 	\h@put@dot {-.1}% lamed
\else \h@put@dot {.1}\fi }	

\def \h@cholem {% depends on carrier
\ifnum \act@cd = \sk@w \h@rdot \else \h@shindot \fi }

\def \h@putvowel #1{\def \hadj {0}\def \vadj {0}% vowel mark
\ifnum \act@cd = \sk@P \put@box {\char \sk@Pv }\let \vadj \v@adj \fi % ayin
\ifnum \act@cd = \sk@kf \def \vadj {.75}\fi % final kaph
\ifnum \act@cd = \sk@r 	\def \hadj  {.3}\fi % resh
\ifnum \act@cd = \sk@d 	\def \hadj  {.2}\fi % daleth
\ifnum \act@cd = \sk@q 	\def \hadj  {.1}\fi % qoph
\ifnum \act@cd = \sk@w 	\def \hadj  {.2}\fi % waw
\ifnum \act@cd = \sk@si	\def \hadj {-.1}\fi % sin
\setbox0 \hbox to \a@wd {\hss #1\hss}%
\rlap {\kern \hadj\a@wd \raise \vadj\a@ht \box0 }}

\def \h@meteg #1{% put vowel and meteg
\h@putvowel {\char 8 #1}}

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

