%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% aedpatch.sty
% patches for EDMAC to operate with ArabTeX
% 19.03.93 2.07 EDMAC 3.00
% 19.06.94 3.02 EDMAC 3.15 compatible
%		\pstart, \pend, \autopar within Arabic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifx \aedatcode \undefined \else \expandafter \endinput
\fi % load only once

\chardef \aedatcode = \catcode`\@  \catcode`\@ = 11

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

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% modify some EDMAC commands in a compatible way

\long \def \text #1#2/{% inside Roman text
% care for delayed expansion of some ArabTeX commands
% depends on EDMAC version used
  \leavevmode \begingroup
     \begingroup \no@expands
        \def \protect {\noexpand \protect \noexpand }%
        \xdef\@tag{#1}\set@line \global\insert@count=0
        \ignorespaces #2\relax \flag@start
     \endgroup
     #1\a@end@lemma
\endgroup \flag@end }

\ifx \end@lemmas \undefined
	\def \a@end@lemma {% for EDMAC 3.00
	\the\end@lemma }
\else
	\def \a@end@lemma {% for EDMAC 3.15
	\ifx\end@lemmas\empty \else
\tracingmacros 1
	    \gl@p\end@lemmas\to\x@lemma
	    \x@lemma
	    \global\let\x@lemma=\relax
\tracingmacros 0
	\fi }
\fi

\def \lemma #1{% in argument of \text
% care for delayed expansion of some ArabTeX commands
  \begingroup \def \protect {\noexpand \protect \noexpand }%
     \xdef\@tag{#1}%
  \endgroup \ignorespaces }

\def \do@line {% break off a line from \raw@text
% guard against overfull \vboxes !
   {\vbadness=10000 \splittopskip=0pt
   \global \setbox\one@line
   \vsplit \raw@text to 1.4\baselineskip }% was 1.0
% arabic lines have a greater height and depth
   \unvbox\one@line \global \setbox\one@line \lastbox \getline@num
   \hbox to \hsize {\affixline@num {\hfil
   \hbox to \wd\one@line {\new@line \unhbox\one@line }}}%
   \add@inserts
   \add@penalties }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% variants for use inside an arabic environment

\def \a@c@text {% internal version of \text
% parameters will have the original catcodes
  \begingroup \unarab@codes \a@@text }

\long \def \a@@text #1{% auxiliary routine
% to kill leading blanks and remove spurious braces from #2
\def \next@command {\a@@@text {#1}}%
\futurelet \next@token \test@space }

\long \def \a@@@text #1#2/{% inside arabic enviroment:
  % stay in vertical mode, put text *and* \writes into a \hbox
  % and deposit the box in the arabic line
  % care for delayed expansion of some ArabTeX commands
   \begingroup \no@expands
     \def \protect {\noexpand \protect \noexpand }% for \@tag
     \xdef \@tag{#1}\set@line \global\insert@count=0
  % prepare for collecting any side effects of #2
     \aftergroup \global  \aftergroup \setbox  \aftergroup \wordb@x
     \aftergroup \hbox    \aftergroup {%
     \aftergroup \flag@start
     \ignorespaces #2\relax
   \endgroup
  % now open the box after the group
   #1\a@end@lemma \flag@end }% close the \box \wordb@x
\endgroup % restore catcodes
\put@word \test@token }

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

\def \a@c@label #1{% outside the arguments of \text
% hide the \write commands inside a box in the arabic line
% otherwise \do@line will not find the correct line breaks
  \do@labelsfile
  \ifx \labelref@list \empty \xdef \label@refs {\zz@@@ }%
  \else \gl@p \labelref@list \to \label@refs
  \fi
  \edef \next {\write\@aux {\string\make@labels \label@refs|{#1}}}%
  \global \setbox \wordb@x \hbox
          {\write\linenum@out {\string\@lab }\next }%
  \put@word \test@token }

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

\let \a@par \a@@par % save for \a@@everypar in \a@c@autopar

\def \a@c@pstart {\a@vmodefalse \pstart \test@token }

\def \a@c@pend {\a@par \pend \a@par \test@token }

\def \a@c@autopar {% use inside Arabic environment
\ifnumbering \else \errmessage 
	{\string\autopar\space must be used within a numbered section}%
	\beginnumbering
\fi
\a@@everypar= {\setbox0 = \box \lineb@x \let \next \test@token
	\a@par \pstart % starts a group
	\def \a@@par {\a@par \pend \a@par }%
	\def \end {\a@par \pend \test@token \end }%
	\a@@everypar= {}\arab@indent }%
\a@spacefalse \test@token }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% allow more EDMAC commands in arabic text also

\all@w@ne \pageref      \all@w@ne \lineref      \all@w@ne \sublineref
\all@w@ne \xpageref     \all@w@ne \xlineref     \all@w@ne \xsublineref
\all@wtw@ \makelabel    \all@wtw@ \xxref

\catcode`\@ = \aedatcode

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

