summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/thmtools/thm-kv.dtx
blob: a24ef9beefcf4f0a8b1772379482afa663716a91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
% \iffalse meta-comment
%
% Copyright (C) 2008 by Ulrich M. Schwarz
%
% This file may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3a.
% The license can be obtained from
% http://www.latex-project.org/lppl/lppl-1-3a.txt
%
% \fi
%
%\iffalse (hide this from DocInput)
%<*driver>
\documentclass{ltxdoc}

\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage[scaled=0.8]{helvet}
\usepackage[scaled]{luximono}

\usepackage{amsmath, amsthm}
\usepackage{thm-kv}
\newtheorem{lemma}{Lemma}
\GetFileInfo{thm-kv.sty}
\providecommand\pkg{\textsf}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}

 \newcommand\thmrestate{\textsf{thm-kv}}
 \title{The \thmrestate\ package\thanks{%
   This file documents version~\fileversion\ of~\filedate,
   RCS ${}$Id: thm-kv.dtx,v 1.8 2008/06/22 12:09:41 ulmi Exp ulmi ${}$.
 }}
 \author{Ulrich M. Schwarz\thanks{ulmi@absatzen.de}}

 \maketitle

\begin{abstract}
\end{abstract}
  \DocInput{thm-kv.dtx}
\end{document}
%</driver>
%<*kv>
%\fi
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
% \CheckSum{160}
%
% \DoNotIndex{\@for,\addtocounter,\arabic,\csname,\endcsname,\cup,\CurrentOption}
% \DoNotIndex{\{,\},\do,\define@key,\def,\DeclareOption,\else,\ensuremath,\expandafter}
% \DoNotIndex{\hspace,\fi,\rule,\ifcase,\ifx,\in,\InputIfFileExists,\leq,\let,\mathpalette}
% \DoNotIndex{\NeedsTeXFormat,\ldots,\ldotp,\newcommand,\newcounter,\or}
% \DoNotIndex{\PackageInfo,\PackageWarning,\parm,\ProcessOptions,\protected@edef}
% \DoNotIndex{\providecommand,\ProvidesPackage,\relax,\renewcommand,\RequirePackage}
% \DoNotIndex{\setcounter,\setkeys,\rlap,\setminus,\widthof,\mathrm}
%
%\section{Usage}
%
% \DescribeMacro{\declaretheorem}
%The macro
%|\declaretheorem|\oarg{key=val-opts}\marg{name} can be used to define a
%new theorem instead of |\newtheorem|. It is hoped that |\declaretheorem| is
%easier to use than |\newtheorem|'s tangle of mutually-exclusive optional
%arguments. The following is the list of keywords understood:
%\begin{description}
%  \item[parent, numberwithin, within]
%    These keys govern when the theorem counter is reset. For example, giving
%    parent=chapter gives you theorems numbered per chapter, so it's
%    equivalent to the second optional argument to |\newtheorem|. There are
%    three names so you'll remember at least one of them.
%  \item[sibling, numberlike, sharenumber]
%    These keys make the theorem share a common numbering with the given
%    theorem. This is just like giving the first optional argument.
%  \item[unnumbered, starred]
%    If your theorem package supports it, this will call |\newtheorem*|,
%    i.e. you'll get a theorem that is never numbered. Currently, only
%    amsmath offers this possibility.
%  \item[name, title, heading] |\newtheorem| takes \emph{two} options, the
%    name of the environment (like |lem|) and its title (|Lemma|).
%    |\declaretheorem| only requires the environment name, and the title
%    defaults to the environment name with the first letter uppercased. If
%    you name your environments |lemma|, |theorem|, etc., you don't need to
%    do anything else. Otherwise, you can always manually specify the title.
%  \item[(pre/post)(head/foot)hook] You can specify extra code that will be
%    executed whenever you use the environment. \textbf{Warning:} this needs
%    the \pkg{thm-patch} package, and you're responsible for loading it
%    yourself if you want these keys to work. This functionality might be
%    shifted over to \pkg{thm-patch} in future releases.
%  \item[style]
%    This will issue a |\theoremstyle{foo}| for you if you give |style=foo|.
%    Note that currently, no care is taken to prevent this from becoming the
%    default style for subsequent theorems.
%\end{description}
%
%\StopEventually{}
%\section{Implementation}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{thm-kv}[2008/06/22 v0.1beta6 thm-kv interface (ulmi)]
\let\@xa\expandafter
\let\@nx\noexpand
\usepackage{keyval}

