summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/computational-complexity/cc.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-05-14 18:21:27 +0000
committerKarl Berry <karl@freefriends.org>2010-05-14 18:21:27 +0000
commit5149405bc761d8518999021fd0019b463bee1fd0 (patch)
tree0619a25bb5299d52477ffc861561338a76b178c9 /Master/texmf-dist/source/latex/computational-complexity/cc.dtx
parent91ea5ca6c438abff6a9ed0c13431ac5d4265f067 (diff)
computational-complexity 2.11 (13may10)
git-svn-id: svn://tug.org/texlive/trunk@18244 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/computational-complexity/cc.dtx')
-rw-r--r--Master/texmf-dist/source/latex/computational-complexity/cc.dtx276
1 files changed, 182 insertions, 94 deletions
diff --git a/Master/texmf-dist/source/latex/computational-complexity/cc.dtx b/Master/texmf-dist/source/latex/computational-complexity/cc.dtx
index ef1dbd79db4..1d214947826 100644
--- a/Master/texmf-dist/source/latex/computational-complexity/cc.dtx
+++ b/Master/texmf-dist/source/latex/computational-complexity/cc.dtx
@@ -2641,6 +2641,8 @@ multilingual,english]{cc}
% Bonn}
% \changes{v2.09}{2010/01/26}{Advanced version to 2.10, just a few
% minor changes, Michael N{\"{u}}sken, Bonn}
+% \changes{v2.10}{2010/05/11}{Advanced version to 2.11, redesign of
+% algorithms, Michael N{\"{u}}sken, Bonn}
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\providecommand\ignorespacesafterend{\@ignoretrue}
@@ -2649,7 +2651,7 @@ multilingual,english]{cc}
\ifclass\expandafter\ProvidesClass\else\expandafter\ProvidesPackage\fi
{\ifclass cc\else cc-cls\fi}
[% CC MAIN DATE AND VERSION ON NEXT LINE
-2010/01/25 v2.10
+2010/01/25 v2.11
computational complexity
\ifclass document class\else package\fi]
% \end{macrocode}
@@ -5515,12 +5517,13 @@ computational complexity
%
% Announce the package and its version:
% \changes{v0.91}{2000/02/29}{Advanced version to official 2.00}
-% \changes{v2.05}{2010/01/25}{Requiring ccaux now.}
+% \changes{v2.10}{2010/05/11}{Redesign. Now at any time item with
+% text label and hanging indentation are possible as used for input
+% and output: \cs{item}[itemtitle] does it.}
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{ccalgo}[2005/08/27 v2.05
algorithm environment for cc. Michael Nuesken, Bonn.]
-\RequirePackage{ccaux}
% \end{macrocode}
% Next we undefine some macros in case of overloading.
% \begin{macrocode}
@@ -5584,7 +5587,10 @@ computational complexity
\fi
\sbox\@tempboxa{\makelabel{#1}}%
% \end{macrocode}
-% We require that |\global| follows this |\makelabel| to insert a hook.
+% We require that |\global| follows this |\makelabel| to insert a
+% hook. Moreover we use that the produced label is put in
+% \cs{@tempboxa} to reinitialize the paragraph indention in
+% \cs{reinit@list@label}.
% \begin{macrocode}
\global\setbox\@labels\hbox{%
\unhbox\@labels
@@ -5607,7 +5613,9 @@ computational complexity
% We load Frank Mittelbach's theorem style, \cc's add-on and the
% \Lpackage{relabel} package. (The latter is for adding prefixes to
% labels and thelike.)
+% \changes{v2.05}{2010/01/25}{Requiring ccaux now.}
% \begin{macrocode}
+\RequirePackage{ccaux}
\RequirePackage{theorem}
\RequirePackage{thcc}
\RequirePackage{relabel}
@@ -5677,7 +5685,7 @@ computational complexity
\newcounter{algonumerate}
\defprefix{algonumerate}{}
% \end{macrocode}
-% This count is the number of named items.
+% This count holds the number of named items.
% \begin{macrocode}
\newcount\algonumerate@items
% \end{macrocode}
@@ -5704,14 +5712,16 @@ computational complexity
% \begin{macrocode}
\newif\if@speciallabel
% \end{macrocode}
-% This macro produces the labels in all cases.
+% This macro produces the labels in all cases.
+% \changes{v2.10}{2010/05/11}{Redesign.}
% \begin{macrocode}
\newcommand{\labelalgonumerate}{%
\count@\value{algonumerate}%
\ifnum\count@<\z@
- \algonumfield:%
+ \algonumfield%
\else
- \makealgolabel{\thealgonumerate}\fi
+ \makealgolabel{\thealgonumerate}%
+ \fi
}%
% \end{macrocode}
% These two dimensions define the width of a label and its distance
@@ -5725,126 +5735,173 @@ computational complexity
\newtoks\AtNextItem
% \end{macrocode}
% A toggle noting whether the named items are complete or not.
+% \changes{v2.10}{2010/05/11}{Redesign: implement another mechanism
+% to get information about the type of \cs{item} that was called.}
% \begin{macrocode}
\newif\if@requireditemscomplete
+\newif\if@noitemargcopy
+\let\orig@item\item
+\def\item{\@ifnextchar[{\@noitemargcopyfalse\orig@item}{\@noitemargcopytrue\orig@item}}
+\newcount\last@algolabeltype
+\newcount\this@algolabeltype
% \end{macrocode}
% This is |\makelabel| for our list. It produces the label,
% inserts the hook and makes all necessary modifications.
% \begin{macrocode}
\newcommand{\algonumerate@label}[1]{%
-% \end{macrocode}
-% Decide whether this is a special item and set the corresponding
-% toggle.
-% \begin{macrocode}
- \def\@tempa{#1}\def\@tempc{\@itemlabel}%
- %%\show\@tempa\show\@tempc
- \ifx\@tempa\@tempc\global\@speciallabelfalse
- \else\global\@speciallabeltrue\fi
-% \end{macrocode}
-% Distinguish cases: named items, first non-named items, numbered items,
-% and special (labelled) items.
-% \begin{macrocode}
- \expandafter\ifnum\value{algonumerate}<\z@
-% \end{macrocode}
-% A named item's label is simply typeset with some space.
-% \begin{macrocode}
- #1\hskip\algo@labelsep%
- \else
- \ifx\@tempa\@empty
-% \end{macrocode}
-% An empty special item's label remains invisible.
-% \begin{macrocode}
- \hskip\steplabelwidth\hskip\algo@labelsep
+ \expandafter\count@\value{algonumerate}%
+% \typeout{algonumerate@label #1}%
+% \typeout{...counter=\the\count@}%
+% \if@noitemargcopy\typeout{...noitemarg}\else\typeout{...explicititemarg}\fi
+% \end{macrocode}
+% Now, fork with respect to the item type. There are four variants:
+% a numbered item with negative counter procudes an item with hanging
+% indention and a text label from the list supplied at the list
+% initialisation. A numbered item with positive counter produces a
+% numbered item. The counter is stepped in these two cases and zero
+% is skipped. An item with empty optional argument produces an
+% item like a numbered one just without a number. An item with a
+% non-empty optional argument produces an item with hanging indention
+% and the optional argument as label.
+% \begin{macrocode}
+ \if@noitemargcopy
+ \ifnum\count@<\z@
+ \let\next\algonumerate@labelautomatic
+ \global\last@algolabeltype\this@algolabeltype
+ \global\this@algolabeltype\m@ne
+ \else
+ \let\next\algonumerate@labelnumber
+ \global\last@algolabeltype\this@algolabeltype
+ \global\this@algolabeltype\@ne
+ \fi
\else
+ \def\@tempa{#1}%
+ \ifx\@tempa\@empty
+ \let\next\algonumerate@labelempty
+ \global\last@algolabeltype\this@algolabeltype
+ \global\this@algolabeltype\tw@
+ \else
+ \global\last@algolabeltype\this@algolabeltype
+ \global\this@algolabeltype\z@
+ \let\next\algonumerate@labelexplicit
+ \fi
+ \fi\next{#1}}
% \end{macrocode}
-% A non-named item's label is typeset in a box using
-% |\makeoptalgolabel| to format a special label.
+% For each of the four variants we now specify how to typeset them.
% \begin{macrocode}
+\newcommand{\algonumerate@makelabelexplicit}[1]{%
+ #1:\hskip\algo@labelsep%
+}
+\newcommand{\algonumerate@makelabelempty}[1]{%
+ \hskip\steplabelwidth\hskip\algo@labelsep%
+}
+\newcommand{\algonumerate@makelabelautomatic}[1]{%
+ #1:\hskip\algo@labelsep%
+}
+\newcommand{\algonumerate@makelabelnumber}[1]{%
\hb@xt@\steplabelwidth{\hss
- \hb@xt@\steplabelwidth{\hfill
- \if@speciallabel
- \makeoptalgolabel{#1}%
- \else
+ %\hb@xt@\steplabelwidth{\hfill
#1%
- \fi
- }}\hskip\algo@labelsep%
- \fi\fi
+ %}
+ }\hskip\algo@labelsep%
+}
% \end{macrocode}
-%
-% The following two lines are a dirty trick!!! This establishes
-% the hook.
-% \begin{macrocode}
- \global\let\algonumerate@global\global
- \gdef\global{\algonumerate@global\let\global\algonumerate@global
-% \end{macrocode}
-% This code is then executed in the |\item| command outside any
-% extra groups.
-%
-% First, we handle the boundary between named and numbered items.
+% The macro \cs{algonumerate@postprocess} contains all the stuff to
+% be done after producing the label and putting it into
+% \cs{@tempboxa}.
% \begin{macrocode}
+\newcommand{\algonumerate@postprocess}[1]{%
\expandafter\count@\value{algonumerate}%
%%{\tracingall\nonstopmode\showbox\@tempboxa}%
% \end{macrocode}
-% The counter jumpes over the value $0$.
-% \begin{macrocode}
- \ifnum\count@=\m@ne
- \stepcounter{algonumerate}%
- \fi
-% \end{macrocode}
-% Test whether we bypassed the boundary and issue |\medskip| once.
+% We insert a \cs{medskip} if a (positively) numbered item follows an
+% automatic or explicit text item.
% \begin{macrocode}
- \ifnum\count@=\z@
- \if@requireditemscomplete\else
- \global\@requireditemscompletetrue
- \ifnum\algonumerate@items>\z@\medskip\fi
- \fi
- \fi
- \ifnum\count@=\@ne
- \if@requireditemscomplete\else
- \global\@requireditemscompletetrue
- \ifnum\algonumerate@items>\z@\medskip\fi
- \fi
+ \ifnum\last@algolabeltype<\@ne
+ \ifnum\this@algolabeltype=\@ne
+ \medskip
\fi
-% \end{macrocode}
-% To enable referencing of special label's we need to define
-% |\@currentlabel| and (for the |\bare| version)
-% |\@bare@currentlabel|.
-% \begin{macrocode}
- \if@speciallabel
- \protected@edef\@currentlabel{\csname p@\@listctr\endcsname
- {\makeoptalgocurrentlabel{#1}}}%
- \protected@edef\@bare@currentlabel{#1}%
\fi
% \end{macrocode}
-% Remember the reference globally. (This is used in the
-% \Lenv{block} environment below.)
+% Next, we execute case specific commands. (For text items we need to
+% set \cs{@currentlabel} here.)
% \begin{macrocode}
+ #1%
\global\let\latest@item@currentlabel\@currentlabel
\global\let\latest@item@bare@currentlabel\@bare@currentlabel
-% \end{macrocode}
-% Reset the special label toggle.
-% \begin{macrocode}
+ \ifnum\count@=\m@ne
+ \stepcounter{algonumerate}%
+ \fi
\global\@speciallabeltrue
% \end{macrocode}
-% Execute |\AtNextItem| once.
+% Execute |\AtNextItem| once and clear it.
% \begin{macrocode}
\the\AtNextItem \global\AtNextItem{}%
% \end{macrocode}
% Reinitialize the list indentions.
% \begin{macrocode}
\reinit@list@label
+}
+% \end{macrocode}
+% The next four macros are similar. For each item type they produces
+% the label and use the dirty trick to get counting and paragraph
+% formatting as desired.
+% \begin{macrocode}
+\newcommand{\algonumerate@labelexplicit}[1]{% For algorithm i/o
+ \typeout{item explicit [#1]}%
+ \algonumerate@makelabelexplicit{#1}%
+% \end{macrocode}
+%
+% The following two lines are a dirty trick!!! This establishes
+% the hook.
+% \begin{macrocode}
+ \global\let\algonumerate@global\global
+ \gdef\global{\algonumerate@global\let\global\algonumerate@global
+ \algonumerate@postprocess{%
+ \protected@edef\@currentlabel{\csname p@\@listctr\endcsname
+ {\makeoptalgocurrentlabel{#1}}}%
+ \protected@edef\@bare@currentlabel{#1}%
+ }%
% \end{macrocode}
% Execute the |\global| which was used to implement this hook.
% \begin{macrocode}
\global}%
- }
+}
+\newcommand{\algonumerate@labelempty}[1]{% For algorithm i/o
+ \typeout{item empty [#1]}%
+ \algonumerate@makelabelempty{}%
+ \global\let\algonumerate@global\global
+ \gdef\global{\algonumerate@global\let\global\algonumerate@global
+ \algonumerate@postprocess{}%
+ \global}%
+}
+\newcommand{\algonumerate@labelautomatic}[1]{% For algorithm steps
+ \typeout{item automatic [#1]}%
+ \algonumerate@makelabelautomatic{#1}%
+ \global\let\algonumerate@global\global
+ \gdef\global{\algonumerate@global\let\global\algonumerate@global
+ \algonumerate@postprocess{%
+ \protected@edef\@currentlabel{\csname p@\@listctr\endcsname
+ {\makeoptalgocurrentlabel{#1}}}%
+ \protected@edef\@bare@currentlabel{#1}%
+ }%
+ \global}%
+}
+\newcommand{\algonumerate@labelnumber}[1]{% For algorithm steps
+ \typeout{item numbered [#1]}%
+ \algonumerate@makelabelnumber{#1}%
+ \global\let\algonumerate@global\global
+ \gdef\global{\algonumerate@global\let\global\algonumerate@global
+ \algonumerate@postprocess{}%
+ \global}%
+}
+%%%
+\newdimen\algonumerate@maxindent
% \end{macrocode}
-%
-% Named items will be indented as far as the label, unless this
-% exceeds the maximal value stored in |\algonumerate@maxindent|.
-% Its default value is $20\%$ of the |\textwidth|.
+% We add a mechanism to find and store the length of the longest
+% macro. However, at present it is not used.
% \begin{macrocode}
-\newdimen\algonumerate@maxindent
+\newdimen\@algolongestlabel
\AtBeginDocument{\ifdim\algonumerate@maxindent=\z@
\algonumerate@maxindent.2\textwidth\fi}
% \end{macrocode}
@@ -5853,6 +5910,9 @@ computational complexity
% is just the comma separated list of the names.
% \begin{macrocode}
\def\algonumerateinit#1{%
+ \setcounter{algonumerate}{-1}%
+ \this@algolabeltype=\@M
+ \@algolongestlabel\z@
\def\@algonumfield{}%
\let\ccorg@or\or\let\or\relax
\algonumerate@items\z@
@@ -5861,6 +5921,9 @@ computational complexity
\@temptokena\expandafter{\@tempa}%
\toks@\expandafter{\@algonumfield}%
\edef\@algonumfield{\the\@temptokena\or\the\toks@}%
+ \setbox\@tempboxa\hbox{\algonumerate@makelabelautomatic{\the\toks@}}%
+ \ifdim\wd\@tempboxa>\@algolongestlabel\relax
+ \@algolongestlabel\wd\@tempboxa\fi
}%
\let\or\ccorg@or
\toks@\expandafter{\@algonumfield}%
@@ -5876,6 +5939,9 @@ computational complexity
% from initiation the list, it also activates the environments
% \Lenv{block} (aka \Lenv{body}), \Lenv{range}, \Lenv{indention},
% and \Lenv{meta}.
+% \changes{v2.10}{2010/05/11}{Added the macro
+% \cs{skipremainingspecialitems} to allow the user to override the
+% standard label item list.}
% \begin{macrocode}
\newenvironment{algonumerate}{%
\if@inlabel~\fi\par
@@ -5914,6 +5980,7 @@ computational complexity
\let\endbody\endalgo@block
\let\meta\algo@meta
\let\endmeta\endalgo@meta
+ \def\skipremainingspecialitems{\setcounter{algonumerate}{0}}%
}{%
\endlist\vskip\topskip}
% \end{macrocode}
@@ -6131,8 +6198,10 @@ computational complexity
\theoremstyle{ccalgo}
\newtheorem{named@lg@r@thm}{\the\algotitle}
\defprefix{named@lg@r@thm}#1{\the\algotitle~#1}
+\ifx\c@namedth@@r@m\@undefined\else
\let\c@named@lg@r@thm\c@namedth@@r@m
\let\thenamed@lg@r@thm\thenamedth@@r@m
+\fi
% \end{macrocode}
%
% \begin{environment}{namedalgorithm}
@@ -6145,6 +6214,9 @@ computational complexity
% reference to the algorithm and in |\algolabel| to prefix
% references inside the algorithm. The forth argument is again
% optional and specifies a title.
+% \changes{v2.10}{2010/05/11}{Added extra optional argument to allow
+% specification of a longest label. But that is of no use at
+% present since this information is never used.}
% \begin{macrocode}
\babel\def\babelInput{Input}[german=Eingabe,french=Entr\'ee]
\babel\def\babelOutput{Output}[german=Ausgabe,french=Sortie]
@@ -6162,12 +6234,24 @@ computational complexity
\algotitle{#1}%
\n@medalgorithm}
{\endalgonumerate\csname end\algo@theorem\endcsname}
-\newcommand{\n@medalgorithm}[2][\babelInput,\protect\babelOutput]{%
+\newcommand{\n@medalgorithm}[1][\babelInput,\protect\babelOutput]{%
\algonumerateinit{#1}%
- \algorithmmasterkey{#2}%
+ \n@m@d@lgorithmgetlongestlabel}
+\newcommand{\n@m@d@lgorithmgetlongestlabel}[1][]{%
+ \def\@tempa{#1}%
+ \ifx\@tempa\@empty\else
+ \setbox\@tempboxa\hbox{\algonumerate@makelabel{#1}}%
+ \ifdim\wd\@tempboxa>\@algolongestlabel\relax
+ \@algolongestlabel\wd\@tempboxa\fi
+ \fi
+ \n@m@d@lgorithmgetmasterkey
+}
+\newcommand{\n@m@d@lgorithmgetmasterkey}[1]{%
+ \algorithmmasterkey{#1}%
\edef\@tempa{\the\algorithmmasterkey}\ifx\@tempa\@empty
\PackageError{ccalgo}{Empty key for algorithm like environment}{}\fi%
- \n@m@d@lgorithm}
+ \n@m@d@lgorithm
+}
\newcommand{\n@m@d@lgorithm}[1][]{%
\def\@tempa{#1}%
\ifx\@tempa\@empty\csname\algo@theorem\endcsname
@@ -6246,6 +6330,9 @@ computational complexity
% these things are only accessible inside algorithm like
% environments.
% \changes{v2.01}{2004/01/26}{Babelized algo@keywords.}
+% \changes{v2.10}{2010/05/11}{Use \cs{selectlanguage} only if
+% \cs{language} is not \texttt{nohyphenation}. This avoids strange
+% errors.}
% \begin{macrocode}
\def\algo@keywords{%
\def\keyword##1{\textsf{##1} \ignorespaces}%
@@ -6263,7 +6350,8 @@ computational complexity
\babel\def\endIF{}[]%
\babel\def\CALL{\keyword{Call}}[german=\keyword{Rufe}]%
\babel\def\RETURN{\keyword{Return}}[german=\keyword{Antworte}]%
- \expandafter\selectlanguage\expandafter{\languagename}
+ \def\@tempa{nohyphenation}\ifx\languagename\@tempa\else%
+ \expandafter\selectlanguage\expandafter{\languagename}\fi%
\def\COMMENT##1{$\{$ ##1 $\}$}%
}
% \end{macrocode}