\listoftheorems:命名定理和可选参数

\listoftheorems:命名定理和可选参数

下面我有三类定理:

  1. 一个“普通”定理,只有头部“定理”,如第三个定理;
  2. 一个定理既有标题又有注释,“定理(...)”,如第二条;
  3. 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/13492https://tex.stackexchange.com/a/180749/13492,https://tex.stackexchange.com/q/509672/13492如何使定理列表中的首字母大写?

答案1

除了您询问的问题之外,您发布的代码中还存在几个问题。

  1. 在您的最小示例中,执行的操作不执行任何操作\patchcmd(它所做的就是删除定理,title使其不显示在listoftheorems 仅适用于未编号定理。这对我来说没有任何意义,所以我在下面的代码中将其删除。
  2. \makeatletter...\makeatother对应该包含使用该@符号的所有内容,目前您的\declaretheoremstyle宏不包括它,因此您显示的代码与其编码意图不同。我已将移至\makeatother正确位置,并\thmt@space从基本中删除了要删除的声明thmstyle,因为该空间应该在那里,不应被删除。
  3. 在定义时namedtheorem,您指定了nametitle;它们是同义词,您应该只指定一个。

现在,谈谈真正的问题:宏的使用与如何处理定理列表\thmtformatoptarg紧密相关。具体来说,我们注意到:thmtools

  1. <project>.loe包含定理列表的所有定理条目的文件使用。\thmtformatoptarg这意味着对 的任何更改\thmtformatoptarg都将自动应用于所有条目,并且您无法有选择地进行更改。
  2. 而且让人恼火的是,输入onlynamed的键会\listoftheorems检测内容行中的存在\thmtformatoptarg来决定是否显示该条目。

为了解决这两个问题,下面是一些小技巧:

  1. 我们重新定义了如何namedtheorem将 写入loe文件,以完全忽略\thmtformatoptarg。最简单的方法是完全重新定义事情的发展方式,而不是修补,所以我还删除了xpatch
  2. 我们假设的每个实例都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}

这提供了

在此处输入图片描述

相关内容