In the following, I have three kinds of theorems:
- an "ordinary" theorem, which just has the head "Theorem", as in the 3rd;
- a theorem having both a head and a note, "Theorem (…)", as in the 2nd; and
- a
namedtheorem
, where the note becomes the name, as in the 1st.
Question: What modification is needed so that the output from \listoftheorems
removes the parentheses from the namedtheorem
entry but preseres the parentheses of the note in a theorem having both head and note?
Failed attempt 1: removes parentheses for namedtheorem
but unfortunately also removes them from the entry with the note.
\documentclass{article}
\usepackage{amsmath,amsthm,thmtools}
% For \listoftheorems
\renewcommand\thmtformatoptarg[1]{#1} % remove parens
\usepackage{xpatch}
\makeatletter
\patchcmd{\thmt@mklistcmd}{\thmt@thmname}{}{}{}
\makeatother
\swapnumbers
\declaretheoremstyle[
headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\slshape,
]{thmstyle}
\declaretheorem[name=Theorem,style=thmstyle]{theorem}
\declaretheoremstyle[
postheadspace=0.5em,
notebraces={}{},
headformat=\NUMBER\let\thmt@space\@empty\NOTE,
notefont=\bfseries,
bodyfont=\slshape,
]{namedthmstyle}
\declaretheorem[
style=namedthmstyle,
name=Theorem,
title = {},
numberlike=theorem
]{namedtheorem}
\begin{document}
\listoftheorems[ignoreall,onlynamed={theorem,namedtheorem}]
\bigskip
\begin{namedtheorem}[Heine-Borel Theorem]
A closed and bounded subset of Euclidean $n$-space is compact.
\end{namedtheorem}
\begin{theorem}[compact subset of Hausdorff space]
A compact subset of a Hausdorff space is closed in that space.
\end{theorem}
\begin{theorem}
The square on the hypotenuse of a right triangle equals the sum of the squares on the other two sides.
\end{theorem}
\end{document}
Failed attempt 2: Comment out the line \renewcommand\thmtformatoptarg[1]{#1}
. Then parentheses still remain around the entry for the namedtheorem
.
Question, restated: Thus, how can I somehow combine different treatments of a theorem
having a parenthesized note, on the one hand, and a namedtheorem
, on the other hand?
Related: https://tex.stackexchange.com/a/193020/13492, https://tex.stackexchange.com/a/180749/13492,https://tex.stackexchange.com/q/509672/13492, How make first letter upper-case in list of theorems?
Best Answer
There are several problems in the code you posted, aside from what you are asking about.
\patchcmd
does nothing in your minimal example (what it does, is to remove the theoremtitle
from being shown in thelistoftheorems
only for unnumbered theorems. This doesn't make any sense to me so I removed it in my code below.\makeatletter...\makeatother
pair should encompass everything that uses the@
symbol, currently your\declaretheoremstyle
macros do not include it, and so the code you showed does something different from its coded intent. I've moved the\makeatother
to the correct place, and removed the declaration to remove\thmt@space
from the basicthmstyle
, since that space should be there and should not be removed.namedtheorem
, you specified bothname
andtitle
; they are synonyms and you should specify only one.Now, on to the real problem: the use of the
\thmtformatoptarg
macro is baked firmly into howthmtools
handle the list of theorems. Specifically, we note that:<project>.loe
file which has all the theorem entries for the list of theorems uses\thmtformatoptarg
. This means that any changes to\thmtformatoptarg
will automatically apply to ALL entries, and you cannot do it selectively.onlynamed
key in\listoftheorems
detects the presence of\thmtformatoptarg
in the contents line to decide whether to show that entry.To work around the two problems, the following is a bit of a hack:
namedtheorem
s are written to theloe
file, to ignore\thmtformatoptarg
completely. This is most easily done by just completely redefining how things goes, rather than patching, so I also removedxpatch
.namedtheorem
comes with an optional argument (if not, the theorem name would be empty....), so instead of testing foronlynamed={namedtheorem}
, we just doshow={namedtheorem}
which should functionally be the same.With that, the following MWE is attained:
Output:
To automate the process somewhat, if you have multiple environments, we can redefine the
\thmt@mklistcmd
to do the right thing automatically. There may be better way to do this logic, but the following should work. (Basically, instead of printing\thmt@thmname
, we test to see if it is empty, and if true, print the optional argument instead. But this means that when it comes time to print the optional argument, we should suppress it from printing at all if it has already been used in place of the empty\thmt@thmname
. Note: I didn't bother to make the analogous change for unnumbered theorems; hopefully you can figure out what to change yourself by comparing this with the definition inthmtools/thm-listof.sty
.)This provides