使用 thmtools 为定理证明中的嵌套声明创建声明环境

使用 thmtools 为定理证明中的嵌套声明创建声明环境

考虑以下声明:

\usepackage{amsmath, amsthm, amssymb, thmtools}

\declaretheorem[numberwithin = section]{theorem}
\declaretheorem[sibling = theorem, style = definition]{definition}
\declaretheorem[sibling = theorem]{lemma}
\declaretheorem[sibling = theorem]{proposition}
\declaretheorem[sibling = theorem]{remark}

我想创建一个声明定理,用于在定理证明中定义声明。例如,

\begin{proposition}
    \begin{proof}
        \begin{claim}
            first claim
            \begin{proof}
                proof of first claim
            \end{proof}
        \end{claim}
        \begin{claim}
            second claim
            \begin{proof}
                proof of second claim
            \end{proof}
        \end{claim}
    \end{proof}
\end{proposition}

第一个主张应自动标记为“主张 1”,第二个主张应自动标记为“主张 2”,依此类推。证明中的文本应缩进,这样可以清楚地看到单个主张的证明在哪里结束,而无需使用 qed 符号。

我们怎样才能实现这一点?我对乳胶还不熟悉,所以请耐心等待。

编辑:结果应该是这样的:

\begin{theorem}
    Text
    \begin{proof}[Proof\textup:\nopunct]
        Some part of the proof of the main theorem ...\newline
        \;\;\;\;\textbf{Claim 1:} Text\newline
        \;\;\;\;\textit{Proof}: Line 1\newline
        \;\;\;\;Line 2\newline
        \;\;\;\;Last Line\newline
        \;\;\;\;\;\;\;\;\textbf{Claim 1.1:} Text\newline
        \;\;\;\;\;\;\;\;\textit{Proof}: Line 1\newline
        \;\;\;\;\;\;\;\;Line 2\newline
        \;\;\;\;\;\;\;\;Last Line\newline
        continuation of main theorem proof ...
    \end{proof}
\end{theorem}

在每个新的定理证明中,权利要求编号应从 1 重新开始。此外,权利要求及其证明应缩进(就像 $\;\;\;\;$ 在等式中所做的那样)。如果权利要求中还有另一个权利要求,则应将其编号为权利要求 1.1 并再次缩进(但这次是针对环境权利要求)。我们该怎么做呢?

答案1

我认为您正在寻找类似这样的输出:

在此处输入图片描述

假设如此,那么下面的代码就会这样做。

\documentclass{article}

\usepackage{amsmath, amsthm, amssymb, thmtools}

\declaretheorem[numberwithin = section]{theorem}
\declaretheorem[sibling = theorem, style = definition]{definition}
\declaretheorem[sibling = theorem]{lemma}
\declaretheorem[sibling = theorem]{proposition}
\declaretheorem[sibling = theorem]{remark}

\usepackage{enumitem,xparse}
\newlist{Claim}{description}{2}
\setlist[Claim]{labelindent=2em,leftmargin=*}
\newif\ifInsideClaim
\newcounter{claim}[theorem]
\newcounter{cclaim}[claim]
\renewcommand\theclaim{\arabic{claim}}
\renewcommand\thecclaim{\arabic{claim}.\arabic{cclaim}}
\let\originalqedsymbol\qedsymbol
\newenvironment{claim}{%
  % disable qed symbol if there is no star
  \let\qedsymbol\relax%
  \ifInsideClaim% we have a nested environment
    \refstepcounter{cclaim}%
    \let\theclaimcounter\thecclaim%
  \else%
    \refstepcounter{claim}%
    \let\theclaimcounter\theclaim%
    \InsideClaimtrue%
  \fi%
  \Claim\item[\textbf{Claim \theclaimcounter:}]%
}{\endClaim\InsideClaimfalse\let\qedsymbol\originalqedsymbol}

\begin{document}

\begin{proposition}
   A  proposition.
