我正在使用amsthm
。thmtools
当推论紧跟其定理时,编号会自动输出为
定理 n
推论 1
命题 n+1
但是,如果我在其中插入其他编号环境会怎样?我如何获得:
定理 n
命题 n+1
定理 n+2
推论 1
命题 n+3
答案1
我建议定义corollary
一个可选参数。如果为空或缺失,则假设推论指的是最后陈述的定理(当然是命题)。
如果推论是分离的,则需要将其添加\label
到父定理并使用标签作为推论的可选参数。
\documentclass{article}
\usepackage{amsmath}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollaryinner}{Corollary}[theorem] % just the internal version
\newenvironment{corollary}[1][]
{% #1 is the cross reference label
\if\relax\detokenize{#1}\relax
% we have a corollary directly following a theorem, do nothing special
\else
\ifcsname #1-used\endcsname
\expandafter\xdef\csname #1-used\endcsname{\the\numexpr\csname #1-used\endcsname+1}%
\else
\expandafter\gdef\csname #1-used\endcsname{1}%
\fi
\renewcommand{\thecorollaryinner}{\ref{#1}.\csname #1-used\endcsname}%
\fi
\corollaryinner
}
{\endcorollaryinner}
\begin{document}
\section{Corollary follows directly}
\begin{theorem}
A theorem
\end{theorem}
\begin{corollary}
A corollary
\end{corollary}
\begin{corollary}
Another corollary
\end{corollary}
\begin{proposition}
A proposition
\end{proposition}
\section{Corollary is detached}
\begin{theorem}\label{theorem}
A theorem
\end{theorem}
\begin{proposition}
A proposition
\end{proposition}
\begin{corollary}[theorem]
A corollary
\end{corollary}
\begin{proposition}
Another proposition
\end{proposition}
\begin{corollary}[theorem]
Another corollary
\end{corollary}
\end{document}
相同的使用expl3
功能:我维护一个带有交叉引用的属性列表,目的与以前相同,即跟踪已经使用的引用。
\documentclass{article}
\usepackage{amsmath}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollaryinner}{Corollary}[theorem] % just the internal version
\ExplSyntaxOn
\NewDocumentEnvironment{corollary}{o}
{
\IfValueT { #1 }
{
\giobrach_corollary_setup:n { #1 }
}
\corollaryinner
}
{ \endcorollaryinner }
\prop_new:N \g_giobrach_corollary_prop
\cs_new_protected:Nn \giobrach_corollary_setup:n
{
\prop_gput:Nnx \g_giobrach_corollary_prop { #1 }
{
\int_eval:n { \prop_item:Nn \g_giobrach_corollary_prop { #1 } + 1 }
}
\cs_set:Npn \thecorollaryinner {\ref {#1}.\prop_item:Nn \g_giobrach_corollary_prop { #1 }}
}
\ExplSyntaxOff
\begin{document}
\section{Corollary follows directly}
\begin{theorem}
A theorem
\end{theorem}
\begin{corollary}
A corollary
\end{corollary}
\begin{corollary}
Another corollary
\end{corollary}
\begin{proposition}
A proposition
\end{proposition}
\section{Corollary is detached}
\begin{theorem}\label{theorem}
A theorem
\end{theorem}
\begin{proposition}
A proposition
\end{proposition}
\begin{corollary}[theorem]
A corollary
\end{corollary}
\begin{proposition}
Another proposition
\end{proposition}
\begin{corollary}[theorem]
Another corollary
\end{corollary}
\end{document}
答案2
这是@egreg 的答案的修改版本。它使用 <...> 作为要遵循的定理的标签,同时保留[...]
为描述文本。因此,正常的推论仍然看起来像
\begin{corollary}[description]
Another corollary
\end{corollary}
而定理中编号的推论则\label{thm:1}
看起来像
\begin{corollary}<thm:1>[description]
A corollary
\end{corollary}
\documentclass{article}
\usepackage{amsmath}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollaryinner}{Corollary}[theorem] % just the internal version
\NewDocumentEnvironment{corollary}{D<>{}}
{% #1 is the cross reference label
\if\relax\detokenize{#1}\relax
% we have a corollary directly following a theorem, do nothing special
\else
\ifcsname #1-used\endcsname
\expandafter\xdef\csname #1-used\endcsname{\the\numexpr\csname #1-used\endcsname+1}%
\else
\expandafter\gdef\csname #1-used\endcsname{1}%
\fi
\renewcommand{\thecorollaryinner}{\ref{#1}.\csname #1-used\endcsname}%
\fi
\corollaryinner
}
{\endcorollaryinner}
\begin{document}
\section{Corollary follows directly}
\begin{theorem}
A theorem
\end{theorem}
\begin{corollary}[description]
A corollary
\end{corollary}
\begin{corollary}[description]
Another corollary
\end{corollary}
\begin{proposition}
A proposition
\end{proposition}
\section{Corollary is detached}
\begin{theorem}\label{theorem}
A theorem
\end{theorem}
\begin{proposition}
A proposition
\end{proposition}
\begin{theorem}
An unrelated theorem
\end{theorem}
\begin{corollary}<theorem>[description]
A corollary
\end{corollary}
\begin{proposition}
Another proposition
\end{proposition}
\begin{corollary}<theorem>[description]
Another corollary
\end{corollary}
\end{document}
旧答案:
您可以存储计数器的值theorem
并对其中的推论进行编号。
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem{theorem}
\declaretheorem[sibling=theorem]{proposition}
\newcounter{theoremrecord}
\let\theoremOriginal=\theorem
\renewcommand{\theorem}{\theoremOriginal\setcounter{theoremrecord}{\value{theorem}}}
\declaretheorem[numberwithin=theoremrecord]{corollary}
\begin{document}
\begin{theorem}
...
\end{theorem}
\begin{proposition}
...
\end{proposition}
\begin{corollary}
...
\end{corollary}
\end{document}