我正在使用 amsthm 包及其提供的证明环境。有时我会为包含多个声明及其各自证明的定理编写证明。我想将 qed 符号重新定义为通常的墓碑符号,其下标提到前一个声明/定理的编号。
我不是高级乳胶用户,所以我不确定如何参考定理/声明计数器,所以任何帮助都值得感激。
答案1
这与您想要获得的类似吗?
\documentclass{article}
\usepackage{amsthm,regexpatch}
\makeatletter
\let\cproof\proof
\def\endcproof{%
\renewcommand\qedsymbol{\openbox\rlap{\textsubscript{\std@currentclaim}}}%
\endproof
}
\makeatother
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{claim}{Claim}[theorem]
\renewcommand{\theclaim}{\arabic{claim}}
\makeatletter
\xpretocmd{\claim}{\std@patch@thm}{}{}
\newcommand{\std@patch@thm}{%
\makeatletter
\regexpatchcmd{\@thm}
{(\c{refstepcounter}\cB.\cP.2\cE.)}
{\1\c{std@savelabel}}
{}{}%
\makeatother
}
\newcommand{\std@savelabel}{\xdef\std@currentclaim{\@currentlabel}}
\makeatother
\begin{document}
\begin{theorem}
Every duck can fly.
\end{theorem}
\begin{proof}
We made a series of steps.
\begin{claim}
Ducks are nice.
\end{claim}
\begin{cproof}
Who can say differently?
\end{cproof}
\begin{claim}
Ducks rule.
\end{claim}
\begin{cproof}
See the \TeX.StackExchange chat.
\end{cproof}
The main statement follows.
\end{proof}
\end{document}
\@thm
LaTeX 没有“最后定理”的概念。因此,当它有时,我们必须介入\refstepcounter
。此代码将手术限制在claim
环境中。
稍微不同的方法。我在\@thm
之后添加了一个钩子\refstepcounter{#2}
,这样\@currentlabel
就可以使用了。
\documentclass{article}
\usepackage{amsthm,xpatch}
\makeatletter
% add a hook to \@thm
\xpatchcmd{\@thm}
{\refstepcounter{#2}}
{\refstepcounter{#2}\csname #2hook\endcsname}
{}{}
\newcommand{\settheoremhook}[2]{%
\@namedef{#1hook}{#2}%
}
\let\cproof\proof
\def\endcproof{%
\renewcommand\qedsymbol{\openbox\rlap{\textsubscript{\currentclaim}}}%
\endproof
}
\makeatother
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{claim}{Claim}[theorem]
\renewcommand{\theclaim}{\arabic{claim}}
\makeatletter
\settheoremhook{claim}{\global\let\currentclaim\@currentlabel}
\makeatother
\begin{document}
\begin{theorem}
Every duck can fly.
\end{theorem}
\begin{proof}
We made a series of steps.
\begin{claim}
Ducks are nice.
\end{claim}
\begin{cproof}
Who can say differently?
\end{cproof}
\begin{claim}
Ducks rule.
\end{claim}
\begin{cproof}
See the \TeX.StackExchange chat.
\end{cproof}
The main statement follows.
\end{proof}
\end{document}
钩子执行\csname #2hook\endcsname
,因此除非钩子已用 定义,否则它不会执行任何操作\settheoremhook
。此类钩子只能为“主”定理设置,因此不能为其他定理的子定理设置(例如,在示例中,您不能执行\settheoremhook{lemma}
)。
输出是一样的。
和hyperref
如果hyperref
已加载,则补丁必须延迟(并且有所不同)。
hyperref
这是无需加载即可运行的代码。
\documentclass{article}
\usepackage{amsthm,xpatch}
\usepackage{hyperref}
\makeatletter
% add a hook to \@thm
\@ifpackageloaded{hyperref}{\@tempswatrue}{\@tempswafalse}
\if@tempswa
\catcode`#=12
\AtBeginDocument{%
\xpatchcmd{\@thm}
{\@currentHref}
{\@currentHref\csname #2hook\endcsname}
{}{}%
}
\catcode`#=6
\else
\xpatchcmd{\@thm}
{\refstepcounter{#2}}
{\refstepcounter{#2}\csname #2hook\endcsname}
{}{}
\fi
\newcommand{\settheoremhook}[2]{%
\@namedef{#1hook}{#2}%
}
\let\cproof\proof
\def\endcproof{%
\renewcommand\qedsymbol{\openbox\rlap{\textsubscript{\currentclaim}}}%
\endproof
}
\makeatother
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{claim}{Claim}[theorem]
\renewcommand{\theclaim}{\arabic{claim}}
\makeatletter
\settheoremhook{claim}{\global\let\currentclaim\@currentlabel}
\makeatother
\begin{document}
\begin{theorem}
Every duck can fly.
\end{theorem}
\begin{proof}
We made a series of steps.
\begin{claim}
Ducks are nice.
\end{claim}
\begin{cproof}
Who can say differently?
\end{cproof}
\begin{claim}
Ducks rule.
\end{claim}
\begin{cproof}
See the \TeX.StackExchange chat.
\end{cproof}
The main statement follows.
\end{proof}
\end{document}
答案2
我不会重新定义命令,而是\qed
定义一个带有可选参数的版本,并将其写为下标。
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newcommand\myqed[1][]{\qed\rlap{$_{\mathit{#1}}$}}
\begin{document}
\begin{theorem}
Let $a$ and $b$ be two odd integers. Then
\begin{enumerate}
\item $ab$ is odd
\item $a+ b$ is even
\end{enumerate}
\end{theorem}
\begin{proof}
Let $a=2k+1$ and $b=2l+1$. Then $ab=(2k+1)(2l+1)=4kl+2k+2l+1=2(2kl+k+l)+1$ which proves the first part.
\myqed[1]
Similarly $a+b=2k+2l+2=2(k+l+1)$, which is even, and the second part is proven.
\myqed[2]
This completes the proof.
\end{proof}
\end{document}