% \iffalse
%%
%% File: nccthm.dtx Copyright (C) 2002--2004 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{nccthm}
%<package>         [2004/12/16 v1.1 NCC Extention to Theorems (NCC)]
%
% \changes{v1.02}{2002/01/31}{This version is uploaded to CTAN}
% \changes{v1.03}{2002/02/17}{Break mode is turned off globally}
% \changes{v1.04}{2002/05/19}{An extra group added in theorem headers
%                             to scope font changes}
% \changes{v1.05}{2002/06/07}{Bug in referencing in APAR mode fixed}
% \changes{v1.06}{2003/01/13}{Spaces after label are ignored now}
% \changes{v1.07}{2004/04/08}{Improvements in interpreting spaces after label}
% \changes{v1.1}{2004/12/16}{In apar mode, ignore indent option if margin option used}
% \changes{v1.1}{2004/12/16}{Documentation was prepared}
%
%<*driver>
\let\makeindex\relax
\documentclass{ltxdoc}
\usepackage{desclist}
\usepackage[blackqed,whiteqed]{nccthm}
\countstyle[apar]{section}
\newtheorem{theorem}{Theorem}
\newtheorem*{atheorem}{Theorem}
\TheoremBreakStyle
\newtheorem{definition}{Definition}[remark]
\TheoremNoBreakStyle
\newtheorem{lemma}[theorem]{Lemma}
\newcommand\Line{\qef\hrule height .4pt width \linewidth\nobreak
 \qef}
