0% found this document useful (0 votes)
15 views24 pages

Keytheorems

The keytheorems package (version 0.2.4) is an expl3 implementation of a key-value interface to amsthm, designed to enhance functionality while avoiding issues found in thmtools. It includes features for defining theorems, managing theorem styles, and listing theorems, with various global options and dependencies outlined. The package aims to provide a more flexible and user-friendly approach to theorem management in LaTeX documents.

Uploaded by

leto.cave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views24 pages

Keytheorems

The keytheorems package (version 0.2.4) is an expl3 implementation of a key-value interface to amsthm, designed to enhance functionality while avoiding issues found in thmtools. It includes features for defining theorems, managing theorem styles, and listing theorems, with various global options and dependencies outlined. The package aims to provide a more flexible and user-friendly approach to theorem management in LaTeX documents.

Uploaded by

leto.cave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

keytheorems package

version 0.2.4
github.com/mbertucci47/keytheorems

Matthew Bertucci
January 21, 2025

Abstract
An expl3-implementation of a key-value interface to amsthm, implementing most
of the functionality provided by thmtools. Several issues encountered with thmtools
are avoided (see the README for a list) and a few new features are added.

Contents
1 Dependencies 2

2 Global options 2
2.1 Compatibility options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Other global options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3 Defining theorems 3
3.1 Keys available to theorem environments . . . . . . . . . . . . . . . . . . 4
3.2 Keys also defined in thmtools . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Keys added by keytheorems . . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Theorem styles 13
4.1 Keys also defined in thmtools . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Keys added by keytheorems . . . . . . . . . . . . . . . . . . . . . . . . . 14

5 Restating theorems 15

6 Listing theorems 15
6.1 Keys also defined in thmtools . . . . . . . . . . . . . . . . . . . . . . . . 16
6.2 Keys added by keytheorems . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.3 Adding code to list of theorems . . . . . . . . . . . . . . . . . . . . . . . 18

7 Theorem hooks 19

8 Miscellaneous notes 20
8.1 beamer support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8.2 Support for other classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8.3 Support for font packages . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8.4 Support for tagged PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8.5 Public coding interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

1
9 Further examples 21

Index 22

1 Dependencies
The package depends on the aliascnt, amsthm, refcount, and translations packages.
The tcolorboxÕ P. 11 and tcolorbox-no-titlebarÕ P. 12 keys require tcolorbox, and the
numbered=unless-uniqueÕ P. 8 key requires the unique package. A LATEX kernel no older
than 2023-06-01 is required; if older than 2024-06-01, nameref is required.

2 Global options
\keytheoremset{⟨options⟩}
Every key in this section can be given as an option to \usepackage or in
\keytheoremset, with the exception that continues-codeÕ P. 3 can only be used
in the latter.

2.1 Compatibility options


overload (initially unset)
Redefines \newtheorem to internally use the keytheorems machinery. The syntax
remains the same. This is automatically set by thmtools-compat.

thmtools-compat (initially unset)


For compatibility with thmtools syntax. For most documents,

\usepackage[thmtools-compat]{keytheorems}

should be a drop-in replacement for \usepackage{amsthm,thmtools}. The op-


tion defines the commands in the left column below. The right column lists the
corresponding keytheorems replacement that should be used in new documents.
thmtools command keytheorems replacement
\declaretheorem → \newkeytheoremÕ P. 3
\declaretheoremstyle → \newkeytheoremstyleÕ P. 13
\listoftheorems → \listofkeytheoremsÕ P. 15
\listtheoremname → titleÕ P. 17 key
\addtotheorempreheadhook
\addtotheorempostheadhook
→ \addtotheoremhookÕ P. 19
\addtotheoremprefoothook
\addtotheorempostfoothook
restatable environment → storeÕ P. 5 key
restatable* environment → store*Õ P. 5 key
Also defined are the shaded and thmbox keys, implemented internally with tcolorbox
rather than the shadethm and thmbox packages, respectively.

2.2 Other global options


auto-translate=true|false (default true, initially true)

2
If false, keytheorems does not automatically translate the title text used for
\listofkeytheoremsÕ P. 15 and the note produced by the continuesÕ P. 5 key.
These texts can be manually customized with the titleÕ P. 17 and continues-
codeÕ P. 3 keys, respectively.

continues-code=⟨code with #1⟩ (initially


