% \iffalse
%%
%% File: nccsect.dtx Copyright (C) 2002--2006 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{nccsect}
%<package>         [2006/01/19 v1.5 Extended Section, Caption, and TOC Handling (NCC)]
%
% \changes{v1.00}{2002/02/01}{This version is uploaded to CTAN}
% \changes{v1.01}{2002/02/08}{\NCC@thetocchapter hook added}
% \changes{v1.02}{2002/02/13}{Bug in using the \nosectiontag fixed}
% \changes{v1.02}{2002/03/19}{Test for caption with empty text added}
% \changes{v1.03}{2002/05/19}{Vskips in captions after style changes now}
% \changes{v1.04}{2002/05/22}{Centering in captions now works}
% \changes{v1.1}{2004/12/12}{Introduce |\NCC@sec@reset@controls|}
% \changes{v1.1}{2004/12/12}{Simplify making sections. The |\NCC@makesection| now
%                            incompatible with previous version!!!}
% \changes{v1.1}{2004/12/12}{Revised version: many internal changes}
% \changes{v1.1}{2004/12/12}{Documentation was prepared}
% \changes{v1.2}{2005/04/15}{Emulate |\@makecaption| for compatibility}
% \changes{v1.2}{2005/04/15}{Compatibility with the supertabular package added}
% \changes{v1.2}{2005/04/15}{Compatibility with the longtable package added}
% \changes{v1.2}{2005/05/20}{Introduce |\beforechapter| hook}
% \changes{v1.2}{2005/05/20}{Add |\StartFromTextArea| and |\StartFromHeaderArea|}
% \changes{v1.2}{2005/05/21}{Add |\epigraph| and |\epigraphparameters|}
% \changes{v1.2}{2005/05/22}{Add |\captionstyle| and related staff}
% \changes{v1.2}{2005/05/22}{Add |\TOCMarginDrift|}
% \changes{v1.2}{2005/05/22}{Add |\applystyle| command to TOC Entry style}
% \changes{v1.2}{2005/06/08}{Set |\@twocolumnfalse| in before-chapter hook}
% \changes{v1.2}{2005/06/08}{Allow sectioning in |\beforechapter| hook}
% \changes{v1.3}{2005/06/15}{Fixed bug with using |\applystyle| command}
% \changes{v1.4}{2005/12/26}{Conditionally define |\StartFromTextArea| and |\StartFromHeaderArea|}
% \changes{v1.4}{2005/12/28}{|\sectionstyle| now has a |type| parameter}
% \changes{v1.4}{2005/12/28}{New section styles: hangparindent, hangparindent*}
% \changes{v1.4}{2005/12/28}{|\NCC@makechapfinal| hook introduced}
% \changes{v1.4}{2005/12/28}{|\NCC@makeparttitle|, |\NCC@makechaptitle| hooks}
% \changes{v1.4}{2005/12/28}{The scope of declarations in |\@svsec| is localized}
% \changes{v1.4}{2005/12/28}{|\aftersectionvspace| introduced}
% \changes{v1.4}{2005/12/29}{Add |\DeclarePart| and |\DeclareTOCPart| commands}
% \changes{v1.4}{2005/12/30}{Make the package completely independent on standard commands}
% \changes{v1.4}{2005/12/31}{Add more hooks and fix |\MakeUppercase| related bugs}
% \changes{v1.4}{2006/01/01}{Introduce |\RunningSectionSuffux| command}
% \changes{v1.4}{2006/01/01}{Introduce |\NCC@preparesectag| hook}
% \changes{v1.4}{2006/01/01}{Remove |\NCC@defaultsectag| hook}
% \changes{v1.4}{2006/01/01}{|\NCC@nexttocnum|, |\NCC@preparetocnum| hooks}
% \changes{v1.4}{2006/01/03}{The |\norunningsuffix| modifier introduced}
% \changes{v1.5}{2006/01/06}{Introduce |\SetTOCStyle| and |\ChapterPrefixStyle|}
% \changes{v1.5}{2006/01/17}{Replace addtopackage to afterpackage}
% \changes{v1.5}{2006/01/17}{Remove \protect before \numberline, because it is robust now}
% \changes{v1.5}{2006/01/19}{Allow caption width be greater than a line width}
% \changes{v1.5}{2006/01/19}{Compatibility with the xtab package added}
% \changes{v1.5}{2006/01/19}{Add |\newplainsectionstyle|, |\newhangsectionstyle|}
% \changes{v1.5}{2006/01/19}{Add |\adjustsectionmargins|}
% \changes{v1.5}{2006/01/19}{Introduce |centerlast| section style}
% \changes{v1.5}{2006/01/19}{Introduce |\sectiontagsuffix| command}
% \changes{v1.5}{2006/01/19}{Introduce |\captiontagsuffix| command}
%
%<*driver>
\let\makeindex\relax
\documentclass{ltxdoc}
\usepackage{nccsect,nccboxes,desclist}
\GetFileInfo{nccsect.sty}
\newhangsectionstyle{margin}{2in}[r]{-2in}{0pt plus 1fil}
\newhangsectionstyle{list}{1in}{0pt}{1in plus 1fil}
\newplainsectionstyle{flushright}{0pt}[r]{1in plus 1fil}{0pt}
\begin{document}
\title{The \textsf{nccsect} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}\ \thanks{Great thanks to Denis G. Samsonenko
        \texttt{<d.g.samsonenko@gmail.com>} who proposed many significant
        improvements to the package.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{nccsect.dtx}
\end{document}
%</driver>
% \fi
%
% \tableofcontents
%
% \section{The Scope and Objectives}
%
% The package provides a new implementation of sections, captions,
% and toc-entries independent on the \LaTeX\ kernel. The reasons for this
% are concerned with the following disadvantages of the
% standard \LaTeX\ implementation:
%
% \paragraph{1} Standard \LaTeX\ sectioning commands can prepare
% display sections in the single style: justified paragraph
% with hang indented number. To change this style to another
% one (centered, par-indented, or else), you need
% to re-implement the internal |\@sect| command. It is no
% control for this style on user's level.
%
% \paragraph{2} If you want to customize the presentation a number in
% a section (for example, put a paragraph mark \S\ before a number
% or put a point after a number), you at least need to
% re-implement the |\@sect| command.
%
% \paragraph{3} The sectioning commands provide no straightforward
% control for running headings. The marking commands
% like the |\sectionmark| solve this problem partially.
% Using them within parameter of sectioning command,
% you can change the mark properly, but this solution does not work in
% complicated documents which use first and last marks
% appearing on a page. The safe solution consists in direct
% replacement a mark prepared within the |\@sect| command
% to a custom mark.
%
% \paragraph{4} Special efforts are required to pass a section
% without number to the header and to the toc-list. There is no simple
% solution providing this action.
%
% \paragraph{5} Captions for tables and figures are prepared in
% just the same way, although, they are usually used in different
% places of floating environments: table captions start
% \textit{before\/} a table, but figure captions go \textit{after\/}
% a figure. So, the vertical skip inserted before a caption is
% unnecessary for table captions. The right solution is to design
% captions for different float types in different ways.
%
% \paragraph{6} The star-form of captions is absent. It is useful
% when a document contains an alone figure or table. Moreover,
% in fiction books, unnumbered captions useful.
%
% \paragraph{7} The design of toc-entries is hard for modifications.
% It is much better to calculate the skips in toc-entries on the
% base of prototyping technique instead of hard-coding them
% with absolute values. Moreover, the skips for nested sections
% must depend on higher level skips. For example, if we
% change skips for a section entry, the skips for subsection entries
% should be adjusted automatically.
%
% \bigskip
% The package eliminates above-mention disadvantages of the standard
% \LaTeX\ implementation. The commands implemented in it are divided
% into two levels: user level and design level. The user-level commands
% are intended for use within a document and the design-level commands
% are directed to class and package writers.
%
% \section{User Interface}
%
% The table below shows sectioning commands provided with standard
% \LaTeX\ classes. Every section has a \textit{level\/} (an integer
% number). Sections can be printed in one of two modes:
% \textit{display\/} or \textit{running\/} mode. Display section is
% prepared as a separate justified paragraph having a hang indent if a
% section has a number. Running section starts a paragraph.
% \begin{center}\catcode`|=12
% \small\tabcolsep=10pt
% \renewcommand\cboxstyle{\footnotesize}
% \begin{tabular}{|l|c|c|}\hline
% \hfill\cbox{Command}\hfill\mbox{} &
% \hfill\cbox{Level}\hfill\mbox{} &
% \hfill\cbox{Mode}\hfill\mbox{}\\\hline
% \Strut/.8/
% \cs{part} & $-$1 or 0\footnotemark & display \\
% \cs{chapter} & 0\footnotemark & display \\
% \cs{section} & 1 & display \\
% \cs{subsection} & 2 & display \\
% \cs{subsubsection} & 3 & display \\
% \cs{paragraph} & 4 & running \\
% \cs{subparagraph} & 5 & running \\
% \hline
% \end{tabular}\footnotetext[1]{The \cs{part} command has zero level
% in article-like classes and has the negative level in book-like
% classes. In book-like classes a part is prepared on
% a separate page.}\footnotetext{The \cs{chapter} command is defined
% in book-like classes only.}
% \end{center}
%
% \DescribeMacro\startsection
% The package redefines all standard sectioning commands. Along with the
% commands shown in the table above, you can use the following
% uniform notations:
% \begin{quote}
% |\startsection|\marg{level}\oarg{toc-entry}\marg{title}\quad or\\
% |\startsection|\marg{level}|*|\marg{title}
% \end{quote}
% The \meta{level} is a level of section. A negative level produces
% a part. The first command
% produces a numbered section (if~the numbering depth allows this)
% and the last one produces a section without number.
% As for the standard \LaTeX\ sectioning, the first variant of
% the |\startsection| command additionally passes their arguments
% to the section mark command (if the mark command exists)
% and to the aux-file.
% The last variant does no additional actions.
%
% \bigskip
% \textbf{NOTE}: The package allows declaring additional section
% levels. They, of course, have no predefined alias names as
% standard section levels.
%
% \bigskip
% \DescribeMacro\sectionstyle
% The |\sectionstyle|\oarg{type}\marg{style} command allows change
% a style of subsequent display sections of the given \meta{type}:
% \begin{desclist}{\tt}{\quad}[subsubsection]\itemsep=0mm
% \item[main] the section of zero level (|\part| or |\chapter|);
% \item[section] the |\section|;
% \item[subsection] the |\subsection|;
% \item[subsubsection] the |\subsubsection|;
% \item[paragraph] the |\paragraph|;
% \item[subparagraph] the |\subparagraph|;
% \item[section@vi] the section of 6th level, and so on.
% \end{desclist}
% If the \meta{type} parameter is omitted, the command acts on
% all subsequent display sections expect those having a specialized style.
% The following styles are predefined:
% \begin{desclist}{\tt}{\quad}[hangparindent*]\itemsep=0mm
% \item[hangindent]  standard LaTeX style (default);
% \item[hangindent*] the same as |hangindent|, but ragged right;
% \item[parindent]   title indented on |\parindent|;
% \item[parindent*] the same as |parindent|, but ragged right;
% \item[hangparindent]  |\parindent| indented with hang number;
% \item[hangparindent*] the same as |hangparindent|, but ragged right;
% \item[center] centered title;
% \item[centerlast] justified title without indent whose last line is centered.
% \end{desclist}
% You can apply the |\sectionstyle| so many times in the document
% as you want. This command complies with standard \LaTeX\ scoping
% rules.
%
% \bigskip
% \textbf{NOTE}: The section style acts on display sections that were
% prepared with the dynamic alignment (see Section~\ref{s:decl}). By default,
% the sections of levels from 0 to 3 have the dynamic alignment. The
% section of zero level has no hang indentation.
%
% \bigskip
% \DescribeMacro\sectiontagsuffix
% The |\sectiontagsuffix|\oarg{type}\marg{style} command allows change
% a suffix inserted after number tag for sections of the given \meta{type}.
% If the \meta{type} parameter is omitted, the command acts on
% all subsequent sections expect those having a specialized tag suffix.
%
% \bigskip
% \DescribeMacro\indentaftersection
% \DescribeMacro\noindentaftersection
% The paragraph indentation after a display section is controlled with
% the |\indentaftersection| and |\noindentaftersection| commands.
% The first one allows and the last one suppresses
% indentation after section. The commands act on the subsequent
% display sections in the scope of their use.
%
% \DescribeMacro\aftersectionvspace
% If a document contains two subsequent sectioning commands (for example,
% |\section| and |\subsection|) the distance between their titles is
% equal to the skip after the first sectioning command. Sometimes
% it is necessary to insert another vertical space here. To override
% the space inserted between sections, use the command
% \begin{quote}
% |\aftersectionvspace|\marg{distance}
% \end{quote}
% This command replaces the space inserted by a previous sectioning
% command with the |\vspace|\marg{distance}. It works in the only case when
% goes right after a command producing a display section. Otherwise, the
% specified \meta{distance}
% is ignored. The following example shows how to customize the
% |\subsection| command in such a way that the distance between it and
% a previous |\section| will be |3ex plus .5ex minus .2ex|:
% \begin{quote}
% |\renewcommand\subsection{%|\\
% |  \aftersectionvspace{3ex plus .5ex minus .2ex}%|\\
% |  \startsection{2}}|
% \end{quote}
%
% \DescribeMacro\adjustsectionmargins
% Margins of a display section can be adjusted using the command
% \begin{quote}
% |\adjustsectionmargins|\marg{left skip}\marg{right skip}
% \end{quote}
% The \meta{left skip} and \meta{right skip} are added to the left and
% right margins of the subsequent section if it is a display section.
% Otherwise, this command is ignored.
%
% \bigskip
% \textbf{Modifiers.} The customization of a number tag and running head of a concrete
% section is provided with so-call \textit{modifiers}. A modifier
% is a command acting on the nearest sectioning command going after it.
% Usually, the modifiers are placed just before a sectioning command.
% All modifiers act with non-starred versions of sections.
% If the next sectioning command is starred, modifiers are ignored.
%
% \DescribeMacro\norunninghead
% The |\norunninghead| modifier suppresses generation of running head for the
% next non-starred section, i.e.\ it skips the call of section mark command
% in the next section.
%
% \DescribeMacro\runninghead
% The |\runninghead|\marg{running-title} modifier overrides a text going to the
% running head when a new non-starred section starts and an appropriate\linebreak
% |\pagestyle| is in use. This command has higher priority
% than the |\norunninghead|.
%
% \DescribeMacro\noheadingtag
% The |\noheadingtag| modifier suppresses a number tag in the next section,
% but all other attendant actions are executed (writing to the aux-file and
% updating the running head).
%
% \DescribeMacro\headingtag
% The |\headingtag|\marg{tag} modifier overrides a number tag in the next
% section. It has the higher priority than |\noheadingtag|. Overridden
% section tag can be referred with the |\label| command.
% All fragile commands in the overridden tag should be protected.
%
% \DescribeMacro{\headingtag*}
% The |\headingtag*|\marg{tag} modifier prepares a number tag as is, ignoring
% the tag style, prefix, and suffix. The aux-file and running head are not
% updated in this case.
%
% \DescribeMacro\skipwritingtoaux
% The |\skipwritingtoaux| suppresses writing to aux-file for the next section
% command.
%
% \bigskip
% \textbf{NOTE}: All modifiers use global settings.
%
% \bigskip
% \DescribeMacro\caption
% \DescribeMacro{\caption*}
% The captions are implemented in this package using the same technique as
% the sectioning commands. There are two versions of caption command
% allowed within floating environments:
% \begin{quote}
% |\caption|\oarg{toc-entry}\marg{title}\quad and\\
% |\caption*|\marg{title}
% \end{quote}
% The first one works in the same manner as the standard \LaTeX\ |\caption|
% command. Its starred version prepares a caption without number and preceding
% words `Figure' or `Table'.
%
% You can use line breaking commands in captions. But in this case,
% you need to set the optional \meta{toc-entry} parameter to avoid
% translation errors.
%
% Caption appearance can be customized. You can customize ether all caption
% types or only selected caption type. The following commands do this:
% \begin{quote}
% |\captionstyle|\oarg{type}\marg{style}\\
% |\captiontagstyle|\oarg{type}\marg{style}\\
% |\captiontagsuffix|\oarg{type}\marg{suffix}\\
% |\captionwidth|\oarg{type}\marg{length}
% \end{quote}
% If \meta{type} is omitted and these commands appear out of float
% environments, they are applied to all types.
% A command without \meta{type} applied within a float environment
% is considered as a command having the type of this environment. Typed
% version of a command has a precedence before a non-typed one.
%
% \medskip\noindent
% \DescribeMacro\captionstyle
% specifies a style
% the caption text will be formatted:
% \begin{desclist}{\tt}{\quad}[centerlast]\itemsep=0mm
% \item[default] standard \LaTeX's style,
% \item[para] simple paragraph without paragraph indent,
% \item[left] all lines are flushed left,
% \item[center] all lines are centered,
% \item[right] all lines are flushed right, or
% \item[centerlast] as |para|, but the last line is centered.
% \end{desclist}
%
% \medskip\noindent
% \DescribeMacro\captiontagstyle
% specifies a position of caption tag:
% \begin{desclist}{\tt}{\quad}[centerlast]\itemsep=0mm
% \item[para] tag is formatted together with text,
% \item[left] tag is adjusted to the left in a separate line,
% \item[center] tag is centered in a separate line, or
% \item[right] tag is adjusted to the right in a separate line.
% \end{desclist}
%
% \medskip\noindent
% \DescribeMacro\captiontagsuffix
% specifies a suffix after caption tag.
%
% \medskip\noindent
% \DescribeMacro\captionwidth
% specifies a width of caption.
%
% \medskip\noindent
% Defaults:
% \begin{quote}
% |\captionstyle{default}|\\
% |\captiontagstyle{para}|\\
% |\captiontagsuffix{:\hspace{0.7em plus 0.2em minus 0.1em}}|\\
% |\captionwidth{\linewidth}|
% \end{quote}
%
% \textbf{NOTE}: The above-described section modifiers can be used with non-starred
% captions. Although, the |\runninghead| and |\norunninghead| commands
% have no sense with captions, but you can do them working if define
% a |\figuremark{}| or |\tablemark{}| command.
%
% \bigskip
% \DescribeMacro\SetTOCStyle
% The |\SetTOCStyle|\marg{declarations} command allows customize
% the table of contents and other content lists. For example, the declaration
% \begin{quote}
% |\SetTOCStyle{\small}|
% \end{quote}
% specifies that content lists will be prepared with the |\small| font.
% This command is allowed in the preamble only.
%
% \DescribeMacro\ChapterPrefixStyle
% The appearance of Chapter/Appendix prefix in a table of contents and
% in a running head can be customized using the command
% \begin{quote}
% |\ChapterPrefixStyle|\marg{appearance list}
% \end{quote}
% The \meta{appearance list} can contain up to two words, namely
% |header| and/or |toc|, delimited with a comma. Using them, you can
% set a prefix-style for the header and/or the table of contents, respectively.
% By default, the prefix-style is specified for the header only. This command
% is allowed for book-like classes in which the |\chapter| command is
% defined. It can be used in the preamble only.
%
% \section{Create New Section Styles}
%
% Along with 8 predefined section styles, you can easy create more styles.
%
% \DescribeMacro\newplainsectionstyle
% The command
% \begin{quote}
% |\newplainsectionstyle|\marg{name}\marg{indent}\oarg{pos}\\
% |                     |\marg{left skip}\marg{right skip}
% \end{quote}
% creates a new paragraph-like section style with the given \meta{name}.
% It has the \meta{indent} paragraph indent
% and margins specified with \meta{left skip} and \meta{right skip} lengths.
% To prepare a centered style, the optional \meta{pos} parameter
% should be equal to |[c]|. In this case, left and right margins must
% have an additional |1fil| glue. If optional parameter is |[r]|, the
% left margin must have an additional |1fil| glue.
%
% Four of predefined section styles are created using this command as follows:
% \begin{quote}
% |\newplainsectionstyle{parindent}{0pt}{\parindent}{0pt}|\\
% |\newplainsectionstyle{parindent*}{0pt}{\parindent}{0pt plus 1fil}|\\
% |\newplainsectionstyle{center}{0pt}[c]{0pt plus 1fil}{0pt plus 1fil}|\\
% |\newplainsectionstyle{centerlast}{0pt}[c]{0pt plus 1fil}{0pt plus -1fil}|
% \end{quote}
%
% \DescribeMacro\newhangsectionstyle
% The command
% \begin{quote}
% |\newhangsectionstyle|\marg{name}\marg{min tag width}\oarg{pos}\\
% |                    |\marg{left skip}\marg{right skip}
% \end{quote}
% creates a new hang-indented section style with the given \meta{name}.
% The \meta{min tag width} length specifies a minimum width of the section
% tag. If a width of section tag is less than this parameter value,
% a white space will be inserted surround the tag to have the required
% width. The method of inserting a white space is the same as in the
% |\makebox| command. It is controlled with the optional \meta{pos}
% parameter (|l|, |c|, or |r|; |l| default). Other parameters have
% the same meaning as in the previous command.
%
% Four of predefined section styles are created using this command as follows:
% \begin{quote}
% |\newhangsectionstyle{hangindent}{0pt}{0pt}{0pt}|\\
% |\newhangsectionstyle{hangindent*}{0pt}{0pt}{0pt plus 1fil}|\\
% |\newhangsectionstyle{hangparindent}{0pt}{\parindent}{0pt}|\\
% |\newhangsectionstyle{hangparindent*}{0pt}{\parindent}{0pt plus 1fil}|
% \end{quote}
%
% The following examples shows possibilities of these commands:
%
% \skipwritingtoaux
% \sectionstyle[subsection]{margin}
% \subsection{This subsection was prepared in the margin style}
%
% The definition of the |margin| style is the following:
% \begin{quote}
% |\newhangsectionstyle{margin}{2in}[r]{-2in}{0pt plus 1fil}|
% \end{quote}
%
% \skipwritingtoaux
% \sectionstyle[subsection]{list}
% \subsection{This subsection was prepared in the list style}
%
% The definition of the |list| style is the following:
% \begin{quote}
% |\newhangsectionstyle{list}{1in}{0pt}{1in plus 1fil}|
% \end{quote}
%
% \skipwritingtoaux
% \sectionstyle[subsection]{flushright}
% \subsection{This subsection was prepared in the flushright style}
%
% The definition of the |flushright| style is the following:
% \begin{quote}
% |\newplainsectionstyle{flushright}{0pt}[r]{1in plus 1fil}{0pt}|
% \end{quote}
% \sectionstyle[subsection]{hangindent}
%
% \section{Declare Sections and Captions\label{s:decl}}
%
% \DescribeMacro\DeclareSection
% To define or redefine a section or caption command, you can use
% in the preamble of your document the
% following command:
% \begin{quote}
% |\DeclareSection|\marg{level}\marg{type}\oarg{indent}\marg{prefix}\marg{beforeskip}\\
% |               |\marg{afterskip}\marg{style}
% \end{quote}
% \begin{desclist}{}{}[\meta{beforeskip}]
% \item[\meta{level}] a section level number. Zero and negative values
%      are interpreted as follows:
%      0 means declaring the |\chapter| or |\part| command depending on a
%        class used; a negative value means declaring a caption.
%
% \item[\meta{type}] a section type. For zero level, this
%      parameter is ignored. For negative level, it defines a float type
%      (i.e., |figure| or |table|). For positive level, it defines
%      a counter name. The name of marking command is composed from
%      the type as |\|\meta{type}|mark|.
%
% \item[\meta{indent}] indentation of heading from the left margin
%      (zero is default). Ignored for negative levels.
%
% \item[\meta{prefix}] a prefix inserted before a section-number tag
%      (usually empty). In chapter, part, or caption declaration commands,
%      it is inserted right before the tag name, e.g., before the |\@chapapp|,
%      |\partname|, |\figurename|, or |\tablename| command.
%
% \item[\meta{beforeskip}] the skip to leave above the heading.
%
% \item[\meta{afterskip}] if positive, then the skip to leave below
%      the heading, else negative of skip to leave to right of running
%      heading. The negative value is allowed for positive section levels
%      only.
%
% \item[\meta{style}] commands to set a style. The last command in
%      this argument may be a command such as |\MakeUppercase| that
%      takes an argument. The section heading will be supplied as the
%      argument to this command. So setting it to, say,
%      |\bfseries\MakeUppercase| would produce bold, uppercase headings.
% \end{desclist}
% Sections having nonnegative \meta{level} and positive \meta{afterskip}
% are display sections. They are declared with the |hangindent| style
% and do not obey the |\sectionstyle| command.
%
% \DescribeMacro{\DeclareSection*}
% To declare a display section having dynamic alignment controlled with the
% |\sectionstyle| command, use the star-version of the previous command:
% \begin{quote}
% |\DeclareSection*|\marg{level}\marg{type}\marg{prefix}\marg{beforeskip}\\
% |                |\marg{afterskip}\marg{style}
% \end{quote}
% A negative \meta{afterskip} has no meaning in this case.
%
% \DescribeMacro\bff
% To prepare bold section headings,
% you can use the |\bff| command in the \meta{style} parameter.
% It tries to set everything bold. Its definition is the following:
% \begin{quote}
% |\newcommand{\bff}{\normalfont\bfseries\mathversion{bold}}|
% \end{quote}
%
% Examples of section and caption declarations:
% \begin{quote}
% |\DeclareSection{-2}{table}{}{0pt}{10pt}{}|\\
% |\DeclareSection{-1}{figure}{}{10pt}{0pt}{}|\\
% |\DeclareSection*{1}{section}{}%|\\
% |                {3.5ex plus 1ex minus .2ex}%|\\
% |                {2.3ex plus .2ex}{\Large\bff}|
% \end{quote}
% Here we declare the table caption command with zero skip
% before it and |10pt| skip after it. On contrary, the
% figure caption command produces |10pt| skip before it
% and zero skip after it. The |\section| command is declared with
% dynamic horizontal alignment. It is prepared in the |\Large|
% font with everything bold.
%
% \DescribeMacro\SectionTagSuffix
% The |\SectionTagSuffix|\marg{suffix} command specifies a default suffix
% inserted after a section number tag. For example, the command
% \begin{quote}
% |\SectionTagSuffix{.\quad}|
% \end{quote}
% sets the decimal point after every section number tag.
% Sections of 0th level ignore this suffix. The default tag is |\quad|.
% The command can be used in the preamble only.
%
% \DescribeMacro\RunningSectionSuffix
% The |\RunningSectionSuffix|\marg{suffix} command specifies a suffix
% inserted after a running section title right before the skip after
% section. It can be used in the preamble only.
% The default value is an empty suffix.
%
% \DescribeMacro\norunningsuffix
% To remove the suffix after a running section, put the
% |\norunningsuffix| modifier in the parameter of running section.
%
% \DescribeMacro\CaptionTagSuffix
% The |\CaptionTagSuffix|\marg{suffix} command specifies a default suffix
% inserted after a caption number tag. It can be used in the preamble only.
% The default caption tag is:
% \begin{quote}
% |\CaptionTagSuffix{:\hspace{0.7em plus 0.2em minus 0.1em}}|
% \end{quote}
%
% \section{Declare TOC-Entries}
%
% \DescribeMacro\DeclareTOCEntry
% To declare an entry of table of contents or other lists
% (list of figures or list of tables), use the following command
% (in the preamble only):
% \begin{quote}
% |\DeclareTOCEntry|\marg{level}\marg{action}\marg{prefix}\marg{prototype}\\
% |                |\marg{style}\oarg{next}
% \end{quote}
% \begin{desclist}{}{\hfill}[\meta{prototype}]
% \item[\meta{level}] a section level number.
%      For zero and negative level the following commands are created:
%      0 means |\l@chapter| or |\l@part| depending on class used;
%      $-1$ means |\l@figure|; $-2$ means |\l@table|. If level
%      is greater than 5, the name of toc-entry command is
%      generated as |\l@section@|\meta{level-in-roman},
%      i.e., the toc-entry of 6th level is |\l@section@vi|.
%
% \item[\meta{action}] commands applied before entry is produced (usually empty).
%
% \item[\meta{prefix}] text inserted before the section number (usually empty).
%
% \item[\meta{prototype}] prototype of number for alignment the toc-entry body.
%      The hang indent of this toc-entry will be equal to the width of
%      \begin{quote}
%      \meta{style}|{|\meta{prefix}\meta{prototype}\meta{numberline-suffix}|}|
%      \end{quote}
%
% \item[\meta{style}] commands to set a style. The last command in this argument
%      may be a command such as |\MakeUppercase| that takes an
%      argument. The produced entry will be supplied as the
%      argument to this command. So setting it to, say,
%      |\bfseries\MakeUppercase| would produce bold,
%      uppercase entry. This style is applied to the number also and to the
%      page number.
%      To apply different styles to the text of entry and to its page
%      number, use in this parameter the command
%      \begin{quote}
%      |\applystyle|\marg{text-style}\marg{number-style}
%      \end{quote}
%
% \item[\meta{next}] prototype for left margin adjustment for an entry of the
%      next level. Default is the hang indent of the current toc-entry.
% \end{desclist}
% A toc-entry is produced within a group.
%
% \DescribeMacro\NumberlineSuffix
% The |\NumberlineSuffix|\marg{calc-suffix}\marg{actual-suffix}
% command allows customize a skip inserted after
% numbers in TOC-like entries. The \meta{calc-suffix} parameter
% is used in calculations of hang indent of toc-entries and the
% \meta{actual-suffix} is really inserted at the end of number.
% The \marg{calc-suffix} is usually wider than the \meta{actual-suffix}.
% The default is |\NumberlineSuffix{\quad}{\enskip}|.
% This command is available in the preamble only.
%
% \DescribeMacro\PnumPrototype
% The |\PnumPrototype|\marg{prototype} command is used for adjustment
% the right margin of the text of toc-entries in toc-lists.
% Default is |\PnumPrototype{99}|.
% If your document has more than 99 pages, use
% |\PnumPrototype{999}|.
% This command is available in the preamble only.
%
% \DescribeMacro\TOCMarginDrift
% The |\TOCMarginDrift|\marg{increment} command specifies a value of
% right-margin drift in TOCs. The increment is applied after the |\@plus|
% token in definition of right margin. Empty argument means no drift.
% Examples:
% \begin{quote}
% |\TOCMarginDrift{2em}|\\
% |\TOCMarginDrift{1fil}|
% \end{quote}
% The command can be use anywhere in the document.
%
% \DescribeMacro\runinsectionskip
% This command is useful in the \meta{action} parameter of the
% toc-entry declaration to produce the skip before a toc-entry
% equal to the skip before run-in sections.
%
% The following example shows how toc-entries are declared in books:
% \begin{quote}
% |\DeclareTOCEntry{-2}{}{}{9.9}{}% table|\\
% |\DeclareTOCEntry{-1}{}{}{9.9}{}% figure|\\
% |\DeclareTOCEntry{0}{\runinsectionskip\def\@dotsep{1000}%|\\
% |  \aftergroup\penalty\aftergroup\@highpenalty}{}{9}{\bff}% chapter|\\
% |\DeclareTOCEntry{1}{}{}{9.9}{}[9.9]% section|\\
% |\DeclareTOCEntry{2}{}{}{9.9.9}{}[9.9.9]% subsection|\\
% |\DeclareTOCEntry{3}{}{}{}{}[\qquad]% subsubsection|
% \end{quote}
% The number prototype for figures and tables is `9.9' here.
% The |\l@chapter| entry applies the run-in section skip before it and
% redefines the |\@dotsep| command to remove dot leaders.
% Using the |\aftergroup| command, it inserts the |\@highpenalty|
% after this toc-entry to avoid a page break at this point.
% The left margin adjustment after section and nested toc-entries
% is calculated here using the prototype of widest section number.
% This produces the following nesting:
% \begin{flushleft}
% {\bf 1\quad Chapter}\\
% \jhbox{{\bf 1\quad}}{}1.1\quad Section\\
% \jhbox{{\bf 1\quad}1.1}{}1.1.1\quad Subsection\\
% \jhbox{{\bf 1\quad}1.11.1.1}{}Subsubsection
% \end{flushleft}
%
% \section{Declare New Float Types}
%
% The standard \LaTeX\ classes provide two types of floating environments:
% figures and tables. If you have prepared a new floating
% environment in some way (i.e., using the |float| package by Anselm
% Lingnau), you can declare a caption for the new float
% with the commands described in previous sections.
%
% \DescribeMacro\RegisterFloatType
% In books, when a new chapter starts, the |\chapter| command
% puts a special vertical skip to the contents of list of figures and
% of list of tables. This behaviour can be easy extended to new float types
% if you register them within this package. The registration is
% provided with the following command:
% \begin{quote}
% |\RegisterFloatType|\marg{float-type}
% \end{quote}
% After the float type is registered, you can declare a toc-entry
% for it using the negation of its registration number in the
% \meta{level} parameter. The
% first new float type is registered third (after the figure and table).
% So, you must
% use \meta{level} = $-3$ for it, $-4$ for the next registered float
% type and so on.
%
% In the following example, we define a new float type, |program|,
% and prepare the caption and toc-entry commands for it.
% The caption of programs
% is supposed to be used at the beginning of program.
% So, we make it in the same manner as the table caption.
% \begin{quote}
% |\documentclass{book}|\\
% |\usepackage{float,nccsect}|\\
% |\newfloat{program}{tp}{lop}[chapter]|\\
% |\floatname{program}{Program}|\\
% |\RegisterFloatType{program}|\\
% |\DeclareSection{-3}{program}{}{0pt}{10pt}{}|\\
% |\DeclareTOCEntry{-3}{}{}{9.9}{}|
% \end{quote}
%
% To produce a list of programs, you can then use the |\listof|
% command from the |float| package as follows:
% \begin{quote}
% |\listof{program}{List of Programs}|
% \end{quote}
% \StopEventually{}
%
% \section{Epigraphs and Related Staff}
%
% \DescribeMacro\beforechapter
% \DescribeMacro\epigraph
% To put epigraph before any chapter, you can use two methods:
% low-level |\beforechapter|\marg{anything} hook or
% user-level command
% \begin{quote}
% |\epigraph|\oarg{width}\marg{text}\marg{author}
% \end{quote}
% The last one applies a special formatting to epigraph and
% calls the first one. The |\beforechapter| hook inserts its
% contents at the beginning of page just before a chapter
% instead of spacing specified in the chapter declaration.
%
% \DescribeMacro\epigraphparameters
% Formatting of user-level epigraph is provided with the
% following command
% \begin{quote}
% |\epigraphparameters|\marg{style}\marg{width}\marg{height}\marg{author-style}\\
% |                   |\marg{after-action}
% \end{quote}
% Here \meta{style} is a style applied to the whole epigraph
% (font selection, spacing and positioning, etc.), the \meta{width}
% is the default epigraph width (can be changed in an epigraph),
% the \meta{author-style} is the style applied to the author's
% signature, and the \meta{after-action} is an action applied after
% the epigraph (usually a vertical spacing). All styles and actions
% are applied in the vertical mode. An \meta{author-style} can finish with
% one-argument macro getting the author of epigraph and formatting it.
%
% \DescribeMacro\epigraphwidth
% In |\epigraphparameters|, you can use the |\epigraphwidth| macro
% which contains a selected epigraph width.
%
% The default style is:
% \begin{quote}
% |\epigraphparameters{\StartFromHeaderArea\small\raggedleft}|\\
% |                   {.45\linewidth}{5\baselineskip}|\\
% |                   {\raggedleft\itshape}{\vspace{2ex}}|
% \end{quote}
%
% \DescribeMacro\StartFromTextArea
% The |\vspace*| command applied at the beginning of page has one serious
% disadvantage: it skips more space that specified in its parameter.
% To remove this disadvantage, we introduce the |\StartFromTextArea|
% command that
% inserts a zero-height strut and allows use the |\vspace| command after it
% without troubles.
%
% \DescribeMacro\StartFromHeaderArea
% You can also extend the text area on the header if apply the
% |\StartFromHeaderArea| command at the beginning of page.
% Such action is useful in epigraphs: the first chapter's page usually
% has an empty header and positioning an epigraph from the header
% is the good practice.{\sloppy\par}
%
% \section{Declare Part}
%
% The |\part| command in book-like classes is the only sectioning command
% that cannot be prepared with the |\DeclareSection| command. So, we add
% special declarations to provide parts in books with features of other
% sectioning commands.
%
% \DescribeMacro\DeclarePart
% To redefine the |\part| in books, use the following declaration:
% \begin{quote}
% |\DeclarePart|\marg{before}\marg{after}\marg{prefix}\marg{style}
% \end{quote}
% \begin{desclist}{}{}[\meta{before}]
% \item[\meta{before}] an action applied before a part at the beginning of
%      page. It usually specifies a vertical skip |\vfil| and a
%      paragraph style to be applied to the part number tag and title.
% \item[\meta{after}] an action applied after the part. It usually contains
%      |\vfil| and page finishing commands.
% \item[\meta{prefix}] a prefix inserted before a part tag. It contains
%      style commands to be applied to the tag and the |\vspace| command
%      specifying a distance between the part tag and title.
%      The |\partname| command goes right after the prefix.
% \item[\meta{style}] a style to be applied to the part title. It can end
%      with |\MakeUppercase|.
% \end{desclist}
%
% The default declaration of the |\part| is the following:
% \begin{quote}
% |\DeclarePart{\StartFromTextArea\vfil\centering}%|\\
% |            {\vfil\newpage \if@twoside\if@openright|\\
% |               \mbox{}\thispagestyle{empty}\newpage\fi\fi}%|\\
% |            {\vspace{4ex}\huge\bff}{\Huge\bff}|
% \end{quote}
% The |\StartFromTextArea| command prevents ignoring a vertical space
% at the beginning of page. All paragraphs of part title are centered
% horizontally using the |\centering| declaration, and the title
% is centered vertically using |\vfil| commands
% before and after it. A page after the part is made empty in two-side
% mode if it is even. The space after the part tag is set to |4ex|.
%
% In Russian typesetting tradition, the part can be prepared in the
% same manner as a chapter, i.e.\ a text going after a part is prepared
% on the same page with the part title. It is easy to re-declare
% the part in such style.
% Let us start a part from the header and delimit it from the text
% with a decorative line. The following declaration does this:
% \begin{quote}
% |\DeclarePart{\StartFromHeaderArea\centering}|\\
% |            {\vspace{2mm}\noindent\hrulefill\par|\\
% |             \addvspace{5mm}}|\\
% |            {\vspace{.5em}\LARGE\bff}{\Huge\bff}|
% \end{quote}
% But when a chapter goes right after a part, we need to place the part and
% chapter titles together
% on the same page. This can be applied using the |\beforechapter| hook:
% \begin{quote}
% |\beforechapter{\part|\marg{part title}|}|\\
% |\chapter|\marg{chapter title}
% \end{quote}
% Modifiers stored in the parameter of |\beforechapter| hook will act on
% the |\part| command. Modifiers outside of |\beforechapter| will act on
% the |\chapter| command.
%
% \DescribeMacro\DeclareTOCPart
% To produce a toc-entry command for a part, the following declaration is
% specified for book-like classes:
% \begin{quote}
% |\DeclareTOCPart|\marg{action}\oarg{afterskip}\marg{prefix}\marg{prototype}\marg{style}
% \end{quote}%
% \begin{desclist}{}{}[\meta{afterskip}]
% \item[\meta{action}] an action applied before the part toc-entry. It usually
%      a skip before part. It is recommended to prepare it with |\NCC@secskip|
%      command.
% \item[\meta{afterskip}] a skip after this entry. If it is omitted,
%      the default |\NCC@runskip| value is applied after this entry.
% \item[\meta{prefix}] a prefix inserted before a part tag (usually empty).
% \item[\meta{prototype}] a prototype of part tag used for calculation the
%      hang indent in this entry.
% \item[\meta{style}] a style applied to the whole text of entry and to
%      the page number. The |\MakeUppercase| is allowed to finish this
%      parameter. The |\applystyle| command can be used inside it to
%      apply different styles to the toc-entry and the page number.
% \end{desclist}
%
% The default declaration of the part toc-entry is the following:
% \begin{quote}
% |\DeclareTOCPart{\NCC@secskip{4ex \@plus .2ex}%|\\
% |                \def\@dotsep{1000}}%|\\
% |               {}{\partname\ II}{\large\bff}|\\
% \end{quote}
%
% \section{The Implementation}
%
% The \textbf{afterpackage} package is used to add compatibility
% commands.
%    \begin{macrocode}
%<*package>
\RequirePackage{afterpackage}
%    \end{macrocode}
%
% \begin{macro}{\NCC@secskip}
% \begin{macro}{\NCC@runskip}
% The package shares the following commands with the
% |nccthm| package:
% \begin{quote}
% |\NCC@secskip|\marg{skip} adds the \meta{skip} before a section,\\
% |\NCC@runskip| is a skip inserted before run-in sections.
% \end{quote}
% We protect the definitions of these commands with testing
% the |nccthm| package to be already loaded.
%    \begin{macrocode}
\@ifpackageloaded{nccthm}{}{%
  \def\NCC@secskip#1{%
    \if@noskipsec \leavevmode \fi \par
    \if@nobreak \everypar{}\else
      \addpenalty\@secpenalty
      \addvspace{#1}%
    \fi
  }
  \def\NCC@runskip{2.75ex \@plus 1ex \@minus .2ex}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\runinsectionskip}
% This command is useful in toc-entries:
%    \begin{macrocode}
\newcommand{\runinsectionskip}{\NCC@secskip{\NCC@runskip}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The Kernel}
%
% We start with declaring the section controls (modifiers):
% \begin{desclist}{\tt}{\hfill}[NCC@secstartag]\raggedright
% \item[NCC@nosectag] is true if |\noheadingtag| is applied;
% \item[NCC@secstartag] is true if |\headingtag*|\marg{tag} is applied;
% \item[\cs{NCC@sectag}] saves a value of the |\headingtag| parameter;
% \item[NCC@nosecmark] is true if |\norunninghead| is applied;
% \item[\cs{NCC@secmark}\rm\marg{mark-command}] executes the \meta{mark-command}
% with the parameter of |\runninghead| command;
% \item[NCC@noaux] is true if |\skipwritingtoaux| is applied.
% \end{desclist}
%    \begin{macrocode}
\newif\ifNCC@nosectag
\newif\ifNCC@secstartag
\newif\ifNCC@nosecmark
\newif\ifNCC@noaux
%    \end{macrocode}
%
% \begin{macro}{\NCC@global}
% We reset all controls globally, but in the |\beforechapter|
% hook we need to reset them locally. So, we reset all controls
% using the |\NCC@global| modifier which value is |\global| by default.
%    \begin{macrocode}
\let\NCC@global\global
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@sec@reset@controls}
% This command resets all controls to default values.
% It must be applied at the end of every section command.
%    \begin{macrocode}
\def\NCC@sec@reset@controls{%
  \NCC@global\NCC@nosectagfalse
  \NCC@global\NCC@secstartagfalse
  \NCC@global\let\NCC@sectag\relax
  \NCC@global\NCC@nosecmarkfalse
  \NCC@global\let\NCC@secmark\relax
  \NCC@global\NCC@noauxfalse
}
\NCC@sec@reset@controls
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\norunninghead}
% \begin{macro}{\runninghead}
% \begin{macro}{\noheadingtag}
% \begin{macro}{\headingtag}
% \begin{macro}{\headingtag*}
% \begin{macro}{\skipwritingtoaux}
% User interface to section controls:
%    \begin{macrocode}
\newcommand{\norunninghead}{\NCC@global\NCC@nosecmarktrue}
\newcommand*{\runninghead}[1]{\NCC@global\def\NCC@secmark##1{##1{#1}}}
\newcommand{\noheadingtag}{\NCC@global\NCC@nosectagtrue}
\newcommand{\headingtag}{%
  \@ifstar{\NCC@global\NCC@secstartagtrue\NCC@setsectag}{\NCC@setsectag}%
}
\def\NCC@setsectag#1{\NCC@global\def\NCC@sectag{#1}}
\newcommand{\skipwritingtoaux}{\NCC@global\NCC@noauxtrue}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@makesection}
% The |\NCC@makesection|\marg{type}\marg{level}\marg{toc-entry}\marg{toc-action}
% produces a section or caption. It analyzes the modifiers and customizes
% sections or captions. The \meta{toc-action} parameter contains an
% attendant action that must be applied at the end of macro.
% It writes a toc-entry to aux-file.
%
% The command uses the following hooks that must be prepared
% before its call:
% \begin{desclist}{}{}[\cs{NCC@make}\marg{action}]
% \item[\cs{NCC@makesectag}\marg{value}] produces a tag in |\@svsec|
%      using the given value;
%
% \item[\cs{NCC@make}\marg{action}] makes a section or caption heading
%      and applies the \meta{action} after heading. Before the call
%      of this command, the |\@svsec| macro is prepared (it contains a
%      prepared tag).
% \end{desclist}
% We start from the case when the |\headingtag*|\marg{tag} modifier was
% applied and the section tag was saved in the |\NCC@sectag| macro.
% We apply the |\NCC@make| procedure with the given section tag.
% Attendant actions are ignored for this case.
%    \begin{macrocode}
\def\NCC@makesection#1#2#3#4{%
  \ifNCC@secstartag
    \let\@svsec\NCC@sectag
    \NCC@make{}%
  \else
%    \end{macrocode}
% Prepare a tag creation command in the |\the|\meta{type} macro.
% We can do some temporary changes here that will be restored
% at the end of macro. The restore hook is prepared in the
% |\NCC@restsec| command.
%    \begin{macrocode}
    \ifx\NCC@sectag\relax
%    \end{macrocode}
% The |\noheadingtag| case: we temporary set the |secnumdepth|
% counter to very low negative value. This prevents numbering
% this section:
%    \begin{macrocode}
      \ifNCC@nosectag
        \edef\NCC@restsec{%
          \noexpand\c@secnumdepth \the\c@secnumdepth\relax
        }%
        \c@secnumdepth -1000
%    \end{macrocode}
% The ordinary case: No restore actions is necessary here.
%    \begin{macrocode}
      \else
        \let\NCC@restsec\relax
        \ifnum#2>\c@secnumdepth \else\refstepcounter{#1}\fi
      \fi
%    \end{macrocode}
% The |\headingtag|\marg{tag} case: we temporary let the
% |\the|\meta{type} macro to be equal to the |\NCC@sectag|
% command produced by the |\headingtag|,
% save the original value in the |\NCC@thesec| command,
% and prepare the |\NCC@restsec| macro.
%    \begin{macrocode}
    \else
      \expandafter\let\expandafter\NCC@thesec\csname the#1\endcsname
      \def\NCC@restsec{%
        \expandafter\let\csname the#1\endcsname\NCC@thesec
      }%
      \expandafter\let\csname the#1\endcsname\NCC@sectag
      \protected@edef\@currentlabel{\NCC@sectag}%
    \fi
%    \end{macrocode}
%
% Prepare section tag in the |\@svsec| command:
%    \begin{macrocode}
    \ifnum #2>\c@secnumdepth
      \let\@svsec\@empty
    \else
      \protected@edef\@svsec{%
        \protect\NCC@makesectag{\csname the#1\endcsname}%
      }%
    \fi
%    \end{macrocode}
%
% We cannot do the marking right now because the producing of section
% can be suspended to the beginning of the nearest paragraph
% (in run-in sections). So, we need to prepare a mark action
% in a command that will save its state as long as necessary.
% This command is |\NCC@makemark|.
%    \begin{macrocode}
    \let\NCC@makemark\@empty
    \@ifundefined{#1mark}{}{%
      \ifx\NCC@secmark\relax
%    \end{macrocode}
% Ordinary case: prepare the section mark with the
% \meta{toc-entry} parameter.
%    \begin{macrocode}
        \ifNCC@nosecmark \else
          \def\NCC@makemark{\csname #1mark\endcsname{#3}}%
        \fi
%    \end{macrocode}
% The |\runninghead|\marg{heading} case:
% pass the mark command in the parameter of |\NCC@secmark|.
% We need to save the |\NCC@secmark| value in some command
% and pass this command within |\NCC@makemark| because
% the |\NCC@secmark| could be removed before the use.
%    \begin{macrocode}
      \else
        \let\NCC@savesecmark\NCC@secmark
        \def\NCC@makemark{%
          \NCC@savesecmark{\csname #1mark\endcsname}%
          \let\NCC@savesecmark\relax
        }%
      \fi
    }%
%    \end{macrocode}
%
% Make the section. We must apply the restore action at
% the end action of |\NCC@make| command by the same reason that
% the section making may be suspended:
%    \begin{macrocode}
    \ifNCC@noaux
      \NCC@make{\NCC@makemark \NCC@restsec}%
    \else
      \NCC@make{\NCC@makemark #4\NCC@restsec}%
    \fi
%    \end{macrocode}
%
% Reset modifiers:
%    \begin{macrocode}
  \fi
  \NCC@sec@reset@controls
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Section Making Commands}
%
% \begin{macro}{\indentaftersection}
% \begin{macro}{\noindentaftersection}
% Introduce macros controlling indentation after display sections:
%    \begin{macrocode}
\newcommand{\indentaftersection}{\@afterindenttrue}
\newcommand{\noindentaftersection}{\@afterindentfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SectionTagSuffix}
% The |\SectionTagSuffix|\marg{suffix} sets a default suffix after
% a section tag.
%    \begin{macrocode}
\newcommand*{\SectionTagSuffix}[1]{\def\NCC@asecnum{#1}}
\@onlypreamble\SectionTagSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sectiontagsuffix}
% |\sectiontagsuffix|\oarg{type}\marg{suffix} changes a suffix after section
% tag that will be used for sections of the given
% \meta{type}. If \meta{type} is omitted, the specified suffix will be used
% in text flow for all sections having no special suffix.
%    \begin{macrocode}
\newcommand*\sectiontagsuffix[2][]{%
  \expandafter\def\csname NCC@asecnum@#1\endcsname{\def\NCC@asecnum{#2}}%
}
\let\NCC@asecnum@\@empty
\def\NCC@setsectionsuffix#1{%
  \edef\@tempa{NCC@asecnum@\NCC@secname{#1}}%
  \@ifundefined{\@tempa}{%
    \let\NCC@asecnumset\NCC@asecnum@
  }{%
    \expandafter\let\expandafter\NCC@asecnumset\csname\@tempa\endcsname
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\RunningSectionSuffix}
% The |\RunningSectionSuffix|\marg{suffix} sets a suffix after a title
% of a running section:
%    \begin{macrocode}
\newcommand*{\RunningSectionSuffix}[1]{\def\NCC@asectitle{\unskip#1}}
\@onlypreamble\RunningSectionSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@preparesectag}
% The |\NCC@preparesectag|\marg{style}\marg{before} hook prepares the
% |\NCC@makesectag| command:
%    \begin{macrocode}
\def\NCC@preparesectag#1#2{\def\NCC@makesectag##1{#1#2##1\NCC@asecnum}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@secname}
% The |\NCC@secname|\marg{level} command generates section name
% (|main|, |section|, |subsection|, \ldots,
% or |section@vi|, |section@vii|, \ldots\ for new section levels).
% This name is used as the second parameter of the |\addcontentsline|
% command, in the declarations of toc-entries, and in the style
% selection command.
%    \begin{macrocode}
\def\NCC@secname#1{%
  \ifcase#1main\or section\or subsection\or subsubsection\or
    paragraph\or subparagraph\else section@\romannumeral#1\fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@startsection}
% The |\NCC@startsection| command
% has the same syntax as its non-NCC prototype:
% \begin{quote}
% |\NCC@startsection|\marg{type}\marg{level}\marg{indent}\marg{beforeskip}\\
% |                 |\marg{afterskip}\marg{style}
% \end{quote}
% but works in a bit different way: it ignores the sign of
% \meta{beforeskip}. In the original version the testing
% was applied to set an appropriate |afterindent| mode.
% But we change this mode using |\indentaftersection| and
% |\noindentaftersection| macros.
%    \begin{macrocode}
\def\NCC@startsection#1#2#3#4#5#6{%
  \@tempskipa #4\relax
  \ifdim \@tempskipa <\z@ \@temskipa -\@tempskipa \fi
  \NCC@secskip \@tempskipa
  \secdef{\NCC@sect{#1}{#2}{#3}{#4}{#5}{#6}}{\NCC@ssect{#3}{#4}{#5}{#6}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makesec}
% The interface of |\NCC@ssect| and |\NCC@sect| commands is similar to their
% \LaTeX's prototypes. They are based on the following
% command:
% \begin{quote}
% |\NCC@makesec|\marg{indent}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
% In fact, there are two versions of this command:
% the traditional version, |\NCC@makesect|, and the
% version with dynamic control of section style,\linebreak |\NCC@makesecx|.
% One of them should be selected before applying the |\NCC@ssect| and |\NCC@sect|
% commands.
% \end{macro}
%
% \begin{macro}{\NCC@ssect}
% The starred form of section:
% \begin{quote}
% |\NCC@ssect|\marg{indent}\marg{beforeskip}\marg{afterskip}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
\def\NCC@ssect#1#2#3#4#5{%
  \let\@svsec\@empty
  \NCC@makesec{#1}{#4}{#5}{#3}{}%
  \NCC@sec@reset@controls
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@sect}
% The base form of section:
% \begin{quote}
% |\NCC@sect|\marg{type}\marg{level}\marg{indent}\marg{beforeskip}\marg{afterskip}\marg{style}\\
% |         |\oarg{toc-entry}\marg{heading}
% \end{quote}
%    \begin{macrocode}
\def\NCC@sect#1#2#3#4#5#6[#7]#8{%
  \def\NCC@make{\NCC@makesec{#3}{#6}{#8}{#5}}%
  \NCC@makesection{#1}{#2}{#7}{%
    \addcontentsline{toc}{\NCC@secname{#2}}{%
      \ifnum #2>\c@secnumdepth \else
        \numberline{\csname the#1\endcsname}%
      \fi
      #7%
    }%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makesect}
% The traditional section making command:
% \begin{quote}
% |\NCC@makesect|\marg{indent}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
%    \begin{macrocode}
\def\NCC@makesect#1#2#3#4#5{%
  \@tempskipa #4\relax
  \ifdim \@tempskipa>\z@
    \begingroup \normalfont
      \NCC@asecnumset
%    \end{macrocode}
% The |\NCC@secttitle|\marg{style}\marg{tag}\marg{title} hook prepares
% traditional display section:
%    \begin{macrocode}
      \NCC@secttitle{#2}{\NCC@hangfrom{\hskip #1\relax\@svsec}}%
        {\interlinepenalty \@M\ignorespaces #3\@@par}
    \endgroup
    #5%
  \else
%    \end{macrocode}
% The |\NCC@secptitle|\marg{style}\marg{tag}\marg{title} hook prepares
% running section. The |\norunningsuffix| modifier applied in the
% parameter of running section removes a suffix after section title.
%    \begin{macrocode}
    \def\@svsechd{{\normalfont
      \NCC@asecnumset
      \def\norunningsuffix{\protect\NCC@nosecsuffix}%
      \NCC@secptitle{#2}{\hskip #1\relax{\@svsec}}%
        {\ignorespaces #3\NCC@asectitle}#5}}%
  \fi
  \@xsect{#4}%
}
\def\NCC@secttitle#1#2#3{#1{#2#3}}
\def\NCC@secptitle#1#2#3{#1{#2#3}}
\newcommand*\norunningsuffix{}
\def\NCC@nosecsuffix{\let\NCC@asectitle\@empty}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Create Section Styles}
%
% \begin{macro}{\NCC@hangfrom}
% |\NCC@hangfrom|\marg{section tag} works as
% the \LaTeX's |\@hangfrom| command, but its margins can be adjusted
% with the |\adjustsectionmargins| command.
%    \begin{macrocode}
\def\NCC@hangfrom{%
  \NCC@setsecmargins{\z@skip}{\z@skip}\NCC@hangsecstyle{\z@}{}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@setsecmargins}
% |\NCC@setsecmargins|\marg{left skip}\marg{right skip} sets
% section margins and applies the hook that can be defined by the
% |\adjustsectionmargins| command.
%    \begin{macrocode}
\def\NCC@setsecmargins#1#2{%
  \leftskip\z@skip \rightskip\z@skip
  \parfillskip\@flushglue
  \let\\\@normalcr
  \NCC@adjsecmargins{#1}{#2}%
  \NCC@secmarginshook
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@adjsecmargins}
% |\NCC@adjsecmargins|\marg{left skip}\marg{right skip} adjusts
% section margins. The |\parfillskip| value is also adjusted to
% a difference between stretchabilities of the \meta{left skip}
% and the \meta{right skip}. Using this trick, we can easy specify
% the |centerlast| style just setting the stretchability of the
% \meta{right skip} as a negation of the \meta{left skip} stretchability.
% To extract a stretchability from a skip, we simply add it multiplied
% by |-1| (while multiplication the stretchability is removed!).
%    \begin{macrocode}
\def\NCC@adjsecmargins#1#2{%
  \setlength\@tempskipa{#1}\advance\leftskip\@tempskipa
  \setlength\@tempskipb{#2}\advance\rightskip\@tempskipb
  \advance\@tempskipa -1\@tempskipa \advance\@tempskipb -1\@tempskipb
  \advance\@tempskipa -\@tempskipb \advance\parfillskip\@tempskipa
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@hangsecstyle}
% |\NCC@hangsecstyle|\marg{min tag width}\marg{pos}\marg{section tag}
% starts a hang paragraph and prints its tag. The \meta{min tag width}
% specifies a minimum width of hang indent and \meta{pos} specifies
% an alignment of \meta{section tag} (|l|, |c|, |r|) if its width
% is less than the minimum width.
%    \begin{macrocode}
\def\NCC@hangsecstyle#1#2#3{%
  \setlength\@tempdima{#1}%
  \setbox\@tempboxa\hbox{#3}%
  \ifdim \wd\@tempboxa > \@tempdima
    \hangindent\wd\@tempboxa \noindent \box\@tempboxa
  \else
    \hangindent\@tempdima
    \noindent \makebox[\@tempdima][#2]{\unhbox\@tempboxa}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjustsectionmargins}
% |\adjustsectionmargins|\marg{left skip}\marg{right skip}
% defines the |\NCC@secmarginshook| macro to be applied after
% margins are set. To be sure this hook will be applied only once,
% we release it in the |\NCC@sec@reset@controls| hook.
%    \begin{macrocode}
\newcommand*\adjustsectionmargins[2]{%
  \NCC@global\def\NCC@secmarginshook{\NCC@adjsecmargins{#1}{#2}}
}
\g@addto@macro\NCC@sec@reset@controls{%
  \NCC@global\let\NCC@secmarginshook\@empty
}
\let\NCC@secmarginshook\@empty
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@sec}
% A style of sections having dynamic control is defined by the
% |\NCC@sec|\marg{tag} hook. This hook is applied inside a group
% preparing a heading. All section style commands redefine this hook.
% \end{macro}
%
% \begin{macro}{\newplainsectionstyle}
% |\newplainsectionstyle|\marg{name}\marg{indent}\oarg{pos}\marg{left skip}\marg{right skip}
%    \begin{macrocode}
\newcommand*\newplainsectionstyle[2]{%
  \@ifnextchar[{\NCC@newplainsec{#1}{#2}}{\NCC@newplainsec{#1}{#2}[l]}%
}
\def\NCC@newplainsec#1#2[#3]#4#5{%
  \def\@tempa{#3}\def\@tempb{c}%
  \ifx\@tempa\@tempb
    \expandafter\newcommand\csname NCC@sec@#1\endcsname
      {\def\NCC@sec{\NCC@setsecmargins{#4}{#5}%
        \let\\\@centercr \advance\parfillskip -\@flushglue
        \setlength\parindent{#2}}}%
  \else
    \def\@tempb{r}%
    \ifx\@tempa\@tempb
      \expandafter\newcommand\csname NCC@sec@#1\endcsname
        {\def\NCC@sec{\NCC@setsecmargins{#4}{#5}%
          \let\\\@centercr \advance\parfillskip -\@flushglue
          \advance\parfillskip -\@flushglue
          \setlength\parindent{#2}}}%
    \else
      \expandafter\newcommand\csname NCC@sec@#1\endcsname
        {\def\NCC@sec{\NCC@setsecmargins{#4}{#5}\setlength\parindent{#2}}}%
    \fi
  \fi
}
\@onlypreamble\newplainsectionstyle
\@onlypreamble\NCC@newplainsec
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newhangsectionstyle}
% |\newhangsectionstyle|\marg{name}\marg{min tag width}\oarg{pos}\marg{left skip}\marg{right skip}
%    \begin{macrocode}
\newcommand*\newhangsectionstyle[2]{%
  \@ifnextchar[{\NCC@newhangsec{#1}{#2}}{\NCC@newhangsec{#1}{#2}[l]}%
}
\def\NCC@newhangsec#1#2[#3]#4#5{%
  \expandafter\newcommand\csname NCC@sec@#1\endcsname
    {\def\NCC@sec{\NCC@setsecmargins{#4}{#5}\NCC@hangsecstyle{#2}{#3}}}%
}
\@onlypreamble\newhangsectionstyle
\@onlypreamble\NCC@newhangsec
%    \end{macrocode}
% \end{macro}
%
% Specify predefined section styles. The |\@flushglue| is equal to |0pt plus 1fil|.
%    \begin{macrocode}
\newhangsectionstyle{hangindent}{\z@}{\z@skip}{\z@skip}
\newhangsectionstyle{hangindent*}{\z@}{\z@skip}{\@flushglue}
\newhangsectionstyle{hangparindent}{\z@}{\parindent}{\z@skip}
\newhangsectionstyle{hangparindent*}{\z@}{\parindent}{\@flushglue}
\newplainsectionstyle{parindent}{\z@}{\parindent}{\z@skip}
\newplainsectionstyle{parindent*}{\z@}{\parindent}{\@flushglue}
\newplainsectionstyle{center}{\z@}[c]{\@flushglue}{\@flushglue}
\newplainsectionstyle{centerlast}{\z@}[c]{\@flushglue}{-\@flushglue}
%    \end{macrocode}
%
% \subsection{Make Sections with Dynamic Control}
%
% \begin{macro}{\sectionstyle}
% The |\sectionstyle|\oarg{type}\marg{style} changes a style
% for display sections of the given \meta{type}.
%    \begin{macrocode}
\newcommand*{\sectionstyle}[2][]{%
  \@ifundefined{NCC@sec@#2}{%
    \PackageError{nccsect}{Unknown section style `#2'}{}%
  }{%
    \expandafter\def\csname NCC@secstyle@#1\endcsname{%
      \csname NCC@sec@#2\endcsname
    }%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@setsectionstyle}