\GetFileInfo{nccthm.sty}
\begin{document}
\title{The \textsf{nccthm} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{nccthm.dtx}
\end{document}
%</driver>
% \fi
%
% \tableofcontents
%
% \section{Overview}
%
% This is yet another extension of the \LaTeX\ theorem making
% environment. Further, we'll call the \textit{theorem}
% any mathematical statement consisting of one or more paragraphs,
% and starting with a header containing an optional number.
% A theorem is set off from the main text with an extra space.
% Its title and body are often emphasized with a font change.
%
% In comparison with the |theorem| package by Frank Mittelbach and the
% |amsthm| package by American Mathematical Society, the
% |nccthm| package is distinct in the following:
%
% \paragraph{1} All new theorem environments generated with the
% |nccthm| package use the \textit{dynamic counters} (see |dcounter|
% package from this bungle for more details). As a result, this allows
% a package writer to generate predefined theorems
% and do not think on how they will be numbered, because the
% decision is later made by a user.
% For example, if you want all theorems to have enumeration
% subordinated to sections, you need to write down the command
% \begin{quote}
% |\countstyle{section}|
% \end{quote}
% in the preamble. In this case, counters of all new theorems will be
% set to zero at the beginning of every section and their enumeration
% will be composed from the section number and the theorem counter number
% itself. You can also change a enumeration style for concrete
% counters (not only for dynamic counters) with the |\countstyle|
% command specifying the list of counters in its optional parameter.
% For example, if you prepare a book and want to subordinate
% the equation and table counters to sections (they are subordinated to
% chapters by default), write down in the preamble the following
% \begin{quote}
% |\countstyle[equation,table]{section}|
% \end{quote}
% The last example: to make a plain enumeration of sections
% and reject their dependance on any other counter, write down
% in the preamble |\countstyle[section]{}|.
%
% \paragraph{2} We have divided all theorem modification features into
% three orthogonal groups.
%
% A \textit{type} defines font shapes used in the theorem.
% Two types are predefined: \textit{theorem} and \textit{remark}.
% You can define more types or redefine existing types.
%
% A \textit{mode} defines the precedence of number in the header.
% In standard mode, a number goes after a theorem title.
% The reverse mode (number starts header), named here the
% \textit{APAR} mode, is special. All theorems using this mode
% are counted with the same |apar| counter. To generate theorems
% in the standard mode, the |\newtheorem| command is used.
% The |\newtheorem*| command is used for generation \textit{apar}
% theorems.
%
% A \textit{style} specifies the appearance of theorems.
% It consists of three modifiers: \textit{breaking},
% \textit{indentation},
% and \textit{marginal numbering}. The breaking modifier determines
% the separation of theorem header from theorem body (run-in header
% or line break after header). The indentation modifier has two
% values: \textit{noindent} and \textit{parindent}. It
% defines an indentation style of a theorem header.
% The marginal numbering modifier affects on apar theorems:
% in \textit{margin} style, the number of an apar theorem
% is typed on margins; in \textit{nomargin}
% style, the number starts a paragraph.
%
% The breaking modifier is controlled with special commands but other
% modifiers are specified with package options.
%
% \paragraph{3} We do not base the implementation of theorems
% on the |trivlist| environment. This allows us to use two methods
% of theorem markup: environment-like markup (|\begin{theorem}| \ldots\
% |\end{theorem}|) or command-like markup (|\theorem| \ldots |\qef|).
% The |\qef| command is used as the end of any theorem. It resets the
% font to the normal font and produces a vertical skip.
% The command-like markup is useful in apar theorems.
%
% \paragraph{4} Service commands are introduced. Using package options
% you can select a type of Q.E.D.\ symbol: black or white. You can use
% both of them. The |\proof| command starts a proof of statement.
% We have no |proof| environment, because the proof is prepared in
% the normal font. To complete a proof, use |\qed| or |\qef|
% (the first one additionally prints the right adjusted Q.E.D. symbol).
% You can easy customize delimiters of theorem and proof headers.
%
% \section{Quod Erat Demonstrandum}
%
% The Q.E.D. symbol is usually used at the end of proof of a
% math statement. Sometimes, another symbol finishes a math
% statement itself. The package allows using two types of Q.E.D.
% symbols: black (\blackqedsymbol) and white (\whiteqedsymbol).
%
% \DescribeMacro\qedsymbol
% The default Q.E.D. symbol is white. It is printed with the
% |\qedsymbol| command.
%
% \DescribeMacro\qed
% \DescribeMacro\qef
% The |\qed| command is used to finish a proof. It prints
% right-adjusted Q.E.D. symbol and applies the |\qef| command
% (it finishes this paragraph).
% The |\qef| command finishes a paragraph,
% changes the current font to the normal font, and skips
% a |\paragraph|-like vertical space.
% \qed
%
% \DescribeMacro{\qed*}
% The star-form of |\qed| command prints the Q.E.D. symbol
% but not applies the |\qef| command.
%
% The usage of the above mentioned commands at the end of
% proof is the following: if the proof end with an ordinary
% paragraph, use the |\qed| command at its end; if the
% proof ends with a list, use the |\qed*| command at
% the end of the last list item and the |\qef|
% command after the end of list; and if the proof ends
% with a display formula, use the |\qedsymbol| command
% as its tag (|\tag*{\qedsymbol}| when use the
% |amsmath| package).
%
% \DescribeMacro{\blackqed}
% \DescribeMacro{\blackqedsymbol}
% If you load the package with the `|blackqed|' option, two
% additional commands are generated, |\blackqedsymbol| and |\blackqed|.
% The default |\qedsymbol| and |\qed| commands are let to be
% equal to their black versions.
%
% \DescribeMacro{\whiteqed}
% \DescribeMacro{\whiteqedsymbol}
% Analogously, the `|whiteqed|' option generates the
% |\whiteqedsymbol| and\linebreak |\whiteqed| commands and lets
% the default |\qedsymbol| and |\qed| commands to be
% equal to their white versions.
%
% If both these options are used, the default
% |\qedsymbol| and |\qed| commands are let to be equal
% the version loaded last. For example, the following command
% loads both versions of Q.E.D. and lets the white
% version to be the default version:
% \begin{quote}
% |\usepackage[blackqed,whiteqed]{nccthm}|
% \end{quote}
%
% \section{Other Package Options}
%
% The package loads options in the order they are written
% in the options list. Along with the `|blackqed|' and `|whiteqed|'
% options described above, the following options are available:
% \begin{desclist}{\tt}{\hfill}[nomargin]
% \item[noindent] theorems are typed without indentation;
% \item[indent]   theorems are typed with paragraph indentation;
% \item[nomargin] numbers for theorems in apar mode are typed normally;
% \item[margin]   numbers for theorems in apar mode are typed on margin.
% \end{desclist}
%
% The default options are |noindent| and |nomargin|. The following
% examples show how the combinations of |(no)indent| and |(no)margin|
% options interact.
%
% \liketheorem{Theorem}{1} The standard theorem in the |noindent + nomargin| style.\qef
% \likeremark*{Remark} The apar theorem in the |noindent + nomargin| style.\qef
% \makeatletter\NCC@thmindenttrue\NCC@thmmarginfalse\makeatother
% \liketheorem{Theorem}{2} The standard theorem in the |indent + nomargin| style.\qef
% \likeremark*{Remark} The apar remark in the |indent + nomargin| style.\qef
% \makeatletter\NCC@thmindentfalse\NCC@thmmargintrue\makeatother
% \liketheorem*{Theorem} The apar theorem in the |noindent + margin| style.\qef
% \makeatletter\NCC@thmindenttrue\NCC@thmmargintrue\makeatother
% \likeremark*{Remark} The apar remark in the |indent + margin| style.\qef
% \makeatletter\NCC@thmindentfalse\NCC@thmmarginfalse\makeatother
%
% As you can see, mixing of all these styles in the same document
% leads to bad results. This is the reason why these styles are
% implemented using options.
%
% As you can also see from the last example,
% the |indent| style is ignored for apar theorems typed in
% the |margin| style.
%
% \section{Structure and Types of Theorems}
%
% The structure of a theorem is the following:
% \begin{desclist}{}{\hfill}[\meta{normal-header}\quad]
% \item[\meta{theorem}] \meta{header} \meta{space-or-break} \meta{body}
% \item[\meta{header}] \meta{normal-header} \verb+|+ \meta{apar-header}
% \item[\meta{normal-header}] \meta{title} \oarg{number} \oarg{comment} \meta{after-char}
% \item[\meta{apar-header}] \meta{apar-tag} \meta{title} \oarg{comment} \meta{after-char}
% \end{desclist}
% A theorem type controls the appearance of the following elements
% of theorems: \meta{title}, \meta{comment}, and \meta{body}.
% The \meta{number} element inherits the style from \meta{title}.
% The \meta{after-char} element inherits either the style of \meta{comment}
% if it presents or the style of \meta{title} otherwise. The style of \meta{apar-tag}
% is controlled with the special way and will be described later.
%
% \DescribeMacro{\newtheoremtype}
% \DescribeMacro{\renewtheoremtype}
% The package provides the following theorem type generation commands:
% \begin{quote}
% |\newtheoremtype|\marg{type}\marg{title-style}\marg{comment-style}\marg{body-style}\\
% |\renewtheoremtype|\marg{type}\marg{title-style}\marg{comment-style}\marg{body-style}
% \end{quote}
% The \meta{type} parameter is a type name. Other parameters
% specify fonts to be used in the corresponding parts of a
% theorem.
% Font style parameters are considered to be used after the
% |\normalfont| command.
%
% \DescribeMacro{\like...}
% When a new theorem type is generated, the |\like|\meta{type} command
% is created for it. It has two forms: normal and starred. The normal version
% prints a theorem in the standard mode and the starred version prints
% an apar theorem. The syntax:
% \begin{quote}
% |\like|\meta{type}\marg{title}\marg{number}\oarg{comment}\\
% |\like|\meta{type}*\marg{title}\oarg{comment}
% \end{quote}
% The starred version of this command has no \meta{number} argument, because
% it is numbered using the |apar| counter.
% If the \meta{number} argument in the non-starred version of this command
% is empty, the number will be omitted in the theorem header.
% If the \meta{comment} argument presents, the comment is typed enclosed
% in round brackets. This behaviour can be changed with customization
% commands.
%
% Two theorem types, `|theorem|' and `|remark|', are predefined as follows:
% \begin{quote}
% |\newtheoremtype{theorem}{\bfseries}{}{\itshape}|\\
% |\newtheoremtype{remark}{\itshape}{}{}|
% \end{quote}
%
% \DescribeMacro\liketheorem
% \DescribeMacro\likeremark
% Using the |\liketheorem| and |\likeremark| commands, you can
% produce a\linebreak theorem of the given type with arbitrary title without
% generation a special environment for it. It is very useful
% if a theorem with the given title appears in a document only once.
%
% \textbf{Note:} Type generation commands are available in the
% preamble only.
%
% \section{Generate New Theorems}
%
% \DescribeMacro\newtheorem
% A standard theorem environment is generated with the
% |\newtheorem| command:
% \begin{quote}
% |\newtheorem|\marg{env-name}\oarg{counter}\marg{title}\oarg{type}
% \end{quote}
% In comparison with the standard \LaTeX\ version of this command,
% the last optional
% parameter has another meaning: it specifies a theorem type.
% This is because its standard meaning (the base counter)
% useless here. If the \meta{type} parameter is omitted,
% the `|theorem|' type is used. The optional argument \meta{counter}
% is a counter this environment will be counted with. If it is
% omitted, the counter name equal to the \meta{env-name} is used.
% We do not test the \meta{counter} on existence when
% a new theorem environment is generated. The theorem counter is declared
% to be the dynamic counter. It is defined at the first use and
% inherits the style declared by the latest use of the command
% \begin{quote}
% |\countstyle|\marg{base-counter}
% \end{quote}
% Its argument contains a name of base-counter for all dynamically
% created counters. Dynamically created counter is set to zero when the
% base counter is stepped. Its |\the| command is the following:
% \begin{quote}
% |\the|\meta{base-counter}.|\arabic|\marg{dynamic-counter}
% \end{quote}
% If the \meta{base-counter} is empty, a dynamic counter will be
% numbered in the plain style.
%
% \qef
% \textbf{Note:} In contrast with the standard definition,
% the described |\newtheorem| command may be used with all
% four parameters.
%
% \qef
% \DescribeMacro{\newtheorem*}
% To generate a new apar theorem environment, the starred version of
% the |\newtheorem| command is applied:
% \begin{quote}
% |\newtheorem*|\marg{env-name}\marg{title}\oarg{type}
% \end{quote}
% All apar theorems are counted with the `|apar|' counter.
%
% \DescribeMacro{\renewtheorem}
% \DescribeMacro{\renewtheorem*}
% You can also redefine already defined theorem environments
% using the commands
% \begin{quote}
% |\renewtheorem|\marg{env-name}\oarg{counter}\marg{title}\oarg{type}\\
% |\renewtheorem*|\marg{env-name}\marg{title}\oarg{type}
% \end{quote}
% While redefinition a theorem environment, you can change values of
% all other parameters after \meta{env-name}.
%
% \DescribeMacro\TheoremBreakStyle
% \DescribeMacro\TheoremNoBreakStyle
% When a theorem environment is defined or redefined, a decision
% what must be inserted after the theorem header (space or break)
% is made on the base of current break style. The
% |\TheoremBreakStyle| and |\TheoremNoBreakStyle| commands change
% this style to the `break' and `no-break' respectively. The default
% style is `no-break'.
%
% \textbf{Note:} Theorem generation commands are available in the preamble only.
%
% \section{Using Theorems}
%
% The syntax of using theorem environments is the following:
% \begin{quote}
% |\begin|\marg{env-name}\oarg{comment} \meta{body}
% |\end|\marg{env-name}
% \end{quote}
% You can also use the command-like syntax:
% \begin{quote}
% |\|\meta{env-name}\oarg{comment} \meta{body} |\qef|
% \end{quote}
% which is more likely for apar theorems.
%
% \DescribeMacro\breakafterheader
% \DescribeMacro\nobreakafterheader
% You can change a break style for a theorem applying
% the |\breakafterheader| and |\nobreakafterheader| commands
% just before using the theorem.
%
% Let us do the following in the preamble:
% \begin{quote}
% |\countstyle[apar]{section}|\\
% |\newtheorem{theorem}{Theorem}|\\
% |\newtheorem*{atheorem}{Theorem}|\\
% |\TheoremBreakStyle|\\
% |\newtheorem{definition}{Definition}[remark]|\\
% |\TheoremNoBreakStyle|\\
% |\newtheorem{lemma}[theorem]{Lemma}|
% \end{quote}
% This code generates 4 theorem environments: the `|theorem|' provides a
% standard Theorem statement;
% the `|atheorem|' provides a Theorem statement in the apar mode
% with per-section numbering;
% the `|definition|' provides a standard Definition statement
% prepared as a remark; and the `|lemma|' provides a standard
% Lemma statement counted with the |theorem| counter. Definitions
% are printed in the break style.
%
% \begin{quote}
% |\begin{theorem} A theorem. \end{theorem}|\\
% |\begin{lemma} A lemma. \end{lemma}|\\
% |\breakafterheader|\\
% |\begin{theorem}[A comment] A theorem with break.\end{theorem}|\\
% |\atheorem A theorem in apar mode. \qef|\\
% |\begin{definition} A definition. \end{definition}|
% \end{quote}
% This code produces the following:
% \Line
% \begin{theorem} A theorem. \end{theorem}
% \begin{lemma} A lemma. \end{lemma}
% \breakafterheader
% \begin{theorem}[A comment] A theorem with break.\end{theorem}
% \atheorem A theorem in apar mode. \qef
% \begin{definition} A definition. \end{definition}
% \Line
%
% To prepare a theorem without number or having a special number,
% use the |\like|\meta{type} command. Examples:
% \begin{quote}
% |\liketheorem{Theorem}{A} Special theorem.\qef|\\
% |\liketheorem{Proposition}{}[Comment] It has no number.\qef|\\
% |\breakafterheader|\\
% |\likeremark{Example}{2.3.5} An example.\qef|\\
% |\likeremark*{Remark} An apar remark. \qef|
% \end{quote}
% This code produces the following:
% \Line
% \liketheorem{Theorem}{A} Special theorem.\qef
% \liketheorem{Proposition}{}[Comment] It has no number.\qef
% \breakafterheader
% \likeremark{Example}{2.3.5} An example.\qef
% \likeremark*{Remark} An apar remark. \qef
% \Line
%
% \DescribeMacro\proof
% The |\proof| command prints the proof of a math statement. Syntax:
% \begin{quote}
% |\proof|\oarg{of-theorem} \meta{body} |\qed|
% \end{quote}
% The optional parameter \meta{of-theorem} contains a
% text appended to the title of proof. The break-style change
% commands can be applied to this command. Examples:
% \begin{quote}
% |\proof An ordinary proof.\qed|\\
% |\proof[of Theorem A] A special proof.\qed|\\
% |\breakafterheader|\\
% |\proof[of the Pythagor Theorem] A proof.\qed|
% \end{quote}
% This code produces the following:
% \Line
% \proof An ordinary proof.\qed
% \proof[of Theorem A] A special proof.\qed
% \breakafterheader
% \proof[of the Pythagor Theorem] A proof.\qed
% \Line
%
% \section{Apar Sections}
%
% Header of an apar theorem is similar to the header printed
% by the |\paragraph| or |\subparagraph| command (except
% paragraph numbering that is usually omitted).
% Moreover, from the logical point of view, the apar
% theorems are specially designed enumerated paragraphs.
% Therefore, it is a good idea to use apar markup
% as some kind of special sectioning.
%
% \DescribeMacro\apar
% The following command supports sectioning in the apar mode:
% \begin{quote}
% |\apar|\oarg{title}
% \end{quote}
% It produces a new paragraph starting with the \meta{apar-tag}
% element and having the optional title. The indentation style and
% marginal style of apar section is the same as for apar theorems.
% The vertical skip before
% the apar section is just the same as before theorems.
% If the |nccsect| package is loaded, the apar skip is equal
% to the skip produced with the |\paragraph| and |\subparagraph|
% commands.
%
% These properties of apar sections are useful in design of
% articles having short sections. For example, if an article
% consists of many short sections prepared with the |\subsection|
% command, it looks very loose, because subsections are produced
% in the display style. It will be better to allow subsections
% run-in paragraph. Using the |\apar| command, you can do this
% very easy: add the following command to the preamble
% \begin{quote}
% |\countstyle[apar]{section}|
% \end{quote}
% and prepare subsections with the |\apar| command. Example:
% \begin{quote}
% |\apar[Subsection title] Subsection body ...|\\
% |\apar[Next title:] The body ...|\\
% |\atheorem In fact, this is a special apar section ...|\\
% |\apar Subsection without title ...|\\
% |\breakafterheader|\\
% |\apar[One more title] Break before its body|
% \end{quote}
% This code produces the following:
% \Line
% \apar[Subsection title] Subsection body ...
% \apar[Next title:] The body ...
% \atheorem In fact, this is a special apar section ...
% \apar Subsection without title ...
% \breakafterheader
% \apar[One more title] Break before its body
% \Line
%
% \section{Customization Commands}
%
% \DescribeMacro{\NCC@runskip}
% The vertical skips before and after theorems are identic. They are
% produced with the |\qef| command. The length of the skip is coded
% in the inner command |\NCC@runskip|. This command is also used in
% the |nccsect| package as a skip inserted before the |\paragraph|
% and |\subparagraph| commands. Its default value
% \begin{quote}
% |2.75ex plus 1ex minus 0.2ex|
% \end{quote}
%
% \DescribeMacro{\TheoremCommentDelimiters}
% The |\TheoremCommentDelimiters|\marg{left}\marg{right} command
% specifies delimiters inserted before and after a theorem comment.
% The default setting is:
% \begin{quote}
% |\TheoremCommentDelimiters{(}{)}|
% \end{quote}
%
% \DescribeMacro{\AfterTheoremHeaderChar}
% The |\AfterTheoremHeaderChar|\marg{after-char} command
% specifies an \meta{after-char} element that ends
% header of theorem and header of proof. The default setting is
% an empty element.
%
% \DescribeMacro{\AfterTheoremHeaderSkip}
% The |\AfterTheoremHeaderSkip|\marg{skip-command} command
% specifies a command inserted between theorem header and body.
% In break style, this command is ignored.
% The default setting is:
% \begin{quote}
% |\AfterTheoremHeaderSkip{\hskip 1em plus 0.2em minus 0.2em}|
% \end{quote}
%
% \DescribeMacro\ProofStyleParameters
% The |\ProofStyleParameters|\marg{style}\marg{title} command
% specifies style parameters used in the |\proof|
% command: the first one is a font style and the last one
% is a proof title. The default setting is:
% \begin{quote}
% |\ProofStyleParameters{\bfseries}{Proof}|
% \end{quote}
%
% \DescribeMacro\AparStyleParameters
% The |\AparStyleParameters|\marg{style}\marg{prefix}\marg{suffix}
% command specifies the style of apar sections: the \meta{style}
% is a style of apar section title; the tag of apar theorems
% and sections is prepared using \meta{prefix} and \meta{suffix}
% specified with this command as follows
% \meta{prefix}|\theapar|\meta{suffix}. The default setting is:
% \begin{quote}
% |\AparStyleParameters{\bfseries}{\bfseries}{\enskip}|
% \end{quote}
%
% \qef
% \textbf{Note:} All customization commands except the
% |\NCC@runskip| are allowed in the preamble only.
% \StopEventually{}
%
% \section{The Implementation}
%
% \begin{macro}{\NCC@secskip}
% \begin{macro}{\NCC@runskip}
% The package shares the following commands with the
% |nccsect| 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 |nccsect| package to be already loaded.
%    \begin{macrocode}
%<*package>
\@ifpackageloaded{nccsect}{}{%
  \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}
%
% \subsection{Q.E.D. Support}
%
% \begin{macro}{\NCC@qedsymbol}
% \begin{macro}{\qedsymbol}
% The |\NCC@qedsymbol| command is the base implementation
% of white Q.E.D. symbol.
% If no Q.E.D. selection options used, the
% |\qedsymbol| is equal to the base version.
%    \begin{macrocode}
\DeclareRobustCommand{\NCC@qedsymbol}{%
  \mbox{\normalsize\normalfont\thinlines \@tempdima 1.5ex
    \advance\@tempdima-2\@wholewidth
    \edef\@tempa{\the\@tempdima}%
    \kern \@wholewidth
    \raisebox\@wholewidth[1.5ex]{%
      \frame{\rule\z@\@tempa\rule\@tempa\z@}}%
    \kern \@wholewidth
  }%
}
\let\qedsymbol\NCC@qedsymbol
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\qed}
% \begin{macro}{\qed*}
% The |\qed| command produces the flush-right Q.E.D. symbol
% and applies the |\qef| command in the non-starred case.
%    \begin{macrocode}
\newcommand{\qed}{\NCC@qed{\qedsymbol}}
\def\NCC@qed#1{\unskip\allowbreak%
  \hspace*{1em plus 1fill minus .2em}#1\@ifstar{}{\qef}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\qef}
% The |\qef| finishes a paragraph, adds the |\@secpenalty|,
% and produces the vertical skip of |\NCC@runskip| size.
% If also sets the normal font and removes the no-break
% condition suppressing indentation in the next
% paragraph.
%    \begin{macrocode}
\newcommand{\qef}{\NCC@secskip{\NCC@runskip}\@nobreakfalse\normalfont}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Package Options}
%
% \begin{macro}{\whiteqedsymbol}
% \begin{macro}{\whiteqed}
% The `|whiteqed|' option:
%    \begin{macrocode}
\DeclareOption{whiteqed}{%
  \let\whiteqedsymbol\NCC@qedsymbol
  \newcommand{\whiteqed}{\NCC@qed{\whiteqedsymbol}}
  \let\qedsymbol\whiteqedsymbol
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\blackqedsymbol}
% \begin{macro}{\blackqed}
% The `|blackqed|' option:
%    \begin{macrocode}
\DeclareOption{blackqed}{%
  \DeclareRobustCommand{\blackqedsymbol}{%
    \begingroup\normalsize\normalfont\thinlines
      \rule{1.5ex}{1.5ex}\endgroup
  }
  \newcommand{\blackqed}{\NCC@qed{\blackqedsymbol}}
  \let\qedsymbol\blackqedsymbol
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ifNCC@thmindent}
% \begin{macro}{\ifNCC@thmmargin}
% Theorem indentation and marginal numbering options
% are based on two if-macros:
% the |NCC@thmindent| controls the indentation of headers and
% the |NCC@thmmargin| controls the marginal numbering in
% the apar mode.
%    \begin{macrocode}
\newif\ifNCC@thmindent
\newif\ifNCC@thmmargin
\DeclareOption{noindent}{\NCC@thmindentfalse}
\DeclareOption{indent}{\NCC@thmindenttrue}
\DeclareOption{nomargin}{\NCC@thmmarginfalse}
\DeclareOption{margin}{\NCC@thmmargintrue}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Set defaults and process all options in the order
% they appear in the options list.
%    \begin{macrocode}
\ExecuteOptions{noindent,nomargin}
\ProcessOptions*
%    \end{macrocode}
%
% \subsection{The Kernel}
%
% We use the |\@ifempty| command from the |amsgen| package
% and dynamic counters from the |dcounter| package.
%    \begin{macrocode}
\RequirePackage{amsgen}
\RequirePackage{dcounter}[1998/12/19]
%    \end{macrocode}
%
% \begin{macro}{\NCC@thmbrmode}
% \begin{macro}{\ifNCC@thmbr}
% A theorem break mode is controlled with the |\NCC@thmbrmode|
% macro and the |\ifNCC@thmbr|. The |\NCC@thmbrmode| can have
% three possible values:
% \begin{desclist}{}{\hfill}[\cs{relax}\ ]
% \item[\cs{relax}] undefined mode;
% \item[\cs{z@}] break mode;
% \item[\cs{@ne}] no-break mode.
% \end{desclist}
% If the break mode is undefined, the decision is made on the
% analyzes of the |NCC@thmbr| value: true value means break,
% false value means no-break.
%    \begin{macrocode}
\let\NCC@thmbrmode\relax
\newif\ifNCC@thmbr
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\breakafterheader}
% \begin{macro}{\nobreakafterheader}
% The |\breakafterheader| and |\nobreakafterheader|
% commands test the current break mode and set an
% appropriate mode if it is undefined yet. As a result,
% usage of these commands before a theorem leads to
% overriding the default break mode specified in
% theorem's macro.
%    \begin{macrocode}
\newcommand\breakafterheader{%
  \ifx\NCC@thmbrmode\relax \global\chardef\NCC@thmbrmode\z@\fi
}
\newcommand\nobreakafterheader{%
  \ifx\NCC@thmbrmode\relax \global\chardef\NCC@thmbrmode\@ne\fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\TheoremBreakStyle}
% \begin{macro}{\TheoremNoBreakStyle}
% \begin{macro}{\TheoremCommentDelimiters}
% \begin{macro}{\AfterTheoremHeaderChar}
% \begin{macro}{\AfterTheoremHeaderSkip}
% Theorem customization commands:
%    \begin{macrocode}
\newcommand{\TheoremBreakStyle}{\NCC@thmbrtrue}
\newcommand{\TheoremNoBreakStyle}{\NCC@thmbrfalse}
\newcommand*{\TheoremCommentDelimiters}[2]{%
  \def\NCC@thmcmt@##1{#1\ignorespaces##1\unskip#2}%
}
\newcommand*{\AfterTheoremHeaderChar}[1]{\def\NCC@thmchar{#1}}
\newcommand*{\AfterTheoremHeaderSkip}[1]{\def\NCC@thmskip{#1}}
\@onlypreamble\TheoremBreakStyle
\@onlypreamble\TheoremNoBreakStyle
\@onlypreamble\TheoremCommentDelimiters
\@onlypreamble\AfterTheoremHeaderChar
\@onlypreamble\AfterTheoremHeaderSkip
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@thmhdr}
% The |\NCC@thmhdr|\marg{style}\marg{header} prints a theorem header
% in the required \meta{style} and implements the current break mode.
% At the end of macro, the break mode is reset to |\relax|.
% The header is prepared in a group.
%    \begin{macrocode}
\def\NCC@thmhdr#1#2{%
  \qef
%    \end{macrocode}
% Insert a negative low penalty to increase a chance of
% page break before the beginning of theorem.
%    \begin{macrocode}
  \addpenalty{-\@lowpenalty}%
  \begingroup
    #1%
%    \end{macrocode}
% Test the break mode. If it is undefined, we set it basing
% on the value of |\ifNCC@thmbr| switch.
%    \begin{macrocode}
    \ifx\NCC@thmbrmode\relax
      \ifNCC@thmbr \chardef\NCC@thmbrmode\z@
      \else \chardef\NCC@thmbrmode\@ne
      \fi
    \fi
%    \end{macrocode}
% The break case: to implement the break in the vertical
% mode, it is enough to put the header in hbox. To allow
% multi-line header, we prepare it in inner vbox.
%    \begin{macrocode}
    \ifnum\NCC@thmbrmode=\z@
      \@tempdima\parindent
      \hbox{\vbox{\hsize\linewidth\@parboxrestore
        \ifNCC@thmindent\parindent\@tempdima\fi
        \leavevmode\strut#2\strut
      }}\nobreak\noindent
%    \end{macrocode}
% The no-break case: The |\ncc@thmskip| command
%    \begin{macrocode}
    \else
      \ifNCC@thmindent\else\noindent\fi
      \leavevmode{#2\normalfont\NCC@thmskip}\nobreak
    \fi
  \endgroup
%    \end{macrocode}
% Reset the break mode to the initial value:
%    \begin{macrocode}
  \global\let\NCC@thmbrmode\relax
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@thmcmt}
% The |\NCC@thmcmt|\marg{comment-style}\marg{comment} tests
% a comment to be nonempty and produces it in corresponding style.
%    \begin{macrocode}
\def\NCC@thmcmt#1#2{%
  \@ifempty{#2}{}{\/\space\normalfont#1\NCC@thmcmt@{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@lthm}
% Standard mode basic command:
% \begin{quote}
% |\NCC@lthm|\marg{header-style}\marg{comment-style}\marg{body-style}\marg{title}\\
% |         |\marg{number}\oarg{comment}
% \end{quote}
%    \begin{macrocode}
\def\NCC@lthm#1#2#3#4#5{%
  \@ifnextchar[{\NCC@lthm@{#1}{#2}{#3}{#4}{#5}}%
               {\NCC@lthm@{#1}{#2}{#3}{#4}{#5}[]}%
}
\def\NCC@lthm@#1#2#3#4#5[#6]{%
%    \end{macrocode}
% Prepare theorem header.
%    \begin{macrocode}
  \NCC@thmhdr{}{%
    #1#4\@ifempty{#5}{}{\space#5}%
    \NCC@thmcmt{#2}{#6}\NCC@thmchar
  }%
%    \end{macrocode}
% Set the body style and do a small skip to avoid extra
% space after the |\label| command.
%    \begin{macrocode}
  #3\hskip 0.001\p@ \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@thxhdr}
% The |\NCC@thxhdr|\marg{style}\marg{header} produces an apar theorem
% header.
%    \begin{macrocode}
\def\NCC@thxhdr#1#2{%
  \refstepcounter{apar}%
  \NCC@thmhdr{%
%    \end{macrocode}
% In margin style, the indent style is turned off for apar theorems:
%    \begin{macrocode}
    \ifNCC@thmmargin \NCC@thmindentfalse \fi
    #1%
  }{%
%    \end{macrocode}
% Put the \meta{apar-tag} (prepared in the |\NCC@thmapar| command)
% before the header using |\llap| or |\hbox|. Then put the header.
%    \begin{macrocode}
    \ifNCC@thmmargin \llap{\NCC@thmapar}\else \hbox{\NCC@thmapar}\fi
    #2%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@lthx}
% Apar mode basic command:
% \begin{quote}
% |\NCC@lthx|\marg{header-style}\marg{comment-style}\marg{body-style}\marg{title}\\
% |         |\oarg{comment}
% \end{quote}
%    \begin{macrocode}
\def\NCC@lthx#1#2#3#4{%
  \@ifnextchar[{\NCC@lthx@{#1}{#2}{#3}{#4}}%
               {\NCC@lthx@{#1}{#2}{#3}{#4}[]}%
}
\def\NCC@lthx@#1#2#3#4[#5]{%
  \NCC@thxhdr{}{%
    \normalfont#1#4\NCC@thmcmt{#2}{#5}\NCC@thmchar
  }%
  #3\hskip 0.001\p@ \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@likethm}
% The base for |\like|\meta{type} commands. It passes the control
% to |\NCC@lthm| or |\NCC@lthx| depending on the star appearing
% after the third parameter:
% \begin{quote}
% |\NCC@likethm|\marg{header-style}\marg{comment-style}\marg{body-style}\marg{title}\\
% |            |\marg{number}\oarg{comment}\\
% |\NCC@likethm|\marg{header-style}\marg{comment-style}\marg{body-style}|*|\marg{title}\\
% |            |\oarg{comment}
% \end{quote}
%    \begin{macrocode}
\def\NCC@likethm#1#2#3{%
  \@ifstar{\NCC@lthx{#1}{#2}{#3}}{\NCC@lthm{#1}{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Apar Sections}
%
% The counter used in the apar mode is dynamic:
%    \begin{macrocode}
\DeclareDynamicCounter{apar}
%    \end{macrocode}
%
% \begin{macro}{\AparStyleParameters}
% Apar style parameters provider:
%    \begin{macrocode}
\newcommand*{\AparStyleParameters}[3]{%
  \def\NCC@thmaparstyle{#1}%
  \def\NCC@thmapar{#2\theapar#3}%
}
\@onlypreamble\AparStyleParameters
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\apar}
% The |\apar|\oarg{title} command starts a new apar-numbered
% paragraph. If the \meta{title} is omitted or empty,
% we must ignore the |\NCC@thmskip|.
%    \begin{macrocode}
\newcommand*{\apar}[1][]{%
  \NCC@thxhdr{\NCC@thmaparstyle}
    {\@ifempty{#1}{\let\NCC@thmskip\@empty}{\ignorespaces#1\unskip}}%
  \hskip 0.001\p@ \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Proof of Theorem}
%
% \begin{macro}{\ProofStyleParameters}
% Proof style parameters provider:
%    \begin{macrocode}
\newcommand*{\ProofStyleParameters}[2]{%
  \def\NCC@thmproofstyle{#1}%
  \def\NCC@thmproof{#2}%
}
\@onlypreamble\ProofStyleParameters
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\proof}
% The |\proof|\oarg{of-theorem} command:
%    \begin{macrocode}
\newcommand*{\proof}[1][]{%
  \NCC@thmhdr{\NCC@thmproofstyle}{%
    \NCC@thmproof
    \@ifempty{#1}{}{\space\ignorespaces#1\unskip}%
    \NCC@thmchar
  }%
  \hskip 0.001\p@ \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Generate New Theorem Types}
%
% \begin{macro}{\like...}
% New theorem type generation means definition a |\like|\meta{type}
% command preparing theorems of corresponding type.
% The syntax of a |\like|\meta{type} command is
% the following:
% \begin{quote}
% |\like|\meta{type}\marg{title}\marg{number}\oarg{comment}\\
% |\like|\meta{type}|*|\marg{title}\oarg{comment}
% \end{quote}
% The first one produces a standard theorem and the last one produces
% an apar theorem.
% \end{macro}
%
% \begin{macro}{\newtheoremtype}
% \begin{macro}{\renewtheoremtype}
% Theorem type generation commands:
% \begin{quote}
% |\newtheoremtype|\marg{type}\marg{title-style}\marg{comment-style}\marg{body-style}\\
% |\renewtheoremtype|\marg{type}\marg{title-style}\marg{comment-style}\marg{body-style}
% \end{quote}
%    \begin{macrocode}
\newcommand*{\newtheoremtype}[1]{%
  \edef\@tempa{\noexpand\newcommand*{\expandafter\noexpand
    \csname like#1\endcsname}}\NCC@nthmtype
}
\newcommand*{\renewtheoremtype}[1]{%
  \edef\@tempa{\noexpand\renewcommand*{\expandafter\noexpand
    \csname like#1\endcsname}}\NCC@nthmtype
}
\def\NCC@nthmtype#1#2#3{\@tempa{\NCC@likethm{#1}{#2}{#3}}}
\@onlypreamble\newtheoremtype
\@onlypreamble\renewtheoremtype
\@onlypreamble\NCC@nthmtype
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Generate New Theorems}
%
% \begin{macro}{\NCC@thmdef}
% Basic theorem generation command:
% \begin{quote}
% |\NCC@thmdef|\marg{env-name}\marg{action}\marg{parameters}\oarg{type}
% \end{quote}
% The |\@tempa| command must contain either |\noexpand\newenvironment| or
% |\noexpand\renewenvironment| before the call.
% The \meta{action} is an action applied at the beginning
% of theorem. The \meta{parameters} contains parameters passed
% to the |\like|\meta{type} command.
%    \begin{macrocode}
\def\NCC@thmdef#1#2#3{%
  \@ifnextchar[{\NCC@thmdef@{#1}{#2}{#3}}%
               {\NCC@thmdef@{#1}{#2}{#3}[theorem]}%
}
\def\NCC@thmdef@#1#2#3[#4]{%
%    \end{macrocode}
% Generate an error if the given type is unknown.
%    \begin{macrocode}
  \@ifundefined{like#4}{%
    \PackageError{nccthm}{Unknown theorem type `#4'}{}%
  }%
