%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% asect.sty
% called by altxext.sty
% 26.04.2003
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Formale Methoden der Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\a@ident {asect.sty} {3.11 section macros for Arabic} {26.04.2003}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sections
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\iffalse % LaTeX 2.09 routines

\def\@xsect#1{\@tempskipa #1\relax
\ifdim \@tempskipa > \z@
       \par \nobreak
       \vskip\@tempskipa
       \@afterheading
\else \global\@nobreakfalse \global\@noskipsectrue
	\everypar 
	{\if@noskipsec \global\@noskipsecfalse
		\clubpenalty\@M \hskip -\parindent
		\begingroup \@svsechd 
		\endgroup 
		\unskip \hskip -#1\relax  % relax added 14 Jan 91
	\else \clubpenalty \@clubpenalty
		\everypar {}%
	\fi}
\fi \ignorespaces }
 
\def\@sect#1#2#3#4#5#6[#7]#8{%
\ifnum #2 > \c@secnumdepth \let\@svsec \@empty
\else \refstepcounter{#1}%
	\edef\@svsec {\csname the#1\endcsname \hskip 1em}%
\fi
\@tempskipa #5\relax
\ifdim \@tempskipa>\z@
	\begingroup #6\relax
		\@hangfrom {\hskip #3\relax \@svsec }%
			{\interlinepenalty \@M #8\par}%
	\endgroup
	\csname #1mark\endcsname {#7}%
	\addcontentsline {toc}{#1}%
		{\ifnum #2>\c@secnumdepth 
		\else \protect\numberline {\csname the#1\endcsname}%
		\fi #7}%
\else \def\@svsechd 
	{#6\hskip #3\relax  %% \relax added 2 May 90
	\@svsec #8\csname #1mark\endcsname {#7}%
	\addcontentsline {toc}{#1}%
		{\ifnum #2>\c@secnumdepth 
		\else \protect\numberline {\csname the#1\endcsname}%
		\fi #7}}%
\fi \@xsect{#5}}
 
\def\@ssect#1#2#3#4#5{\@tempskipa #3\relax
\ifdim \@tempskipa > \z@
	\begingroup #4%
		\@hangfrom {\hskip #1}%
			{\interlinepenalty \@M #5\par}%
	\endgroup
\else \def\@svsechd {#4\hskip #1\relax #5}%
\fi \@xsect{#3}}
 
\def\@startsection#1#2#3#4#5#6{\if@noskipsec \leavevmode \fi
\par \@tempskipa #4\relax
\@afterindenttrue
\ifdim \@tempskipa < \z@ 
	\@tempskipa -\@tempskipa \@afterindentfalse
\fi
\if@nobreak \everypar{}%
\else \addpenalty{\@secpenalty}\addvspace{\@tempskipa}%
\fi 
\@ifstar {\@ssect{#3}{#4}{#5}{#6}}%
	{\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
 
\def\@afterheading{\global\@nobreaktrue
\everypar {\if@nobreak \global\@nobreakfalse \clubpenalty \@M
		\if@afterindent \else {\setbox\z@\lastbox}\fi
	\else \clubpenalty \@clubpenalty \everypar{}%
	\fi}}

\fi % end of LaTeX 2.09 routines
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arabic versions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \a@startsection #1#2#3#4#5#6{% Arabic mode
%\tracingmacros 1
\if@noskipsec \leavea@vmode \fi
\a@@par \@tempskipa #4\relax \@afterindenttrue
\ifdim \@tempskipa <\z@ \@tempskipa -\@tempskipa \@afterindentfalse
\fi
\if@nobreak \a@@everypar {}%
\else \addpenalty \@secpenalty \addvspace \@tempskipa
\fi 
\@ifstar {\a@ssect {#3}{#4}{#5}{#6}}%
	{\@dblarg {\a@sect {#1}{#2}{#3}{#4}{#5}{#6}}}}
 
\def \a@ssect #1#2#3#4#5{% Arabic mode
\@tempskipa #3\relax
\ifdim \@tempskipa > \z@
	\begingroup \let \end \a@@par 
		#4\relax \set@arabfont % style
        	\a@hangfrom {\hskip #1\relax }% indentation
		\test@token #5 \end
	\endgroup
\else \def \@svsechd {\putwordb@x {#4\xpa\RL \xpa{#5}\hskip #1\relax }}%
\fi \a@xsect{#3}}
 
\def\a@sect #1#2#3#4#5#6[#7]#8{% Arabic mode
\ifnum #2 > \c@secnumdepth \let \@svsec \@empty 
\else \refstepcounter{#1}%
	\edef \@svsec {\hskip 1em \nxp\RL {\csname the#1\endcsname }}%
\fi
\@tempskipa #5\relax
\ifdim \@tempskipa > \z@
	\begingroup \let \end \a@@par 
		#6\relax \set@arabfont % style
	        \a@hangfrom {\hskip #3\relax \@svsec }% section number
		\test@token #8 \end
	\endgroup
	\csname #1mark\endcsname {\RL {#7}}%
	\addcontentsline {toc}{#1}%
		{\ifnum #2 > \c@secnumdepth \else
		\protect\numberline {\csname the#1\endcsname }\fi
		\protect\RL {#7}}%
\else \def \@svsechd % saved head, executed by \everypar
	{\putwordb@x {#6\xpa\RL {#8}\@svsec \hskip #3\relax }%
        \csname #1mark\endcsname {\RL {#7}}%
	\addcontentsline {toc}{#1}%
		{\ifnum #2>\c@secnumdepth \else
		\protect\numberline {\csname the#1\endcsname}\fi
		\protect\RL {#7}}}% \@svsechd
\fi \a@xsect {#5}}
 
\def\a@xsect #1{% Arabic mode
\@tempskipa #1\relax
\ifdim \@tempskipa>\z@ \a@@par \nobreak \vskip \@tempskipa
       \a@afterheading
\else \global\@nobreakfalse \global\@noskipsectrue
\a@@everypar {\if@noskipsec \global\@noskipsecfalse \clubpenalty \@M 
        	\putwordb@x {\hskip -\a@parindent }\@svsechd
        	\putwordb@x {\hskip -#1\relax }%
             \else \clubpenalty \@clubpenalty \a@@everypar {}%
             \fi}
\fi \a@spacefalse 
%\tracingmacros 0
\test@token }

\def \a@afterheading {% Arabic mode
\global\@nobreaktrue
\a@@everypar {% when entering Arabic horizontal mode
	\if@nobreak \global\@nobreakfalse \clubpenalty \@M
		\if@afterindent \else \putwordb@x {\hskip -\a@parindent }%
		\fi
	\else \clubpenalty \@clubpenalty \a@@everypar{}%
	\fi}}
 
\def \a@hangfrom #1{% hanging indentation for rest of paragraph (group)
\setbox0 \hbox {#1}\@tempdima \wd0
\advance \leftskip \@tempdima \advance \a@limit -\@tempdima
\putlineb@x {\rlap {\unhbox0 }}\a@spacefalse }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for table of contents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\iffalse % LaTeX 2.09 routines

\def\contentsline#1{\csname l@#1\endcsname}
 
% \@dottedtocline{LEVEL}{INDENT}{NUMWIDTH}{TITLE}{PAGE} :
%   Macro to produce a table of contents line with the following
%   parameters:
%     LEVEL    : If LEVEL > \c@tocdepth, then no line produced.
%     INDENT   : Total indentation from the left margin.
%     NUMWIDTH : Width of box for number if the TITLE has a
%                \numberline command.
%                As of 25 Jan 88, this is also the amount of extra indentation
%                added to second and later lines of a multiple line entry.
%     TITLE    : Contents of entry.
%     PAGE     : Page number.
%
%  Uses the following parameters, which must be set by the document style.
%  They should be defined with \def's.
%    \@pnumwidth : Width of box in which page number is set.
%    \@tocrmarg  : Right margin indentation for all but last line of
%                  multiple-line entries.
%    \@dotsep    : Separation between dots, in mu units.  Should be \def'd to
%                  a number like 2 or 1.7
%

%% RmS 91/09/29: added \reset@font for page number 
\def\@dottedtocline#1#2#3#4#5{\ifnum #1>\c@tocdepth \else
  \vskip \z@ plus.2\p@
  {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
    \parindent #2\relax\@afterindenttrue
   \interlinepenalty\@M
   \leavevmode
   \@tempdima #3\relax \advance\leftskip \@tempdima \hbox{}\hskip -\leftskip
    #4\nobreak\leaders\hbox{$\m@th \mkern \@dotsep mu.\mkern \@dotsep
       mu$}\hfill \nobreak
           \hbox to\@pnumwidth{\hfil\reset@font\rm #5}\par}\fi}
 
 
%%% Note: \nobreak's added 7 Jan 86 to prevent bad line break that
%%% left the page number dangling by itself at left edge of a new line.
%%%
%%% Changed 25 Jan 88 to use \leftskip instead of \hangindent so
%%% leaders of multiple-line contents entries would line up properly.
 
% \numberline{NUMBER} : For use in a \contentsline command.
%   It puts NUMBER flushleft in a box of width \@tempdima
%   (Before 25 Jan 88 change, it also added \@tempdima to the hanging
%   indentation.)
 
\def\numberline#1{\hbox to\@tempdima{#1\hfil}}
 
\fi % end of LaTeX 2.09 routines

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arabic versions of toc auxiliary routines
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \a@c@starttoc #1{\endarabtext 
\the\arabtext@hook \@starttoc {#1}\arabtext }
 
\def \a@t@ble #1#2{% \tableofcontents etc.
\a@c@section *{#1}\@mkboth {#1}{#1}\starttoc {#2}}

\def \a@c@@mkboth #1#2{\@mkboth {\RL{#1}}{\RL{#2}}\test@token }

\def \a@@lsection #1#2#3{% common part for \part and \section
	\begin{arabtext}
%	\tocp@rs {\z@ }{\@tempdima }#3 #1 {\hfill \thep@geno {#2}}
	\tocp@rs {\z@ }{\@tempdima }#3 #1 {#3\hfill \thep@geno {#2}}
	\end{arabtext}}

\def \a@dottedtocline #1#2#3#4#5{% for Arabic mode
\ifnum #1>\c@tocdepth 
\else \vskip \z@ plus.2\p@
	\begin{arabtext}
	\tocp@rs {#2}{#3}#4 {\le@ders \thep@geno {#5}}
	\end{arabtext}
\fi }

\def \a@c@tocp@rs #1#2{% change toc parameters
\advance \leftskip #1\relax \advance \a@limit -#1\relax
\advance \leftskip #2\relax \advance \a@limit -#2\relax
\advance \rightskip \@tocrmarg \advance \a@limit -\@tocrmarg
\@tempdima #2\relax % for \numberline, width of number
\parfillskip \z@ \test@token }

\def \a@c@le@ders {% for toc
\setbox \wordb@x \hbox to \z@ {\leaders \hbox 
{$\m@th \mkern \@dotsep mu\hbox {.}\mkern \@dotsep mu$}\hfill }%
\put@word \test@token }

\def \a@c@thep@geno #1{% pagenumber of width \@pnumwidth
\dimen@ \@pnumwidth \advance \dimen@ -\rightskip
\a@c@spreadbox {\dimen@ }{\hss #1 \hspace {-\rightskip }}}

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

\iffalse
\def \a@numberline #1#2{% for arabic mode
#2\hbox to\@tempdima {\hfil \<#1>}}

\def \a@numberline #1\a@RL #2{% for arabic mode
\RL {\spreadbox \@tempdima {#1 \hfill }#2}}
\fi

\def \a@c@numberline #1{% external Arabic command
\a@c@hspace {-\@tempdima }\spreadbox \@tempdima {#1 \hfill }}

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

\at@arabtext {% modify LaTeX for Arabic mode
	\let \numberline \a@numberline
	\let \@dottedtocline \a@dottedtocline
\if@twocolumn
	\def\@pnumwidth{1.0em}
	\def\@tocrmarg {1em}
\fi
} 

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

\def \a@c@addcontentsline #1#2#3{% Arabic version
\addcontentsline {#1}{#2}{\LR{#3}}\arab@tail }

\let \a@c@abstract \a@c@quotation
\let \endabstract \endquotation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\iffalse % LaTeX 2.09 routines

\def\@starttoc#1{\begingroup
  \makeatletter
  \@input{\jobname.#1}\if@filesw \expandafter\newwrite\csname tf@#1\endcsname
             \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
  \fi \global\@nobreakfalse \endgroup}
 
\fi % end of LaTeX 2.09 routines

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

\def\a@sect #1#2#3#4#5#6[#7]#8{% Arabic mode
\ifnum #2 > \c@secnumdepth \let \@svsec \@empty 
\else \refstepcounter{#1}%
	\edef \@svsec 
	{\nxp\RL {\nxp\stdcode {\csname the#1\endcsname }\hskip 1em}}%
\fi
\@tempskipa #5\relax
\ifdim \@tempskipa > \z@
	\begingroup \let \end \a@@par 
		#6\relax \set@arabfont % style
	        \a@hangfrom {\hskip #3\relax \@svsec }% section number
		\test@token #8 \end
	\endgroup
	\csname #1mark\endcsname {\RL {#7}}%
	\addcontentsline {toc}{#1}%
		{\ifnum #2 > \c@secnumdepth \else \protect\numberline 
		{\protect\RL{\protect\stdcode{\csname the#1\endcsname }}}\fi
		\protect\RL {#7}}%
\else \def \@svsechd {% saved head, executed by \everypar
	#6\relax \set@arabfont % style
	\let \a@@end \end \def \end {\let \end \a@@end }%
	\test@token \@svsec % saved section number
	\hskip #3\relax #8 \end
        \csname #1mark\endcsname {\RL {#7}}%
	\addcontentsline {toc}{#1}%
		{\ifnum #2>\c@secnumdepth \else \protect\numberline 
		{\protect\RL{\protect\stdcode{\csname the#1\endcsname }}}\fi
		\protect\RL {#7}}}% \@svsechd
\fi \a@xsect {#5}}

\allowarab \@svsec
 
\def\a@xsect #1{% Arabic mode
\@tempskipa #1\relax
\ifdim \@tempskipa>\z@ \a@@par \nobreak \vskip \@tempskipa
       \a@afterheading
\else \global\@nobreakfalse \global\@noskipsectrue
\a@@everypar {\if@noskipsec \global\@noskipsecfalse \clubpenalty \@M 
        	\putwordb@x {\hskip -\a@parindent }\@svsechd
        	\putwordb@x {\hskip -#1\relax }%
             \else \clubpenalty \@clubpenalty \a@@everypar {}%
             \fi}
\fi \a@spacefalse \test@token }

\def \a@c@numberline #1{% external Arabic command
\a@c@hspace {-\@tempdima }\spreadbox \@tempdima {#1 \hfill }}

\def \a@@lsection #1#2#3{% Text, Pageno, Font
% common part for \part and \section
	\begin{arabtext}
	#3\tocp@rs {\z@ }{\@tempdima }#1 \hfill \thep@geno {#2}
	\end{arabtext}}

\def \a@dottedtocline #1#2#3#4#5{% Level, Indent, Numwidth, Text, Pageno
% for Arabic mode
\ifnum #1>\c@tocdepth 
\else \vskip \z@ plus.2\p@
	\begin{arabtext}
	\tocp@rs {#2}{#3}#4 {\le@ders \thep@geno {#5}}
	\end{arabtext}
\fi }

\def \a@c@tocp@rs #1#2{% Indent, Numwidth
% change toc parameters
\leftskip #1\relax \advance \leftskip #2\relax 
\advance \rightskip \@tocrmarg 
\@tempdima #2\relax % for \numberline, width of number
\a@parindent \z@ \parfillskip \z@ \test@token }

\at@arabtext {% modify LaTeX for Arabic mode
	\let \numberline \a@numberline
	\let \@dottedtocline \a@dottedtocline
}

\c@secnumdepth \c@tocdepth % for test TOC

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