Debian Codegraph @

texmf-dist/doc/latex/thmtools/thmtools-manual.tex

raw
1 % !TeX program = pdflatex
2 \documentclass[paper=a4, pagesize, DIV=20,
3 english,
4 headings=small,11pt,
5 titlepage=false,
6 numbers=noendperiod
7 ]{scrreprt}
8 \addtokomafont{sectioning}{\rmfamily}
9
10 \usepackage[T1]{fontenc}
11 \usepackage[charter]{mathdesign}
12 \usepackage{luximono}
13 \usepackage[scaled]{helvet}
14
15 \usepackage[dvipsnames]{xcolor}
16
17 \usepackage{doc}[=v2] % to achieve max backward compatibility
18 \usepackage{shortvrb,xspace}
19 \makeatletter
20 % to be fixed at some point...
21 \AtBeginDocument{% prepare for doc v3
22 \let\PrintDescribeMacro\@gobble
23 \let \PrintDescribeEnv\@gobble
24 \let \PrintMacroName\@gobble
25 \let \PrintEnvName\@gobble
26 }
27 \makeatother
28 \CodelineNumbered
29
30 \usepackage{listings}
31
32 \usepackage{amsmath, amsthm}
33 \usepackage{enumitem}
34 \setlist[description, 1]{labelindent=2em, leftmargin=2em, rightmargin=2em, labelwidth=!}
35 \usepackage{tikz}
36 \usetikzlibrary{tikzmark}
37
38 \usepackage{nameref}
39 \usepackage{hyperref}
40 \hypersetup{
41 colorlinks,
42 linkcolor=RoyalBlue,
43 urlcolor=RoyalBlue,
44 linktoc=all
45 }
46 \usepackage{cleveref}[2010/05/01]
47
48 \usepackage{thmtools, thm-restate}
49 \usepackage[unq]{unique}
50
51 \providecommand\pkg[1]{\textsf{#1}}
52 \providecommand\Thmtools{\pkg{Thmtools}\xspace}
53 \providecommand\thmtools{\pkg{thmtools}\xspace}
54 \providecommand\oarg[1]{\texttt{[}\textit{#1}\texttt{]}}
55 \providecommand\marg[1]{\texttt{\{}\textit{#1}\texttt{\}}}
56
57
58 \providecommand\clap{\makebox[0pt][c]}
59
60 \newcommand\key[2][\keydefaultcontext]{%
61 % todo: create an index from this...
62 \paragraph*{\texttt{#2}}
63 }
64
65 \newcommand\change[2]{%
66 (\textbf{#1: \textsf{#2}})%
67 }
68
69 \lstloadlanguages{[LaTeX]TeX}
70 \lstset{language=[LaTeX]TeX,basicstyle=\small\ttfamily,keywordstyle=\mdseries,aboveskip=0pt}
71
72 \lstnewenvironment{preamble}[1][]{%
73 \lstset{backgroundcolor=\color{Purple!15},#1}%
74 }{%
75 }
76 \lstnewenvironment{body}[1][]{%
77 \lstset{backgroundcolor=\color{Yellow!30},#1}%
78 }{%
79 }
80
81 \newenvironment{source}{%
82 \par\noindent\strut\minipage[t]{0.61\linewidth}
83 }{%
84 \endminipage
85 }
86 \newenvironment{result}{%
87 \hfill\minipage[t]{0.37\linewidth}
88 \vspace{1pt}%
89 }{%
90 \endminipage\strut\par
91 \vspace{3pt}%
92 }
93 %\MakeShortVerb{\|}
94 \lstMakeShortInline{|}
95
96
97 \declaretheorem{theorem}
98 \declaretheorem[numberwithin=section]{theoremS}
99 \declaretheorem[name=\"Ubung]{exercise}
100 \declaretheorem[sibling=theorem]{lemma}
101 \declaretheorem[numbered=no,
102 name=Euclid's Prime Theorem]{euclid}
103 \declaretheorem[numbered=unless unique]{singleton}
104 \declaretheorem[numbered=unless unique]{couple}
105 \declaretheorem[style=remark]{remark}
106 \declaretheorem{Theorem}
107
108 \declaretheorem[shaded={bgcolor=Lavender,
109 textwidth=12em}]{BoxI}
110
111 \declaretheorem[shaded={rulecolor=Lavender,
112 rulewidth=2pt, bgcolor={rgb}{1,1,1}}]{BoxII}
113
114 \declaretheorem[thmbox=L]{boxtheorem L}
115 \declaretheorem[thmbox=M]{boxtheorem M}
116 \declaretheorem[thmbox=S]{boxtheorem S}
117
118 \declaretheoremstyle[
119 spaceabove=6pt, spacebelow=6pt,
120 headfont=\normalfont\bfseries,
121 notefont=\mdseries, notebraces={(}{)},
122 bodyfont=\normalfont,
123 postheadspace=1em,
124 qed=\qedsymbol
125 ]{mystyle}
126 \declaretheorem[style=mystyle
127 ]{styledtheorem}
128
129 \declaretheorem[name=Theorem, refname={theorem,theorems},
130 Refname={Theorem,Theorems}]{callmeal}
131
132 % make the full toc entry clickable while only the page number part is colored
133 % based on my own TeX-SX answer https://tex.stackexchange.com/a/555695
134 \usepackage{xpatch}
135
136 \makeatletter
137
138 \xpatchcmd\contentsline
139 {%
140 \csname l@#1\endcsname{%
141 \Hy@toclinkstart{#2}\Hy@toclinkend
142 }{%
143 \Hy@toclinkstart{#3}\Hy@toclinkend
144 }%
145 }
146 {%
147 \csname l@#1\endcsname{%
148 \begingroup
149 \def\@linkcolor{black}%
150 \Hy@toclinkstart{#2}\Hy@toclinkend
151 \endgroup
152 }{%
153 \Hy@toclinkstart{#3}\Hy@toclinkend
154 }%
155 }
156 {}{\PatchFailed}
157
158 % set default input path
159 \def\input@path{{../source/}}
160 \makeatother
161
162
163 \input{VERSION.tex}
164
165 \title{\Thmtools Users' Guide}
166 \author{2008–2014 Dr. Ulrich M. Schwarz -- [email protected]\thanks{%
167 who would like to thank the users for testing, encouragement, feature requests, and
168 bug reports. In particular, Denis Bitouz\'e prompted further improvement
169 when \thmtools got stuck in a ``good enough for me'' slump.}
170 \and
171 \rule{20pt}{0pt}2020-- Yukai Chou\rule{20pt}{0pt} % force newline
172 }
173 \date{\VERSION\\{\small\url{https://github.com/muzimuzhi/thmtools}}}
174
175 \begin{document}
176 \maketitle
177 \section*{\abstractname}
178
179 The \thmtools bundle is a collection of packages that is designed to
180 provide an easier interface to theorems, and to facilitate some more
181 advanced tasks.
182
183 If you are a first-time user and you don't think your requirements are out
184 of the ordinary, browse the examples in \autoref{cha:impatient}. If you're
185 here because the other packages you've tried so far just can't do what you
186 want, take inspiration from \autoref{cha:extravagant}. If you're a repeat
187 customer, you're most likely to be interested in the refence section in
188 \autoref{cha:reference}.
189
190 \begin{multicols}{2}[\section*{\contentsname}]
191 \makeatletter
192 \let\chapter\@gobbletwo
193 \tableofcontents
194 \end{multicols}
195 \clearpage
196
197 \chapter{\Thmtools for the impatient}\label{cha:impatient}
198
199 \section*{How to use this document}
200
201 This guide consists mostly of examples and their output, sometimes with a
202 few additional remarks. Since theorems are defined in the preamble and
203 used in the document, the snippets are two-fold:
204 \begin{source}
205 \begin{preamble}[gobble=4]
206 % Preamble code looks like this.
207 \usepackage{amsthm}
208 \usepackage{thmtools}
209 \declaretheorem{theorem}
210 \end{preamble}
211 \begin{body}[gobble=4]
212 % Document code looks like this.
213 \begin{theorem}[Euclid]
214 \label{thm:euclid}%
215 For every prime $p$, there is a prime $p'>p$.
216 In particular, the list of primes,
217 \begin{equation}\label{eq:1}
218 2,3,5,7,\dots
219 \end{equation}
220 is infinite.
221 \end{theorem}
222 \end{body}
223 \end{source}
224 \begin{result}
225 The result looks like this:
226 % \begin{theorem}[Euclid]
227 % For every prime $p$, there is a prime $p'>p$.
228 % In particular, there are infinitely many primes.
229 % \end{theorem}
230 \begin{restatable}[Euclid]{theorem}{firsteuclid}
231 \label{thm:euclid}%
232 For every prime $p$, there is a prime $p'>p$.
233 In particular, the list of primes,
234 \begin{equation}\label{eq:1}
235 2,3,5,7,\dots
236 \end{equation}
237 is infinite.
238 \end{restatable}
239 \end{result}
240
241 Note that in all cases, you will need a \emph{backend} to provide the
242 command |\newtheorem| with the usual behaviour. The \LaTeX\
243 kernel has a built-in backend which cannot do very much; the most common
244 backends these days are the \pkg{amsthm} and \pkg{ntheorem} packages.
245 Throughout this document, we'll use \pkg{amsthm}, and some of the features
246 won't work with \pkg{ntheorem}.
247
248 \section{Elementary definitions}
249
250 As you have seen above, the new command to define theorems is
251 |\declaretheorem|, which in its most basic form just takes the
252 name of the environment. All other options can be set through a key-val
253 interface:
254 \begin{source}
255 \begin{preamble}[gobble=4]
256 \usepackage{amsthm}
257 \usepackage{thmtools}
258 \declaretheorem[numberwithin=section]{theoremS}
259 \end{preamble}
260 \begin{body}[gobble=4]
261 \begin{theoremS}[Euclid]
262 For every prime $p$, there is a prime $p'>p$.
263 In particular, there are infinitely many primes.
264 \end{theoremS}
265 \end{body}
266 \end{source}
267 \begin{result}
268 \begin{restatable}[Euclid]{theoremS}{euclidii}
269 For every prime $p$, there is a prime $p'>p$.
270 In particular, there are infinitely many primes.
271 \end{restatable}
272 \end{result}
273
274 Instead of |numberwithin=|, you can also use |parent=| and
275 |within=|. They're all the same, use the one you find easiest to
276 remember.
277
278 Note the example above looks somewhat bad: sometimes, the name of the environment,
279 with the first
280 letter uppercased, is not a good choice for the theorem's title.
281
282 \begin{source}
283 \begin{preamble}[gobble=4]
284 \usepackage{amsthm}
285 \usepackage{thmtools}
286 \declaretheorem[name=\"Ubung]{exercise}
287 \end{preamble}
288 \begin{body}[gobble=4]
289 \begin{exercise}
290 Prove Euclid's Theorem.
291 \end{exercise}
292 \end{body}
293 \end{source}
294 \begin{result}
295 \begin{exercise}
296 Prove Euclid's Theorem.
297 \end{exercise}
298 \end{result}
299
300 To save you from having to look up the name of the key every time, you can
301 also use |title=| and |heading=| instead of |name=|; they do exactly
302 the same and hopefully one of these will be easy to remember for you.
303
304 Of course, you do not have to follow the abominal practice of numbering
305 theorems, lemmas, etc., separately:
306 \begin{source}
307 \begin{preamble}[gobble=4]
308 \usepackage{amsthm}
309 \usepackage{thmtools}
310 \declaretheorem[sibling=theorem]{lemma}
311 \end{preamble}
312 \begin{body}[gobble=4]
313 \begin{lemma}
314 For every prime $p$, there is a prime $p'>p$.
315 In particular, there are infinitely many primes.
316 \end{lemma}
317 \end{body}
318 \end{source}
319 \begin{result}
320 \begin{lemma}
321 For every prime $p$, there is a prime $p'>p$.
322 In particular, there are infinitely many primes.
323 \end{lemma}
324 \end{result}
325
326 Again, instead of |sibling=|, you can also use |numberlike=| and
327 |sharecounter=|.
328
329 Some theorems have a fixed name and are not supposed to get a number.
330 To this end, \pkg{amsthm} provides |\newtheorem*|, which is
331 accessible through \thmtools:
332 \begin{source}
333 \begin{preamble}[gobble=4]
334 \usepackage{amsthm}
335 \usepackage{thmtools}
336 \declaretheorem[numbered=no,
337 name=Euclid's Prime Theorem]{euclid}
338 \end{preamble}
339 \begin{body}[gobble=4]
340 \begin{euclid}
341 For every prime $p$, there is a prime $p'>p$.
342 In particular, there are infinitely many primes.
343 \end{euclid}
344 \end{body}
345 \end{source}
346 \begin{result}
347 \begin{euclid}
348 For every prime $p$, there is a prime $p'>p$.
349 In particular, there are infinitely many primes.
350 \end{euclid}
351 \end{result}
352
353 As a somewhat odd frill, you can turn off the number if there's only one
354 instance of the kind in the document. This might happen when you split and
355 join your papers into short conference versions and longer journal papers
356 and tech reports. Note that this doesn't combine well with the sibling
357 key: how do you count like somebody who suddenly doesn't count anymore?
358 Also, it takes an extra \LaTeX\ run to settle.
359 \begin{source}
360 \begin{preamble}[gobble=4]
361 \usepackage{amsthm}
362 \usepackage{thmtools}
363 \usepackage[unq]{unique}
364 \declaretheorem[numbered=unless unique]{singleton}
365 \declaretheorem[numbered=unless unique]{couple}
366 \end{preamble}
367 \begin{body}[gobble=4]
368 \begin{couple}
369 Marc \& Anne
370 \end{couple}
371 \begin{singleton}
372 Me.
373 \end{singleton}
374 \begin{couple}
375 Buck \& Britta
376 \end{couple}
377 \end{body}
378 \end{source}
379 \begin{result}
380 \begin{couple}
381 Marc \& Anne
382 \end{couple}
383 \begin{singleton}
384 Me.
385 \end{singleton}
386 \begin{couple}
387 Buck \& Britta
388 \end{couple}
389 \end{result}
390
391 \change{New}{2020/08/01} Actually, the mandatory argument of |\declaretheorem| accepts a list of environment names, so you can define similar theorems at once. Moreover, similar to |\setmainfont| from \pkg{fontspec} package, the key-value interface can be used both before and after the mandatory argument.
392 \begin{source}
393 \begin{preamble}[gobble=4]
394 \declaretheorem[numberwithin=section]
395 {theorem, definition}
396 \declaretheorem{lemma, proposition, corollary}[
397 style=plain,
398 numberwithin=theorem
399 ]
400 \end{preamble}
401 \end{source}
402
403 \clearpage
404 \section{Frilly references}
405
406 In case you didn't know, you should: \pkg{hyperref}, \pkg{nameref} and
407 \pkg{cleveref} offer ways of ``automagically'' knowing that
408 |\label{foo}| was inside a theorem, so that a reference adds the
409 string ``Theorem''. This is all done for you, but there's one catch: you
410 have to tell \thmtools\ what the name to add is. By default, it will use
411 the title of the theorem, in particular, it will be uppercased.
412 (This happens to match the guidelines of all
413 publishers I have encountered.) But there is an alternate spelling
414 available, denoted by a capital letter, and in any case, if you use
415 \pkg{cleveref}, you should give two values separated by a comma, because
416 it will generate plural forms if you reference many theorems in one
417 |\cite|.
418 \begin{source}
419 \begin{preamble}[gobble=6]
420 \usepackage{amsthm, thmtools}
421 \usepackage{
422 hyperref,%\autoref
423 % n.b. \Autoref is defined by thmtools
424 cleveref,% \cref
425 % n.b. cleveref after! hyperref
426 }
427 \declaretheorem[name=Theorem,
428 refname={theorem,theorems},
429 Refname={Theorem,Theorems}]{callmeal}
430 \end{preamble}
431 \begin{body}[gobble=6]
432 \begin{callmeal}[Simon]\label{simon}
433 One
434 \end{callmeal}
435 \begin{callmeal}\label{garfunkel}
436 and another, and together,
437 \autoref{simon}, ``\nameref{simon}'',
438 and \cref{garfunkel} are referred
439 to as \cref{simon,garfunkel}.
440 \Cref{simon,garfunkel}, if you are at
441 the beginning of a sentence.
442 \end{callmeal}
443 \end{body}
444 \end{source}
445 \begin{result}
446 \begin{callmeal}[Simon]\label{simon}
447 One
448 \end{callmeal}
449 \begin{callmeal}\label{garfunkel}
450 and another, and together, \autoref{simon}, ``\nameref{simon}'',
451 and \cref{garfunkel} are referred to as \cref{simon,garfunkel}.
452 \Cref{simon,garfunkel}, if you are at the beginning of a sentence.
453 \end{callmeal}
454 \end{result}
455
456 \section{Styling theorems}
457 \label{sec:styling}
458
459 The major backends provide a command |\theoremstyle| to switch
460 between looks of theorems. This is handled as follows:
461 \begin{source}
462 \begin{preamble}[gobble=4]
463 \usepackage{amsthm}
464 \usepackage{thmtools}
465 \declaretheorem[style=remark]{remark}
466 \declaretheorem{Theorem}
467 \end{preamble}
468 \begin{body}[gobble=4]
469 \begin{Theorem}
470 Note how it still retains the default style,
471 `plain'.
472 \end{Theorem}
473 \begin{remark}
474 This is a remark.
475 \end{remark}
476 \end{body}
477 \end{source}
478 \begin{result}
479 \begin{Theorem}
480 Note how it still retains the default style,
481 `plain'.
482 \end{Theorem}
483 \begin{remark}
484 This is a remark.
485 \end{remark}
486 \end{result}
487
488 \newpage
489 Thmtools also supports the \pkg{shadethm} and \pkg{thmbox} packages:
490 \begin{source}
491 \begin{preamble}[gobble=4]
492 \usepackage{amsthm}
493 \usepackage{thmtools}
494 \usepackage[dvipsnames]{xcolor}
495 \declaretheorem[shaded={bgcolor=Lavender,
496 textwidth=12em}]{BoxI}
497 \declaretheorem[shaded={rulecolor=Lavender,
498 rulewidth=2pt, bgcolor={rgb}{1,1,1}}]{BoxII}
499 \end{preamble}
500 \begin{body}[gobble=4]
501 \begin{BoxI}[Euclid]
502 For every prime $p$, there is a prime $p'>p$.
503 In particular, there are infinitely many primes.
504 \end{BoxI}
505 \begin{BoxII}[Euclid]
506 For every prime $p$, there is a prime $p'>p$.
507 In particular, there are infinitely many primes.
508 \end{BoxII}
509 \end{body}
510 \end{source}
511 \begin{result}
512 \begin{BoxI}
513 For every prime $p$, there is a prime $p'>p$.
514 In particular, there are infinitely many primes.
515 \end{BoxI}
516 \begin{BoxII}
517 For every prime $p$, there is a prime $p'>p$.
518 In particular, there are infinitely many primes.
519 \end{BoxII}
520 \end{result}
521
522 As you can see, the color parameters can take two forms: it's either the
523 name of a color that is already defined, without curly braces, or it can
524 start with a curly brace, in which case it is assumed that
525 |\definecolor{colorname}|$\langle$\textsl{what you said}$\rangle$ will be
526 valid \LaTeX\ code. In our case, we use the |rgb| model to manually specify
527 white. (|shadethm|'s default background color is {\fboxsep=0pt \fcolorbox{black}[gray]{0.92}{\phantom{XX}}} |[gray]{0.92}|)
528
529 For the \pkg{thmbox} package, use the |thmbox| key:
530 \begin{source}
531 \begin{preamble}[gobble=4]
532 \usepackage{amsthm}
533 \usepackage{thmtools}
534 \declaretheorem[thmbox=L]{boxtheorem L}
535 \declaretheorem[thmbox=M]{boxtheorem M}
536 \declaretheorem[thmbox=S]{boxtheorem S}
537 \end{preamble}
538 \begin{body}[gobble=4]
539 \begin{boxtheorem L}[Euclid]
540 For every prime $p$, there is a prime $p'>p$.
541 In particular, there are infinitely many primes.
542 \end{boxtheorem L}
543 \begin{boxtheorem M}[Euclid]
544 For every prime $p$, there is a prime $p'>p$.
545 In particular, there are infinitely many primes.
546 \end{boxtheorem M}
547 \begin{boxtheorem S}[Euclid]
548 For every prime $p$, there is a prime $p'>p$.
549 In particular, there are infinitely many primes.
550 \end{boxtheorem S}
551 \end{body}
552 \end{source}
553 \begin{result}
554 \begin{boxtheorem L}[Euclid]
555 For every prime $p$, there is a prime $p'>p$.
556 In particular, there are infinitely many primes.
557 \end{boxtheorem L}
558 \begin{boxtheorem M}[Euclid]
559 For every prime $p$, there is a prime $p'>p$.
560 In particular, there are infinitely many primes.
561 \end{boxtheorem M}
562 \begin{boxtheorem S}[Euclid]
563 For every prime $p$, there is a prime $p'>p$.
564 In particular, there are infinitely many primes.
565 \end{boxtheorem S}
566 \end{result}
567
568 Note that for both |thmbox| and |shaded| keys, it's quite possible they will not
569 cooperate with a style key you give at the same time.
570
571 \newpage
572 \subsection{Declaring new theoremstyles}
573
574 \Thmtools\ also offers a new command to define new theoremstyles. It is
575 partly a frontend to the |\newtheoremstyle| command of \pkg{amsthm} or
576 \pkg{ntheorem}, but it offers (more or less successfully) the settings of both to
577 either. So we are talking about the same things, consider the sketch in
578 \autoref{fig:params}. To get a result like that, you would use something
579 like
580 \begin{source}
581 \begin{preamble}[gobble=4]
582 \declaretheoremstyle[
583 spaceabove=6pt, spacebelow=6pt,
584 headfont=\normalfont\bfseries,
585 notefont=\mdseries, notebraces={(}{)},
586 bodyfont=\normalfont,
587 postheadspace=1em,
588 qed=\qedsymbol
589 ]{mystyle}
590 \declaretheorem[style=mystyle]{styledtheorem}
591 \end{preamble}
592 \begin{body}[gobble=4]
593 \begin{styledtheorem}[Euclid]
594 For every prime $p$\dots
595 \end{styledtheorem}
596 \end{body}
597 \end{source}
598 \begin{result}
599 \begin{styledtheorem}[Euclid]
600 For every prime $p$\dots
601 \end{styledtheorem}
602 \end{result}
603 Again, the defaults are reasonable and you don't
604 have to give values for everything.
605
606 There is one important thing you cannot see in this example: there are
607 more keys you can pass to |\declaretheoremstyle|: if \thmtools\ cannot
608 figure out at all what to do with it, it will pass it on to the
609 |\declaretheorem| commands that use that style. For example, you may use
610 the |boxed| and |shaded| keys here.
611
612 To change the order in which title, number and note appear, there is a key
613 |headformat|. Currently, the values ``margin'' and ``swapnumber'' are
614 supported. The daring may also try to give a macro here that uses the
615 commands |\NUMBER|, |\NAME| and |\NOTE|.
616 You cannot circumvent the fact
617 that |headpunct| comes at the end, though, nor the fonts and braces you
618 select with the other keys.
619
620 \begin{figure}
621 \centering
622 \fbox{%
623 \begin{tikzpicture}[
624 remember picture,
625 >=latex,
626 nodes={
627 font=\normalfont\sffamily\itshape\small,
628 RoyalBlue
629 },
630 every subnode/.style={
631 inner sep=0pt
632 },
633 tip/.style={|<->|}
634 ]
635 \node[black, font=\Large, text width=.618\textwidth, align=justify]
636 {%
637 which resulted in the following insight: \\
638 \subnode{space above}{\rule{0pt}{1.3\baselineskip}} \\
639 \subnode{head indent}{\strut\hspace*{4em}}
640 \textbf{%
641 \subnode{head}{Theorem} 1.2
642 \subnode{note brace}{(}%
643 \subnode{note}{\textit{Euclid}})%
644 \subnode{head punct}{.} %
645 }
646 \subnode{post head space}{\strut\hspace*{4.5em}}
647 For every prime~$p$, there is a prime~$p'>p$. In particular, the list
648 of primes, $2,3,5,7,\dots$, is infinite. \hfill
649 \subnode{qed}{$\Box$} \\
650 \subnode{space below}{\rule{0pt}{1.3\baselineskip}} \\
651 As a consequence, lorem ipsum dolor sit amet frob-%nicate foo
652 % paret.
653 };
654
655 \draw[tip] (space above.south west) -- node[right] {spaceabove} (space above.north west);
656 \draw[tip] (head indent.west) -- node[above] {headindent} (head indent.east);
657 \draw (head.center) -- +(0, 10pt) node[above] {headfont};
658 \draw (note brace.north) -- +(0, 20pt) node[above] {notebraces};
659 \draw (note.center) -- +(0, 10pt) node[above] {notefont};
660 \draw (head punct.base east) -- +(0, 28pt) node[above] {headpunct};
661 \draw[tip] (post head space.west) -- node[above] {postheadspace} (post head space.east);
662 \node at ([xshift=-12pt]qed.150) {qed};
663 \draw[tip] (space below.south west) -- node[right] {spacebelow} (space below.north west);
664 \end{tikzpicture}%
665 }
666 \caption{Settable parameters of a theorem style.}
667 \label{fig:params}
668 \end{figure}
669
670 \newpage
671 \section{Repeating theorems}
672
673 Sometimes, you want to repeat a theorem you have given in full earlier,
674 for example you either want to state your strong result in the
675 introduction and then again in the full text, or you want to re-state a
676 lemma in the appendix where you prove it. For example, I lied about
677 \autoref{thm:euclid} on p.\,\pageref{thm:euclid}: the true code used was
678 \begin{source}
679 \begin{preamble}[gobble=6]
680 \usepackage{thmtools, thm-restate}
681 \declaretheorem{theorem}
682 \end{preamble}
683 \begin{body}[gobble=6]
684 \begin{restatable}[Euclid]{theorem}{firsteuclid}
685 \label{thm:euclid}%
686 For every prime $p$, there is a prime $p'>p$.
687 In particular, the list of primes,
688 \begin{equation}\label{eq:1}
689 2,3,5,7,\dots
690 \end{equation}
691 is infinite.
692 \end{restatable}
693 \end{body}
694 and to the right, I just use
695 \begin{body}[gobble=6]
696 \firsteuclid*
697 \vdots
698 \firsteuclid*
699 \end{body}
700 \end{source}
701 \begin{result}
702 \firsteuclid*
703 \vdots
704 \firsteuclid*
705 \end{result}
706
707 Note that in spite of being a theorem-environment, it gets number one all
708 over again. Also, we get equation number~\eqref{eq:1} again. The star in
709 |\firsteuclid*| tells thmtools that it should redirect the label
710 mechanism, so that this reference: \autoref{thm:euclid} points to
711 p.\,\pageref{thm:euclid}, where the unstarred environment is used. (You can
712 also use a starred environment and an unstarred command, in which case the
713 behaviour is reversed.) Also, if you use \pkg{hyperref} (like you see in this manual), the links will lead you
714 to the unstarred occurence.
715
716 Just to demonstrate that we also handle more involved cases, I repeat
717 another theorem here, but this one was numbered within its section: note
718 we retain the section number which does not fit the current section:
719 \begin{source}
720 \begin{body}[gobble=6]
721 \euclidii*
722 \end{body}
723 \end{source}
724 \begin{result}
725 \euclidii*
726 \end{result}
727
728 \newpage
729 \section{Lists of theorems}
730
731 To get a list of theorems with default formatting, just use
732 |\listoftheorems|:
733 \begin{source}
734 \begin{body}[gobble=6]
735 \listoftheorems
736 \end{body}
737 \end{source}
738 \begin{result}
739 \let\chapter\section
740 \let\clearpage\relax
741 \listoftheorems
742 \end{result}
743
744 Not everything might be of the same importance, so you can filter out
745 things by environment name:
746 \begin{source}
747 \begin{body}[gobble=6]
748 \listoftheorems[ignoreall,
749 show={theorem,Theorem,euclid}]
750 \end{body}
751 \end{source}
752 \begin{result}
753 \let\chapter\section
754 \let\clearpage\relax
755 \listoftheorems[ignoreall, show={theorem,Theorem,euclid}]
756 \end{result}
757
758 And you can also restrict to those environments that have an optional
759 argument given. Note that two theorems disappear compared to the previous
760 example. You could also say just |onlynamed|, in which case it will
761 apply to \emph{all} theorem environments you have defined.
762 \begin{source}
763 \begin{body}[gobble=6]
764 \listoftheorems[ignoreall,
765 onlynamed={theorem,Theorem,euclid}]
766 \end{body}
767 \end{source}
768 \begin{result}
769 \let\chapter\section
770 \let\clearpage\relax
771 \listoftheorems[ignoreall, onlynamed={theorem,Theorem,euclid}]
772 \end{result}
773
774 As might be expected, the heading given is defined in |\listtheoremname|.
775 %And finally, you can configure |\listoftheorems| in advance by |\setlisttheoremstyle{keys}|.
776
777 \section{Extended arguments to theorem environments}
778
779 Usually, the optional argument of a theorem serves just to give a note
780 that is shown in the theorem's head. \Thmtools\ allows you to have a
781 key-value list here as well. The following keys are known right now:
782 \begin{description}
783 \item[name] This is what used to be the old argument. It usually holds
784 the name of the theorem, or a source. This key also accepts an
785 \emph{optional} argument, which will go into the list of theorems. Be
786 aware that since we already are within an optional argument, you have to
787 use an extra level of curly braces:
788 |\begin{theorem}[name={[Short name]A long name,...]}|
789
790 \item[label] This will issue a |\label| command after the head. Not very
791 useful, more of a demo.
792
793 \item[continues] Saying |continues=foo| will cause the number that is
794 given to be changed to |\ref{foo}|, and a text is added to the note.
795 (The exact text is given by the macro |\thmcontinues|, which takes the
796 label as its argument.)
797
798 \item[restate] Saying |restate=foo| will hopefully work like
799 wrapping this theorem in a restatable environment. (It probably still fails
800 in cases that I didn't think of.) This key also accepts an optional
801 argument: when restating, the restate key is replaced by this argument,
802 for example, |restate=[name=Boring rehash]foo| will result in a
803 different name. (Be aware that it is possible to give the same key
804 several times, but I don't promise the results. In case of the name key,
805 the names happen to override one another.)
806 \end{description}
807 \begin{source}
808 \begin{body}[gobble=6]
809 \begin{theorem}[name=Keyed theorem,
810 label=thm:key]
811 This is a
812 key-val theorem.
813 \end{theorem}
814 \begin{theorem}[continues=thm:key]
815 And it's spread out.
816 \end{theorem}
817 \end{body}
818 \end{source}
819 \begin{result}
820 \begin{theorem}[name=Keyed theorem,
821 label=thm:key]
822 This is a key-val theorem.
823 \end{theorem}
824 \begin{theorem}[continues=thm:key]
825 And it's spread out.
826 \end{theorem}
827 \end{result}
828
829
830
831 \chapter{\Thmtools for the extravagant}\label{cha:extravagant}
832
833 This chapter will go into detail on the slightly more technical offerings
834 of this bundle. In particular, it will demonstrate how to use the general
835 hooks provided to extend theorems in the way you want them to behave.
836 Again, this is done mostly by some examples.
837
838 \section{Understanding \thmtools' extension mechanism}
839
840 \Thmtools\ draws most of its power really only from one feature:
841 the |\newtheorem| of the backend will, for example, create
842 a theorem environment, i.e. the commands |\theorem| and
843 |\endtheorem|. To add functionality, four places immediately
844 suggest themselves: ``immediately before'' and ``immediately after'' those
845 two.
846
847 There are two equivalent ways of adding code there: one is to call
848 |\addtotheorempreheadhook| and its brothers and sisters
849 |...postheadhook|, |...prefoothook|
850 and |...postfoothook|.
851 All of these take an \emph{optional} argument, the name of the
852 environment, and the new code as a mandatory argument. The name of environment is
853 optional because there is also a set of ``generic'' hooks added to every
854 theorem that you define.
855
856 The other way is to use the keys |preheadhook| et al. in your
857 |\declaretheorem|. (There is no way of accessing the generic
858 hook in this way.)
859
860 The hooks are arranged in the following way: first the specific prehead,
861 then the generic one. Then, the original |\theorem| (or
862 whatever) will be called. Afterwards, first the specific posthead again,
863 then the generic one. (This means that you cannot wrap the head alone in
864 an environment this way.) At the end of the theorem, it is the other way
865 around: first the generic, then the specific, both before and after that
866 |\endtheorem|. This means you can wrap the entire theorem
867 easily by adding to the prehead and the postfoot hooks. Note that
868 \thmtools\ does not look inside |\theorem|, so you cannot get
869 inside the head formatting, spacing, punctuation in this way.
870
871 In many situations, adding static code will not be enough. Your code can
872 look at |\thmt@envname|, |\thmt@thmname| and
873 |\thmt@optarg|, which will contain the name of the environment,
874 its title, and, if present, the optional argument (otherwise, it is
875 |\@empty|).
876 \emph{However}, you should not make assumptions about the optional
877 argument in the preheadhook: it might still be key-value, or it might
878 already be what will be placed as a note. (This is because the key-val
879 handling itself is added as part of the headkeys.)
880
881
882 \section{Case in point: the \texttt{shaded} key}
883
884 Let us look at a reasonably simple example: the |shaded| key, which we've
885 already seen in the first section. You'll observe that we run into a
886 problem similar to the four-hook mess: your code may either want to modify
887 parameters that need to be set beforehand, or it wants to modify the
888 environment after it has been created. To hide this from the user, the
889 code you define for the key is actually executed twice, and
890 |\thmt@trytwice{A}{B}| will execute A on the first pass, and B
891 on the second. Here, we want to add to the hooks, and the hooks are only
892 there in the second pass.
893
894 \DocInput{thmdef-shaded.dtx}
895
896 \section{Case in point: the \texttt{thmbox} key}
897
898 \DocInput{thmdef-thmbox.dtx}
899
900 \section{Case in point: the \texttt{mdframed} key}
901 \DocInput{thmdef-mdframed.dtx}
902
903 \section{How \thmtools\ finds your extensions}
904
905 Up to now, we have discussed how to write the code that adds functionality
906 to your theorems, but you don't know how to activate it yet.
907 Of course, you can put it in your preamble, likely embraced by
908 |\makeatletter| and |\makeatother|, because you are
909 using internal macros with @ in their name (viz.,
910 |\thmt@envname| and friends). You can also put them into a
911 package (then, without the |\makeat...|),
912 which is simply a file ending in |.sty| put somewhere that \LaTeX\ can find
913 it, which can then be loaded with |\usepackage|.
914 To find out where exactly that is, and if you'd need to update
915 administrative helper files such as a filename database FNDB,
916 please consult the documentation of your \TeX\ distribution.
917
918 Since you most likely want to add keys as well, there is a shortcut that
919 \thmtools\ offers you: whenever you use a key |key| in a
920 |\declaretheorem| command, and \thmtools\ doesn't already know
921 what to do with it, it will try to |\usepackage{thmdef-key}| and
922 evaluate the key again. (If that doesn't work, \thmtools\ will cry
923 bitterly.)
924
925 For example, there is no provision in \thmtools\ itself that make the
926 |shaded| and |thmbox| keys described above special:
927 in fact, if you want to use a different package to create frames, you just
928 put a different |thmdef-shaded.sty| into a preferred texmf tree.
929 Of course, if your new package doesn't offer the old keys, your old
930 documents might break!
931
932 The behaviour for the keys in the style definition is slightly different:
933 if a key is not known there, it will be used as a ``default key'' to every
934 theorem that is defined using this style. For example, you can give the
935 |shaded| key in a style definition.
936
937 Lastly, the key-val arguments to the theorem environments themselves need
938 to be loaded manually, not least because inside the document it's too late
939 to call |\usepackage|.
940
941 \chapter{\Thmtools for the completionist}\label{cha:reference}
942
943 This will eventually contain a reference to all known keys, commands, etc.
944
945
946 \section{Known keys to \texttt{\textbackslash declaretheoremstyle}}
947 \def\keydefaultcontext{declaretheoremstyle}
948
949 N.b. implementation for \pkg{amsthm} and \pkg{ntheorem} is separate for
950 these, so if it doesn't work for \pkg{ntheorem}, try if it works with
951 \pkg{amsthm}, which in general supports more things.
952
953 Also, all keys listed as known to |\declaretheorem| are valid.
954
955 \key{spaceabove} Value: a length. Vertical space above the theorem,
956 possibly discarded if the theorem is at the top of the page.
957
958 \key{spacebelow} Value: a length. Vertical space after the theorem,
959 possibly discarded if the theorem is at the top of the page.
960
961 \key{headfont} Value: \TeX\ code. Executed just before the head of the
962 theorem is typeset, inside a group. Intended use it to put font switches here.
963
964 \key{notefont}
965 Value: \TeX\ code. Executed just before the note in the head is typeset, inside a group.
966 Intended use it to put font switches here. Formatting also applies to
967 the braces around the note.
968 Not supported by \pkg{ntheorem}.
969
970 \key{bodyfont}
971 Value: \TeX\ code. Executed before the begin part of the theorem ends,
972 but before all afterheadhooks. Intended use it to put font switches here.
973
974 \key{headpunct}
975 Value: \TeX\ code, usually a single character. Put at the end of the
976 theorem's head, prior to linebreaks or indents.
977
978 \key{notebraces}
979 Value: Two characters, the opening and closing symbol to use around a
980 theorem's note.
981 (Not supported by \pkg{ntheorem}.)
982
983 \key{postheadspace}
984 Value: a length. Horizontal space inserted after the entire head of the
985 theorem, before the body. Does probably not apply (or make sense) for
986 styles that have a linebreak after the head.
987
988 \key{headformat}
989 Value: \LaTeX\ code using the special placeholders |\NUMBER|, |\NAME|
990 and |\NOTE|, which correspond to the (formatted, including the braces
991 for |\NOTE| etc.) three parts of a theorem's head. This can be used to
992 override the usual style ``1.1 Theorem (Foo)'', for example to let the
993 numbers protude in the margin or put them after the name.
994
995 Additionally, a number of keywords are allowed here instead of \LaTeX\
996 code:
997 \begin{description}
998 \item[margin] Lets the number protrude in the (left) margin.
999
1000 \item[swapnumber] Puts the number before the name. Currently
1001 not working so well for unnumbered theorems.
1002 \item[] \emph{This list is likely to grow}
1003 \end{description}
1004
1005 \key{headindent}
1006 Value: a length. Horizontal space inserted before the head. Some
1007 publishers like |\parindent| here for remarks, for example.
1008
1009
1010 \section{Known keys to \texttt{\textbackslash declaretheorem}}
1011 \def\keydefaultcontext{declaretheorem}
1012
1013 \key{parent}
1014 Value: a counter name. The theorem will be reset whenever that counter
1015 is incremented. Usually, this will be a sectioning level, |chapter| or
1016 |section|.
1017
1018 \key{numberwithin}
1019 (Same as |parent|.)
1020
1021 \key{within}
1022 (Same as |parent|.)
1023
1024
1025 \key{sibling}
1026 Value: a counter name. The theorem will use this counter for numbering.
1027 Usually, this is the name of another theorem environment.
1028
1029 \key{numberlike}
1030 (Same as |sibling|.)
1031
1032 \key{sharenumber}
1033 (Same as |sibling|.)
1034
1035
1036 \key{title}
1037 Value: \TeX\ code. The title of the theorem. Default is the name of the
1038 environment, with |\MakeUppercase| prepended. You'll have to give
1039 this if your title starts with an accented character, for example.
1040
1041 \key{name}
1042 (Same as |title|.)
1043
1044 \key{heading}
1045 (Same as |title|.)
1046
1047 \key{numbered}
1048 Value: one of the keywords |yes|, |no| or |unless unique|. The theorem
1049 will be numbered, not numbered, or only numbered if it occurs more than
1050 once in the document. (The latter requires another \LaTeX\ run and works well combined with |sibling|.)
1051
1052 \key{style}
1053 Value: the name of a style defined with |\declaretheoremstyle| or
1054 |\newtheoremstyle|. The theorem will use the settings of this style.
1055
1056 \key{preheadhook}
1057 Value: \LaTeX\ code. This code will be executed at the beginning of the
1058 environment, even before vertical spacing is added and the head is
1059 typeset. However, it is already within the group defined by the
1060 environment.
1061
1062 \key{postheadhook}
1063 Value: \LaTeX\ code. This code will be executed after the call to the
1064 original begin-theorem code. Note that all backends seem to delay
1065 typesetting the actual head, so code here should probably enter
1066 horizontal mode to be sure it is after the head, but this will change
1067 the spacing/wrapping behaviour if your body starts with another list.
1068
1069 \key{prefoothook}
1070 Value: \LaTeX\ code. This code will be executed at the end of the body
1071 of the environment.
1072
1073 \key{postfoothook}
1074 Value: \LaTeX\ code. This code will be executed at the end of the
1075 environment, even after eventual vertical spacing, but still within the
1076 group defined by the environment.
1077
1078 \key{refname}
1079 Value: one string, or two strings separated by a comma (no spaces). This
1080 is the name of the theorem as used by |\autoref|, |\cref| and friends. If it is
1081 two strings, the second is the plural form used by |\cref|. Default
1082 value is the value of |name|, i.e. usually the environment name, with
1083 |\MakeUppercase| prepended.
1084
1085 \key{Refname}
1086 Value: one string, or two strings separated by a comma (no spaces). This
1087 is the name of the theorem as used by |\Autoref|, |\Cref| and friends. If it is
1088 two strings, the second is the plural form used by |\Cref|. This can be
1089 used for alternate spellings, for example if your style requests no
1090 abbreviations at the beginning of a sentence. No default.
1091
1092
1093 \key{shaded}
1094 Value: a key-value list, where the following keys are possible:
1095 \begin{description}
1096 \item[textwidth]
1097 The linewidth within the theorem.
1098 \item[bgcolor]
1099 The color of the background of the theorem. Either a color name or a
1100 color spec as accepted by |\definecolor|, such as |{gray}{0.5}|.
1101 \item[rulecolor]
1102 The color of the box surrounding the theorem. Either a color name or
1103 a color spec.
1104 \item[rulewidth]
1105 The width of the box surrounding the theorem.
1106 \item[margin]
1107 The length by which the shade box surrounds the text.
1108 \end{description}
1109
1110 \key{thmbox}
1111 Value: one of the characters |L|, |M| and |S|; see examples in \autoref{sec:styling}.
1112
1113
1114 \section{Known keys to in-document theorems}
1115 \def\keydefaultcontext{theorem}
1116
1117 \key{label} Value: a legal |\label| name.
1118 Issues a |\label| command after the theorem's head.
1119
1120 \key{name} Value: \TeX\ code that will be typeset.
1121 What you would have put in the optional argument in the
1122 non-keyval style, i.e. the note to the head. This is \emph{not} the same
1123 as the |name| key to |\declaretheorem|, you cannot override that from within
1124 the document.
1125
1126 \key{listhack} Value: doesn't matter. (But put something to trigger
1127 key-val behaviour, maybe |listhack=true|.) Linebreak styles in \pkg{amsthm}
1128 don't linebreak if they start with another list, like an |enumerate|
1129 environment. Giving the |listhack| key fixes that. \emph{Don't} give this
1130 key for non-break styles, you'll get too little vertical space! (Just use
1131 |\leavevmode| manually there.)
1132 An all-around |listhack| that handles both situations might come in a
1133 cleaner rewrite of the style system.
1134
1135 \section{Known keys to \texttt{\textbackslash listoftheorems}}
1136 \def\keydefaultcontext{listof}
1137
1138 \key{title} Value: title of |\listoftheorems|. Initially |List of Theorems|.
1139
1140 \key{ignore} Value: list of theorem environment names. Filter out things by environment names. Default value is list of all defined theorem environments.
1141
1142 \key{ignoreall} Ignore every theorem environment. This key is usually followed by keys |show| and |onlynamed|.
1143
1144 \key{show} Value: list of theorem environments. Leave theorems that belong to specified list and filter out others. Default value is list of all defined theorem environments.
1145
1146 \key{showall} The opposite effect of |ignoreall|.
1147
1148 \key{onlynamed} Value: list of theorem environments. Leave things that are given an optional argument and belong to specified list, and filter out others. Default value is list of all defined theorem environments.
1149
1150 \key{swapnumber} Value: |true| or |false|. Initially |false| and default value is |true|. No default.
1151 \begin{source}
1152 \begin{body}[gobble=6]
1153 \listoftheorems[ignoreall, onlynamed={lemma}]
1154 \listoftheorems[ignoreall, onlynamed={lemma},
1155 swapnumber
1156 ]
1157 \end{body}
1158 \end{source}
1159 \begin{result}
1160 \let\chapter\section
1161 \let\clearpage\relax
1162 \listoftheorems[ignoreall, onlynamed={lemma}]
1163 \vspace{-1ex}
1164 \listoftheorems[ignoreall, onlynamed={lemma}, swapnumber]
1165 \end{result}
1166
1167 \key{numwidth} Value: a length. If |swapnumber=false|, the theorem number is typeset in a box of of width |numwidth|. Initially |1.5pc| for AMS classes and |2.3em| for others.
1168
1169 \section{Restatable -- hints and caveats}
1170
1171 TBD.
1172 \begin{itemize}
1173 \item Some counters are saved so that the same values appear when you
1174 re-use them. The list of these counters is stored in the macro
1175 |\thmt@innercounters| as a comma-separated list without spaces; default: |equation|.
1176
1177 \item To preserve the influence of other counters (think: equation
1178 numbered per section and recall the theorem in another section), we need
1179 to know all macros that are used to turn a counter into printed output.
1180 Again, comma-separated list without spaces, without leading backslash, stored as
1181 |\thmt@counterformatters|. Default:
1182 |@alph,@Alph,@arabic,@roman,@Roman,@fnsymbol|.
1183 All these only take
1184 the \LaTeX\ counter |\c@foo| as arguments. If you bypass this and use
1185 |\romannumeral|, your numbers go wrong and you get what you deserve.
1186 Important if you have very strange numbering, maybe using greek letters
1187 or somesuch.
1188
1189 \item I think you cannot have one stored counter within another one's
1190 typeset representation. I don't think that ever occurs in reasonable
1191 circumstances, either. Only one I could think of: multiple subequation
1192 blocks that partially overlap the theorem. Dude, that doesn't even nest.
1193 You get what you deserve.
1194
1195 \item |\label| and \pkg{amsmath}'s |\ltx@label| are disabled inside the
1196 starred execution. Possibly, |\phantomsection| should be disabled as
1197 well?
1198 \end{itemize}
1199
1200 \appendix
1201
1202
1203 \chapter{\Thmtools for the morbidly curious}\label{cha:sourcecode}
1204
1205 This chapter consists of the implementation of \thmtools, in case you
1206 wonder how this or that feature was implemented. Read on if you want a
1207 look under the bonnet, but you enter at your own risk, and bring an oily
1208 rag with you.
1209
1210 \section{Core functionality}
1211
1212 \subsection{The main package}
1213 \DocInput{thmtools.dtx}
1214
1215 \subsection{Adding hooks to the relevant commands}
1216 \DocInput{thm-patch.dtx}
1217
1218 \subsection{The key-value interfaces}
1219 \DocInput{thm-kv.dtx}
1220
1221 \subsection{Lists of theorems}
1222 \DocInput{thm-listof.dtx}
1223
1224 \subsection{Re-using environments}
1225 \DocInput{thm-restate.dtx}
1226
1227 \subsection{Fixing \texttt{autoref} and friends}
1228 \DocInput{thm-autoref.dtx}
1229
1230 \section{Glue code for different backends}
1231
1232 \subsection{\texttt{amsthm}}
1233 \DocInput{thm-amsthm.dtx}
1234
1235 \subsection{\texttt{beamer}}
1236 \DocInput{thm-beamer.dtx}
1237
1238 \subsection{\texttt{ntheorem}}
1239 \DocInput{thm-ntheorem.dtx}
1240
1241 \section{Generic tools}
1242
1243 \subsection{A generalized argument parser}
1244 \DocInput{parseargs.dtx}
1245
1246 \subsection{Different counters sharing the same register}
1247 \DocInput{aliasctr.dtx}
1248
1249 \subsection{Tracking occurrences: none, one or many}
1250 \DocInput{unique.dtx}
1251
1252
1253
1254
1255 \end{document}