Debian Codegraph @

texmf-dist/doc/latex/keytheorems/README.md

raw
1 # keytheorems
2
3 A LaTeX package to use [`amsthm`](https://www.ctan.org/pkg/amsthm)
4 with a key-value interface.
5 Provides all of the functionality of [`thmtools`](https://www.ctan.org/pkg/thmtools) (and a lot more!) but written in expl3.
6 If you find a bug please open an issue or pull request.
7
8 The package is maintained by Matthew Bertucci.
9
10 ## Sample document
11 ```tex
12 \documentclass{article}
13 \usepackage{amssymb,amsmath}
14 \usepackage{keytheorems}
15 \usepackage{hyperref}
16
17 \newkeytheoremstyle{mystyle}{
18 % <insert options>
19 }
20 \newkeytheorem{theorem}[
21 style=mystyle,
22 parent=section
23 ]
24 \newkeytheorem{remark}[
25 style=remark,
26 numbered=no
27 ]
28
29 \begin{document}
30
31 \section{Some theorems}
32
33 \begin{theorem}[
34 note=Strong Bertini over $\mathbb{C}$,
35 label=strongbertini
36 ]
37 Let $X$ be a smooth complex variety and let $\mathfrak{D}$ be a positive
38 dimensional linear system on $X$. Then the general element of $\mathfrak{D}$ is
39 smooth away from the base locus $B_{\mathfrak{D}}$. That is, the set
40 \[\{H\in\mathfrak{D}\mid D_H \text{ is smooth away from } B_{\mathfrak{D}}\}\]
41 is a Zariski dense open subset of $\mathfrak{D}$.
42 \end{theorem}
43
44 \begin{remark}
45 In fact, \autoref{strongbertini} holds over any algebraically closed field of
46 characteristic zero.
47 \end{remark}
48
49 \begin{theorem}[Bertini over any field]
50 Let $X\subset\mathbb{P}_k^n$ be a smooth projective variety over a field $k$.
51 Then the set of hyperplanes $H\subseteq\mathbb{P}_k^n$ such that $X\cap H$ is
52 smooth is a Zariski dense open subset of $(\mathbb{P}_k^n)^*$.
53 \end{theorem}
54
55 \listofkeytheorems
56
57 %%% compare with
58 %\listofkeytheorems[ignoreall,show=theorem]
59 %\listofkeytheorems[swapnumber]
60 %\listofkeytheorems[title=BLUB]
61 %\listofkeytheorems[print-body] % needs 'store-all' package option
62
63 \end{document}
64 ```
65
66 ## Documentation
67 There is a list of commands and keys offered by the package
68 [here](https://github.com/mbertucci47/keytheorems/blob/develop/doc/keytheorems-doc.pdf).
69
70 ## Differences with thmtools
71
72 Some of the code is a direct translation from thmtools but a few things are changed:
73 - The only backend supported is amsthm, and it is loaded by the package. As I understand it,
74 [`ntheorem`](https://www.ctan.org/pkg/ntheorem) has quite a few bugs and no active development, and
75 if you're just using the kernel `\newtheorem` then you don't need a package like this.
76 - Theorem hooks use the kernel hooks. Thus unlike the `prefoot` and `postfoot` hooks of
77 thmtools, all code chunks are added to hooks in the order declared (unless given a
78 distinct label; then the chunks are reversed). The order of generic/specific hooks
79 remains the same. Furthermore, the command for adding to theorem hooks is `\addtotheoremhook{<hook name>}{<theorem name>}`.
80 - thmtools changes some style settings to be default that are different from
81 amsthm defaults, but only if a custom style is called. Example:
82 ```tex
83 \declaretheoremstyle[spaceabove=20pt]{mythmsty}
84 \declaretheorem[style=mythmsty]{mythm}
85 ```
86
87 is different from just
88
89 ```tex
90 \declaretheorem{mythm}
91 ```
92
93 as in the former, `bodyfont` is `\normalfont`, not the default `\itshape`.
94 This package keeps the defaults unless a key is specifically given.
95 - There is no `restatable(*)` environment except with package option `thmtools-compat`. Use the
96 `store` (alias `restate`) key. For counters and labels pointing to the restated theorem,
97 use `store*` (alias `restate*`).
98 - Rather than `restate=foo` defining a command `\foo*`, theorems are retrieved with `\getkeytheorem{foo}`.
99 For just the theorem body, use `\getkeytheorem[body]{foo}`. Also, this retrieval
100 can happen even before the theorem is stated since keytheorems writes the contents
101 to a file.
102 - The `shaded` and `thmbox` keys are only available with the package option `thmtools-compat`,
103 and they are emulated with [`tcolorbox`](https://www.ctan.org/pkg/tcolorbox). Instead there's
104 an interface to tcolorbox with the `tcolorbox={<options>}` and `tcolorbox-no-titlebar={<options>}` key.
105 The `mdframed` key is not implemented.
106 - You can reuse styles with the `inherit-style` key.
107 - With thmtools, the command `\newtheorem{<envname>}{<heading>}` is changed to behave like
108 `\declaretheorem[name=<heading>]{<envname>}`. This is not the default here. Instead either
109 only use the new interface or load the package with option `overload`.
110 - Adds many new keys and commands &mdash; see the documentation for details.
111
112 ## thmtools issues resolved by keytheorems
113 Issues from the thmtools [github page](https://github.com/muzimuzhi/thmtools),
114 with corresponding keytheorems code that shows the issue resolved.
115 ### [\listoftheorems: filter out restated ones #7](https://github.com/muzimuzhi/thmtools/issues/7)
116 keytheorems does not list restated theorems in the `\listofkeytheorems`.
117 ```tex
118 \documentclass{article}
119 \usepackage{keytheorems}
120
121 \newkeytheorem{theorem}
122
123 \begin{document}
124
125 \begin{theorem}[store=foo]
126 text
127 \end{theorem}
128
129 \getkeytheorem{foo}
130
131 \listofkeytheorems
132
133 \end{document}
134 ```
135
136 ### [\listoftheorems: hide title #8](https://github.com/muzimuzhi/thmtools/issues/8)
137 keytheorems provides the `no-title` key.
138 ```tex
139 \documentclass{article}
140 \usepackage{keytheorems}
141
142 \newkeytheorem{axiom}
143 \newkeytheorem{theorem}
144
145 \begin{document}
146
147 \listofkeytheorems[ignoreall,show=axiom]
148 \listofkeytheorems[ignoreall,show=theorem,no-title]
149
150 \begin{axiom}
151 some axiom
152 \end{axiom}
153
154 \begin{theorem}
155 some theorem
156 \end{theorem}
157
158 \begin{axiom}
159 another axiom
160 \end{axiom}
161
162 \begin{theorem}
163 another theorem
164 \end{theorem}
165
166 \end{document}
167 ```
168
169 ### [Case in point: the tcolorbox key #9](https://github.com/muzimuzhi/thmtools/issues/9)
170 keytheorems provides the `tcolorbox` and `tcolorbox-no-titlebar` keys.
171 ```tex
172 \documentclass{article}
173 \usepackage{keytheorems}
174
175 \newkeytheorem{theorem}[
176 tcolorbox={
177 colback=blue!10,
178 colframe=blue!75
179 }
180 ]
181 \newkeytheorem{corollary}[
182 tcolorbox-no-titlebar={colback=red!10}
183 ]
184
185 \begin{document}
186
187 \begin{theorem}
188 some theorem
189 \end{theorem}
190
191 \begin{corollary}
192 some corollary
193 \end{corollary}
194
195 \end{document}
196 ```
197
198 ### [thm-listof: document \thmtformatoptarg, new list option? #14](https://github.com/muzimuzhi/thmtools/issues/14)
199 keytheorems provides the `note-code` key for `\listofkeytheorems` and
200 `\keytheoremlistset`.
201 ```tex
202 \documentclass{article}
203 \usepackage{keytheorems}
204
205 \newkeytheorem{theorem}
206
207 \begin{document}
208
209 \begin{theorem}[my heading]
210 some theorem
211 \end{theorem}
212
213 \listofkeytheorems[note-code={ [\textit{#1}]}]
214
215 \end{document}
216 ```
217
218 ### [Style inheritance in thmtools #15](https://github.com/muzimuzhi/thmtools/issues/15)
219 keytheorems provides the `inherit-style` key.
220 ```tex
221 \documentclass{article}
222 \usepackage{keytheorems}
223
224 \newkeytheoremstyle{mysty1}{notefont=\itshape}
225 \newkeytheoremstyle{mysty2}{inherit-style=mysty1,bodyfont=\normalfont}
226 \newkeytheorem{theorem}[style=mysty1]
227 \newkeytheorem{corollary}[style=mysty2]
228
229 \begin{document}
230
231 \begin{theorem}[my heading]
232 some theorem
233 \end{theorem}
234
235 \begin{corollary}[my heading]
236 some corollary
237 \end{corollary}
238
239 \end{document}
240 ```
241
242 ### [Restate without theorem headings (head + note) #19](https://github.com/muzimuzhi/thmtools/issues/19)
243 Use `\getkeytheorem[body]{foo}`.
244 ```tex
245 \documentclass{article}
246 \usepackage{keytheorems}
247
248 \newkeytheorem{theorem}
249
250 \begin{document}
251
252 \begin{theorem}[store=hello]
253 Hello!
254 \end{theorem}
255
256 \getkeytheorem{hello}
257
258 \section{\getkeytheorem[body]{hello}}
259
260 \end{document}
261 ```
262
263 ### [Anyway to restate theorem in external file? #23](https://github.com/muzimuzhi/thmtools/issues/23)
264 Use the `\externaltheorems` command.
265 ```tex
266 % mycoolpaper.tex
267 \documentclass{article}
268 \usepackage{keytheorems}
269 \newkeytheorem{theorem}
270 \begin{document}
271 \begin{theorem}[store=cooltheorem]
272 My cool theorem.
273 \end{theorem}
274 \end{document}
275 ```
276 ```tex
277 % myothercoolpaper.tex
278 \documentclass{article}
279 \usepackage{keytheorems}
280 \externaltheorems[orig:]{mycoolpaper}
281 \newkeytheorem{theorem}
282 \begin{document}
283 \getkeytheorem{orig:cooltheorem}
284 \end{document}
285 ```
286
287 ### [Option clash: numbered=no and thmbox #25](https://github.com/muzimuzhi/thmtools/issues/25)
288 Fixed with keytheorem's implementation of the `thmbox` key with `thmtools-compat`.
289 ```tex
290 \documentclass{article}
291 \usepackage[thmtools-compat]{keytheorems}
292
293 \declaretheorem[numbered=no, name=TheoremA, ]{mytheo1}
294 \declaretheorem[ name=TheoremB, thmbox=M]{mytheo2}
295 \declaretheorem[numbered=no, name=TheoremC, thmbox=M]{mytheo3}
296
297 \begin{document}
298
299 \begin{mytheo1}
300 test1
301 \end{mytheo1}
302
303 \begin{mytheo2}
304 test2
305 \end{mytheo2}
306
307 \begin{mytheo3}
308 test3
309 \end{mytheo3}
310
311 \end{document}
312 ```
313
314 ### [Skip the title of the theorem but leave the []. #30](https://github.com/muzimuzhi/thmtools/issues/30)
315 Fixed in keytheorems.
316 ```tex
317 \documentclass{article}
318 \usepackage{keytheorems}
319
320 \newkeytheorem{Teorema}[name=Theorem]
321
322 \begin{document}
323
324 \begin{Teorema}
325 body
326 \end{Teorema}
327
328 \begin{Teorema}[]
329 body
330 \end{Teorema}
331
332 \begin{Teorema}[title]
333 body
334 \end{Teorema}
335
336 \end{document}
337 ```
338
339 ### [FR: Predefined theorems #31](https://github.com/muzimuzhi/thmtools/issues/31)
340 See the `predefined` option of keytheorems.
341 ```tex
342 \documentclass{article}
343 \usepackage[predefined]{keytheorems}
344
345 \begin{document}
346
347 \begin{lemma}
348 Some lemma.
349 \end{lemma}
350 \begin{theorem}
351 Some theorem.
352 \end{theorem}
353
354 \end{document}
355 ```
356
357 ### [too much space with restatable #40](https://github.com/muzimuzhi/thmtools/issues/40)
358 Fixed in keytheorems.
359 ```tex
360 \documentclass{article}
361 \usepackage{keytheorems}
362 \usepackage{kantlipsum}
363
364 \newkeytheorem{theorem}
365
366 \begin{document}
367
368 \begin{theorem}
369 \kant[2][1]
370 \end{theorem}
371
372 \begin{theorem}[store=foo]
373 \kant[1][2]
374 \end{theorem}
375
376 \begin{theorem}
377 \kant[2][1]
378 \end{theorem}
379
380 \getkeytheorem{foo}
381
382 \end{document}
383 ```
384
385 ### [restate key with no name leads to (,) in restated title #41](https://github.com/muzimuzhi/thmtools/issues/41)
386 Fixed in keytheorems.
387 ```tex
388 \documentclass{article}
389 \usepackage{keytheorems}
390 \usepackage{kantlipsum}
391
392 \newkeytheorem{theorem}
393
394 \begin{document}
395
396 \begin{theorem}[restate=foo]
397 \kant[1][2]
398 \end{theorem}
399
400 \getkeytheorem{foo}
401
402 \begin{theorem}[restate=foobar,name=Heading]
403 \kant[2][1]
404 \end{theorem}
405
406 \getkeytheorem{foobar}
407
408 \end{document}
409 ```
410 ### [[Help Wanted] Print all Theorems? #43](https://github.com/muzimuzhi/thmtools/issues/43)
411 Use the `store-all` load-time option with `\listofkeytheorems[print-body]`.
412 ```tex
413 \documentclass{article}
414 \usepackage[store-all]{keytheorems}
415
416 \newkeytheorem{theorem}
417 \newkeytheorem{lemma}
418
419 \begin{document}
420
421 \begin{theorem}
422 some theorem
423 \end{theorem}
424
425 \begin{lemma}
426 some lemma
427 \end{lemma}
428
429 \listofkeytheorems[print-body]
430
431 \end{document}
432 ```
433
434 ### [qed option without value fails in \declaretheoremstyle #47](https://github.com/muzimuzhi/thmtools/issues/47)
435 Fixed in keytheorems.
436 ```tex
437 \documentclass{article}
438 \usepackage{keytheorems}
439
440 \newkeytheoremstyle{mythmsty}{qed}
441 \newkeytheorem{theorem}[style=mythmsty]
442
443 \begin{document}
444
445 \begin{theorem}
446 Text
447 \end{theorem}
448
449 \end{document}
450 ```
451
452 ### [prefoot and postfoot hooks called twice with restate key #54](https://github.com/muzimuzhi/thmtools/issues/54)
453 Fixed in keytheorems.
454 ```tex
455 \documentclass{article}
456 \usepackage{keytheorems}
457
458 \newkeytheorem{theorem}
459
460 \addtotheoremhook{prehead}{PREHEAD}
461 \addtotheoremhook{posthead}{POSTHEAD}
462 \addtotheoremhook{prefoot}{PREFOOT}
463 \addtotheoremhook{postfoot}{POSTFOOT}
464
465 \begin{document}
466
467 \begin{theorem}
468 body text
469 \end{theorem}
470
471 \begin{theorem}[store=foo]
472 body text
473 \end{theorem}
474
475 \end{document}
476 ```
477
478 ### [beamer theorem syntax not fully supported #57](https://github.com/muzimuzhi/thmtools/issues/57)
479 Fixed in keytheorems.
480 ```tex
481 \documentclass{beamer}
482 \setbeamertemplate{theorems}[numbered]
483 \usepackage{keytheorems}
484
485 \newkeytheorem{MyTheorem}
486
487 \begin{document}
488
489 \begin{frame}
490 \begin{MyTheorem}[name=bla]
491 first text
492 \end{MyTheorem}
493 \begin{MyTheorem}<2->[name=bla]
494 second text
495 \end{MyTheorem}
496 \begin{MyTheorem}[name=bla]<3->
497 third text
498 \end{MyTheorem}
499 \end{frame}
500
501 % Compare:
502
503 \begin{frame}
504 \begin{theorem}[bla]
505 first text
506 \end{theorem}
507 \begin{theorem}<2->[bla]
508 second text
509 \end{theorem}
510 \begin{theorem}[bla]<3->
511 third text
512 \end{theorem}
513 \end{frame}
514
515 \end{document}
516 ```
517
518 ### [restate key incompatible with beamer #58](https://github.com/muzimuzhi/thmtools/issues/58)
519 ```tex
520 \documentclass{beamer}
521 \setbeamertemplate{theorems}[numbered]
522 \usepackage{keytheorems}
523
524 \newkeytheorem{MyTheorem}
525
526 \begin{document}
527
528 \begin{frame}
529 \begin{MyTheorem}[restate=foo]
530 text
531 \end{MyTheorem}
532
533 \getkeytheorem{foo}
534 \end{frame}
535
536 \end{document}
537 ```
538
539 ## Notes/issues on thmtools, not on Github
540
541 ### continues with unless unique and restate
542 Should this be numbered or not?
543 ```tex
544 \documentclass{article}
545 \usepackage{amsthm,thmtools}
546
547 \declaretheorem[numbered=unless unique]{theorem}
548
549 \begin{document}
550
551 \begin{theorem}[label=foo]
552 bla
553 \end{theorem}
554
555 \begin{theorem}[continues=foo]
556 bla
557 \end{theorem}
558
559 \end{document}
560 ```
561 It does the correct thing when a parent counter is given and is split across that counter.
562 ```tex
563 \documentclass{article}
564 \usepackage{amsthm,thmtools}
565
566 \declaretheorem[numbered=unless unique,parent=section]{theorem}
567
568 \begin{document}
569
570 \begin{theorem}[label=foo]
571 bla
572 \end{theorem}
573
574 \section{bla}
575
576 \begin{theorem}[continues=foo]
577 bla
578 \end{theorem}
579
580 \end{document}
581 ```
582 Also adds a number if restated, which seems wrong.
583 ```tex
584 \documentclass{article}
585 \usepackage{amsthm,thmtools}
586
587 \declaretheorem[numbered=unless unique]{theorem}
588
589 \begin{document}
590
591 \begin{restatable}{theorem}{foo}
592 bla
593 \end{restatable}
594
595 \foo*
596
597 \end{document}
598 ```
599
600 ### qed in both `\declaretheoremstyle` and `\declaretheorem`
601 One would expect the one in `\declaretheorem` to overwrite, but because the code just adds to the hooks without checking,
602 it's additive.
603 ```tex
604 \documentclass{article}
605 \usepackage{amsthm,thmtools}
606
607 \declaretheoremstyle[qed=$\clubsuit$]{mysty}
608 \declaretheorem[style=mysty,qed]{theorem}
609
610 \begin{document}
611
612 \begin{theorem}
613 bla
614 \end{theorem}
615
616 \end{document}
617 ```
618
619 ### restate incompatible with thmbox
620 ```tex
621 \documentclass{article}
622 \usepackage{amsthm,thmtools}
623
624 \declaretheorem[thmbox]{theorem}
625
626 \begin{document}
627
628 \begin{theorem}[restate=foo]
629 bla
630 \end{theorem}
631
632 \foo*
633
634 \end{document}
635 ```
636
637 ### adding to listoftheorems doesn't work as expected
638 ```tex
639 \documentclass{article}
640 \usepackage{amsthm,thmtools}
641
642 \declaretheorem{theorem}
643
644 \begin{document}
645
646 \begin{theorem}
647 bla
648 \end{theorem}
649
650 \addcontentsline{loe}{section}{some text}
651
652 \begin{theorem}
653 bla
654 \end{theorem}
655
656 \listoftheorems
657
658 \end{document}
659 ```
660
661 ### new theorem styles do not preserve "plain" keys
662 With keytheorems, this is handled only for the AMS classes, acmart, aomart, and jlreq.
663 ```tex
664 \documentclass{amsbook}
665 \usepackage{thmtools}
666
667 \declaretheoremstyle[bodyfont=\upshape]{upsty}
668 \declaretheorem{theorem}
669 \declaretheorem[style=upsty]{lemma}
670
671 \begin{document}
672
673 \begin{theorem}
674 blub
675 \end{theorem}
676
677 \begin{lemma}
678 blub
679 \end{lemma}
680
681 \end{document}
682 ```
683
684 ## License
685 Released under the LaTeX Project Public License v1.3c or later. See https://www.latex-project.org/lppl.txt.