![\listoftheorems:命名定理和可选参数](https://linux22.com/image/465910/%5Clistoftheorems%EF%BC%9A%E5%91%BD%E5%90%8D%E5%AE%9A%E7%90%86%E5%92%8C%E5%8F%AF%E9%80%89%E5%8F%82%E6%95%B0.png)
下面我有三类定理:
- 一个“普通”定理,只有头部“定理”,如第三个定理;
- 一个定理既有标题又有注释,“定理(...)”,如第二条;
- a
namedtheorem
,其中注释成为名称,与第一个一样。
问题:需要进行哪些修改才能使输出\listoftheorems
中删除namedtheorem
,但在具有头部和注释的定理中保留注释的括号?
失败尝试 1:删除了括号,namedtheorem
但不幸的是,也删除了带有注释的条目中的括号。
\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}
失败尝试2:注释掉该行
\renewcommand\thmtformatoptarg[1]{#1}
。然后括号仍然保留在条目周围namedtheorem
。
问题重述:theorem
因此,我怎样才能以某种方式结合具有括号注释的 和 的不同处理方式namedtheorem
呢?
有关的: https://tex.stackexchange.com/a/193020/13492,https://tex.stackexchange.com/a/180749/13492,https://tex.stackexchange.com/q/509672/13492,如何使定理列表中的首字母大写?
答案1
除了您询问的问题之外,您发布的代码中还存在几个问题。
- 在您的最小示例中,执行的操作不执行任何操作
\patchcmd
(它所做的就是删除定理,title
使其不显示在listoftheorems
仅适用于未编号定理。这对我来说没有任何意义,所以我在下面的代码中将其删除。 - 该
\makeatletter...\makeatother
对应该包含使用该@
符号的所有内容,目前您的\declaretheoremstyle
宏不包括它,因此您显示的代码与其编码意图不同。我已将移至\makeatother
正确位置,并\thmt@space
从基本中删除了要删除的声明thmstyle
,因为该空间应该在那里,不应被删除。 - 在定义时
namedtheorem
,您指定了name
和title
;它们是同义词,您应该只指定一个。
现在,谈谈真正的问题:宏的使用与如何处理定理列表\thmtformatoptarg
紧密相关。具体来说,我们注意到:thmtools
<project>.loe
包含定理列表的所有定理条目的文件使用。\thmtformatoptarg
这意味着对 的任何更改\thmtformatoptarg
都将自动应用于所有条目,并且您无法有选择地进行更改。- 而且让人恼火的是,输入
onlynamed
的键会\listoftheorems
检测内容行中的存在\thmtformatoptarg
来决定是否显示该条目。
为了解决这两个问题,下面是一些小技巧:
- 我们重新定义了如何
namedtheorem
将 写入loe
文件,以完全忽略\thmtformatoptarg
。最简单的方法是完全重新定义事情的发展方式,而不是修补,所以我还删除了xpatch
。 - 我们假设的每个实例都
namedtheorem
带有一个可选参数(如果没有,定理名称将为空......),因此,onlynamed={namedtheorem}
我们不需要测试,而只需执行show={namedtheorem}
功能上应该相同的操作。
这样,就可以获得以下 MWE:
\documentclass{article}
\usepackage{amsmath,amsthm,thmtools}
\swapnumbers
\makeatletter
\declaretheoremstyle[
headformat=\NAME\NUMBER\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,
title = \@empty,
numberlike=theorem
]{namedtheorem}
%% Note, the following line must come AFTER the \declaretheorem...{namedtheorem}
%% as we are trying to overwrite the definition provided by thmtools
%% that occurs during the \declaretheorem process
%% The definition below will still work if you don't \swapnumbers, but
%% it does assume that the namedtheorems are numbered.
\@xa\def\csname ll@namedtheorem\endcsname{%
\protect\ifthmt@listswap
\thmt@shortoptarg~\csname thenamedtheorem\endcsname
\protect\else
\protect\numberline{\csname thenamedtheorem\endcsname}%
\thmt@shortoptarg
\protect\fi
}%
\makeatother
\declaretheorem[name=Remark,style=thmstyle,numbered=no]{remark}
\begin{document}
\listoftheorems[ignoreall,onlynamed={theorem,remark},show={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}
\begin{remark}[Test]
Test
\end{remark}
\end{document}
输出:
为了使该过程自动化,如果您有多个环境,我们可以重新定义\thmt@mklistcmd
以自动执行正确的操作。可能有更好的方法来实现这种逻辑,但以下方法应该可行。(基本上,\thmt@thmname
我们不是打印 ,而是测试它是否为空,如果为真,则打印可选参数。但这意味着当需要打印可选参数时,如果它已经代替了空的 ,我们应该完全抑制它的打印\thmt@thmname
。注意:我没有费心对无编号定理进行类似的更改;希望您可以通过将其与 中的定义进行比较来自己找出要更改的内容thmtools/thm-listof.sty
。)
\documentclass{article}
\usepackage{amsmath,amsthm,thmtools}
\swapnumbers
\makeatletter
\renewcommand\thmt@mklistcmd{%
\thmtlo@newentry
\ifthmt@isstarred
\@xa\def\csname ll@\thmt@envname\endcsname{%
\protect\ifthmt@listswap
\protect\else
\protect\numberline{\protect\let\protect\autodot\protect\@empty}%
\protect\fi
\thmt@thmname
\ifx\@empty\thmt@shortoptarg\else\protect\thmtformatoptarg{\thmt@shortoptarg}\fi
}%
\else
\@xa\def\csname ll@\thmt@envname\endcsname{%
\protect\ifthmt@listswap
\ifx\@empty\thmt@thmname\thmt@shortoptarg\else\thmt@thmname\fi~\csname the\thmt@envname\endcsname
\protect\else
\protect\numberline{\csname the\thmt@envname\endcsname}%
\ifx\@empty\thmt@thmname\thmt@shortoptarg\else\thmt@thmname\fi
\protect\fi
\ifx\@empty\thmt@thmname\else\ifx\@empty\thmt@shortoptarg\else\protect\thmtformatoptarg{\thmt@shortoptarg}\fi\fi
}%
\fi
\@xa\gdef\csname thmt@contentsline@\thmt@envname\endcsname{%
\thmt@contentslineShow% default:show
}%
}
\declaretheoremstyle[
headformat=\NAME\NUMBER\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,
title = \@empty,
numberlike=theorem
]{namedtheorem}
\declaretheorem[
style=namedthmstyle,
title = {},
numberlike=theorem
]{namedlemma}
\makeatother
\begin{document}
\listoftheorems[ignoreall,onlynamed={theorem},show={namedtheorem,namedlemma}]
\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}
\begin{namedlemma}[Borel-Cantelli Lemma]
Very useful in analysis
\end{namedlemma}
\end{document}
这提供了