summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/coolthms
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-02-08 23:07:54 +0000
committerKarl Berry <karl@freefriends.org>2013-02-08 23:07:54 +0000
commit872f1c6c598cdf1da901a0a06d09405cacb75268 (patch)
tree7eb2188db24172798bbfd0ed21140925cf2c9a38 /Master/texmf-dist/source/latex/coolthms
parentfd62f1ff5ad45396e8da1f36be8ba7c8e19d6e48 (diff)
coolthms (8feb13)
git-svn-id: svn://tug.org/texlive/trunk@29062 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/coolthms')
-rw-r--r--Master/texmf-dist/source/latex/coolthms/coolthms.dtx187
1 files changed, 144 insertions, 43 deletions
diff --git a/Master/texmf-dist/source/latex/coolthms/coolthms.dtx b/Master/texmf-dist/source/latex/coolthms/coolthms.dtx
index 552ec8e8284..8212c0621ac 100644
--- a/Master/texmf-dist/source/latex/coolthms/coolthms.dtx
+++ b/Master/texmf-dist/source/latex/coolthms/coolthms.dtx
@@ -26,6 +26,7 @@
\usepackage{enumitem}
\usepackage{csquotes}
\usepackage{fancyvrb}
+\PassOptionsToPackage{nameinlink}{cleveref}
\usepackage{coolthms}
\EnableCrossrefs
\CodelineIndex
@@ -38,7 +39,7 @@
%
% \iffalse package preamble
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{coolthms}[2012/04/01 v1.1 Theorem markup and advanced referencing]
+\ProvidesPackage{coolthms}[2013/02/04 v1.2 Theorem markup and advanced referencing]
% \fi
%
% \MakeShortVerb{\"}
@@ -97,8 +98,12 @@
%
% \section{Usage}
%
+% \subsection{Main Commands}
+%
% The \ctp{} package only defines three useful commands and uses one from the "cleveref" package.
%
+% \DescribeMacro{\theoremmarkup} This command changes the formatting of theorems. It is explained in \cref{format}.
+%
% \DescribeMacro{\definetheorem} The "\definetheorem" command expands "ntheorem"'s "\newtheorem" by saving information later to be used in generating the labels. The syntax is as follows:
%
% \begin{syntax}"\definetheorem["\meta{counter1}"]{"\meta{env name}"}["\meta{thm plural name}"]"\\
@@ -108,14 +113,10 @@
%
% The counter arguments are similar to those of "\newtheorem". The \meta{counter1} is the counter that is used for this type of theorem. The package creates a dummy counter, named "thmcnt", and this is the default value of \meta{counter1}. Hence, the default setting is for all different types of theorems to be numbered consecutively. If you want to number some type of theorem seperately, you should specify a new counter name via the optional argument \meta{counter1}; if the counter does not exist, it will be created. You can also provide the counter of another theorem environment, to group several types of theorem together.
%
-% The \meta{counter2} is a counter that resets \meta{counter1} every time it is incremented. It has the default value "section" so the theorems are numbered within a section and \meta{counter1} is reset to $0$ whenever a new section starts. If you want a theorem type to be numbered document-wide without the counter being reset at any time, you should give an empty (i.e. no) \meta{counter2} argument.
+% The \meta{counter2} is a counter that resets \meta{counter1} every time it is incremented. Its default value is "section", so the theorems are numbered within sections and \meta{counter1} is reset to $0$ whenever a new section starts. If you want a theorem type to be numbered document-wide without the counter being reset at any time, you should give an empty \meta{counter2} argument.
%
% The default numbering of the theorem environment is \meta{counter2}.\meta{counter1}. See \cref{examples} for concrete examples.
%
-% \DescribeMacro{\theoremmarkup} "\theoremmarkup" is a command for formating theorems. Similar to the corresponding
-% commands from "ntheorem", it is called \emph{before} defining theorems with "\definetheorem", affecting the appereance of all
-% theorems defined afterwards until it is called again. Details can be found in \cref{format}.
-%
% \DescribeMacro{\Label} The "\Label" command replaces (or re-implements) the `conventional' "\label" command and is to be used \emph{only} inside theorem-like environments (which were previously defined with "\definetheorem"!). The "\label" command can (and should) of course still be used, if no special behaviour is desired\footnote{Actually, if you use the "Label" command inside an unnested theorem environment, or for the theorem itself, it will simply display the theorem number twice as the counter is used both in the reference name and, of course, the reference counter. See \cref{implementation}.}. The syntax is exactly the same as for "\label":
%
% \begin{syntax}"\Label"\marg{label name}\end{syntax}
@@ -127,7 +128,9 @@
%
% \noindent This is the "cleveref" `version' of "\ref" and is being used here without being altered in any way.
%
-% The package can be called with several options, which are described in the table below.
+% \subsection{Package Options}
+%
+% The package can be called with several options, which are listed in the table below.
%
% \medskip
%
@@ -136,14 +139,15 @@
% \hline
% Option & Default value & Description\\
% \hline\hline
-% "indent" & "0em" & The space every theorem's \emph{content} will be indented. \\
-% "separator" & ":" & The punctuation sign that will be printed after the caption. \\
-% "proofname" & "\proofname" & The caption for proofs. \\
-% "proofsymbol" & "$\Box$" & The symbol that will be printed at the end of proofs. \\
-% "proofcaptionstyle" & "\it" & The font shape in which the caption for proofs (as given in "proofname") is printed. \\
-% "proofindent" & "indent" & The space proofs will be indented. \\
-% "minskip" & "0pt" & The minimal theorem pre- and post skip amount. \\
-% "maxskip" & "6pt" & The maximal theorem pre- and post skip amount. \\
+% "indent" & "0em" & The space every theorem's \emph{content} will be indented. \\
+% "separator" & ":" & The punctuation sign that will be printed after the caption. \\
+% "proofname" & "\proofname" & The caption for proofs. \\
+% "proofsymbol" & "$\Box$" & The symbol that will be printed at the end of proofs. \\
+% "proofcaptionstyle" & "\it" & The font shape in which the caption for proofs (as given in "proofname") is printed. \\
+% "proofindent" & "indent" & The space proofs will be indented. \\
+% "minskip" & "0pt" & The minimal theorem pre- and post skip amount. \\
+% "maxskip" & "6pt" & The maximal theorem pre- and post skip amount. \\
+% "externalchapters" & "False" & Turn on external chapter mode (see below). \\
% \hline
% \end{tabular}
%
@@ -152,7 +156,12 @@
% Note that the "\proofname" macro is defined by "babel" or "polyglossia" and is a language-specific string containing the proof name. If none of these package is loaded, we define "\proofname" just as \enquote{Proof} and use that as a default value. If no value is supplied for "proofindent", proofs are indented the same amount as all other theorems (i.e. the default value is taken from "indent").
%\changes{v1.1}{2012/04/01}{Included new default value of "proofindent" in option description list.}
%
-% \section{Formatting Details}\label{format}
+% \DescribeMacro{externalchapters} When the (boolean) option "externalchapters" is given \emph{and} you use a document class that has chapters, a special behaviour is turned on (if there are no chapters, nothing happens). Usually, sections are numbered within chapters by \meta{chapter number}.\meta{section number}. Consequently, when numbering theorem-like environments within a section (which is the default behaviour), such an environment gets the number \meta{chapter number}.\meta{section number}.\meta{thm number}.
+%
+% In the external chapter mode, however, section numbers are \emph{not} preceded by the chapter number, i.e. they are numbered by a \emph{single} (arabic) number (it follows that subsections then have only two numbers instead of three, and so on). To avoid having chapters and sections with the same numbers, chapters are numbered by roman numerals in this mode (if you don't like this, you can change it by redefining "\thechapter"). Consequently theorems are then numbered by \meta{section number}.\meta{thm number}, without any reference to the chapter in their number. Therefore, there can be theorems that have the same number (if they are in the same section in different chapters). To avoid confusion, in external chapter mode, in every reference to anything that is in another chapter as the current one, the number for whatever we are referring to is additionally preceded by the chapter number (except when referencing a chapter). When referring to something from the current chapter, the chapter number is omitted.
+%\changes{v1.2}{2013/02/04}{Included new option "externalchapters".}
+%
+% \subsection{Formatting Details}\label{format}
%
% \DescribeMacro{\theoremmarkup} The "\theoremmarkup" command is used to describe how your theorems will be formatted. It should be
% called prior to any "\definetheorem" command. All theorems you define afterwards with "\definetheorem" will be formatted in
@@ -194,8 +203,6 @@
% \DescribeEnv{proof}
% The package also defines a theorem environment intended for proofs, which is called "proof".
%
-% \DescribeMacro{\sectionname}
-% While the "babel" and "polyglossia" packages define language specific commands for the word \enquote{chapter} ("\chaptername"), they include no "\sectionname". The package therefore defines "\sectionname", however at the moment it is left blank in all languages but German (\enquote{Abschnitt}) and English (\enquote{section}), see \cref{implementation}.
%
% \section{Examples}\label{examples}
%
@@ -307,6 +314,8 @@
% \begin{macrocode}
\RequirePackage{hyperref}
\RequirePackage{etoolbox}
+\RequirePackage{scrbase} % for \ifstr string comparison macro
+\RequirePackage{letltxmacro}
\RequirePackage{ifthen}
\RequirePackage{xargs}
\RequirePackage{kvoptions}
@@ -321,7 +330,7 @@
% \begin{macrocode}
\RequirePackage{cleveref}
% \end{macrocode}
-%% \begin{macro}{\ctp@hashchar}
+% \begin{macro}{\ctp@hashchar}
% In order to write a verbatim `hash' sign into our files later, it's practical to write the "\catcode" change into a small macro:
% \begin{macrocode}
\begingroup
@@ -332,9 +341,19 @@
% \end{macro}
% \begin{macro}{\proofname}
% We provide options for the proofname, the theorem separator, the proof end symbol and the amount to indent theorem content. The default value of "proofname" should be "\proofname", which is set by "babel" or "polyglossia". If the command is not defined, we simply define it as \enquote{Proof}. The value of "proofindent" is set to that of "indent" if none is specified.
+%
+% \changes{v1.2}{2012/04/23}{Fixed bug concerning proofname}
+% There's a funny aspect of using "\proofname" here: If your proof environment is named \enquote{proof}, then we have a problem, because if it's ever called with an \emph{optional} argument, "ntheorem" defines the \emph{internal} command "\proofname" to be the optional argument just passed to the environment. This results in \emph{all} proofs after this to have \emph{only} the optional argument of \emph{this} proof as their title!
+%
+% \begin{macro}{\ctp@temp}
+% To solve this, we simply expand "\proofname", revealing the string behind it. The only problem is that if we do so immediately, we might miss any change of language, i.e. a \enquote{legal} change of "\proofname" by "polyglossia" or "babel". Therefore, we define "\ctp@temp" to be an unexpanded "\proofname" first and -- using "\AtBeginDocument" -- substitute that for an expanded version and do so \emph{every time the language is changed}. Then, at the end of a proof, we simply substitute the \enquote{real} "\proofname" for the one just created by the "proof" environment.
% \begin{macrocode}
\@ifundefined{proofname}{\newcommand{\proofname}{Proof}}{}
-\DeclareStringOption[\proofname]{proofname}
+\let\ctp@temp\proofname\relax
+\AtBeginDocument{\edef\ctp@temp{\proofname}%
+ \apptocmd{\select@language}{\edef\ctp@temp{\proofname}}{}{}}
+\AfterEndEnvironment{proof}{\gdef\proofname{\ctp@temp}}
+\DeclareStringOption[\ctp@temp]{proofname}
\DeclareStringOption[$\Box$]{proofsymbol}
\DeclareStringOption[\it]{proofcaptionstyle}
\DeclareStringOption[\coolthms@indent]{proofindent}
@@ -342,12 +361,87 @@
\DeclareStringOption[0em]{indent}
\DeclareStringOption[0pt]{minskip}
\DeclareStringOption[6pt]{maxskip}
+\DeclareBoolOption{externalchapters}
\DeclareLocalOptions{separator,indent,minskip,maxskip%
- proofname,proofsymbol,proofcaptionstyle,proofindent}
+ proofname,proofsymbol,proofcaptionstyle,proofindent,externalchapters}
\ProcessKeyvalOptions*
% \end{macrocode}
% \changes{v1.1}{2012/04/01}{Default value for "proofindent" is "indent".}
-% \end{macro}
+% \end{macro}\end{macro}
+%
+% If there are no chapters (e.g. article class), we should manually create that counter and set it to 1, as we need that in the name of our label:
+% \begin{macrocode}
+\@ifundefined{c@chapter}{%
+ \newcounter{chapter}%
+ \setcounter{chapter}{1}%
+}{}%
+% \end{macrocode}
+% We now handle external chapters. If these were requested, "\thesection" should be redefined to contain only a single number.
+% \begin{macrocode}
+\ifcoolthms@externalchapters
+\renewcommand{\thechapter}{\Roman{chapter}}
+\renewcommand{\thesection}{\arabic{section}}
+% \end{macrocode}
+% Next, we overwrite some definitions made by "cleveref", namely "\refstepcounter@noarg" and "\refstepcounter@optarg" (which together are used by "cleveref" to redefine the "\refstepcounter" macro). These are invoked when a counter is incremented, and create "\cref@currentlabel". This definition is altered by us to contain a conditional which might print the chapter number. However, we repeat "cleveref"'s original definition of "\cref@currentlabel" to define "\cref@old@currentlabel", which we will need later to define the "\Label" command. The last "\ifstr" command ensures that no extra chapter number is printed when referring a chapter.
+%
+% Note that we are still in the external chapters case.
+% \begin{macrocode}
+\def\refstepcounter@noarg#1{%
+ \cref@old@refstepcounter{#1}%
+ \cref@constructprefix{#1}{\cref@result}%
+ \@ifundefined{cref@#1@alias}%
+ {\def\@tempa{#1}}%
+ {\def\@tempa{\csname cref@#1@alias\endcsname}}%
+ \edef\chapter@current@value{\the\value{chapter}}
+ \protected@edef\cref@currentlabel{%
+ [\@tempa][\arabic{#1}][\cref@result]%
+ \string\ifstr{\string\the\string\value{chapter}}%
+ {\chapter@current@value}{\string\relax}{\thechapter.}%
+ \csname p@#1\endcsname\csname the#1\endcsname}
+ \protected@edef\cref@old@currentlabel{%
+ [\@tempa][\arabic{#1}][\cref@result]%
+ \csname p@#1\endcsname\csname the#1\endcsname}
+ \ifstr{\@tempa}{chapter}{\protected@edef\cref@currentlabel{\cref@old@currentlabel}}{}}
+\def\refstepcounter@optarg[#1]#2{%
+ \cref@old@refstepcounter{#2}%
+ \cref@constructprefix{#2}{\cref@result}%
+ \edef\chapter@current@value{\the\value{chapter}}
+ \protected@edef\cref@currentlabel{%
+ [#1][\arabic{#2}][\cref@result]%
+ \string\ifstr{\string\the\string\value{chapter}}%
+ {\chapter@current@value}{\string\relax}{\thechapter.}%
+ \csname p@#2\endcsname\csname the#2\endcsname}
+ \protected@edef\cref@old@currentlabel{%
+ [#1][\arabic{#2}][\cref@result]%
+ \csname p@#2\endcsname\csname the#2\endcsname}
+ \ifstr{#1}{chapter}{\protected@edef\cref@currentlabel{\cref@old@currentlabel}}{}}
+% \end{macrocode}
+% Next we redefine the "label" command.
+% We are still in the external chapters case.
+% \begin{macrocode}
+ \def\ctp@label@noarg#1{%
+ \letcs{\mycurrentlabel}{@currentlabel}
+ \expandafter\def\csname @currentlabel\endcsname{\string\ifstr%
+ {\string\the\string\value{chapter}}{\the\value{chapter}}%
+ {\string\relax}{\thechpt}\mycurrentlabel}
+ \label@noarg{#1}
+ \cslet{@currentlabel}{\mycurrentlabel}
+ }%
+ \def\ctp@label@optarg[#1]#2{%
+ \letcs{\mycurrentlabel}{@currentlabel}
+ \expandafter\def\csname @currentlabel\endcsname{\string\ifstr%
+ {\string\the\string\value{chapter}}{\the\value{chapter}}%
+ {\string\relax}{\thechpt}\mycurrentlabel}
+ \label@optarg[#1]{#2}
+ \cslet{@currentlabel}{\mycurrentlabel}
+ \def\label{\@ifnextchar[\ctp@label@optarg\ctp@label@noarg}%]
+ }
+% \end{macrocode}
+% This is where the external chapters case ends.
+% \begin{macrocode}
+\else % belongs to \ifcoolthms@externalchapters
+\fi
+% \end{macrocode}
% Now we need to define various (an unnumbered, a numbered and a third one for proofs) "theoremstyle"s\footnote{Here we use the "ntheorem" package.} we will be using:
% \begin{macrocode}
\newtheoremstyle{keinenummern}%
@@ -362,14 +456,6 @@
{\item[{\hskip\labelsep\theorem@headerfont ##1\theorem@separator}]}%
{\item[\hskip\labelsep{\theorem@headerfont ##3\theorem@separator}]}
% \end{macrocode}
-%
-% If there are no chapters (e.g. article class), we should manually create that counter and set it to 1, as we need that in the name of our label:
-% \begin{macrocode}
-\@ifundefined{c@chapter}{%
- \newcounter{chapter}%
- \setcounter{chapter}{1}%
-}{}%
-% \end{macrocode}
% \begin{macro}{\definetheorem}
% Now comes the real work: the "\definetheorem" command. "\definetheorem" takes five arguments and passes them to "ntheorem"'s "\newtheorem" in a slightly altered order. We then create a numbered theorem style by name of "#2" and an unnumbered style by name of "n#2". This is necessary as the starred versions have a different meaning in the "ntheorem" package.
%
@@ -414,24 +500,48 @@
% \end{macro}
% We then write all this information (including the \emph{format} of the label) to the "aux" file so that it is available at the next run of \LaTeX.
% \begin{macrocode}
+\ifcoolthms@externalchapters
+ \immediate\write\@auxout{\string\crefname{\ctp@labelcode}%
+ {#4\noexpand~%
+ \string\ifstr{\string\the\string\value{chapter}}%
+ {\chapter@current@value}{\string\relax}{\thechapter.}%
+ \csname the#1\endcsname}%
+ {#3\noexpand~\csname the#1\endcsname}}\relax%
+ \immediate\write\@auxout{\string\crefformat{\ctp@labelcode}%
+ {\string##2#4\noexpand~%
+ \string\ifstr{\string\the\string\value{chapter}}%
+ {\chapter@current@value}{\string\relax}{\thechapter.}%
+ \csname the#1\endcsname\noexpand~%
+ \ctp@hashchar1\ctp@hashchar3}}\relax%
+\else
\immediate\write\@auxout{\string\crefname{\ctp@labelcode}%
{#4\noexpand~\csname the#1\endcsname}%
{#4 plural\noexpand~\csname the#1\endcsname}}\relax%
\immediate\write\@auxout{\string\crefformat{\ctp@labelcode}%
{\string##2#4\noexpand~\csname the#1\endcsname\noexpand~%
\ctp@hashchar1\ctp@hashchar3}}\relax%
+\fi
% \end{macrocode}
% \begin{macro}{\Label}
-% We finally (re)define the "\Label" command. All it does is call the classic "\label" command (from "cleveref") with our unique label name as identifier:
+% We finally (re)define the "\Label" command. Without the "externalchapters" option, all it does is call the classic "\label" command (from "cleveref") with our unique label name as identifier. With that option, it does exactly what "cref"'s original "\label@optarg" command (which is simply the "label" command with an optional argument, as defined by "cref") would do if it were called with "\ctp@labelcode" as optional argument, except that it uses "\cref@old@currentlabel" instead of "\cref@currentlabel".
% \begin{macrocode}
+\ifcoolthms@externalchapters
+ \def\Label##1{\cref@old@label{##1}%
+ \protected@edef\cref@currentlabel{%
+ \expandafter\cref@override@label@type%
+ \cref@old@currentlabel\@nil{\ctp@labelcode}}%
+ \protected@write\@auxout{}%
+ {\string\newlabel{##1@cref}{{\cref@currentlabel}{\thepage}}}}
+\else
\edef\Label##1{\noexpand\label[\ctp@labelcode]{##1}}%
+\fi
% \end{macrocode}
% \end{macro}
% Now we're done, all we need to do is correct "#1".
% \begin{macrocode}
\addtocounter{#1}{-1} %
- }%
-}%
+ }% End of \BeforeBeginEnvironment
+}% End of \newcommandx*{\definetheorem}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\theoremmarkup}
@@ -457,15 +567,6 @@
\crefformat{equation}{#2(#1)#3}
\crefformat{chapter}{#2\chaptername~#1#3}
% \end{macrocode}
-% \begin{macro}{\sectionname}
-% Interestingly enough, "\sectionname" is provided neither by "polyglossia" nor "babel", so we add it in the appropriate languages.
-% \begin{macrocode}
-\@ifundefined{sectionname}{\newcommand{\sectionname}{}}{}
- \gappto\captionsgerman{\renewcommand{\sectionname}{Abschnitt}}%
- \gappto\captionsenglish{\renewcommand{\sectionname}{section}}
-\crefformat{section}{#2\sectionname~#1#3}
-% \end{macrocode}
-% \end{macro}
% \begin{macro}{\theorempreskipamount}\begin{macro}{\theorempostskipamount}
% We set theorem pre- and post skip amounts.
% \begin{macrocode}
@@ -478,7 +579,7 @@
\theoremstyle{unserbeweis}
\theoremmarkup[\coolthms@proofcaptionstyle][\normalfont]%
[\coolthms@proofsymbol][\coolthms@proofindent]
-\newtheorem{proof}{\coolthms@proofname}
+\expandafter\newtheorem{proof}{\coolthms@proofname}
% \end{macrocode}
% At the end we invoke "\theoremmarkup" to set everything back to the default values.
% \begin{macrocode}