summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/thmtools/thm-kv.dtx
blob: d731d62f1ea13aa3ed6f98ca6a32091e3f27464f (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
% \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, thm-patch}
\newtheorem{lemma}{Lemma}
\declaretheorem[sibling=lemma, shaded, name={Rule of Thumb}]{ruleofthumb}
\usepackage{color}
\declaretheorem[shaded={bgcolor={rgb}{1,0,0},rulecolor={rgb}{0,1,0},rulewidth=2em,
   margin=1em, textwidth=5cm}]{eyesore}


\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}
% 
% \subsection{Examples}
% In many cases, you'll just get by with
% \begin{verbatim}
%  \declaretheorem{lemma}   
% \end{verbatim}
% which creates the environment `lemma', which will be labeled `Lemma' and
% numbered consecutively throughout:
%\begin{lemma}
%  This is what it looks like.
%\end{lemma}
% If you have more environments, you
% might want
% \begin{verbatim}
%  \declaretheorem[sibling=lemma]{theorem} 
% \end{verbatim}
% which will make the theorems share the numbering with the lemmas. If you
% had wanted per-chapter numbering for everything, you would have said
%\begin{verbatim}
%  \declaretheorem[parent=chapter]{lemma}
%\end{verbatim}
% without need to change subsequent declarations. A very fancy declaration
% using the shadethm and thm-patch package would look like this:
%\begin{verbatim}
%  \declaretheorem[sibling=theorem, shaded, name={Rule of Thumb}]{ruleofthumb}
%\end{verbatim}
%
%\begin{ruleofthumb}
% If all else fails, read the manual. Usually all else fails because you
% didn't.   
% \end{ruleofthumb}
%
% You can customize the colors and border like this:
%\begin{verbatim}
%\declaretheorem[shaded={bgcolor={rgb}{1,0,0},rulecolor={rgb}{0,1,0},rulewidth=2em,
%   margin=1em, textwidth=5cm}]{eyesore}
%\end{verbatim}
%\begin{eyesore}
%  But doing that is strongly discouraged.
%\end{eyesore}
%
% There is also an interface to the thmbox package: you can use |thmbox=X|, 
% where X is one of the styles L, M, S as defined by that package.
% (Actually, the parameter you give here is just passed on as optional
% argument to |\newboxtheorem|, so the other parameters like headstyle are valid as well.)
% The
% redefinition of proof and example is suppressed unless you load the thmbox
% package manually before you load thmtools.
%
%\StopEventually{}
%\section{Implementation}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{thm-kv}[2009/07/30 v0.1beta11 thm-kv interface (ulmi)]
\let\@xa\expandafter
\let\@nx\noexpand
\RequirePackage{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}%
    \RequirePackage{thm-patch}%
    \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