
Я использую 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}