我正在使用该amsthm
包和thmtools
包来格式化我的手稿。
我正在对定理中的注释进行编号,也就是说备注2.1.,备注2.2.等等定理 2。然而,如果在之后只发表了一条评论,比如说,定理 1,我希望它可以被编号为备注1.代替备注 1.1。
numbered=unless unique
通过使用中的选项thmtools
,可以完全消除编号,得到评论。这不是我真正想要的,因为我希望我以后可以通过编号方便地引用该注释,而不是说“定理 1 之后的评论“。
下面是一个 MWE,我被困住了,想知道是否有任何快速的调整来实现我的目的。提前感谢您提供可能的解决方案。
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\declaretheorem[numberwithin=thm, name=Remark, numbered=unless unique]{rmk}
\begin{document}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\begin{rmk}
The style is Remark 2.1., 2.2., and 2.3., etc.
\end{rmk}
\end{document}
答案1
您可以使用包“手动”定义所需的行为unique
。以下内容只是模拟了thmtools
的操作numbered=unless unique
,但它不会将注释设置为 (如果唯一),而是将其设置\thermk
为\thethm
。
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[unq]{unique}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\declaretheorem[numberwithin=thm, name=Remark]{rmk}
\addtotheorempreheadhook[rmk]{%
\setuniqmark{rmk.\thethm}%
\ifuniq{rmk.\thethm}
{\def\thermk{\thethm}}
{}%
}
\begin{document}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\begin{rmk}
The style is Remark 2.1., 2.2., and 2.3., etc.
\end{rmk}
\begin{thm}
bla
\end{thm}
\begin{rmk}
more bla
\end{rmk}
\end{document}
定义一个具有相同效果的键并不难。
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\makeatletter
\define@key{thmdef}{uniquewithparent}{%
\setkeys{thmdef}{parent=#1}
\RequirePackage[unq]{unique}
\addtotheorempreheadhook[\thmt@envname]{%
\setuniqmark{\thmt@envname.\csname the#1\endcsname}%
\ifuniq{\thmt@envname.\csname the#1\endcsname}
{\@xa\def\csname the\thmt@envname\endcsname{\csname the#1\endcsname}}
{}%
}
}
\makeatother
\newtheorem{thm}{Theorem}
\declaretheorem[uniquewithparent=section]{lemma}
\theoremstyle{remark}
\declaretheorem[name=Remark,uniquewithparent=thm]{rmk}
\begin{document}
\section{A section}
\begin{lemma}
Some text.
\end{lemma}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\section{Another section}
\begin{lemma}
More text.
\end{lemma}
\begin{lemma}
Even more text.
\end{lemma}
\end{document}
答案2
我们expl3
可以将遵循定理的注释数存储在属性列表中(进一步的值将会覆盖,因此我们可以获得最大值)。
运行结束时,这些值以以下形式写入辅助文件中
\rmklist{1=1,2=3,1=1,}
(示例中的值),因此在下次运行开始时,我们可以填充用于检查的另一个属性列表。如果存储的数字大于 1,则.\arabic{rmk}
使用。
\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\newtheorem{rmk}{Remark}[thm]
\renewcommand{\thermk}{\thethm\checkrmk}
\ExplSyntaxOn
% populate the property list for the checks
\NewDocumentCommand{\rmklist}{m}
{
\prop_gset_from_keyval:Nn \g_dustrain_rmk_in_prop { #1 }
}
% check whether the number of remarks is > 1
\NewExpandableDocumentCommand{\checkrmk}{}
{
\__dustrain_rmk_check:e { \arabic{thm} }
}
% at end of rmk, store the last value of rmk
\AddToHook{env/rmk/after}
{
\prop_gput:Nee \g_dustrain_rmk_out_prop { \arabic{thm} } { \arabic{rmk} }
}
% at end document, write down the values in the aux file
\AtEndDocument
{
\iow_now:ce { @auxout }
{
\rmklist { \prop_map_function:NN \g_dustrain_rmk_out_prop \__dustrain_rmk_write:nn }
}
}
% variables
\prop_new:N \g_dustrain_rmk_out_prop
\prop_new:N \g_dustrain_rmk_in_prop
% internal functions
\cs_new:Nn \__dustrain_rmk_write:nn { #1=#2, }
\cs_new:Nn \__dustrain_rmk_check:n
{
\int_compare:nT { 0\prop_item:Nn \g_dustrain_rmk_in_prop { #1 } > 1 } { .\arabic{rmk} }
}
\cs_generate_variant:Nn \__dustrain_rmk_check:n { e }
\ExplSyntaxOff
\begin{document}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\begin{rmk}
The style is Remark 2.1., 2.2., and 2.3., etc.
\end{rmk}
\begin{thm}
bla
\end{thm}
\begin{rmk}
more bla
\end{rmk}
\end{document}