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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
%%
%% This is file `thm-kv.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% thm-kv.dtx (with options: `kv')
%% This is a generated file.
%%
%% This file is part of the `thmtools' package.
%% The `thmtools' package has the LPPL maintenance status: maintained.
%% Current Maintainer is Yukai Chou, muzimuzhi@gmail.com
%%
%% Copyright (C) 2008-2014 by Ulrich M. Schwarz
%% Copyright (C) 2019 by Frank Mittelbach
%% Copyright (C) 2020- by Yukai Chou
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, version 1.3c.
%% This version is obtainable at
%% http://www.latex-project.org/lppl/lppl-1-3c.txt
%%
%%
\NeedsTeXFormat {LaTeX2e}
\ProvidesPackage {thm-kv}[2023/05/04 v0.76]
\let\@xa\expandafter
\let\@nx\noexpand
\DeclareOption{lowercase}{%
\PackageInfo{thm-kv}{Theorem names will be lowercased}%
\global\def\thmt@modifycase{\protect\MakeLowercase}}
\DeclareOption{uppercase}{%
\PackageInfo{thm-kv}{Theorem names will be uppercased}%
\global\def\thmt@modifycase{\protect\MakeUppercase}}
\DeclareOption{anycase}{%
\PackageInfo{thm-kv}{Theorem names will be unchanged}%
\global\def\thmt@modifycase{}}
\ExecuteOptions{uppercase}
\ProcessOptions\relax
\RequirePackage{keyval,kvsetkeys,thm-patch}
\long\def\thmt@kv@processor@default#1#2#3{%
\def\kvsu@fam{#1}% new
\@onelevel@sanitize\kvsu@fam% new
\def\kvsu@key{#2}% new
\@onelevel@sanitize\kvsu@key% new
\unless\ifcsname KV@#1@\kvsu@key\endcsname
\unless\ifcsname KVS@#1@handler\endcsname
\kv@error@unknownkey{#1}{\kvsu@key}%
\else
\csname KVS@#1@handler\endcsname{#2}{#3}%
% still using #2 #3 here is intentional: handler might
% be used for strange stuff like implementing key names
% that contain strange characters or other strange things.
\relax
\fi
\else
\ifx\kv@value\relax
\unless\ifcsname KV@#1@\kvsu@key @default\endcsname
\kv@error@novalue{#1}{\kvsu@key}%
\else
\csname KV@#1@\kvsu@key @default\endcsname
\relax
\fi
\else
\csname KV@#1@\kvsu@key\endcsname{#3}%
\fi
\fi
}
\@ifpackagelater{kvsetkeys}{2012/04/23}{%
\PackageInfo{thm-kv}{kvsetkeys patch (v1.16 or later)}%
\long\def\tmp@KVS@PD#1#2#3{%
\def \kv@fam {#1}%
\unless \ifcsname KV@#1@#2\endcsname
\unless \ifcsname KVS@#1@handler\endcsname
\kv@error@unknownkey {#1}{#2}%
\else
\kv@handled@true
\csname KVS@#1@handler\endcsname {#2}{#3}\relax
\ifkv@handled@ \else
\kv@error@unknownkey {#1}{#2}%
\fi
\fi
\else
\ifx \kv@value \relax
\unless \ifcsname KV@#1@#2@default\endcsname
\kv@error@novalue {#1}{#2}%
\else
\csname KV@#1@#2@default\endcsname \relax
\fi
\else
\csname KV@#1@#2\endcsname {#3}%
\fi
\fi
}%
\ifx\tmp@KVS@PD\KVS@ProcessorDefault
\let\KVS@ProcessorDefault\thmt@kv@processor@default
\def\kv@processor@default#1#2{%
\begingroup
\csname @safe@activestrue\endcsname
\@xa\let\csname ifincsname\@xa\endcsname\csname iftrue\endcsname
\edef\KVS@temp{\endgroup
\noexpand\KVS@ProcessorDefault{#1}{\unexpanded{#2}}%
}%
\KVS@temp
}%
\else
\PackageError{thm-kv}{kvsetkeys patch failed}{Try kvsetkeys v1.16 or earlier}
\fi
}{\@ifpackagelater{kvsetkeys}{2011/04/06}{%
% Patch has disappeared somewhere... thanksalot.
\PackageInfo{thm-kv}{kvsetkeys patch (v1.13 or later)}
\long\def\tmp@KVS@PD#1#2#3{% no non-etex-support here...
\unless\ifcsname KV@#1@#2\endcsname
\unless\ifcsname KVS@#1@handler\endcsname
\kv@error@unknownkey{#1}{#2}%
\else
\csname KVS@#1@handler\endcsname{#2}{#3}%
\relax
\fi
\else
\ifx\kv@value\relax
\unless\ifcsname KV@#1@#2@default\endcsname
\kv@error@novalue{#1}{#2}%
\else
\csname KV@#1@#2@default\endcsname
\relax
\fi
\else
\csname KV@#1@#2\endcsname{#3}%
\fi
\fi
}%
\ifx\tmp@KVS@PD\KVS@ProcessorDefault
\let\KVS@ProcessorDefault\thmt@kv@processor@default
\def\kv@processor@default#1#2{%
\begingroup
\csname @safe@activestrue\endcsname
\let\ifincsname\iftrue
\edef\KVS@temp{\endgroup
\noexpand\KVS@ProcessorDefault{#1}{\unexpanded{#2}}%
}%
\KVS@temp
}
\else
\PackageError{thm-kv}{kvsetkeys patch failed, try kvsetkeys v1.13 or earlier}
\fi
}{%
\RequirePackage{etex}
\PackageInfo{thm-kv}{kvsetkeys patch applied (pre-1.13)}%
\let\kv@processor@default\thmt@kv@processor@default
}}
\newcommand\thmt@mkignoringkeyhandler[1]{%
\kv@set@family@handler{#1}{%
\thmt@debug{Key `##1' with value `##2' ignored by #1.}%
}%
}
\newcommand\thmt@mkextendingkeyhandler[3]{%
\kv@set@family@handler{#1}{%
\thmt@selfextendingkeyhandler{#1}{#2}{#3}%
{##1}{##2}%
}%
}
\newcommand\thmt@selfextendingkeyhandler[5]{%
% #1: family
% #2: prefix for file
% #3: key hint for error
% #4: actual key
% #5: actual value
\IfFileExists{#2-#4.sty}{%
\PackageInfo{thmtools}%
{Automatically pulling in `#2-#4'}%
\RequirePackage{#2-#4}%
\ifcsname KV@#1@#4\endcsname
\csname KV@#1@#4\endcsname{#5}%
\else
\PackageError{thmtools}%
{#3 `#4' not known}
{I don't know what that key does.\MessageBreak
I've even loaded the file `#2-#4.sty', but that didn't help.
}%
\fi
}{%
\PackageError{thmtools}%
{#3 `#4' not known}
{I don't know what that key does by myself,\MessageBreak
and no file `#2-#4.sty' to tell me seems to exist.
}%
}%
}
\newif\if@thmt@firstkeyset
\def\thmt@trytwice{%
\if@thmt@firstkeyset
\@xa\@firstoftwo
\else
\@xa\@secondoftwo
\fi
}
\@for\tmp@keyname:=parent,numberwithin,within\do{%
\define@key{thmdef}{\tmp@keyname}{%
\thmt@trytwice{%
\thmt@setparent{#1}
\thmt@setsibling{}%
}{}%
}%
}
\newcommand\thmt@setparent{%
\def\thmt@parent
}
\@for\tmp@keyname:=sibling,numberlike,sharenumber\do{%
\define@key{thmdef}{\tmp@keyname}{%
\thmt@trytwice{%
\thmt@setsibling{#1}%
\thmt@setparent{}%
}{}%
}%
}
\newcommand\thmt@setsibling{%
\def\thmt@sibling
}
\@for\tmp@keyname:=title,name,heading\do{%
\define@key{thmdef}{\tmp@keyname}{\thmt@trytwice{\thmt@setthmname{#1}}{}}%
}
\newcommand\thmt@setthmname{%
\def\thmt@thmname
}
\@for\tmp@keyname:=unnumbered,starred\do{%
\define@key{thmdef}{\tmp@keyname}[]{\thmt@trytwice{\thmt@isnumberedfalse}{}}%
}
\def\thmt@YES{yes}
\def\thmt@NO{no}
\def\thmt@UNIQUE{unless unique}
\newif\ifthmt@isnumbered
\newif\ifthmt@isunlessunique
\define@key{thmdef}{numbered}[yes]{
\def\thmt@tmp{#1}%
\thmt@trytwice{%
\ifx\thmt@tmp\thmt@YES
\thmt@isnumberedtrue
\else\ifx\thmt@tmp\thmt@NO
\thmt@isnumberedfalse
\else\ifx\thmt@tmp\thmt@UNIQUE
\RequirePackage[unq]{unique}
\thmt@isunlessuniquetrue
\else
\PackageError{thmtools}{Unknown value `#1' to key numbered}{}%
\fi\fi\fi
}{% trytwice: after definition
\ifx\thmt@tmp\thmt@UNIQUE
\ifx\thmt@parent\@empty
\addtotheorempreheadhook[\thmt@envname]{\setuniqmark{\thmt@envname}}%
\else
\protected@edef\thmt@tmp{%
% expand \thmt@envname and \thmt@parent
\@nx\addtotheorempreheadhook[\thmt@envname @unique]{%
\@nx\setuniqmark{\thmt@envname.\@nx\@nameuse{the\thmt@parent}}}%
\@nx\addtotheorempreheadhook[\thmt@envname @numbered]{%
\@nx\setuniqmark{\thmt@envname.\@nx\@nameuse{the\thmt@parent}}}%
\@nx\addtotheorempreheadhook[\thmt@envname @unique]{%
\def\@nx\thmt@dummyctrautorefname{\thmt@thmname\@nx\@gobble}}%
\@nx\addtotheorempreheadhook[\thmt@envname @numbered]{%
\def\@nx\thmt@dummyctrautorefname{\thmt@thmname\@nx\@gobble}}%
}%
\thmt@tmp
\fi
% \addtotheorempreheadhook[\thmt@envname]{%
% \def\thmt@dummyctrautorefname{\thmt@thmname\@gobble}}%
\fi
}%
}
\define@key{thmdef}{preheadhook}{%
\thmt@trytwice{}{\addtotheorempreheadhook[\thmt@envname]{#1}}}
\define@key{thmdef}{postheadhook}{%
\thmt@trytwice{}{\addtotheorempostheadhook[\thmt@envname]{#1}}}
\define@key{thmdef}{prefoothook}{%
\thmt@trytwice{}{\addtotheoremprefoothook[\thmt@envname]{#1}}}
\define@key{thmdef}{postfoothook}{%
\thmt@trytwice{}{\addtotheorempostfoothook[\thmt@envname]{#1}}}
\define@key{thmdef}{style}{\thmt@trytwice{\thmt@setstyle{#1}}{}}
\define@key{thmdef0}{style}{%
\ifcsname thmt@style #1@defaultkeys\endcsname
\thmt@toks{\kvsetkeys{thmdef}}%
\@xa\@xa\@xa\the\@xa\@xa\@xa\thmt@toks\@xa\@xa\@xa{%
\csname thmt@style #1@defaultkeys\endcsname}%
\fi
}
\thmt@mkignoringkeyhandler{thmdef0}
\def\thmt@setstyle#1{%
\PackageWarning{thm-kv}{%
Your backend doesn't have a `\string\theoremstyle' command.
}%
}
\ifcsname theoremstyle\endcsname
\let\thmt@originalthmstyle\theoremstyle
\def\thmt@outerstyle{plain}
\renewcommand\theoremstyle[1]{%
\def\thmt@outerstyle{#1}%
\thmt@originalthmstyle{#1}%
}
\def\thmt@setstyle#1{%
\thmt@originalthmstyle{#1}%
}
\g@addto@macro\thmt@newtheorem@postdefinition{%
\thmt@originalthmstyle{\thmt@outerstyle}%
}
\fi
\thmt@mkextendingkeyhandler{thmdef}{thmdef}{\string\declaretheorem\space key}
\let\thmt@newtheorem\newtheorem
\newcommand\declaretheorem[2][]{%
% TODO: use \NewDocumentCommand from xparse?
% xparse will be part of latex2e format from latex2e 2020 Oct.
\@ifnextchar[%
{\declaretheorem@i{#1}{#2}}
{\declaretheorem@i{#1}{#2}[]}%
}
\@onlypreamble\declaretheorem
\def\declaretheorem@i#1#2[#3]{%
\@for\thmt@tmp:=#2\do{%
% strip spaces, \KV@@sp@def is defined in keyval.sty
\@xa\KV@@sp@def\@xa\thmt@tmp\@xa{\thmt@tmp}%
\@xa\declaretheorem@ii\@xa{\thmt@tmp}{#1,#3}%
}%
}
\def\declaretheorem@ii#1#2{%
% why was that here?
%\let\thmt@theoremdefiner\thmt@original@newtheorem
% init options
\thmt@setparent{}%
\thmt@setsibling{}%
\thmt@isnumberedtrue
\thmt@isunlessuniquefalse
\def\thmt@envname{#1}%
\thmt@setthmname{\thmt@modifycase #1}%
% use true code in \thmt@trytwice{<true>}{<false>}
\@thmt@firstkeysettrue
% parse options
\kvsetkeys{thmdef0}{#2}% parse option "style" first
\kvsetkeys{thmdef}{#2}%
% call patched \newtheorem
\ifthmt@isunlessunique
\ifx\thmt@parent\@empty
% define normal "unless unique" thm env
\ifuniq{#1}{\thmt@isnumberedfalse}{\thmt@isnumberedtrue}%
\declaretheorem@iii{#1}%
\else
% define special "unless unique" thm env,
% when "numbered=unless unique" and "numberwithin=<counter>" are both used
\declaretheorem@iv{#1}%
\thmt@isnumberedtrue
\declaretheorem@iii{#1@numbered}%
\thmt@isnumberedfalse
\declaretheorem@iii{#1@unique}%
\fi
\else
% define normal thm env
\declaretheorem@iii{#1}%
\fi
% use false code in \thmt@trytwice{<true>}{<false>}
\def\thmt@envname{#1}%
\@thmt@firstkeysetfalse
% uniquely ugly kludge: some keys make only sense afterwards.
% and it gets kludgier: again, the default-inherited
% keys need to have a go at it.
\kvsetkeys{thmdef0}{#2}%
\kvsetkeys{thmdef}{#2}%
}
\def\declaretheorem@iii#1{%
\protected@edef\thmt@tmp{%
\@nx\thmt@newtheorem
\ifthmt@isnumbered
{#1}%
\ifx\thmt@sibling\@empty\else [\thmt@sibling]\fi
{\thmt@thmname}%
\ifx\thmt@parent\@empty\else [\thmt@parent]\fi
\else
*{#1}{\thmt@thmname}%
\fi
\relax% added so we can delimited-read everything later
}%
\thmt@debug{Define theorem `#1' by ^^J\meaning\thmt@tmp}%
\thmt@tmp
}
\def\declaretheorem@iv#1{%
\protected@edef\thmt@tmp{%
% expand \thmt@envname and \thmt@parent
\@nx\newenvironment{#1}{%
\@nx\ifuniq{\thmt@envname.\@nx\@nameuse{the\thmt@parent}}{%
\def\@nx\thmt@rawenvname{#1@unique}%
}{%
\def\@nx\thmt@rawenvname{#1@numbered}%
}%
\begin{\@nx\thmt@rawenvname}%
}{%
\end{\@nx\thmt@rawenvname}%
}%
}%
\thmt@debug{Define special theorem `#1' by ^^J\meaning\thmt@tmp}%
\thmt@tmp
}
\providecommand\thmt@quark{\thmt@quark}
\thmt@mkextendingkeyhandler{thmuse}{thmuse}{\thmt@envname\space optarg key}
\addtotheorempreheadhook{%
\ifx\thmt@optarg\@empty\else
\@xa\thmt@garbleoptarg\@xa{\thmt@optarg}\fi
}%
\newif\ifthmt@thmuse@iskv
\providecommand\thmt@garbleoptarg[1]{%
\thmt@thmuse@iskvfalse
\def\thmt@newoptarg{\@gobble}%
\def\thmt@newoptargextra{}%
\let\thmt@shortoptarg\@empty
\def\thmt@warn@unusedkeys{}%
\@for\thmt@fam:=\thmt@thmuse@families\do{%
\kvsetkeys{\thmt@fam}{#1}%
}%
\ifthmt@thmuse@iskv
\protected@edef\thmt@optarg{%
\@xa\thmt@newoptarg
\thmt@newoptargextra\@empty
}%
\ifx\thmt@shortoptarg\@empty
\protected@edef\thmt@shortoptarg{\thmt@newoptarg\@empty}%
\fi
\thmt@warn@unusedkeys
\else
\def\thmt@optarg{#1}%
\def\thmt@shortoptarg{#1}%
\fi
}
\def\thmt@thmuse@families{thm@track@keys}
\kv@set@family@handler{thm@track@keys}{%
\@onelevel@sanitize\kv@key
\@namedef{thmt@unusedkey@\kv@key}{%
\PackageWarning{thmtools}{Unused key `#1'}%
}%
\@xa\g@addto@macro\@xa\thmt@warn@unusedkeys\@xa{%
\csname thmt@unusedkey@\kv@key\endcsname
}
}
\def\thmt@define@thmuse@key#1#2{%
\g@addto@macro\thmt@thmuse@families{,#1}%
\define@key{#1}{#1}{\thmt@thmuse@iskvtrue
\@namedef{thmt@unusedkey@#1}{}%
#2}%
\thmt@mkignoringkeyhandler{#1}%
}
\thmt@define@thmuse@key{label}{%
\addtotheorempostheadhook[local]{\label{#1}}%
}
\thmt@define@thmuse@key{name}{%
\thmt@setnewoptarg #1\@iden%
}
\newcommand\thmt@setnewoptarg[1][]{%
\def\thmt@shortoptarg{#1}\thmt@setnewlongoptarg
}
\def\thmt@setnewlongoptarg #1\@iden{%
\def\thmt@newoptarg{#1\@iden}}
\providecommand\thmt@suspendcounter[2]{%
\@xa\protected@edef\csname the#1\endcsname{#2}%
\@xa\let\csname c@#1\endcsname\c@thmt@dummyctr
}
\providecommand\thmcontinues[1]{%
\ifcsname hyperref\endcsname
\hyperref[#1]{continuing}
\else
continuing
\fi
from p.\,\pageref{#1}%
}
\thmt@define@thmuse@key{continues}{%
\thmt@suspendcounter{\thmt@envname}{\thmt@trivialref{#1}{??}}%
\g@addto@macro\thmt@newoptarg{{, }%
\thmcontinues{#1}%
\@iden}%
}
\def\thmt@declaretheoremstyle@setup{}
\def\thmt@declaretheoremstyle#1{%
\PackageWarning{thmtools}{Your backend doesn't allow styling theorems}{}
}
\newcommand\declaretheoremstyle[2][]{%
\def\thmt@style{#2}%
\@xa\def\csname thmt@style \thmt@style @defaultkeys\endcsname{}%
\thmt@declaretheoremstyle@setup
\kvsetkeys{thmstyle}{#1}%
\thmt@declaretheoremstyle{#2}%
}
\@onlypreamble\declaretheoremstyle
\kv@set@family@handler{thmstyle}{%
\@onelevel@sanitize\kv@value
\@onelevel@sanitize\kv@key
\PackageInfo{thmtools}{%
Key `\kv@key' (with value `\kv@value')\MessageBreak
is not a known style key.\MessageBreak
Will pass this to every \string\declaretheorem\MessageBreak
that uses `style=\thmt@style'%
}%
\ifx\kv@value\relax% no value given, don't pass on {}!
\@xa\g@addto@macro\csname thmt@style \thmt@style @defaultkeys\endcsname{%
#1,%
}%
\else
\@xa\g@addto@macro\csname thmt@style \thmt@style @defaultkeys\endcsname{%
#1={#2},%
}%
\fi
}
\endinput
%%
%% End of file `thm-kv.sty'.
|