\define@key{thmt}{parent}{\thmt@setparent{#1}}
\define@key{thmt}{numberwithin}{\thmt@setparent{#1}}
\define@key{thmt}{within}{\thmt@setparent{#1}}

\define@key{thmt}{sibling}{\thmt@setsibling{#1}}
\define@key{thmt}{numberlike}{\thmt@setsibling{#1}}
\define@key{thmt}{sharenumber}{\thmt@setsibling{#1}}

\define@key{thmt}{title}{\thmt@setthmname{#1}}
\define@key{thmt}{name}{\thmt@setthmname{#1}}
\define@key{thmt}{heading}{\thmt@setthmname{#1}}

\define@key{thmt}{unnumbered}[]{\thmt@isnumberedfalse}
\define@key{thmt}{starred}[]{\thmt@isnumberedfalse}

\define@key{thmt}{preheadhook}{\addtotheorempreheadhook[\thmt@envname]{#1}}
\define@key{thmt}{postheadhook}{\addtotheorempostheadhook[\thmt@envname]{#1}}
\define@key{thmt}{prefoothook}{\addtotheoremprefoothook[\thmt@envname]{#1}}
\define@key{thmt}{postfoothook}{\addtotheorempostfoothook[\thmt@envname]{#1}}

\define@key{thmt}{style}{\thmt@setstyle{#1}}

\providecommand\theoremstyle[1]{%
  \PackageWarning{thm-kv}{%
    Your backend doesn't have a `\string\theoremstyle' command.\MessageBreak
    Your style request `#1' was ignored
  }%
}
\let\thmt@setstyle\theoremstyle

\newif\ifthmt@isnumbered
\newcommand\thmt@setparent[1]{%
  \def\thmt@parent{#1}%
}
\newcommand\thmt@setsibling{%
  \def\thmt@sibling
}
\newcommand\thmt@setthmname{%
  \def\thmt@thmname
}


\newcommand\declaretheorem[2][]{%
  \let\thmt@theoremdefiner\thmt@original@newtheorem
  \def\thmt@envname{#2}%
  \thmt@setthmname{\MakeUppercase #2}%
  \thmt@setparent{}%
  \thmt@setsibling{}%
  \thmt@isnumberedtrue%
  \setkeys{thmt}{#1}%
  \protected@edef\thmt@tmp{%
    \@nx\newtheorem
    \ifthmt@isnumbered\else *\fi
    {#2}%
    \ifx\thmt@sibling\@empty\else [\thmt@sibling]\fi
    {\thmt@thmname}%
    \ifx\thmt@parent\@empty\else [\thmt@parent]\fi
  }%\show\thmt@tmp
  \thmt@tmp
  % uniquely ugly kludge: some keys make only sense
  % afterwards.
  \setkeys{thmt}{#1}%
}
%    \end{macrocode}
% \subsection{Package-specific extensions}
% This is code that requires additional packages. These might be mutually
% incompatible.
%
% \subsubsection{shadethm}
%    \begin{macrocode}
  \define@key{thmt}{shaded}[{}]{%
    \RequirePackage{shadethm}%
    \addtotheorempreheadhook[\thmt@envname]{%
      \setlength\shadedtextwidth{\linewidth}%
      \setkeys{thmt@shade}{#1}\begin{shadebox}}%
    \addtotheorempostfoothook[\thmt@envname]{\end{shadebox}}%
  }
%   There are some parameters you could set the default for (try them as is,
% first).
%    (i) shadethmcolor  The shading color of the background.  See the
%      documentation for the color package, but with a `gray' model, I find .97
%      looks good out of my printer, while a darker shade like .92 is needed
%      to make it copy well.  (Black is  0, white is 1.)
%    (i*) shaderulecolor  The shading color of the border of the shaded box.
%      See (i).  If \shadeboxrule is set to 0pt then this won't print anyway.
%    (i**) shadeboxrule  The width of the border around the shading.  Set it to
%      0pt (not just 0) to make it disappear.
%    (i***) shadeboxsep  The length by which the shade box surrounds the text.
\define@key{thmt@shade}{textwidth}{\setlength\shadedtextwidth{#1}}
\define@key{thmt@shade}{bgcolor}{\definecolor{shadethmcolor}#1}
\define@key{thmt@shade}{rulecolor}{\definecolor{shaderulecolor}#1}
\define@key{thmt@shade}{rulewidth}{\setlength\shadeboxrule{#1}}
\define@key{thmt@shade}{margin}{\setlength\shadeboxsep{#1}}
%    \end{macrocode}
% \subsubsection{thmbox}
% Emmanuel Beffara's thmbox package lets you draw certain sorts of borders
% around the theorems. Note that I don't think it honours \string\theoremstyle.
%    \begin{macrocode}
  \define@key{thmt}{thmbox}[L]{%
    \let\oldproof=\proof
    \let\oldendproof=\endproof
    \let\oldexample=\example
    \let\oldendexample=\endexample
    \RequirePackage[nothm]{thmbox}
    \let\proof=\oldproof
    \let\endproof=\oldendproof
    \let\example=\oldexample
    \let\endexample=\oldendexample
    \def\thmt@theoremdefiner{\newboxtheorem[#1]}%
  }%
%    \end{macrocode}
% \subsubsection{beamer}
% Nothing yet.
%    \begin{macrocode}
%    \end{macrocode}
%\iffalse
%</kv>
%\fi