\end{proposition}
\begin{proof}
  Start the proof.
    \begin{claim}
        first claim
        \begin{proof}
            proof of first claim
        \end{proof}
        \begin{claim}
            first subclaim
            \begin{proof}
                proof of first subclaim
            \end{proof}
        \end{claim}
    \end{claim}
    \begin{claim}
      Second claim
      \begin{proof}
        Proof of second claim
      \end{proof}
    \end{claim}
\end{proof}

\end{document}

以下是其工作原理的简单解释:

  • 我为声明环境和子声明环境分别定义了两个计数器claim和。计数器编号为“内部” ,计数器编号为“内部” ,因此只要父级计数器发生变化,它们就会被重置。cclaimclaimtheoremcclaimclaim
  • 我定义了一个claim环境和一个布尔变量\ifInClaim来检测claim环境何时嵌套。代码只允许声明和子声明。允许进一步嵌套很容易,但我怀疑您或您的读者是否愿意这样做。
  • 为了达到所要求的缩进,我使用了枚举项包(并且每个声明环境实际上都是一个伪装的环境)。您可以通过更改代码行中的和description来轻松调整声明环境的缩进。2em4em\setlist
  • 编辑\qedsymbol在声明环境中,通过设置为相等\relax,然后在证明结束时将其恢复为原始值,可以禁用 qedsymbol 。

编辑

以下是代码的细微变化,允许三级子声明。下面的代码不使用 switch\ifInClaim和计数器claim,而是有计数器、和以及。从记忆中看,这与嵌套环境的完成方式类似(尽管我确信这些完成得更有效率……)。只要你有足够宽的纸张,就可以很容易地将新框架扩展到任意级别的嵌套。cclaimclaimiclaimiiclaimiiiclaimlevelenumerate

这是新的输出:

在此处输入图片描述

...以下是修改后的代码:

\documentclass{article}

\usepackage{amsmath, amsthm, amssymb, thmtools, etoolbox}

\declaretheorem[numberwithin = section]{theorem}
\declaretheorem[sibling = theorem, style = definition]{definition}
\declaretheorem[sibling = theorem]{lemma}
\declaretheorem[sibling = theorem]{proposition}
\declaretheorem[sibling = theorem]{remark}

\usepackage{enumitem,xparse}
\newlist{Claim}{description}{3}% allow 3 levels of nesting
\setlist[Claim]{labelindent=2em,leftmargin=*}

\newcounter{claimlevel}% records nesting level
\newcounter{claimi}[theorem] % claim counters for each nesting level
\newcounter{claimii}[claimi]
\newcounter{claimiii}[claimii]
\renewcommand\theclaimi{\arabic{claimi}}
\renewcommand\theclaimii{\theclaimi.\arabic{claimii}}
\renewcommand\theclaimiii{\theclaimii.\arabic{claimiii}}
\let\originalqedsymbol\qedsymbol
\newenvironment{claim}{%
  % disable qed symbol if there is no star
  \let\qedsymbol\relax%
  \stepcounter{claimlevel}
  \refstepcounter{claim\roman{claimlevel}}%
  \Claim\item[\textbf{Claim \csuse{theclaim\roman{claimlevel}}:}]%
  }{\endClaim\addtocounter{claimlevel}{-1}\let\qedsymbol\originalqedsymbol}

\begin{document}

\begin{proposition}
   A  proposition.
\end{proposition}
\begin{proof}
  Start the proof.
    \begin{claim}
        first claim
        \begin{proof}
            proof of first claim
        \end{proof}
        \begin{claim}
            first subclaim
            \begin{proof}
                proof of first subclaim
            \end{proof}
            \begin{claim}
                  first subsubclaim
                  \begin{proof}
                      proof of first subsubclaim
                  \end{proof}
            \end{claim}
        \end{claim}
    \end{claim}
    \begin{claim}
      Second claim
      \begin{proof}
        Proof of second claim
      \end{proof}
    \end{claim}
\end{proof}

\end{document}

相关内容