我喜欢用 LaTeX 记笔记,为了提高速度,我使用可重述定理,这样当教授提到它时,我就可以快速回忆起文本并将其重新插入到我的笔记中。然而,问题是当我想使用命令\listoftheorems
在开头列出所有定理(以帮助快速搜索我的笔记)时,它会重复所有重述定理。我该如何阻止它这样做?
平均能量损失
\documentclass[12pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsthm,amsmath,amssymb,amsfonts}
\usepackage{thmtools}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=black,
urlcolor=blue,
}
\declaretheorem[numberwithin=chapter]{theorem}
\declaretheorem[numberwithin=chapter]{definition}
\renewcommand{\listtheoremname}{List of Theorems and Definitions}
\begin{document}
\listoftheorems[ignoreall,show={theorem,definition}]
\vspace*{\baselineskip}
\hrule
\begin{restatable}[Defintition 1]{definition}{defn}
This is definition 1
\end{restatable}
\begin{restatable}[Theorem 1]{theorem}{thm}
This is theorem 1
\end{restatable}
We will now restate theorem 1,
\thm*
We will now restate Definition 1,
\defn*
\end{document}
答案1
可重述定理thmtools
首先进行通用定理定义,其中包含有关该定理的所有信息,然后仅使用该定义。它区分定理的主要陈述和重述的方式是使用条件。当您使用或并且没有参数\ifthmt@thisistheone
时,此条件为假。\begin{restatable*}
\<theorem-command>*
*
然而,在编写定理列表条目时,它是无条件写入的。此补丁(将其添加到序言中,在加载后thmtools
)将添加\ifthmt@thisistheone
到写入中,以便只对主语句进行操作:
\usepackage{etoolbox}
\makeatletter
\patchcmd\thmt@generic@postheadhook
{\addcontentsline}
{\ifthmt@thisistheone
\expandafter\addcontentsline
\else
\expandafter\@firstoftwo\expandafter\@gobbletwo
\fi}
{}{\FAILED}
\makeatother
\documentclass[12pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsthm,amsmath,amssymb,amsfonts}
\usepackage{thmtools}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=black,
urlcolor=blue,
}
\usepackage{etoolbox}
\makeatletter
\patchcmd\thmt@generic@postheadhook
{\addcontentsline}
{\ifthmt@thisistheone
\expandafter\addcontentsline
\else
\expandafter\@firstoftwo\expandafter\@gobbletwo
\fi}
{}{\FAILED}
\makeatother
\declaretheorem[numberwithin=chapter]{theorem}
\declaretheorem[numberwithin=chapter]{definition}
\renewcommand{\listtheoremname}{List of Theorems and Definitions}
\begin{document}
\listoftheorems[ignoreall,show={theorem,definition}]
\vspace*{\baselineskip}
\hrule
\begin{restatable}[Defintition 1]{definition}{defn}
This is definition 1
\end{restatable}
\begin{restatable}[Theorem 1]{theorem}{thm}
This is theorem 1
\end{restatable}
We will now restate theorem 1,
\thm*
We will now restate Definition 1,
\defn*
\end{document}