% The |\NCC@setsectionstyle|\marg{level} set a style for the
% given section level. If a style for the given level is
% undefined, the default style is selected.
%    \begin{macrocode}
\def\NCC@setsectionstyle#1{%
  \edef\@tempa{NCC@secstyle@\NCC@secname{#1}}%
  \@ifundefined{\@tempa}{\NCC@secstyle@}{\csname\@tempa\endcsname}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makesecx}
% The dynamic section making command:
% \begin{quote}
% |\NCC@makesecx|\marg{indent}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
% It prepares only display sections and ignores the \meta{indent} parameter.
%    \begin{macrocode}
\def\NCC@makesecx#1#2#3#4#5{%
  \begingroup\normalfont
    \NCC@asecnumset
%    \end{macrocode}
% The |\NCC@secxtitle|\marg{style}\marg{tag}\marg{title} hook prepares
% display section with dynamic control. The |\NCC@sec| macro is protected
% to prevent its expansion by |\MakeUppercase|.
%    \begin{macrocode}
    \NCC@secxtitle{#2}{\protect\NCC@sec{\@svsec}}
      {\interlinepenalty \@M\ignorespaces #3\@@par}%
  \endgroup #5%
  \par \nobreak \vskip #4\relax \@afterheading \ignorespaces
}
\def\NCC@secxtitle#1#2#3{#1{#2#3}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Make the Main Section}
%
% \begin{macro}{\partmark}
% Define the |\partmark| if it is undefined yet.
%    \begin{macrocode}
\providecommand*\partmark[1]{\markboth{}{}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@startmainsec}
% The main section is a section of zero level.
% It is prepared with the following command:
% \begin{quote}
% |\NCC@startmainsec|\marg{alignment}\marg{prefix}\marg{beforeskip}\\
% |                 |\marg{afterskip}\marg{style}
% \end{quote}
% It starts either a new chapter or a new part depending on the class
% loaded. To decide what version should be prepared, we test the
% |\chapter| command on existence.
%    \begin{macrocode}
\@ifundefined{chapter}{%
%    \end{macrocode}
%
% The case of an article-like class. Zero-level section is the |\part|.
%    \begin{macrocode}
  \def\NCC@startmainsec#1#2#3#4#5{%
    \NCC@preparesectag{\leavevmode#2}{\partname\nobreakspace}%
    \NCC@secskip{#3}%
    \secdef{\NCC@part{#1}{#4}{#5}}{\NCC@spart{#1}{#4}{#5}}%
  }
%    \end{macrocode}
%
% \begin{macro}{\NCC@spart}
% Prepare the starred version of part:
% \begin{quote}
% |\NCC@spart|\marg{alignment}\marg{afterskip}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@spart#1#2#3#4{%
    \let\@svsec\@empty
    \NCC@makepart{#1}{#3}{#4}{#2}{}%
    \NCC@sec@reset@controls
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@part}
% Prepare the non-starred version of part:
% \begin{quote}
% |\NCC@part|\marg{alignment}\marg{afterskip}\marg{style}\oarg{toc-entry}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@part#1#2#3[#4]#5{%
    \def\NCC@make{\NCC@makepart{#1}{#3}{#5}{#2}}%
    \NCC@makesection{part}{\z@}{#4}{%
      \addcontentsline{toc}{part}{%
        \ifnum \c@secnumdepth>\m@ne \numberline{\thepart}\fi
        #4%
      }%
    }%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makepart}
% This command makes a part.
% \begin{quote}
% |\NCC@makepart|\marg{alignment}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a part tag.
%    \begin{macrocode}
  \def\NCC@makepart#1#2#3#4#5{%
    \begingroup \normalfont
      \NCC@asecnumset
      \NCC@makeparttitle{#1}{#2}{#3}%
    \endgroup
    #5%
    \par\nobreak \vskip #4\relax \@afterheading \ignorespaces
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makeparttitle}
% This command makes a part title itself. The |\NCC@secmain| hook contains
% the dynamic alignment style or nothing.
% \begin{quote}
% |\NCC@makeparttitle|\marg{alignment}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@makeparttitle#1#2#3{%
    \ifx\@svsec\@empty \else
      \NCC@secmain#1{\let\NCC@asecnum\@empty\@svsec\@@par}\nobreak
    \fi
    \interlinepenalty \@M \NCC@secmain#1{#2{#3\@@par}}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@partsection}
% Define the |\NCC@partsection| to be equal to the |\NCC@mainsection| command
% which will be specified later when a main section will be declared.
%    \begin{macrocode}
  \def\NCC@partsection{\NCC@mainsection}
}{
%    \end{macrocode}
% \end{macro}
%
% The case of a book-like class. Zero-level section is the |\chapter|.
%    \begin{macrocode}
  \def\NCC@startmainsec#1#2#3#4#5{%
    \NCC@startchap
    \NCC@preparesectag{\leavevmode#2}{\@chapapp\nobreakspace}%
    \secdef{\NCC@chapter{#1}{#3}{#4}{#5}}{\NCC@schapter{#1}{#3}{#4}{#5}}%
  }
%    \end{macrocode}
%
% \begin{macro}{\NCC@startchap}
% The start chapter hook:
%    \begin{macrocode}
  \def\NCC@startchap{%
    \if@openright\cleardoublepage\else\clearpage\fi
    \thispagestyle{plain}\global\@topnum\z@
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@schapter}
% Prepare the starred version of chapter:
% \begin{quote}
% |\NCC@schapter|\marg{alignment}\marg{beforeskip}\marg{afterskip}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@schapter#1#2#3#4#5{%
    \let\@svsec\@empty
    \NCC@makechapter{#1}{#2}{#4}{#5}{#3}{}%
    \NCC@sec@reset@controls
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@chapter}
% Prepare the non-starred version of chapter:
% \begin{quote}
% |\NCC@chapter|\marg{alignment}\marg{beforeskip}\marg{afterskip}\marg{style}\\
% |            |\oarg{toc-entry}\marg{heading}
% \end{quote}
% It uses the |\NCC@infloats|\marg{action} hook that applies the specified
% action for all registered float types.
%    \begin{macrocode}
  \def\NCC@chapter#1#2#3#4[#5]#6{%
    \@ifundefined{if@mainmatter}{}{\if@mainmatter\else\noheadingtag\fi}%
    \def\NCC@make{\NCC@makechapter{#1}{#2}{#4}{#6}{#3}}%
    \NCC@makesection{chapter}{\z@}{#5}{%
      \typeout{\@chapapp\space\thechapter.}%
      \addcontentsline{toc}{chapter}{%
        \ifnum \c@secnumdepth>\m@ne
          \numberline{\NCC@thetocchapter}\fi
        #5%
      }%
      \NCC@infloats{\addtocontents{\@nameuse{ext@\@captype}}%
                      {\protect\runinsectionskip}}%
    }%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\beforechapter}
% The |\beforechapter|\marg{something} hook is applied to the nearest
% chapter. An empty value of its parameter means no hook.
%    \begin{macrocode}
  \newcommand\beforechapter[1]{\gdef\NCC@beforechapter{#1}}
  \beforechapter{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@thetocchapter}
% The following hook allows redefine the appearance of chapter name
% in the TOC:
%    \begin{macrocode}
  \def\NCC@thetocchapter{\thechapter}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makechapter}
% This command makes a chapter:
% \begin{quote}
% |\NCC@makechapter|\marg{alignment}\marg{beforeskip}\marg{style}\marg{heading}\\
% |                |\marg{afterskip}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a chapter tag.
%    \begin{macrocode}
  \def\NCC@makechapter#1#2#3#4#5#6{%
    \if@twocolumn
      \@topnewpage[\NCC@makechaphead{#1}{#2}{#3}{#4}{#5}]%
    \else
      \NCC@makechaphead{#1}{#2}{#3}{#4}{#5}%
    \fi
    \NCC@makechapfinal{#6}%
    \@afterheading
    \ignorespaces
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makechapfinal}
% \begin{macro}{\NCC@makechapfinalgobble}
% The |\NCC@makechapfinal| hook applies a final action which can contain the
% |\chaptermark| command. Its default value is to put the parameter as is.
% If you let this command to be equal to the |\NCC@makechapfinalgobble|, the
% chapter mark will contain no chapter name.
%    \begin{macrocode}
  \let\NCC@makechapfinal\@firstofone
  \def\NCC@makechapfinalgobble#1{%
    \let\NCC@makechapmark\NCC@makemark
    \def\NCC@makemark{%
      \let\NCC@temp\@chapapp
      \let\@chapapp\@gobble
      \NCC@makechapmark
      \let\@chapapp\NCC@temp
    }%
    #1%
  }
  \@onlypreamble\NCC@makechapfinalgobble
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@makechaphead}
% This command makes a chapter head:
% \begin{quote}
% |\NCC@makechaphead|\marg{alignment}\marg{beforeskip}\marg{style}\marg{heading}\\
% |                 |\marg{afterskip}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@makechaphead#1#2#3#4#5{%
    \ifx\NCC@beforechapter\@empty
      \StartFromTextArea \vskip #2%
    \else
      \begingroup
        \@twocolumnfalse
        \let\NCC@global\@empty
        \NCC@sec@reset@controls
        \normalfont \NCC@beforechapter \par
      \endgroup
      \beforechapter{}%
    \fi
    \begingroup \normalfont
      \NCC@asecnumset
      \NCC@makechaptitle{#1}{#3}{#4}%
    \endgroup
    \par\nobreak \vskip #5\relax
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makechaptitle}
% This command makes a chapter title itself:
% \begin{quote}
% |\NCC@makechaptitle|\marg{alignment}\marg{style}\marg{heading}
% \end{quote}
% The |\NCC@secmain| hook contains the dynamic alignment style
% or nothing.
%    \begin{macrocode}
  \def\NCC@makechaptitle#1#2#3{%
    \ifx\@svsec\@empty \else
      \NCC@secmain#1{\let\NCC@asecnum\@empty\@svsec\@@par}%
    \fi
    \interlinepenalty \@M \NCC@secmain#1{#2{#3\@@par}}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\epigraph}
% \begin{macro}{\epigraphparameters}
% \begin{quote}
% |\epigraph|\oarg{width}\marg{text}\marg{author}\\
% |\epigraphparameters|\marg{style}\marg{width}\marg{height}\marg{author-style}\\
% |                   |\marg{after-action}
% \end{quote}
%    \begin{macrocode}
  \newcommand*\epigraph[1][\NCC@epigraphwidth]{\NCC@epigraph{#1}}
  \newcommand*\epigraphparameters[5]{%
    \def\NCC@epigraphwidth{#2}%
    \long\def\NCC@epigraph##1##2##3{
      \beforechapter{\def\epigraphwidth{##1}%
        #1\par
        \NCC@makeepigraph{#3}{##2}{#4{##3}}\par
        #5%
      }%
    }%
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@makeepigraph}
% \begin{quote}
% |\NCC@makeepigraph|\marg{height}\marg{text}\marg{author}
% \end{quote}
%    \begin{macrocode}
  \long\def\NCC@makeepigraph#1#2#3{%
    \@begin@tempboxa\vtop{\setlength{\hsize}{\epigraphwidth}%
        \@parboxrestore{#2\@@par}#3\@@par
      }%
      \setlength\@tempdima{#1}\advance\@tempdima -\totalheight
      \ifdim\@tempdima>\z@
        \advance\@tempdima\depth
        \dp\@tempboxa\@tempdima
      \fi
      \leavevmode\box\@tempboxa
    \@end@tempboxa
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Make Part in Book-like Classes}
%
% \begin{macro}{\NCC@startpart}
% The start-part hook:
%    \begin{macrocode}
  \def\NCC@startpart{%
    \if@openright\cleardoublepage\else\clearpage\fi
    \thispagestyle{plain}%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@spart}
% Prepare the starred version of part:
% \begin{quote}
% |\NCC@spart|\marg{before}\marg{after}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@spart#1#2#3#4{%
    \let\@svsec\@empty
    \NCC@makepart{#1}{#3}{#4}{#2}{}%
    \NCC@sec@reset@controls
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@part}
% Prepare the non-starred version of part:
% \begin{quote}
% |\NCC@part|\marg{before}\marg{after}\marg{style}\oarg{toc-entry}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@part#1#2#3[#4]#5{%
    \def\NCC@make{\NCC@makepart{#1}{#3}{#5}{#2}}%
    \NCC@makesection{part}{\m@ne}{#4}{%
      \addcontentsline{toc}{part}{%
        \ifnum \c@secnumdepth>-2
          \numberline{\NCC@thetocpart}\fi
        #4%
      }%
    }%
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@thetocpart}
% The following hook allows redefine the appearance of part name
% in the TOC:
%    \begin{macrocode}
  \def\NCC@thetocpart{\thepart}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makepart}
% This command makes a part:
% \begin{quote}
% |\NCC@makepart|\marg{before}\marg{style}\marg{heading}\marg{after}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a part tag.
%    \begin{macrocode}
  \def\NCC@makepart#1#2#3#4#5{%
    \if@twocolumn \onecolumn \@tempswatrue \else \@tempswafalse \fi
    \begingroup\normalfont
      \NCC@asecnum@
      \NCC@makeparttitle{#1}{#2}{#3}%
    \endgroup
    \NCC@makepartfinal{#5}#4%
    \if@tempswa \twocolumn \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makepartfinal}
% \begin{macro}{\NCC@makepartfinalgobble}
% The |\NCC@makepartfinal| hook applies a final action which can contain the
% |\partmark| command. Its default value is to put the parameter as is.
% If you let this command to be equal to the |\NCC@makepartfinalgobble|, the
% chapter mark will contain no chapter name.
%    \begin{macrocode}
  \let\NCC@makepartfinal\@firstofone
  \def\NCC@makepartfinalgobble#1{%
    \let\NCC@makepartmark\NCC@makemark
    \def\NCC@makemark{%
      \let\NCC@temp\partname
      \let\partname\@gobble
      \NCC@makepartmark
      \let\partname\NCC@temp
    }%
    #1%
  }
  \@onlypreamble\NCC@makepartfinalgobble
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@makeparttitle}
% This command makes a part title itself:
% \begin{quote}
% |\NCC@makeparttitle|\marg{before}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@makeparttitle#1#2#3{#1%
    \ifx\@svsec\@empty \else
      {\let\NCC@asecnum\@empty\@svsec\@@par}\nobreak \fi
    \interlinepenalty \@M #2{#3\@@par}
  }
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Make Captions}
%
% \begin{macro}{\CaptionTagSuffix}
% |\CaptionTagSuffix|\marg{suffix} sets a default suffix after caption tag:
%    \begin{macrocode}
\newcommand*{\CaptionTagSuffix}[1]{\def\NCC@acapnum{#1}}
\@onlypreamble\CaptionTagSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\captiontagsuffix}
% |\captiontagsuffix|\oarg{type}\marg{suffix} changes a suffix after caption
% tag.
%    \begin{macrocode}
\newcommand*\captiontagsuffix[2][]{%
  \NCC@prepare@capkey{suffix}{#1}{\def\NCC@acapnum{#2}}%
}
\let\NCC@capsuffix@\@empty
%    \end{macrocode}
% \end{macro}

%
% \begin{macro}{\captionstyle}
% |\captionstyle|\oarg{type}\marg{style} selects a style to be applied
% to the caption text. Three styles are available now: |default|, |center|,
% and |centerlast|.
%    \begin{macrocode}
\newcommand*\captionstyle[1][]{%
  \NCC@set@capkey{style}{style}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\captiontagstyle}
% |\captiontagstyle|\oarg{type}\marg{style} selects a style of caption tag:
% |right| or |para|.
%    \begin{macrocode}
\newcommand*\captiontagstyle[1][]{%
  \NCC@set@capkey{tag}{tag style}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\captionwidth}
% The |\captionwidth|\oarg{type}\marg{length} specifies a caption width
% in |\@tempdima|. Default width is |\linewidth|.
%    \begin{macrocode}
\newcommand*\captionwidth[2][]{%
  \NCC@prepare@capkey{width}{#1}{\setlength{\@tempdima}{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@set@capkey}
% |\NCC@set@capkey|\marg{key}\marg{description}\marg{type}\marg{value}
%    \begin{macrocode}
\def\NCC@set@capkey#1#2#3#4{%
  \@ifundefined{NCC@makecap#1@#4}
  {\PackageError{nccsect}{Unknown caption #2 `#4'}{}%
  }{%
    \edef\@tempa{\noexpand\NCC@prepare@capkey{#1}{#3}{%
        \expandafter\noexpand\csname NCC@makecap#1@#4\endcsname
      }%
    }%
    \@tempa
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@prepare@capkey}
% |\NCC@prepare@capkey|\marg{key}\marg{type}\marg{definition}
%    \begin{macrocode}
\def\NCC@prepare@capkey#1#2{%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty
    \ifx\@captype\@undefined \else \let\@tempa\@captype \fi
  \fi
  \expandafter\def\csname NCC@cap#1@\@tempa\endcsname
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@apply@cap}
% |\NCC@apply@cap|\marg{key}
%    \begin{macrocode}
\def\NCC@apply@cap#1{%
  \@ifundefined{NCC@cap#1@\@captype}%
    {\let\@tempa\@empty}{\let\@tempa\@captype}%
  \csname NCC@cap#1@\@tempa\endcsname
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@startcaption}
% This command starts a caption:
% \begin{quote}
% |\NCC@startcaption|\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
%    \begin{macrocode}
\def\NCC@startcaption#1#2#3{%
  \secdef{\NCC@caption{#1}{#2}{#3}}{\NCC@scaption{#1}{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@scaption}
% Starred version of caption:
% \begin{quote}
% |\NCC@scaption|\marg{beforeskip}\marg{afterskip}\marg{style}\marg{text}
% \end{quote}
%    \begin{macrocode}
\long\def\NCC@scaption#1#2#3#4{%
  \let\@svsec\@empty
  \NCC@makecaption{#3}{#1}{#4}{#2}{}%
  \NCC@sec@reset@controls
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@caption}
% Non-starred version of caption:
% \begin{quote}
% |\NCC@caption|\marg{beforeskip}\marg{afterskip}\marg{style}\oarg{toc-entry}\marg{text}
% \end{quote}
%    \begin{macrocode}
\long\def\NCC@caption#1#2#3[#4]#5{%
  \def\NCC@make{\NCC@makecaption{#3}{#1}{#5}{#2}}%
  \NCC@makesection{\@captype}{\z@}{#4}{%
    \begingroup
      \let\centering\@empty
      \addcontentsline{\@nameuse{ext@\@captype}}{\@captype}{%
        \ifnum \c@secnumdepth>\m@ne
          \numberline{\@nameuse{the\@captype}}\fi
        #4%
      }%
    \endgroup
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaption}
% This command makes a caption:
% \begin{quote}
% |\NCC@makecaption|\marg{style}\marg{beforeskip}\marg{text}\marg{afterskip}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a caption tag.
%    \begin{macrocode}
\long\def\NCC@makecaption#1#2#3#4#5{%
  \begingroup\par\normalfont
    #1{}\addvspace{#2}\noindent
%    \end{macrocode}
% Calculate in |\@tempcnta| caption variants:
% 0~-- no caption, 1~-- caption tag only, 2~-- caption text only,
% 3~-- both caption tag and text are nonempty.
%    \begin{macrocode}
    \ifx\@svsec\@empty \@tempcnta\z@ \else \@tempcnta\@ne \fi
    \def\@tempa{#3}%
    \ifx\@tempa\@empty \else \advance\@tempcnta\tw@ \fi
%    \end{macrocode}
% Put caption in a parbox aligned at the top line.
%    \begin{macrocode}
    \ifnum\@tempcnta=\z@ \else
      \NCC@apply@cap{suffix}%
      \NCC@apply@cap{width}%
      \NCC@vtopcap{\@parboxrestore\NCC@apply@cap{tag}{#3}\@@par}\par
%    \end{macrocode}
% We avoid insert zero skip after parbox to allow captions of
% side-by-side figures to be aligned at their top line.
%    \begin{macrocode}
      \setlength\@tempskipa{#4}%
      \ifdim\@tempskipa=\z@ \else \vskip \@tempskipa\fi
    \fi
  \endgroup
  #5%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@vtopcap}
% |\NCC@vtopcap|\marg{text} places a text in a vertical
% top-aligned box. Its width is prepared in |\@tempdima|
% before this macro. If its width is greater than the
% |\linewidth|, we allow overlap the box out of line.
% The overlapping directions are calculated from stretches of
% paragraph marginal skips.
%    \begin{macrocode}
\def\NCC@vtopcap#1{%
  \ifdim\@tempdima>\linewidth
    \@tempskipa \leftskip \advance\@tempskipa -1\@tempskipa
    \@tempskipb \rightskip \advance\@tempskipb \parfillskip
    \advance\@tempskipb -1\@tempskipb
    \vtop{\hb@xt@\linewidth{%
      \NCC@ifzeroskip\@tempskipa{}{\hss}%
      \vtop{\hsize\@tempdima#1}%
      \NCC@ifzeroskip\@tempskipb{}{\hss}%
    }}%
  \else
    \vtop{\hsize\@tempdima#1}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@ifzeroskip}
% |\NCC@ifzeroskip|\marg{register}\marg{true-clause}\marg{false-clause}
% executes the \meta{true-clause} if the value of skip register
% is exactly zero skip without stretchability. Otherwise, the
% \meta{false-clause} is executed.
%    \begin{macrocode}
\def\NCC@ifzeroskip#1{%
  \edef\@tempa{\the#1}\edef\@tempb{\the\z@skip}%
  \ifx\@tempa\@tempb
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@para}
% The |\NCC@makecaptag@para|\marg{text} prepares run-in tag.
%    \begin{macrocode}
\long\def\NCC@makecaptag@para#1{%
  \ifnum\@tempcnta<\thr@@ \let\NCC@acapnum\@empty\fi
  \NCC@apply@cap{style}{{\@svsec}\ignorespaces#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@left}
% The |\NCC@makecaptag@left|\marg{text} prepares flush-left tag.
%    \begin{macrocode}
\def\NCC@makecaptag@left{\NCC@separate@captag\raggedright}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@center}
% The |\NCC@makecaptag@center|\marg{text} prepares centered tag.
%    \begin{macrocode}
\def\NCC@makecaptag@center{\NCC@separate@captag\centering}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@right}
% The |\NCC@makecaptag@right|\marg{text} prepares flush-right tag.
%    \begin{macrocode}
\def\NCC@makecaptag@right{\NCC@separate@captag\raggedleft}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@separate@captag}
% The |\NCC@separate@captag|\marg{style}\marg{text} prepares a
% caption tag in a separate line.
%    \begin{macrocode}
\long\def\NCC@separate@captag#1#2{%
  \ifodd\@tempcnta
    {\let\NCC@acapnum\@empty #1\@svsec\@@par}%
  \fi
  \ifnum\@tempcnta>\@ne
    \ifnum\@tempcnta=\thr@@ \vskip .5ex\fi
    \NCC@apply@cap{style}{#2}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@default}
% The |\NCC@makecapstyle@default|\marg{text} prepares caption text
% in default \LaTeX's style.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@default#1{%
  \setbox\@tempboxa\vtop{\hsize\linewidth\@parboxrestore#1\@@par}%
  \ifdim\dp\@tempboxa<\baselineskip \centering#1%
  \else \box\@tempboxa \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@para}
% The |\NCC@makecapstyle@para|\marg{text} prepares ordinary caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@para#1{#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@left}
% The |\NCC@makecapstyle@left|\marg{text} prepares flush-left caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@left#1{\raggedright#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@right}
% The |\NCC@makecapstyle@right|\marg{text} prepares flush-right caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@right#1{\raggedleft#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@center}
% The |\NCC@makecapstyle@center|\marg{text} prepares centered caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@center#1{\centering#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@centerlast}
% The |\NCC@makecapstyle@centerlast|\marg{text} prepares caption with
% last line centered.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@centerlast#1{%
  \leftskip\@flushglue \rightskip -\@flushglue
  \parfillskip\z@\@plus 2fil\relax#1%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\RegisterFloatType}
% The |\RegisterFloatType|\marg{type} command registers a float type:
%    \begin{macrocode}
\newcommand*{\RegisterFloatType}[1]{%
  \edef\NCC@floatlist{\NCC@floatlist{#1}}%
}
\let\NCC@floatlist\@empty
\@onlypreamble\RegisterFloatType
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@infloats}
% The |\NCC@infloats|\marg{action} command applies the given \meta{action}
% to all registered float types. During the cycle,
% the |\@captype| contains a name of float and
% the |\@tempcnta| is equal to its registration number
% (1~for the figure float, 2~for the table float, and so on).
%    \begin{macrocode}
\def\NCC@infloats#1{%
  \@tempcnta\z@
  \let\NCC@temp \@captype
  \expandafter \@tfor \expandafter \@captype
    \expandafter :\expandafter =\NCC@floatlist \do
  {\advance\@tempcnta\@ne #1}%
  \let\@captype\NCC@temp
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Declare Sections and Captions}
%
% \begin{macro}{\DeclareSection}
% Now we can implement the |\DeclareSection| command.
% It generates:
% \begin{desclist}{}{}
% \item[\cs{NCC@mainsection}] command if \meta{level} = 0;
% \item[\cs{NCC@section}\meta{level-in-roman}] command if \meta{level} $>$ 0;
% \item[\cs{NCC@cap@}\meta{float-type}] command if \meta{level} $<$ 0.
% \end{desclist}
%    \begin{macrocode}
\newcommand{\DeclareSection}{\@ifstar{\NCC@dsecx}{\NCC@dsec}}
\def\NCC@dsec#1#2{%
  \@ifnextchar[{\NCC@dsect{#1}{#2}}{\NCC@dsect{#1}{#2}[\z@skip]}%
}
\@onlypreamble\DeclareSection
\@onlypreamble\NCC@dsec
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@dsect}
% The non-starred version of section declaration command
% prepares display sections with traditional formatting:
% \begin{quote}
% |\NCC@dsect|\marg{level}\marg{type}\oarg{indent}\marg{prefix}\marg{beforeskip}\\
% |          |\marg{afterskip}\marg{style}
% \end{quote}
% It is also used for generation of run-in sections
% and captions.
%    \begin{macrocode}
\def\NCC@dsect#1#2[#3]#4#5#6#7{%
  \ifnum#1>\z@
    \expandafter\def\csname NCC@section\romannumeral#1\endcsname{%
      \NCC@setsectionsuffix{#1}%
      \NCC@preparesectag{#4}{}%
      \let\NCC@makesec\NCC@makesect
      \NCC@startsection{#2}{#1}{#3}{#5}{#6}{#7}}%
  \else
    \ifnum#1=\z@
      \def\NCC@mainsection{%
        \NCC@setsectionsuffix\z@
        \let\NCC@secmain\@empty
%    \end{macrocode}
% The empty |\NCC@secmain| means standard alignment of main section
%    \begin{macrocode}
        \NCC@startmainsec{%
          \NCC@hangfrom{\hskip #3}\NCC@adjsecmargins{}\@flushglue
          \ignorespaces}%
          {#4}{#5}{#6}{#7}%
      }%
    \else
      \NCC@dsecf{#2}{#4}{#5}{#6}{#7}%
    \fi
  \fi
}
\@onlypreamble\NCC@dsect
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@dsecx}
% The starred version of section declaration command
% prepares display sections with dynamic formatting:
% \begin{quote}
% |\NCC@dsecx|\marg{level}\marg{type}\marg{prefix}\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
% It can also be used for generation of captions.
%    \begin{macrocode}
\def\NCC@dsecx#1#2#3#4#5#6{%
  \ifnum#1>\z@
    \expandafter\def\csname NCC@section\romannumeral#1\endcsname{%
      \NCC@setsectionsuffix{#1}%
      \NCC@setsectionstyle{#1}%
      \NCC@preparesectag{#3}{}%
      \let\NCC@makesec\NCC@makesecx
      \NCC@startsection{#2}{#1}{\z@}{#4}{#5}{#6}}%
  \else
    \ifnum#1=\z@
%    \end{macrocode}
% The non-empty |\NCC@secmain| hook means the dynamic alignment.
% We also redefine the dynamic section style |\NCC@sec| in such a way that the
% right skip stretchability will be |1fil| if the section style has
% no flush glue.
%    \begin{macrocode}
      \def\NCC@mainsection{%
        \NCC@setsectionsuffix\z@
        \NCC@setsectionstyle\z@
        \let\NCC@secsave\NCC@sec \let\NCC@sec\NCC@secflush
        \def\NCC@secmain{\protect\NCC@sec{}}%
        \NCC@startmainsec{}{#3}{#4}{#5}{#6}%
      }%
    \else
      \NCC@dsecf{#2}{#3}{#4}{#5}{#6}%
    \fi
  \fi
}
\@onlypreamble\NCC@dsecx
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@secflush}
% |\NCC@secflush|\marg{tag} applies a section style saved in the
% |\NCC@secsave| macro and adjusts |\rightskip| and |\parfillskip|
% if left and right margins have no stretchability in sum.
% To adjust the right skip, we do the same tricks as in
% |\NCC@adjsecmargins|.
%    \begin{macrocode}
\def\NCC@secflush#1{\NCC@secsave{#1}%
  \@tempskipa\leftskip \advance\@tempskipa\rightskip
  \advance\@tempskipa -1\@tempskipa
  \NCC@ifzeroskip\@tempskipa{%
    \@tempskipa 1\rightskip \advance\@tempskipa -\rightskip
    \advance\@tempskipa \@flushglue
    \advance\rightskip \@tempskipa
    \advance\parfillskip -\@tempskipa
  }{}%
  \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@dsecf}
% This command declares captions of floats:
% \begin{quote}
% |\NCC@dsecf|\marg{type}\marg{prefix}\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
%    \begin{macrocode}
\def\NCC@dsecf#1#2#3#4#5{%
  \expandafter\def\csname NCC@cap@#1\endcsname{%
    \def\NCC@makesectag####1{#2{\csname #1name\endcsname}%
      \nobreakspace####1\NCC@acapnum}%
    \NCC@startcaption{#3}{#4}{#5}%
  }%
}
\@onlypreamble\NCC@dsectf
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclarePart}
% In book-like classes, a part is declared in a special way:
% \begin{quote}
% |\DeclarePart|\marg{before}\marg{after}\marg{prefix}\marg{style}
% \end{quote}
% Long parameters are allowed in this declaration.
%    \begin{macrocode}
\@ifundefined{chapter}{}{%
  \newcommand\DeclarePart[4]{%
    \def\NCC@partsection{%
      \NCC@startpart
      \NCC@preparesectag{\leavevmode#3}{\partname\nobreakspace}%
      \secdef{\NCC@part{#1}{#2}{#4}}{\NCC@spart{#1}{#2}{#4}}%
    }%
  }
  \@onlypreamble\DeclarePart
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Caption Patches}
%
% \begin{macro}{\@makecaption}
% We emulate here the |\@makecaption{\fnum@|\meta{type}|}|\marg{caption}
% command to provide the compatibility with packages using it.
% It calls the |\NCC@cap@|\meta{type} command using the type specified
% in |\@captype| command. The counter is already stepped
% before this command and all necessary things are written
% to aux. Therefore, we turn off writing to aux and decrease a value of
% the float counter by |-1| because it will be stepped within again.
%    \begin{macrocode}
\long\def\@makecaption#1#2{%
  \begingroup
    \skipwritingtoaux
    \addtocounter\@captype\m@ne
    \csname NCC@cap@\@captype\endcsname[]{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% Add patch to the \textbf{supertabular} package:
%    \begin{macrocode}
\AfterPackage{supertabular}{%
  \long\def\ST@caption#1[#2]#3{\par%
    \addcontentsline{\csname ext@#1\endcsname}{#1}%
      {\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
    \begingroup\centering
      \def\@captype{#1}%
      \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
    \endgroup
  }
}
%    \end{macrocode}
%
% Add patch to the \textbf{xtab} package:
%    \begin{macrocode}
\AfterPackage{xtab}{%
  \long\def\ST@caption#1[#2]#3{\par%
    \@initisotab
    \addcontentsline{\csname ext@#1\endcsname}{#1}%
      {\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
    \begingroup\centering
      \def\@captype{#1}%
      \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
    \endgroup
    \global\advance\ST@pageleft -\PWSTcapht
    \ST@trace\tw@{Added caption. Space left for xtabular: \the\ST@pageleft}%
  }
}
%    \end{macrocode}
%
% Add patch to the \textbf{longtable} package:
%    \begin{macrocode}
\AfterPackage{longtable}{%
  \def\LT@makecaption#1#2#3{%
    \LT@mcol\LT@cols c{\hbox to\z@{\hss
      \parbox[t]\LTcapwidth{\centering\def\@captype{table}%
        \ifx#1\@gobble \NCC@cap@table*{#3}%
        \else \@makecaption{\fnum@table}{#3}%
        \fi
      }%
      \hss
    }}%
  }
}
%    \end{macrocode}
%
% \subsection{Declare TOC-Entries}
%
% \begin{macro}{\DeclareTOCEntry}
% The toc-entries declaration command:
% \begin{quote}
% |\DeclareTOCEntry|\marg{level}\marg{action}\marg{prefix}\marg{prototype}\\
% |                |\marg{style}\oarg{next}
% \end{quote}
%    \begin{macrocode}
\newcommand*{\DeclareTOCEntry}[5]{%
  \@ifnextchar[{\NCC@dtoc{#1}{#2}{#3}{#4}{#5}}%
               {\NCC@dtoc{#1}{#2}{#3}{#4}{#5}[\NCC@nexttocnum{#3}{#4}]}%
}
\def\NCC@dtoc#1#2#3#4#5[#6]{%
%    \end{macrocode}
% Declare a toc-entry command for a registered float.
% We scan the registration list and find the necessary
% float type comparing its registration number with the negation
% of level. The generated command is |\l@|\meta{float-type}:
%    \begin{macrocode}
  \ifnum#1<\z@
    \@tempswatrue
    \NCC@infloats{%
      \ifnum#1=-\@tempcnta
        \expandafter\def\csname l@\@captype\endcsname
          {\NCC@tocentry\z@{#2}{#3}{#4}{#5}}%
        \@tempswafalse
        \@break@tfor
      \fi
    }%
%    \end{macrocode}
% Incorrect level number. Generate an error.
%    \begin{macrocode}
    \if@tempswa
      \@tempcnta#1\relax
      \@tempcnta -\@tempcnta
      \PackageError{nccsect}%
        {Float type registration number \the\@tempcnta\space
         is out of range}{}%
    \fi
  \else
%    \end{macrocode}
% Prepare in |\@tempa| a command name: |\l@section| or |\l@subsection|
% or \ldots\ or |\l@subparagraph| or |\l@section@vi| or \ldots:
%    \begin{macrocode}
    \ifnum#1>\z@
      \edef\@tempa{\noexpand\def\expandafter\noexpand
                   \csname l@\NCC@secname{#1}\endcsname}%
%    \end{macrocode}
% or |\l@part| or |\l@chapter|:
%    \begin{macrocode}
    \else
      \@ifundefined{chapter}{\def\@tempa{\def\l@part}}%
                            {\def\@tempa{\def\l@chapter}}%
    \fi
%    \end{macrocode}
% Declare the toc-entry:
%    \begin{macrocode}
    \@tempa{\NCC@tocentry{#1}{#2}{#3}{#4}{#5}}%
%    \end{macrocode}
% Prepare in the |\l@tocskip@|\meta{next-level-in-roman} command
% the left margin adjustment command. The
% |\NCC@tocnumprototype|\marg{style}\marg{prototype} hook
% applies a style to the prototype of toc-entry number.
%    \begin{macrocode}
    \@tempcnta #1\relax \advance\@tempcnta\@ne
    \expandafter\def\csname l@tocskip@\romannumeral\@tempcnta
      \endcsname{\NCC@tocadj{\NCC@tocnumprototype{#5}{#6}}}%
  \fi
}
\@onlypreamble\DeclareTOCEntry
\@onlypreamble\NCC@dtoc
\def\NCC@nexttocnum#1#2{#1#2\NCC@atocnum}
\def\NCC@tocnumprototype#1#2{\let\applystyle\@firstoftwo#1{#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@tocadj}
% The command increases |\@tempdimb| on the width of the argument:
%    \begin{macrocode}
\def\NCC@tocadj#1{%
  \settowidth\@tempdima{\let\NCC@atocdo\@firstoftwo#1}%
  \advance\@tempdimb\@tempdima
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclareTOCPart}
% Part toc-entry declaration in book-like classes. If optional
% \meta{afterskip} is omitted, the default |\NCC@runskip| value
% is applied after this entry.
% \begin{quote}
% |\DeclareTOCPart|\marg{action}\oarg{afterskip}\marg{prefix}\marg{prototype}\marg{style}
% \end{quote}
%    \begin{macrocode}
\@ifundefined{chapter}{}{%
  \newcommand*\DeclareTOCPart[1]{%
    \@ifnextchar[{\NCC@dtocpart{#1}}{\NCC@dtocpart{#1}[\NCC@runskip]}%
  }
  \def\NCC@dtocpart#1[#2]#3#4#5{%
    \def\l@part##1##2{%
      \NCC@tocentry{-1}{%
%    \end{macrocode}
% We temporary add |1fil| to the toc right margin to prepare
% a ragged right toc-entry.
%    \begin{macrocode}
        \TOCMarginDrift{1fil}%
%    \end{macrocode}
% Breaks before part are preferred.
%    \begin{macrocode}
        \addpenalty{-\@highpenalty}#1%
      }{#3}{#4}{#5}{##1}{\hss##2}%
      \nobreak \vskip #2\relax
      \@nobreaktrue
      \everypar{\@nobreakfalse\everypar{}}%
    }%
  }
  \@onlypreamble\DeclareTOCPart
  \@onlypreamble\NCC@dtocpart
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@tocentry}
% This command makes a toc-entry:
% \begin{quote}
% |\NCC@tocentry|\marg{level}\marg{action}\marg{prefix}\marg{prototype}\\
% |             |\marg{style}\marg{entry}\marg{page-number}
% \end{quote}
%    \begin{macrocode}
\def\NCC@tocentry#1#2#3#4#5#6#7{%
  \ifnum #1>\c@tocdepth \else
    \par\begingroup\normalfont #2%
      \let\applystyle\@firstoftwo
%    \end{macrocode}
% Calculate the left margin in the |\@tempdimb| register
% applying the |\l@tocskip@i|, \ldots, |\l@tocskip@|\meta{level-in-roman}
% commands:
%    \begin{macrocode}
      \@tempdimb\z@ \@tempcnta #1\relax
      \@whilenum \@tempcnta >\z@\do
        {\@nameuse{l@tocskip@\romannumeral \@tempcnta}%
         \advance\@tempcnta\m@ne}%
%    \end{macrocode}
% The |\NCC@preparetocnum|\marg{style}\marg{prefix} hook prepares
% the |\NCC@maketocnum|\marg{tag} command creating
% a number-line tag:
%    \begin{macrocode}
      \NCC@preparetocnum{#5}{#3}%
%    \end{macrocode}
% Calculate the hang indent value in |\@tempdima|:
%    \begin{macrocode}
      \settowidth\@tempdima{\let\NCC@atocdo\@firstoftwo\NCC@maketocnum{#4}}%
%    \end{macrocode}
% Produce the toc-entry. The |\NCC@tocentrytitle|\marg{style}\marg{title}
% hook applies the style to the toc-entry title.
%    \begin{macrocode}
      \@dottedtocline{#1}{\@tempdimb}{\@tempdima}%
        {\let\NCC@atocdo\@secondoftwo\NCC@tocentrytitle{#5}{#6\unskip}}%
        {\let\applystyle\@secondoftwo#5{#7}}%
%    \end{macrocode}
% Allow break after toc-entry:
%    \begin{macrocode}
      \@nobreakfalse
    \endgroup
  \fi
}
\def\NCC@preparetocnum#1#2{%
  \def\NCC@maketocnum##1{\NCC@atocdo{#1}{}{#2##1\NCC@atocnum}}%
}
\def\NCC@tocentrytitle#1#2{#1{\ignorespaces#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\numberline}
% Redefine the |\numberline|\marg{tag} command to work correct
% if the width of tag is greater than |\@tempdima|. The
% tag is prepared with the |\NCC@maketocnum|\marg{tag} command.
%    \begin{macrocode}
\DeclareRobustCommand*\numberline[1]{%
  \setbox\@tempboxa\hbox{\NCC@maketocnum{#1}}%
  \ifdim \wd\@tempboxa > \@tempdima
    \box\@tempboxa
  \else
    \hb@xt@\@tempdima{\unhbox\@tempboxa\hfil}%
  \fi
  \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@maketocnum}
% The default implementation of the |\NCC@maketocnum|\marg{tag} command.
% We must define it because the |\numberline| command must
% work out of scope of toc-entries.
%    \begin{macrocode}
\def\NCC@maketocnum#1{#1\NCC@atocnum}
\let\NCC@atocdo\@secondoftwo
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NumberlineSuffix}
% The |\NumberlineSuffix|\marg{calc-suffix}\marg{actual-suffix}
% command saves suffices inserted after number tag in the |\numberline|
% command. It saves it in the |\NCC@atocnum| hook as parameters of
% |\NCC@atocdo| command. Letting the last one to |\@firstoftwo| or
% |\@secondoftwo|, we select the \meta{calc-suffix} or \meta{actual-suffix}
% respectively.
%    \begin{macrocode}
\newcommand*{\NumberlineSuffix}[2]{\def\NCC@atocnum{\NCC@atocdo{#1}{#2}}}
\@onlypreamble\NumberlineSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TOCMarginDrift}
% The |\TOCMarginDrift|\marg{drift} specifies allowed drift of right margin
% in TOC.
%    \begin{macrocode}
\newcommand*\TOCMarginDrift[1]{%
  \def\@tempa{#1}%
  \ifx\@tempa\@empty \let\NCC@tocdrift\@empty
  \else \def\NCC@tocdrift{\@plus #1\relax}\fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\PnumPrototype}
% The |\PnumPrototype|\marg{prototype} command saves the page number
% prototype in the |\NCC@pnum| hook and applies the |\NCC@setpnum|
% command.
%    \begin{macrocode}
\newcommand*{\PnumPrototype}[1]{\def\NCC@pnum{#1}\NCC@setpnum}
\@onlypreamble\PnumPrototype
\def\NCC@setpnum{%
  \settowidth\@tempdima{\NCC@pnum}%
  \edef\@pnumwidth{\the\@tempdima}%
  \advance\@tempdima 1em
  \edef\@tocrmarg{\the\@tempdima \noexpand\NCC@tocdrift}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SetTOCStyle}
% The toc-style hook is embedded into the |\@starttoc| command.
% We also recalculate the page number prototype and update
% margins when a toc starts.
%    \begin{macrocode}
\newcommand*{\SetTOCStyle}[1]{\def\NCC@tocstyle{#1}}
\@onlypreamble\SetTOCStyle
\let\NCC@latexstarttoc\@starttoc
\def\@starttoc#1{%
  \begingroup
    \normalfont \NCC@tocstyle \NCC@setpnum
    \NCC@latexstarttoc{#1}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Service and Defaults}
%
% \begin{macro}{\StartFromTextArea}
% \begin{macro}{\StartFromHeaderArea}
% These commands are applied at the beginning of page
% to set current position exactly at the first line
% of text area or at the header line, respectively.
% Both these commands are defined in two packages: in this one and in
% the \textbf{textarea}. To be sure that the commands are specified
% in these packages only, we mutually test packages to be loaded.
%    \begin{macrocode}
\@ifpackageloaded{textarea}{}{%
  \newcommand\StartFromTextArea{\par
    {\parskip\z@ \strut\par}\vskip -\baselineskip
  }
  \newcommand\StartFromHeaderArea{%
    \StartFromTextArea
    \vskip -\headsep \vskip -\ht\strutbox
  }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\bff}
% The |\bff| command tries to set everything bold.
%    \begin{macrocode}
\newcommand{\bff}{\normalfont\bfseries\mathversion{bold}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\aftersectionvspace}
% This command eliminates a vertical space inserted after a previous
% section and inserts a vertical space specified.
%    \begin{macrocode}
\newcommand*\aftersectionvspace[1]{%
  \ifvmode \if@nobreak
    \vskip -\lastskip \vskip #1\relax
  \fi \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\startsection}
% Define the |\startsection| command. In article-class,
% both zero and negative levels refer to the same part section.
%    \begin{macrocode}
\newcommand*{\startsection}[1]{%
  \ifnum#1>\z@
    \def\@tempa{\csname NCC@section\romannumeral#1\endcsname}%
  \else
    \ifnum#1=\z@
      \def\@tempa{\NCC@mainsection}%
    \else
      \def\@tempa{\NCC@partsection}%
    \fi
  \fi
  \@tempa
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\part}
% \begin{macro}{\section}
% \begin{macro}{\subsection}
% \begin{macro}{\subsubsection}
% \begin{macro}{\paragraph}
% \begin{macro}{\subparagraph}
% Set aliases for almost all section levels, except chapter.
% The part is called here as a section of a negative level.
%    \begin{macrocode}
\def\part{\startsection\m@ne}
\def\section{\startsection\@ne}
\def\subsection{\startsection\tw@}
\def\subsubsection{\startsection\thr@@}
\def\paragraph{\startsection4}
\def\subparagraph{\startsection5}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\caption}
% Redefine the |\caption| command. We do this at the beginning
% of document to reject possible redefinitions of captions
% in other packages such as |float|. I think this is not the
% |float|'s responsibility to decide where a caption must go on:
% before or after the float body. And what about complicated
% floats consisting of side floats and etc.? We also reset to zero
% the |\abovecaptionskip| and |\belowcaptionskip| registers if they
% are specified to provide partial compatibility with the |float|
% package. If the registers are not specified (as in |ncc| class),
% they are emulated with macros.
%    \begin{macrocode}
\AtBeginDocument{%
  \def\caption{%
    \ifx\@captype\@undefined
      \@latex@error{\noexpand\caption outside float}\@ehd
      \expandafter\@gobble
    \else
      \expandafter\@firstofone
    \fi
    {\csname NCC@cap@\@captype\endcsname}%
  }%
  \@ifundefined{abovecaptionskip}{\def\abovecaptionskip{\z@}}%
               {\abovecaptionskip\z@}%
  \@ifundefined{belowcaptionskip}{\def\belowcaptionskip{\z@}}%
               {\belowcaptionskip\z@}%
}
%    \end{macrocode}
% \end{macro}
%
% Registration of standard floats:
%    \begin{macrocode}
\RegisterFloatType{figure}
\RegisterFloatType{table}
%    \end{macrocode}
%
% Declare all sections and captions except the part and chapter:
%    \begin{macrocode}
\DeclareSection{-2}{table}{}{\z@}{10pt}{}
\DeclareSection{-1}{figure}{}{10pt}{\z@}{}
\DeclareSection*1{section}{}%
                {3.5ex \@plus 1ex \@minus .2ex}%
                {2.3ex \@plus .2ex}{\Large\bff}
\DeclareSection*2{subsection}{}%
                {3.25ex \@plus 1ex \@minus .2ex}%
                {1.5ex \@plus .2ex}{\large\bff}
\DeclareSection*3{subsubsection}{}%
                {3ex \@plus 1ex \@minus .2ex}%
                {1.5ex \@plus .2ex}{\normalsize\bff}
\DeclareSection4{paragraph}{}%
                {\NCC@runskip}{-1em}{\normalsize\bff}
\DeclareSection5{subparagraph}[\parindent]{}%
                {\NCC@runskip}{-1em}{\normalsize\bff}
\@ifundefined{chapter}{
%    \end{macrocode}
%
% Declare the part and toc-entries for the article-like style:
%    \begin{macrocode}
  \DeclareSection*0{part}{\Large\bff}%
                  {5ex \@plus 1ex \@minus .2ex}%
                  {4ex \@plus .2ex}{\huge\bff}
  \DeclareTOCEntry{-2}{}{}{9}{}% table
  \DeclareTOCEntry{-1}{}{}{9}{}% figure
  \DeclareTOCEntry0{\runinsectionskip\def\@dotsep{1000}}{}{III}{\bff}[]
  \DeclareTOCEntry1{\runinsectionskip}{}{9}{}
  \DeclareTOCEntry2{}{}{9.9}{}
  \DeclareTOCEntry3{}{}{9.9.9}{}
}{
%    \end{macrocode}
%
% \begin{macro}{\ChapterPrefixStyle}
% Specify the appearance of chapter prefix in the toc and the header.
%    \begin{macrocode}
  \newcommand*{\ChapterPrefixStyle}[1]{%
    \def\NCC@thetocchapter{\thechapter}%
    \let\NCC@makechapfinal\NCC@makechapfinalgobble
    \@for\@tempa:=#1\do{%
      \@ifundefined{NCC@chapin@\@tempa}{%
        \PackageError{nccsect}{Unknown style `\@tempa'\MessageBreak
        Only the `toc' and `header' styles are allowed}{}%
      }{\csname NCC@chapin@\@tempa\endcsname}%
    }%
  }
  \def\NCC@chapin@toc{\def\NCC@thetocchapter{\@chapapp\ \thechapter}}
  \def\NCC@chapin@header{\let\NCC@makechapfinal\@firstofone}
  \@onlypreamble\ChapterPrefixStyle
  \@onlypreamble\NCC@chapin@toc
  \@onlypreamble\NCC@chapin@header
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\chapter}
% Declare the part, the chapter, toc-entries for the
% book-like style, and specify default epigraph parameters:
%    \begin{macrocode}
  \def\chapter{\startsection\z@}
  \DeclarePart{\StartFromTextArea\vfil\centering}%
              {\vfil\newpage \if@twoside\if@openright
                 \mbox{}\thispagestyle{empty}\newpage\fi\fi}%
              {\vspace{4ex}\huge\bff}{\Huge\bff}
  \DeclareSection*0{chapter}{\vspace{3ex}\huge\bff}{10ex}%
                  {8ex \@plus .2ex}{\Huge\bff}
  \DeclareTOCEntry{-2}{}{}{9.9}{}% table
  \DeclareTOCEntry{-1}{}{}{9.9}{}% figure
  \DeclareTOCPart{\NCC@secskip{4ex \@plus .2ex}\def\@dotsep{1000}}
                 {}{II}{\large\bff}
  \DeclareTOCEntry0{\runinsectionskip\def\@dotsep{1000}%
                    \aftergroup\penalty\aftergroup\@highpenalty}{}{9}{\bff}
  \DeclareTOCEntry1{}{}{9.9}{}[9.9]
  \DeclareTOCEntry2{}{}{9.9.9}{}[9.9.9]
  \DeclareTOCEntry3{}{}{}{}[\qquad]
  \epigraphparameters{\StartFromHeaderArea\small\raggedleft}%
                     {.45\linewidth}{5\baselineskip}%
                     {\raggedleft\itshape}{\vspace{2ex}}
}
%    \end{macrocode}
% \end{macro}
%
% Declare other toc-entries:
%    \begin{macrocode}
\DeclareTOCEntry4{}{}{}{}[\qquad]
\DeclareTOCEntry5{}{}{}{}[\qquad]
%    \end{macrocode}
%
% Set defaults:
%    \begin{macrocode}
\noindentaftersection
\sectionstyle{hangindent}
\SectionTagSuffix{\quad}
\RunningSectionSuffix{}
\captionwidth{\linewidth}
\captionstyle{default}
\captiontagstyle{para}
\CaptionTagSuffix{:\hskip .7em \@plus .2em \@minus .1em}
\NumberlineSuffix{\quad}{\enskip}
\PnumPrototype{99}
\TOCMarginDrift{}
\SetTOCStyle{}
%</package>
%    \end{macrocode}
\endinput
