刪除註釋編號中的「.1」部分,如果它是遵循某個定理的唯一註釋

刪除註釋編號中的「.1」部分,如果它是遵循某個定理的唯一註釋

我正在使用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可以將定理後面的註釋數量儲存在屬性列表中(進一步的值將被覆蓋,因此我們獲得最大值)。

運行結束時,這些值將以以下形式寫入 aux 檔案中

\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}

在此輸入影像描述

相關內容