%    \end{macrocode}
% |\@tempa := \[re]newenvironment|\marg{env-name}|{#1\like|\meta{type}|#2}|
%    \begin{macrocode}
  \edef\@tempa##1##2{%
    \@tempa{#1}{##1\expandafter\noexpand\csname like#4\endcsname##2}%
  }%
%    \end{macrocode}
% Generate a theorem envirinment:
%    \begin{macrocode}
  \ifNCC@thmbr
    \@tempa{#2\breakafterheader}{#3}{\qef\ignorespacesafterend}%
  \else
    \@tempa{#2\nobreakafterheader}{#3}{\qef\ignorespacesafterend}%
  \fi
}
\@onlypreamble\NCC@thmdef
\@onlypreamble\NCC@thmdef@
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newtheorem}
% \begin{macro}{\renewtheorem}
% \begin{macro}{\newtheorem*}
% \begin{macro}{\renewtheorem*}
% Theorem generation commands:
% \begin{quote}
% |\newtheorem|\marg{env-name}\oarg{counter}\marg{title}\oarg{type}\\
% |\renewtheorem|\marg{env-name}\oarg{counter}\marg{title}\oarg{type}\\
% |\newtheorem*|\marg{env-name}\marg{title}\oarg{type}\\
% |\renewtheorem*|\marg{env-name}\marg{title}\oarg{type}
% \end{quote}
%    \begin{macrocode}
\renewcommand*{\newtheorem}{\def\@tempa{\noexpand\newenvironment}%
  \@ifstar{\NCC@nthx}{\NCC@nthm}}
\newcommand*{\renewtheorem}{\def\@tempa{\noexpand\renewenvironment}%
  \@ifstar{\NCC@nthx}{\NCC@nthm}}
\def\NCC@nthx#1#2{\NCC@thmdef{#1}{}{*{#2}}}
\def\NCC@nthm#1{\@ifnextchar[{\NCC@nthm@{#1}}{\NCC@nthm@{#1}[#1]}}
\def\NCC@nthm@#1[#2]#3{%
  \DeclareDynamicCounter{#2}%
  \NCC@thmdef{#1}{\refstepcounter{#2}}{{#3}{\csname the#2\endcsname}}%
}
\@onlypreamble\newtheorem
\@onlypreamble\renewtheorem
\@onlypreamble\NCC@nthx
\@onlypreamble\NCC@nthm
\@onlypreamble\NCC@nthm@
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Defaults}
%
%    \begin{macrocode}
\newtheoremtype{theorem}{\bfseries}{}{\itshape}
\newtheoremtype{remark}{\itshape}{}{}
\TheoremNoBreakStyle
\TheoremCommentDelimiters{(}{)}
\AfterTheoremHeaderChar{}
\AfterTheoremHeaderSkip{\hskip 1em \@plus .2em \@minus .2em}
\AparStyleParameters{\bfseries}{\bfseries}{\enskip}
\ProofStyleParameters{\bfseries}{Proof}
%</package>
%    \end{macrocode}
\endinput