\GetTranslation{keythms_continues}\pageref{#1})
The code used to typeset the note produced by the continuesÕ P. 5 key. If English
or an unknown language is used, defaults to continuing from p.\,\pageref{#1}.
Currently (likely inaccurate!) translations exist for several European languages.

qed-symbol=⟨symbol⟩ (initially \openbox)


Redefines \qedsymbol to be ⟨symbol⟩.

restate-counters={⟨comma-list of counters⟩} (initially {equation})


Additional counters whose values are preserved when a theorem is restated. This
key does not reset the list, so you don’t need to include equation in ⟨comma-list⟩.

store-all (initially unset)


Tells keytheorems to grab the body of each theorem so it can later be printed with
the print-bodyÕ P. 18 option of \listofkeytheoremsÕ P. 15 . Note that this means
a theorem body cannot contain verbatim material.

store-sets-label (initially unset)


Õ P. 5 Õ P. 4
Defines the store key to also set label , i.e. it makes store=⟨tag⟩ equiv-
alent to store=⟨tag⟩,label=⟨tag⟩. Similarly for store*Õ P. 5 .

3 Defining theorems
\newkeytheorem{⟨env name⟩}[⟨options⟩]
Defines a theorem environment ⟨env name⟩ which itself takes a few options (see
subsection 3.1). You can also declare multiple theorems at once by replacing ⟨env
name⟩ with a comma-list of names, e.g.
\newkeytheorem{theorem,lemma,proposition}[⟨options⟩].
By default, the theorem’s printed name is a title-cased ⟨env name⟩. This can
be changed with the nameÕ P. 8 key. All ⟨options⟩ are described in subsections 3.2
and 3.3.

% preamble
\newkeytheorem{theorem}
% document
\begin{theorem}
There are infinitely many prime numbers.
\end{theorem}

Theorem 1. There are infinitely many prime numbers.

\renewkeytheorem{⟨env name⟩}[⟨options⟩]
\providekeytheorem{⟨env name⟩}[⟨options⟩]

3
\declarekeytheorem{⟨env name⟩}[⟨options⟩]
Sometimes a package or class defines theorems that need to be overwritten by
the user. For this case, keytheorems provides \renewkeytheorem which redefines
⟨env name⟩ or errors if it is not defined. For completeness, also provided are
\providekeytheorem and \declarekeytheorem. The former only defines ⟨env
name⟩ if it is not already defined; the latter always overwrites ⟨env name⟩.

3.1 Keys available to theorem environments


As in amsthm, theorems can take an optional argument that contains a note or heading.

\begin{theorem}[Bertrand's postulate]
For every $n\geq 1$, there is a prime number $p$ with $n<p\leq 2n$.
\end{theorem}

Theorem 2 (Bertrand’s postulate). For every 𝑛 ≥ 1, there is a prime number 𝑝


with 𝑛 < 𝑝 ≤ 2𝑛.

Alternatively, the optional argument may contain any of the following keys.

note=⟨text⟩ (initially unset)


Alias name. This is the key-value equivalent of the optional argument described
above. This syntax, however, allows the argument to contain other keys.

\begin{theorem}[note=Legendre's formula]
The number $n!$ contains the prime factor $p$ exactly
\[ \sum_{k\geq 1} \Bigl\lfloor\frac{n}{p^k}\Bigr\rfloor \]
times.
\end{theorem}

Theorem 3 (Legendre’s formula). The number 𝑛! contains the prime factor


𝑝 exactly
𝑛
∑⌊ 𝑘 ⌋
𝑘≥1
𝑝
times.

short-note=⟨text⟩ (initially unset)


Alias short-name. This replaces the value of note when displayed in the list of
theorems (\listofkeytheoremsÕ P. 15 ).

label=⟨label name⟩ (initially unset)


This is the key-value equivalent of \begin{theorem} \label{⟨label name⟩}.

\begin{theorem}[label=bezout]
Let $a$ and $b$ be integers. Then there exist integers $x$ and $y$
such that $ax+by=\gcd(a,b)$.
\end{theorem}
See \zcref{bezout}.

4
Theorem 4. Let 𝑎 and 𝑏 be integers. Then there exist integers 𝑥 and 𝑦 such
that 𝑎𝑥 + 𝑏𝑦 = gcd(𝑎, 𝑏).

See theorem 4.

manual-num={⟨text⟩} (initially unset)


Use this to override the printed number of a theorem. It is useful for making
“starred” versions of other theorems, perhaps to represent a reformulated or more
difficult version.

\begin{theorem}[manual-num=\ref*{bezout}*]
Let $a_1,\dots,a_n$ be integers. Then there exist integers
$x_1,\dots,x_n$ such that $a_1x_1+\dots+a_nx_n=\gcd(a_1,\dots,a_n)$.
\end{theorem}
\begin{theorem}[manual-num=\faRocket] % requires fontawesome5
Don't confuse your readers by changing the numbering without good
reason.
\end{theorem}

Theorem 4*. Let 𝑎1 , … , 𝑎𝑛 be integers. Then there exist integers 𝑥1 , … , 𝑥𝑛


such that 𝑎1 𝑥1 + ⋯ + 𝑎𝑛 𝑥𝑛 = gcd(𝑎1 , … , 𝑎𝑛 ).
Theorem ROCKET. Don’t confuse your readers by changing the numbering without
good reason.

continues*=⟨label name⟩ (initially unset)


Pick up a theorem where you left off. The theorem number remains the same. The
printed text can be customized with the continues-codeÕ P. 3 option. The starred
version also copies the theorem note, if it exists.

\begin{theorem}[continues=bezout]
Moreover, the integers of the form $az+bt$ are exactly the multiples
of $\gcd(a,b)$.
\end{theorem}

Theorem 4 (continuing from p. 5). Moreover, the integers of the form 𝑎𝑧+𝑏𝑡
are exactly the multiples of gcd(𝑎, 𝑏).

store*=⟨tag⟩ (initially unset)


Alias restate*. Stores the the theorem to be restated at any point in the document
with \getkeytheoremÕ P. 15 . With the starred version, counters and labels are taken
from the copy called with \getkeytheorem, so in this case can only be restated once.
This allows you, for example, to write all theorems and proofs in the appendix and
call \getkeytheorem at the appropriate time mid-document. For the numbering
to be correct, the unstarred key will need at most two runs and the starred key at
most three runs.

\begin{theorem}[store=blub]
A theorem worth restating.
\end{theorem}

5
More brilliant mathematics.
\getkeytheorem{blub}

Theorem 5. A theorem worth restating.


More brilliant mathematics.

Theorem 5. A theorem worth restating.

A theorem given this key cannot contain verbatim material or other unexpected
catcodes such as a tikz-cd diagram. The latter issue can be averted with the
ampersand-replacement key.

% preamble
\usepackage{tikz}
\usetikzlibrary{cd}
% document
\begin{lemma}[store=fiberprod]
For any $S$-schemes $X$ and $Y$, there exists a scheme $X\times_S Y$
with morphisms to $X$ and $Y$ such that the diagram
\[\begin{tikzcd}[ampersand replacement=\&]
X\times_S Y \ar[r] \ar[d] \& X \ar[d] \\
Y \ar[r] \& S
\end{tikzcd}\]
commutes and is universal with respect to this property.
\end{lemma}
\dots
\getkeytheorem{fiberprod}

Lemma 6. For any 𝑆-schemes 𝑋 and 𝑌, there exists a scheme 𝑋 ×𝑆 𝑌 with


morphisms to 𝑋 and 𝑌 such that the diagram

𝑋 ×𝑆 𝑌 𝑋

𝑌 𝑆

commutes and is universal with respect to this property.



Lemma 6. For any 𝑆-schemes 𝑋 and 𝑌, there exists a scheme 𝑋 ×𝑆 𝑌 with
morphisms to 𝑋 and 𝑌 such that the diagram

𝑋 ×𝑆 𝑌 𝑋

𝑌 𝑆

commutes and is universal with respect to this property.

restate-keys={⟨list of keys⟩} (initially unset)


Allows passing different keys to the restated theorem. At the moment this is only

6
useful with the noteÕ P. 4 key.

\begin{theorem}[
store=rktest,
note=ORIGINAL,
restate-keys={note=RESTATED}
]
Wow, yet another theorem.
\end{theorem}
\getkeytheorem{rktest}

Theorem 7 (ORIGINAL). Wow, yet another theorem.


Theorem 7 (RESTATED). Wow, yet another theorem.

listhack=true|false (initially false)


Õ P. 14
Meant only to be used with the break style key for a theorem starting with a
list. Compare:

% preamble
\newkeytheoremstyle{breaksty}{break}
\newkeytheorem{observation}[style=breaksty]
% document
\begin{observation}
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
\end{observation}

\begin{observation}[listhack=true]
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
\end{observation}

Observation 1. 1. First item


2. Second item
Observation 2.

1. First item
2. Second item

Note that the value true must be explicitly set so that listhack is not inter-
preted as the note text.

seq=⟨name⟩ (initially unset)


Adds the theorem to a custom sequence ⟨name⟩ that can then be listed with
\listofkeytheorems[seq=⟨name⟩]. See seqÕ P. 18 for more details.

7
3.2 Keys also defined in thmtools
These are the [⟨options⟩] available to \newkeytheorem. Except for nameÕ P. 8 and
styleÕ P. 9 , each key below can also be used in \newkeytheoremstyleÕ P. 13 . For more
description, see the thmtools package.
name=⟨display name⟩ (initially title-cased ⟨env name⟩)
Aliases heading and title.

% preamble
\newkeytheorem{mythm}[name=Some Name]
% document
\begin{mythm}
Some text
\end{mythm}

Some Name 1. Some text

numbered=true|false|unless-unique (default true, initially true)


For compatibility with thmtools, also accepts the values yes, no, and unless
unique.

% preamble
\newkeytheorem{theorem*}[name=Theorem, numbered=false]
% document
\begin{theorem*}
An unnumbered theorem.
\end{theorem*}

Theorem. An unnumbered theorem.

parent=⟨counter⟩ (initially unset)


Aliases numberwithin and within.

% preamble
\newkeytheorem{conjecture}[parent=section]
% document
\begin{conjecture}
The first number is the section.
\end{conjecture}

Conjecture 3.1. The first number is the section.

sibling=⟨counter⟩ (initially unset)


Aliases numberlike and sharenumber.

% preamble
\newkeytheorem{lemma}[sibling=theorem]
% document

8
\begin{lemma}
This shares its counter with \texttt{theorem}.
\end{lemma}

Lemma 8. This shares its counter with theorem.

style=⟨style name⟩ (initially unset)


Õ P. 13
Accepts any ⟨style name⟩ defined by \newkeytheoremstyle , as well as any of
the predefined amsthm styles: plain, definition, and remark.

% preamble
\newkeytheorem{remark}[style=remark]
% document
\begin{remark}
It's nice to distinguish remarks from definitions and theorems.
\end{remark}

Remark 1. It’s nice to distinguish remarks from definitions and theorems.

preheadhook=⟨code⟩ (initially unset)


postheadhook=⟨code⟩ (initially unset)
prefoothook=⟨code⟩ (initially unset)
postfoothook=⟨code⟩ (initially unset)
Details in section 7.

% preamble
\newkeytheorem{test}[
preheadhook=PREHEAD,
postheadhook=POSTHEAD,
prefoothook=PREFOOT,
postfoothook=POSTFOOT
]
% document
\begin{test}
Some text
\end{test}

PREHEAD
Test 1. POSTHEADSome text PREFOOT
POSTFOOT

qed=⟨symbol⟩ (default \qedsymbol, initially unset)


Adds ⟨symbol⟩ to the end of the theorem body. If no value is given, the symbol
is used.

% preamble
\newkeytheorem{example}[qed]
\newkeytheorem{solution}[qed=$\clubsuit$]

9
% document
\begin{example}
Some text.
\end{example}
\begin{solution}
Some more text.
\end{solution}

Example 1. Some text.


Solution 1. Some more text. ♣

refname=⟨ref name⟩ or {⟨singular name⟩,⟨plural name⟩} (initially ⟨display name⟩)


If a single string, then the name used by hyperref’s \autoref, cleveref’s \cref, and
zref-clever’s \zcref. If two strings separated by a comma, then the second string is
the plural form used by \cref.

Refname=⟨ref name⟩ or {⟨singular name⟩,⟨plural name⟩} (initially ⟨display name⟩)


Same as refname but for \Autoref, \Cref, and \zcref with any of its capitalizing
options. Note that \Autoref is defined by keytheorems, but requires hyperref to
work. As with \autoref, there is also a starred version \Autoref* that suppresses
the hyperlink.

% preamble
\newkeytheorem{prop}[
name=Proposition,
refname={proposition,propositions},
Refname={Proposition,Propositions}
]
% document
\begin{prop}[label=abc]
Some text.
\end{prop}
\begin{prop}[label=def]
Some more text.
\end{prop}
Consider \zcref{abc,def}. \Autoref{abc} \dots

Proposition 1. Some text.

Proposition 2. Some more text.


Consider propositions 1 and 2. Proposition 1 …

The cleverefÕ CTAN package has not been updated since 2018 and contains sev-
eral incompatibilities with the LATEX kernel. These are often patched by the LATEX
! team, but further incompatibilities are likely to arise with each future update. For
this reason, I recommend moving to zref-cleverÕ CTAN . It offers all the same
features as cleveref and is actively maintained.

10
3.3 Keys added by keytheorems
leftmargin=⟨length⟩
rightmargin=⟨length⟩
Sets the left (respectively, right) margin of the theorem relative to the text width.
This sets the theorem apart from the text, similar to a block quote. The code was
adapted from Enrico Gregorio’s TEX Stack Exchange answers:
• How to change margins in enunciation (theorem-like environment)?
• A theoremstyle with complete indentation using amsthm

% preamble
\newcommand{\marginthmtext}{%
We need some text to show off theorems with margins. }
\newkeytheorem{quotethm}[
name=Quote Theorem,
leftmargin=1cm, rightmargin=1cm]
\newkeytheorem{indentedthm}[name=Indented Theorem, leftmargin=1cm]
% document
\marginthmtext\marginthmtext\marginthmtext

\begin{quotethm}
\marginthmtext\marginthmtext\marginthmtext
\end{quotethm}

\marginthmtext\marginthmtext\marginthmtext

\begin{indentedthm}
\marginthmtext\marginthmtext\marginthmtext
\end{indentedthm}

We need some text to show off theorems with margins. We need some text
to show off theorems with margins. We need some text to show off theorems
with margins.

Quote Theorem 1. We need some text to show off theorems


with margins. We need some text to show off theorems with
margins. We need some text to show off theorems with margins.
We need some text to show off theorems with margins. We need some
text to show off theorems with margins. We need some text to show off
theorems with margins.
Indented Theorem 1. We need some text to show off theorems with
margins. We need some text to show off theorems with margins. We
need some text to show off theorems with margins.

tcolorbox={⟨tcolorbox options⟩} (initially unset)


This key specifies that the theorem be placed inside a tcolorbox environment with
⟨options⟩. The theorem head is typeset as a tcolorbox title; to avoid this see
tcolorbox-no-titlebarÕ P. 12 .

11
% preamble
\tcbset{
defstyle/.style={
arc=0mm,
colback=blue!5!white,
colframe=blue!75!black
},
}
\newkeytheorem{corollary}[tcolorbox]
\newkeytheorem{definition}[style=definition, tcolorbox={defstyle}]
% document
\begin{corollary}
Some text.
\end{corollary}
\begin{definition}[A nice definition]
Some more text.
\end{definition}

Corollary 1.

Some text.

Definition 1 (A nice definition).

Some more text.

tcolorbox-no-titlebar={⟨tcolorbox options⟩} (initially unset)


Õ P. 11
Same usage as tcolorbox but the theorem head is typeset as usual, not as a
tcolorbox title.

% preamble
\newkeytheorem{boxcor}[
tcolorbox-no-titlebar={colback=red!10},
name=Corollary, sibling=corollary
]
% document
\begin{boxcor}
Some text.
\end{boxcor}

Corollary 2. Some text.

tcolorbox offers its own comprehensive theorems library. If all of your theorems are
to be tcolorboxes, I highly recommend using it instead of this package! However, if
only some of your theorems will use a tcolorbox, you may want to replicate the styles
of \NewTcbTheorem. Here is an example that emulates tcolorbox’s standard theorem
style.

12
% preamble
\tcbset{
thmstyle/.style={
colback=green!5,
colframe=green!35!black},
}
\newkeytheoremstyle{tcb-standard}{
tcolorbox=thmstyle,
headpunct={},
notebraces={}{},
noteseparator={: },
notefont=\bfseries,
bodyfont=\normalfont,
}
\newkeytheorem{mytheo}[
name=My Theorem,
style=tcb-standard
]
% document
\begin{mytheo}[This is my title]
Some theorem text.
\end{mytheo}

My Theorem 1: This is my title

Some theorem text.

4 Theorem styles
\newkeytheoremstyle{⟨name⟩}{⟨options⟩}
This is keytheorems’ version of thmtools’ \declaretheoremstyle. Since it makes
little sense to define a style with no keys, we’ve made the ⟨options⟩ argument
mandatory. Note that unlike amsthm’s \newtheoremstyle, this command will
error if a style has already been defined. To overwrite an existing style, there
is the analogous \renewkeytheoremstyle. For completeness, there are also
\providekeytheoremstyle and \declarekeytheoremstyle.
The defined style can be used with either the styleÕ P. 9 key or the traditional
\theoremstyle.

For the AMS classes amsart, amsbook, and amsproc, as well as the amsart-based
! acmart and aomart, the initial key values are slightly different than what’s below
in order to match those class’s defaults. See subsection 8.2 for details.

4.1 Keys also defined in thmtools


The following keys have the same meaning and syntax as the corresponding thmtools
keys. In addition to the list below, most of the keys available to \newkeytheoremÕ P. 3
can be used in \newkeytheoremstyle.

bodyfont=⟨font declarations⟩ (initially \itshape)

13
break (initially unset)
Do not use this with the postheadspace key.
headfont=⟨font declarations⟩ (initially \bfseries)

headformat=margin|swapnumber|⟨code using \NAME, \NUMBER, and \NOTE ⟩


Alias headstyle. Within ⟨code⟩, the commands \NAME, \NUMBER, and \NOTE corre-
spond to the formatted parts of the theorem head.

In headformat, you may also use the traditional amsthm commands \thmname,
\thmnumber, and \thmnote, where #1 is the theorem name, #2 the number,
and #3 the note. keytheorems expands the head spec inside \text_expand:n
so for these commands to work properly, the package adds them to
! \l_text_expand_exclude_tl. Note also that if you use these lower-level com-
mands, the style keys notebraces, notefont, noteseparator, and numberfont
will have no effect (of course, you can manually control these things inside the
commands’ arguments).

headindent=⟨length⟩ (initially 0pt)

headpunct=⟨code⟩ (initially {.})

notebraces={⟨left brace⟩}{⟨right brace⟩} (initially {(}{)})

notefont=⟨font declarations⟩ (initially \fontseries\mddefault\upshape)

postheadspace=⟨skip expr⟩ (initially 5pt plus 1pt minus 1pt)


Do not use this with the break key.
spaceabove=⟨skip expr⟩ (initially \topsep)

spacebelow=⟨skip expr⟩ (initially \topsep)

With tcolorboxÕ P. 11 and tcolorbox-no-titlebarÕ P. 12 , the spaceabove and


spacebelow keys are internally passed to tcolorbox’s before skip and after
! skip. When no explicit spaceabove or spacebelow values are given, tcolorbox
defaults are used instead of \topsep.

4.2 Keys added by keytheorems


inherit-style=⟨style name⟩ (initially unset)
Õ P. 13
Inherit the keys of any style declared with \newkeytheoremstyle . Addition-
ally, the three styles predefined by amsthm are possible values: plain, definition,
and remark.
noteseparator=⟨code⟩ (initially ␣)
The code inserted before the note, and printed only if there is a note. This is
executed before the font commands set by notefont take effect.
numberfont=⟨font declarations⟩ (initially )
For almost all theorem styles, it is recommended that you do not change this setting.

14
5 Restating theorems
When a theorem is given the storeÕ P. 5 key, the contents of the theorem are saved and
written to a .thlist file. At the start of the next run, this file is input at the beginning
of the document and allows you to retrieve the stored theorems at any point, before or
after the original theorem.
\getkeytheorem[⟨property⟩]{⟨tag⟩}
Retrieves the theorem given the key store=⟨tag⟩ or store*=⟨tag⟩. An optional
⟨property⟩ can be given to retrieve only the corresponding part of the theorem.
Currently only the property body is implemented, which retrieves the (unformatted)
body of the theorem.

\getkeytheorem{mytag}

\begin{example}[store=mytag]
Fascinating example.
\end{example}

\getkeytheorem[body]{mytag}

Example 2. Fascinating example.

Example 2. Fascinating example.


Fascinating example.

\IfRestatingTF{⟨true code⟩}{⟨false code⟩}


\IfRestatingT{⟨true code⟩}
\IfRestatingF{⟨false code⟩}
Executes ⟨true code⟩ if being retrieved with \getkeytheorem and ⟨false code⟩ if in
the original theorem. This is reversed if store* is used.

\begin{example}[store=hmm]
I am the \IfRestatingTF{restated}{original} example!
\end{example}

\getkeytheorem{hmm}

Example 3. I am the original example!


Example 3. I am the restated example!

6 Listing theorems
\listofkeytheorems[⟨options⟩]
Similar to \listoffigures or \listoftables but for theorems. For memoir and
the AMS classes, keytheorems tries to copy the formatting of these commands as
defined by the class. For other classes, manual adjustments to numwidthÕ P. 17 and
indentÕ P. 17 may be necessary.
\keytheoremlistset{⟨options⟩}

15
\listofkeytheorems

List of Theorems
1 Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Theorem (Bertrand’s postulate) . . . . . . . . . . . . . . . . . . . . 4
3 Theorem (Legendre’s formula) . . . . . . . . . . . . . . . . . . . . . 4
4 Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4* Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ROCKET Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Theorem (continuing from p. 5) . . . . . . . . . . . . . . . . . . . . 5
5 Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
6 Lemma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
7 Theorem (ORIGINAL) . . . . . . . . . . . . . . . . . . . . . . . . . 6
1 Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1 Some Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1 Conjecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
8 Lemma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1 Remark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Proposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Proposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1 Quote Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1 Indented Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1 Corollary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1 Definition (A nice definition) . . . . . . . . . . . . . . . . . . . . . 11
2 Corollary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1 My Theorem (This is my title) . . . . . . . . . . . . . . . . . . . . 12
2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

6.1 Keys also defined in thmtools


ignore={⟨comma-list of env names⟩} (initially unset)

ignoreall (initially unset)

\listofkeytheorems[ignoreall,show=theorem]
\listofkeytheorems[
ignoreall, show=conjecture,
title=List of Conjectures
]

List of Theorems
1 Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

16
2 Theorem (Bertrand’s postulate) . . . . . . . . . . . . . . . . . 4
3 Theorem (Legendre’s formula) . . . . . . . . . . . . . . . . . . 4
4 Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4* Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ROCKET Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Theorem (continuing from p. 5) . . . . . . . . . . . . . . . . . 5
5 Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
7 Theorem (ORIGINAL) . . . . . . . . . . . . . . . . . . . . . . 6

List of Conjectures
3.1 Conjecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

numwidth=⟨length⟩ (initially 2.3em)


For the AMS classes, this is initially 1.5pc.

onlynamed={⟨comma-list of env names⟩} (initially unset)

show={⟨comma-list of env names⟩} (initially all theorems)

showall (initially set)

swapnumber=true|false (initially false)

title=⟨text⟩ (initially \GetTranslation{keythms_listof_title})


Defaults to “List of Theorems” if English or an unknown language is used. Currently
several European languages have (likely inaccurate!) translations. A translation can
be added with a GitHub pull request or manually with
\DeclareTranslation{⟨lang⟩}{keythms_listof_title}{⟨text⟩}.

6.2 Keys added by keytheorems


format-code=⟨code with #1, #2, and #3⟩ (initially \numberline{#2}#1#3)
Allows full control over the format for list entries. The theorem name is #1, the
number is #2, and the (formatted) note is #3. The note formatting is still controlled
by note-codeÕ P. 18 .

indent=⟨length⟩ (initially 1.5em)


Sets the left indent of items in the list of theorems. For memoir and the AMS
classes, the indent is initially 0pt. It is not recommended to change this unless
your class has different defaults not already covered.

no-chapter-skip=true|false (initially false)


By default a small vertical space is inserted between each chapter’s chunk of theo-
rems. Setting this key to true removes this space.

chapter-skip-length=⟨length⟩ (initially 10pt)


Controls the amount of space inserted between chunks.

17
no-continues=true|false (initially false)
Õ P. 5
Suppresses the printing of theorems given the continues key in the list of
theorems.
no-title=true|false (initially false)
Suppresses the title of the list of theorems. Useful for custom ordering of the list.

\keytheoremlistset{ignoreall}
\listofkeytheorems[show=example]
\listofkeytheorems[show=solution, no-title]

List of Theorems
1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

no-toc=true|false (initially false)


With the standard classes, lists of figures/tables are not added to the table of
contents by default. The same is true for \listofkeytheorems, and with those
classes this key does nothing. However some classes, notably memoir and the AMS
classes, do add lists to the table of contents. With these classes, this key suppresses
the addition of the list of theorems to the table of contents.
note-code=⟨code with #1⟩ (initially { (#1)})
Formats the optional note in the list of theorems.

onlynumbered={⟨comma-list of env names⟩} (initially unset)


Õ P. 17
Similar to onlynamed , but lists only those theorems which are numbered. This
is useful if you’d like to exclude things like unnumbered definitions and remarks from
the list of theorems.
print-body (initially unset)
Instead of listing the theorem headings, the theorems are restated with their body
text. Not very useful without the store-allÕ P. 3 load-time option.

seq=⟨name⟩ (initially unset)


Used to list only the theorems added to the custom sequence ⟨name⟩ with the
seqÕ P. 7 theorem key. This is the only way to fully customize which theorems
appear in the list of theorems. Unlike with showÕ P. 17 , you do not need to use
ignoreallÕ P. 16 to prevent theorems not in ⟨name⟩ from being printed.

title-code=⟨code with #1⟩ (initially \section*{#1})


If \chapter is defined, then initially this is instead \chapter*{#1}. This key has
no effect if used with an AMS class because these classes hard-code the section
heading into \@starttoc.

6.3 Adding code to list of theorems


There are analogous commands to \addcontentsline and \addtocontents for adding
entries or arbitrary code to the list of theorems.

18
You must use these commands rather than the aforementioned because the
! .thlist file is also used to define restated theorems and cannot contain unex-
pected code.

\addtheoremcontentsline{⟨level⟩}{⟨text⟩}

\addtotheoremcontents{⟨code⟩}

7 Theorem hooks
\addtotheoremhook[⟨env name⟩]{⟨hook name⟩}{⟨code⟩}
The ⟨hook name⟩ can be prehead, posthead, prefoot, postfoot, or restated. If
no ⟨env name⟩ is given, the ⟨code⟩ is added to the “generic” hook, i.e. applied to
all theorems. As in thmtools, the order of hooks is as follows:

⟨env name⟩ generic ⟨env name⟩ generic


→ → \begin{⟨env name⟩} → →
prehead prehead posthead posthead

→ ⟨theorem body⟩ →

generic ⟨env name⟩ generic ⟨env name⟩


→ → \end{⟨env name⟩} → →
prefoot prefoot postfoot postfoot

The restated hook is applied at the start of theorems retrieved with the com-
mand \getkeytheorem, after the prehead hook. This can be useful for disabling
commands such as \footnote in the restated theorems, e.g.

\addtotheoremhook{restated}{\renewcommand\footnote[2][]{}}

By default, keytheorems disables the \label and \RecordProperties commands


in restated theorems.
In thmtools, the prefoot and postfoot hooks always prepend code, i.e. the
code

\addtotheorempostfoothook{A}
\addtotheorempostfoothook{B}

results in BA after the theorem. With keytheorems, code is added in the order
declared, meaning

\addtotheoremhook{postfoot}{A}
\addtotheoremhook{postfoot}{B}

results in AB after the theorem. This is the behavior of the LATEX kernel hooks that
keytheorems uses under the hood.
Code added using the hook keys preheadhookÕ P. 9 , etc. is outermost, meaning
executed first in prehead and posthead and last in prefoot and postfoot.

19
8 Miscellaneous notes
8.1 beamer support
The package contains some highly experimental code to support theorems with beamer,
including overlays. Most style keys are disabled by the default beamer theorem tem-
plate. More become functional by setting

\setbeamertemplate{theorems}[ams style]

in the preamble. Alternatively, you have full control of theorems by setting the class
option noamsthm.
Note that by default beamer defines a set of theorems when the class is loaded.
These can be overwritten with \renewkeytheoremÕ P. 3 or disabled entirely with the
notheorems class option.
Due to complications with overlays, writing contents of theorems to the thlist file
is disabled. This means theorems can only be restated after their original statement.
Furthermore, \listofkeytheoremsÕ P. 15 is disabled and a warning issued if used.
User feedback is necessary to make this code fully compatible. Please report issues
on the Github page!

8.2 Support for other classes


As mentioned in section 4, the initial style key values set by keytheorems are adjusted
for the AMS classes amsart, amsbook, and amsproc, the amsart-based acmart and aomart,
and jlreq. You can find the exact changed values in the support files keythms-⟨class⟩-
support.tex.
These class support files also contain code to adapt to class’ formatting of lists-of as
mentioned in section 6; changes are made for the AMS classes, memoir, IEEEtran, and
jlreq.

8.3 Support for font packages


Some font packages, all by Michael Sharpe, offer a theoremfont option that redefines
the plain style body font to have italic text with upright figures, punctuation, and
delimiters. keytheorems detects this option and sets its initial style values accordingly.
The supported packages are baskervillef, cochineal, libertinust1math, newpxtext, newtx-
text, scholax, and XCharter.

8.4 Support for tagged PDF


The LATEX team has been working hard to support the creation of tagged PDFs (see
https://latex3.github.io/tagging-project/). The current dev formats make am-
sthm compatible with the kernel tagging code. Most of keytheorems is supported too,
and anything that doesn’t work should be reported. Explicitly not supported are the
tcolorboxÕ P. 11 and tcolorbox-no-titlebarÕ P. 12 keys.
To produce a tagged PDF, add \DocumentMetadata in the first line of your docu-
ment (additional instructions are found on the Tagging Project website). An example
invocation might look like

20
\DocumentMetadata
{
lang=en-US,
pdfversion=2.0,
pdfstandard=ua-2,
testphase={phase-III,math,table,title,firstaid}
}

At a minimum, the testphase modules phase-III and firstaid are required.

8.5 Public coding interfaces


\l_keythms_thmuse_envname_tl
Inside theorem environments and in all theorem hooks, you have access to the
theorem’s environment and counter name in this token list variable.
keytheorems/allthms/⟨hook name⟩
keytheorems/⟨envname⟩/⟨hook name⟩
These are the “real” names for the hooks described in section 7. They can be useful
with \AddToHookNext or the kernel’s label mechanism for hooks.

9 Further examples
More examples will be added soon – rather, eventually… For now, you can find a
keytheorems adaptation of amsthm’s classic thmtest.tex in the Github tests folder:
keytheorems-amsthmtest.tex. There is also a version for tagged PDF: tagged-
keytheorems-amsthmtest.tex.

21
Index
\addtheoremcontentsline, 19 \IfRestatingT, 15
\addtotheoremcontents, 19 \IfRestatingTF, 15
\addtotheoremhook, 19 ignore key, 16
auto-translate key, 2 ignoreall key, 16
\Autoref, 10 indent key, 17
\Autoref*, 10 inherit-style key, 14

bodyfont key, 13 Keys


break key, 14 auto-translate, 2
bodyfont, 13
chapter-skip-length key, 17 break, 14
Commands chapter-skip-length, 17
\addtheoremcontentsline, 19 continues, 5
\addtotheoremcontents, 19 continues-code, 3
\addtotheoremhook, 19 format-code, 17
\Autoref, 10 headfont, 14
\Autoref*, 10 headformat, 14
\declarekeytheorem, 4 headindent, 14
\declarekeytheoremstyle, 13 heading, 8
\getkeytheorem, 15 headpunct, 14
\IfRestatingF, 15 headstyle, 14
\IfRestatingT, 15 ignore, 16
\IfRestatingTF, 15 ignoreall, 16
\keytheoremlistset, 15 indent, 17
\keytheoremset, 2 inherit-style, 14
\l_keythms_thmuse_envname_tl, 21 label, 4
\listofkeytheorems, 15 leftmargin, 11
\NAME, 14 listhack, 7
\newkeytheorem, 3 manual-num, 5
\newkeytheoremstyle, 13 name, 4, 8
\NOTE, 14 no-chapter-skip, 17
\NUMBER, 14 no-continues, 18
\providekeytheorem, 3 no-title, 18
\providekeytheoremstyle, 13 no-toc, 18
\renewkeytheorem, 3 note, 4
\renewkeytheoremstyle, 13 note-code, 18
continues key, 5 notebraces, 14
continues-code key, 3 notefont, 14
noteseparator, 14
\declarekeytheorem, 4 numbered, 8
\declarekeytheoremstyle, 13 numberfont, 14
definition value, 9, 14 numberlike, 8
numberwithin, 8
format-code key, 17
numwidth, 17
\getkeytheorem, 15 onlynamed, 17
onlynumbered, 18
headfont key, 14 overload, 2
headformat key, 14 parent, 8
headindent key, 14 postfoothook, 9
heading key, 8 postheadhook, 9
headpunct key, 14 postheadspace, 14
headstyle key, 14 prefoothook, 9
preheadhook, 9
\IfRestatingF, 15 print-body, 18

22
qed, 9 numberlike key, 8
qed-symbol, 3 numberwithin key, 8
Refname, 10 numwidth key, 17
refname, 10
restate, 5 onlynamed key, 17
restate-counters, 3 onlynumbered key, 18
restate-keys, 6 overload key, 2
rightmargin, 11
seq, 7, 18 parent key, 8
sharenumber, 8 plain value, 9, 14
short-name, 4 postfoothook key, 9
short-note, 4 postheadhook key, 9
show, 17 postheadspace key, 14
showall, 17 prefoothook key, 9
sibling, 8 preheadhook key, 9
spaceabove, 14 print-body key, 18
spacebelow, 14 \providekeytheorem, 3
store, 5 \providekeytheoremstyle, 13
store-all, 3
store-sets-label, 3 qed key, 9
style, 9 qed-symbol key, 3
swapnumber, 17
tcolorbox, 11 Refname key, 10
tcolorbox-no-titlebar, 12 refname key, 10
thmtools-compat, 2 remark value, 9, 14
title, 8, 17 \renewkeytheorem, 3
title-code, 18 \renewkeytheoremstyle, 13
within, 8 restate key, 5
\keytheoremlistset, 15 restate-counters key, 3
\keytheoremset, 2 restate-keys key, 6
rightmargin key, 11
\l_keythms_thmuse_envname_tl, 21
label key, 4 seq key, 7, 18
leftmargin key, 11 sharenumber key, 8
listhack key, 7 short-name key, 4
\listofkeytheorems, 15 short-note key, 4
show key, 17
manual-num key, 5 showall key, 17
margin value, 14 sibling key, 8
spaceabove key, 14
\NAME, 14 spacebelow key, 14
name key, 4, 8 store key, 5
\newkeytheorem, 3 store-all key, 3
\newkeytheoremstyle, 13 store-sets-label key, 3
no-chapter-skip key, 17 style key, 9
no-continues key, 18 swapnumber key, 17
no-title key, 18 swapnumber value, 14
no-toc key, 18
\NOTE, 14 tcolorbox key, 11
note key, 4 tcolorbox-no-titlebar key, 12
note-code key, 18 thmtools-compat key, 2
notebraces key, 14 title key, 8, 17
notefont key, 14 title-code key, 18
noteseparator key, 14
unless-unique value, 8
\NUMBER, 14
numbered key, 8
Values
numberfont key, 14
definition, 9, 14

23
margin, 14
plain, 9, 14
remark, 9, 14
swapnumber, 14
unless-unique, 8

within key, 8

24

You might also like