
% \iffalse
%%% From File: chapter.dtx
% \fi
%
%    \begin{macrocode}

%<*chapter>
%    \end{macrocode}
%
% \subsection{Глава}
%
% \subsubsection{Параметры формата главы в оглавлении}
%
% \DescribeMacro{\tocprethechapter}\index{Макросы!\verb*+\tocprethechapter+}
% \DescribeMacro{\tocpostthechapter}\index{Макросы!\verb*+\tocpostthechapter+}
% \DescribeMacro{\tocchapterfill}\index{Макросы!\verb*+\tocchapterfill+}
%
% \DescribeMacro{\tocchapterfont}\index{Макросы!\verb*+\tocchapterfont+}
% \DescribeMacro{\tocchapterfillfont}\index{Макросы!\verb*+\tocchapterfillfont+}
% \DescribeMacro{\tocchapternumfont}\index{Макросы!\verb*+\tocchapternumfont+}
%    \begin{macrocode}
\providecommand\tocprethechapter{\protect\chaptername~}
\providecommand\tocpostthechapter{.\@postskip}
\providecommand\tocchapterfill{\tocfill{.}}

\providecommand\tocchapterfont{\bfseries}
\providecommand\tocchapterfillfont{\normalfont}
\providecommand\tocchapternumfont{\normalfont}

%    \end{macrocode}
% \subsubsection{Параметры формата нумеруемой главы в тексте}
% \DescribeMacro{\thechapteralign}\index{Макросы!\verb*+\thechapteralign+}
% \DescribeMacro{\thechapterfont}\index{Макросы!\verb*+\thechapterfont+}
% \DescribeMacro{\prethechapter}\index{Макросы!\verb*+\prethechapter+}
% \DescribeMacro{\postthechapter}\index{Макросы!\verb*+\postthechapter+}
%
% \DescribeMacro{\chapteralign}\index{Макросы!\verb*+\chapteralign+}
% \DescribeMacro{\chapterfont}\index{Макросы!\verb*+\chapterfont+}
% \DescribeMacro{\beforechapter}\index{Макросы!\verb*+\beforechapter+}
% \DescribeMacro{\afterchapter}\index{Макросы!\verb*+\afterchapter+}
%    \begin{macrocode}
\providecommand\thechapteralign{\centering}
\providecommand\thechapterfont{\Large}
\providecommand\prethechapter{\protect\chaptername~}
\providecommand\postthechapter{\par\nobreak\vskip 5\p@}

\providecommand\chapteralign{\centering}
\providecommand\chapterfont{\Large\bfseries}
\providecommand\beforechapter{}
\providecommand\afterchapter{\par\nobreak\vskip 20\p@}
\newlength{\chapterindent}
\setlength{\chapterindent}{0\p@}

%    \end{macrocode}
% \subsubsection{Параметры формата ненумеруемой главы в тексте}
% \DescribeMacro{\schapteralign}\index{Макросы!\verb*+\schapteralign+}
% \DescribeMacro{\schapterfont}\index{Макросы!\verb*+\schapterfont+}
% \DescribeMacro{\beforeschapter}\index{Макросы!\verb*+\beforeschapter+}
% \DescribeMacro{\afterschapter}\index{Макросы!\verb*+\afterschapter+}
%    \begin{macrocode}
\providecommand\schapteralign{\chapteralign}
\providecommand\schapterfont{\chapterfont}
\providecommand\beforeschapter{\beforechapter}
\providecommand\afterschapter{\afterchapter}
\newlength{\schapterindent}
\setlength{\schapterindent}{0\p@}

%    \end{macrocode}
%
% \subsubsection{Низкоуровневые команды}
%
% Пустое определение колонтитула главы.
% \DescribeMacro{\chaptermark}\index{Макросы!\verb*+\chaptermark+}
%    \begin{macrocode}
\newcommand*\chaptermark[1]{}

