% Copyright 2006 Konstantin Korikov <lostclus@ua.fm>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
% 
% This Current Maintainer of this work is Konstantin Korikov.
%
% This work consists of all files listed in manifest.txt.
%

%
% This is automaticaly generated file, do not edit it.
%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{espdsect}[2010/01/14 v0.98 Sectioning]
\RequirePackage{calc}

\newcommand{\ESPD@point@style}{single}

\DeclareOption{pointsingle}{\renewcommand{\ESPD@point@style}{single}}
\DeclareOption{pointsection}{\renewcommand{\ESPD@point@style}{section}}
\DeclareOption{pointsubsection}{\renewcommand{\ESPD@point@style}{subsection}}

\ProcessOptions\relax

\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{}%
    \divide \@tempskipa by 2
    \vskip -\@tempskipa
    \vskip\z@skip
  \else
    \addpenalty\@secpenalty\addvspace\@tempskipa
  \fi
  \@ifstar
    {\@ssect{#3}{#4}{#5}{#6}}%
    {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}

\newcommand{\ESPDsectAlignLeft}{%
  \let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip%
  \leftskip\z@skip}
\newcommand{\ESPDsectAlignRight}{%
  \let\\\@centercr\rightskip\z@skip\leftskip\@flushglue
  \parindent\z@\parfillskip\z@skip}
\newcommand{\ESPDsectAlignCenter}{%
  \let\\\@centercr
  \rightskip\@flushglue\leftskip\@flushglue
  \parindent\z@\parfillskip\z@skip}

\newcommand{\ESPDsectionAlign}{\ESPDsectAlignLeft}
\newcommand{\ESPDsubsectionAlign}{\ESPDsectAlignLeft}
\newcommand{\ESPDsubsubsectionAlign}{\ESPDsectAlignLeft}

\newcommand{\ESPDsectAlign}[2]{%
  \expandafter\renewcommand\csname\string ESPD#1Align\endcsname{%
  \@nameuse{ESPDsectAlign#2}}}

\newcommand{\ESPDsectionStyle}{\normalfont\normalsize\MakeUppercase}
\newcommand{\ESPDsubsectionStyle}{\normalfont\normalsize}
\newcommand{\ESPDsubsubsectionStyle}{\normalfont\normalsize}

\newcommand{\ESPDsectStyle}[2]{%
  \expandafter\renewcommand\csname\string ESPD#1Style\endcsname{#2}}

\newlength{\ESPDsectionSkipBefore}
\newlength{\ESPDsectionSkipAfter}
\setlength{\ESPDsectionSkipBefore}{-5mm \@plus -3mm \@minus -2mm}
\setlength{\ESPDsectionSkipAfter}{5mm \@plus 1mm \@minus 2mm}
\newlength{\ESPDsubsectionSkipBefore}
\newlength{\ESPDsubsectionSkipAfter}
\setlength{\ESPDsubsectionSkipBefore}{-5mm \@plus -3mm \@minus -2mm}
\setlength{\ESPDsubsectionSkipAfter}{5mm \@plus 1mm \@minus 2mm}
\newlength{\ESPDsubsubsectionSkipBefore}
\newlength{\ESPDsubsubsectionSkipAfter}
\setlength{\ESPDsubsubsectionSkipBefore}{-5mm \@plus -3mm \@minus -2mm}
\setlength{\ESPDsubsubsectionSkipAfter}{5mm \@plus 1mm \@minus 2mm}

\providecommand{\plus}{\@plus}
\providecommand{\minus}{\@minus}

\newcommand{\ESPDsectSkip}[3]{%
  \expandafter\setlength\csname\string ESPD#1SkipBefore\endcsname{#2}%
  \expandafter\setlength\csname\string ESPD#1SkipAfter\endcsname{#3}}

\renewcommand\section{\@startsection {section}{1}{\parindent}%
                                   {\ESPDsectionSkipBefore}%
                                   {\ESPDsectionSkipAfter}%
                                   {\ESPDsectionAlign\ESPDsectionStyle}}
\renewcommand\subsection{\@startsection{subsection}{2}{\parindent}%
                                     {\ESPDsubsectionSkipBefore}%
                                     {\ESPDsubsectionSkipAfter}%
                                     {\ESPDsubsectionAlign\ESPDsubsectionStyle}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\parindent}%
                                     {\ESPDsubsubsectionSkipBefore}%
                                     {\ESPDsubsubsectionSkipAfter}%
                                     {\ESPDsubsubsectionAlign\ESPDsubsubsectionStyle}}

\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}

\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thesubsubsection}{\thesubsection\arabic{subsubsection}.}
\newif\ifESPD@point@style@single
\ESPD@point@style@singlefalse

\newcommand{\ESPD@point@style@single}{
  \newcounter{point}
  \renewcommand{\thepoint}{\arabic{point}}
  \newcommand{\theHpoint}{\arabic{point}}
  \ESPD@point@style@singletrue}

\newcommand{\ESPD@point@style@section}{
  \newcounter{point}[section]
  \renewcommand{\thepoint}{\thesection.\arabic{point}}
  \newcommand{\theHpoint}{\theHsection.\arabic{point}}}

\newcommand{\ESPD@point@style@subsection}{
  \newcounter{point}[subsection]
  \renewcommand{\thepoint}{\thesubsection.\arabic{point}}
  \newcommand{\theHpoint}{\theHsubsection.\arabic{point}}}

\@nameuse{ESPD@point@style@\ESPD@point@style}
\newcounter{subpoint}[point]
\newcounter{subsubpoint}[subpoint]
\renewcommand{\thesubpoint}{\thepoint.\arabic{subpoint}}
\newcommand{\theHsubpoint}{\theHpoint.\arabic{subpoint}}
\renewcommand{\thesubsubpoint}{\thesubpoint.\arabic{subsubpoint}}
\newcommand{\theHsubsubpoint}{\theHsubpoint.\arabic{subsubpoint}}

\newcommand{\point}{%
  \par\refstepcounter{point}\thepoint\quad}
\newcommand{\subpoint}{%
  \par\refstepcounter{subpoint}\thesubpoint\quad}
\newcommand{\subsubpoint}{%
  \par\refstepcounter{subsubpoint}\thesubsubpoint\quad}


\newcounter{pointII}[section]
\newcounter{pointIII}[subsection]
\newcounter{pointIV}[subsubsection]

\renewcommand{\thepointII}{\thesection\arabic{pointII}.}
\renewcommand{\thepointIII}{\thesubsection\arabic{pointIII}.}
\renewcommand{\thepointIV}{\thesubsubsection\arabic{pointIV}.}

\newcommand{\pointII}{%
  \par\refstepcounter{pointII}\thepointII\quad}
\newcommand{\pointIII}{%
  \par\refstepcounter{pointIII}\thepointIII\quad}
\newcommand{\pointIV}{%
  \par\refstepcounter{pointIV}\thepointIV\quad}

\newcounter{subpointIII}[pointII]
\newcounter{subpointIV}[pointIII]

\renewcommand{\thesubpointIII}{\thepointII\arabic{subpointIII}.}
\renewcommand{\thesubpointIV}{\thepointIII\arabic{subpointIV}.}

\newcommand{\subpointIII}{%
  \par\refstepcounter{subpointIII}\thesubpointIII\quad}
\newcommand{\subpointIV}{%
  \par\refstepcounter{subpointIV}\thesubpointIV\quad}




\newcounter{appendix}
\renewcommand{\theappendix}{\Asbuk{appendix}}
\newlength{\ESPDappendixSkip}
\setlength{\ESPDappendixSkip}{15mm \@plus 3mm \@minus 10mm}

\newcommand{\ESPDappendix}[2]{%
  \ESPDclearDoublePage%
  \refstepcounter{appendix}%
  \setcounter{point}{0}%
  \ifESPD@point@style@single%
    \renewcommand{\thepoint}{\theappendix.\arabic{point}}%
  \fi
  \setcounter{section}{0}%
  \renewcommand{\thesection}{\theappendix.\arabic{section}}%
  \setcounter{equation}{0}%
  \renewcommand{\theequation}{\theappendix.\arabic{equation}}%
  \setcounter{figure}{0}%
  \renewcommand{\thefigure}{\theappendix.\arabic{figure}}%
  \setcounter{table}{0}%
  \renewcommand{\thetable}{\theappendix.\arabic{table}}%
  \addcontentsline{toc}{section}{\appendixname\ \theappendix\ #2}%
  \begin{list}{}{%
    \setlength{\itemindent}{0mm}%
    \setlength{\labelwidth}{0mm}%
    \setlength{\labelsep}{0mm}%
    \setlength{\leftmargin}{0mm}%
    \setlength{\topsep}{0mm}%
    \setlength{\parskip}{0mm}%
    \setlength{\partopsep}{0mm}%
    \setlength{\itemsep}{0mm}%
    \setlength{\parsep}{0mm}}
    \item\centering\appendixname\ \theappendix
    \ifx#1\@empty\else\\(#1)\fi\\
    \item\centering\bf #2
  \end{list}%
  \par\nobreak\addvspace{\ESPDappendixSkip}}

%\renewcommand\tableofcontents{%
%  \begingroup
%  \ESPDsectAlign{section}{Center}
%  \section*{\contentsname
%    \@mkboth{%
%      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
%  \endgroup
%  \@starttoc{toc}}

\RequirePackage[style]{abstract}
\renewcommand{\abstitlestyle}[1]{\center\normalsize\MakeUppercase #1}
\ESPDsectAlign{section}{Center}

\RequirePackage[titles]{tocloft}
\renewcommand{\cftsecfont}{\normalfont\normalsize}
\renewcommand{\cftsubsecfont}{\normalfont\normalsize}
\renewcommand{\cftsubsubsecfont}{\normalfont\normalsize}
\renewcommand{\cftsecpagefont}{\normalfont\normalsize}
\renewcommand{\cftsubsecpagefont}{\normalfont\normalsize}
\renewcommand{\cftsubsubsecpagefont}{\normalfont\normalsize}
\renewcommand\cftsecafterpnum{\vskip0pt}
\renewcommand\cftsubsecafterpnum{\vskip0pt}
\renewcommand\cftsubsubsecafterpnum{\vskip0pt}
\renewcommand\cftbeforesecskip{0pt}
\renewcommand\cftbeforesubsecskip{0pt}
\renewcommand\cftbeforesubsubsecskip{0pt}

\renewcommand{\cftdot}{}