%    \end{macrocode}
% Интерфейс.
% \DescribeMacro{\chapter}\index{Макросы!\verb*+"\chapter+}
%    \begin{macrocode}
\newcommand\chapter{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{\@chapterpagestyle}%
  \global\@topnum\z@
  \@afterindentfalse
  \secdef\@chapter\@schapter
}

%    \end{macrocode}
% Команда, формирующая нумеруемый заголовок |\chapter|.
% \DescribeMacro{\@chapter}\index{Макросы!\verb+"\"@chapter+}
%    \begin{macrocode}
\def\@chapter[#1]#2{
  \ifnum \c@secnumdepth >\m@ne
    \refstepcounter{chapter}%
    {\addcontentsline{toc}{chapter}{\@tocseccntformat{chapter} #1}}%
  \else
    {\addcontentsline{toc}{chapter}{#1}}%
  \fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]%
  \else
    \@makechapterhead{#2}%
    \@afterheading
  \fi
}

%    \end{macrocode}
% Формат нумеруемого заголовка.
% \DescribeMacro{\@makechapterhead}\index{Макросы!\verb+"\"@makechapterhead+}
%    \begin{macrocode}
\def\@makechapterhead#1{{%
  \parindent\z@
  \normalfont\hskip\chapterindent%
  \ifnum \c@secnumdepth >\m@ne
    {\thechapterfont\thechapteralign\@seccntformat{chapter}}
  \fi
  \interlinepenalty\@M
  \chapterfont\chapteralign\beforechapter #1\afterchapter
}}

%    \end{macrocode}
% Команда, формирующая ненумеруемый заголовок |\chapter*|.
% \DescribeMacro{\@schapter}\index{Макросы!\verb+"\"@schapter+}
%    \begin{macrocode}
\def\@schapter#1{
  \if@twocolumn
    \@topnewpage[\@makeschapterhead{#1}]%
  \else
    \@makeschapterhead{#1}%
    \@afterheading
  \fi
}

%    \end{macrocode}
%
% \DescribeMacro{\@makeschapterhead}\index{Макросы!\verb+"\"@makeschapterhead+}
% Формат ненумеруемого заголовка.
%    \begin{macrocode}
\def\@makeschapterhead#1{{%
  \parindent\z@
  \normalfont\hskip\schapterindent%
  \interlinepenalty\@M
  \schapteralign\schapterfont\beforeschapter #1\afterschapter
}}

%    \end{macrocode}
%
% \DescribeMacro{\l@chapter}\index{Макросы!\verb+"\l"@chapter+}
% Команда, создающая запись в оглавлении.
%    \begin{macrocode}
\newcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode\tocchapterfont
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak
      \tocchapterfillfont\tocchapterfill\hfill
      \nobreak\hb@xt@\@pnumwidth{\hss\tocchapternumfont #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi
}

%    \end{macrocode}
%
% \subsection{Приложение}
%
% \subsubsection{Параметры формата записи в оглавлении}
% \DescribeMacro{\tocpretheappendix}\index{Макросы!\verb*+\tocpretheappendix+}
% \DescribeMacro{\tocposttheappendix}
%   \index{Макросы!\verb*+\tocposttheappendix+}
% \DescribeMacro{\tocappendixfill}\index{Макросы!\verb*+\tocappendixfill+}
% \DescribeMacro{\tocappendixfont}\index{Макросы!\verb*+\tocappendixfont+}
% \DescribeMacro{\tocappendixfillfont}
%   \index{Макросы!\verb*+\tocappendixfillfont+}
% \DescribeMacro{\tocappendixnumfont}
%   \index{Макросы!\verb*+\tocappendixnumfont+}
%    \begin{macrocode}
\providecommand\tocpretheappendix{\protect\appendixname~}
\providecommand\tocposttheappendix{.\@postskip}
\providecommand\tocappendixfill{\tocfill{.}}

\providecommand\tocappendixfont{\bfseries}
\providecommand\tocappendixfillfont{\normalfont}
\providecommand\tocappendixnumfont{\normalfont}

%    \end{macrocode}
% \subsubsection{Параметры формата в тексте}
% \DescribeMacro{\theappendixalign}\index{Макросы!\verb*+\theappendixalign+}
% \DescribeMacro{\theappendixfont}\index{Макросы!\verb*+\theappendixfont+}
% \DescribeMacro{\pretheappendix}\index{Макросы!\verb*+\pretheappendix+}
% \DescribeMacro{\posttheappendix}\index{Макросы!\verb*+\posttheappendix+}
%
% \DescribeMacro{\appendixalign}\index{Макросы!\verb*+\appendixalign+}
% \DescribeMacro{\appendixfont}\index{Макросы!\verb*+\appendixfont+}
% \DescribeMacro{\beforeappendix}\index{Макросы!\verb*+\beforeappendix+}
% \DescribeMacro{\afterappendix}\index{Макросы!\verb*+\afterappendix+}
%    \begin{macrocode}
\providecommand\theappendixalign{\centering}
\providecommand\theappendixfont{\Large}
\providecommand\pretheappendix{\protect\appendixname~}
\providecommand\posttheappendix{\par\nobreak\vskip 5\p@}

\providecommand\appendixalign{\centering}
\providecommand\appendixfont{\Large\bfseries}
\providecommand\beforeappendix{}
\providecommand\afterappendix{\par\nobreak\vskip 20\p@}
\providecommand\appendixindent{0\p@}
%    \end{macrocode}
%
% Команда для создания глав приложений. Сохранение и восстановление
% значений параметров формата глав делаются для случая, когда
% приложения идут до списка литературы.
% \DescribeMacro{\appendix}\index{Макросы!\verb*+\appendix+}
%    \begin{macrocode}
\newcommand\appendix{
  \setcounter{chapter}{0}
  \setcounter{section}{0}

%    \end{macrocode}
% Сохранение старых значений.
%    \begin{macrocode}
  \let\oldtocprethechapter=\tocprethechapter
  \let\oldtocpostthechapter=\tocpostthechapter
  \let\oldtocchapterfill=\tocchapterfill

  \let\oldtocchapterfont=\tocchapterfont
  \let\oldtocchapterfillfont=\tocchapterfillfont
  \let\oldtocchapternumfont=\tocchapternumfont

  \let\oldthechapteralign=\thechapteralign
  \let\oldthechapterfont=\thechapterfont
  \let\oldprethechapter=\prethechapter
  \let\oldpostthechapter=\postthechapter

  \let\oldchapteralign=\chapteralign
  \let\oldchapterfont=\chapterfont
  \let\oldchapterindent=\chapterindent
  \let\oldbeforechapter=\afterchapter
  \let\oldafterchapter=\afterchapter
  \let\oldthechapter=\thechapter

%    \end{macrocode}
% Перезапись параметров формата главы для оформления приложений.
%    \begin{macrocode}
  \renewcommand\tocprethechapter{\tocpretheappendix}
  \renewcommand\tocpostthechapter{\tocposttheappendix}
  \renewcommand\tocchapterfill{\tocappendixfill}

  \renewcommand\tocchapterfont{\tocappendixfont}
  \renewcommand\tocchapterfillfont{\tocappendixfillfont}
  \renewcommand\tocchapternumfont{\tocappendixnumfont}

  \renewcommand\thechapteralign{\theappendixalign}
  \renewcommand\thechapterfont{\theappendixfont}
  \renewcommand\prethechapter{\pretheappendix}
  \renewcommand\postthechapter{\posttheappendix}

  \renewcommand\chapteralign{\appendixalign}
  \renewcommand\chapterfont{\appendixfont}
  \renewcommand\beforechapter{\beforeappendix}
  \renewcommand\afterchapter{\afterappendix}
  \renewcommand\chapterindent{\appendixindent}

  \gdef\thechapter{\theappendix}
}

%    \end{macrocode}
% Восстановление исходных параметров формата заголовков глав.
% \DescribeMacro{\noappendix}\index{Макросы!\verb*+\noappendix+}
%    \begin{macrocode}
\newcommand\noappendix{
  \let\tocprethechapter=\oldtocprethechapter
  \let\tocpostthechapter=\oldtocpostthechapter
  \let\tocchapterfill=\oldtocchapterfill

  \let\tocchapterfont=\oldtocchapterfont
  \let\tocchapterfillfont=\oldtocchapterfillfont
  \let\tocchapternumfont=\oldtocchapternumfont

  \let\thechapteralign=\oldthechapteralign
  \let\thechapterfont=\oldthechapterfont
  \let\prethechapter=\oldprethechapter
  \let\postthechapter=\oldpostthechapter

  \let\chapteralign=\oldchapteralign
  \let\chapterfont=\oldchapterfont
  \let\beforechapter=\oldbeforechapter
  \let\afterchapter=\oldafterchapter

  \gdef\thechapter{\oldthechapter}
}

%</chapter>
%    \end{macrocode}
