仅当有多个注释时才智能编号“注释”

仅当有多个注释时才智能编号“注释”

问题。我正在使用该amsthm包,并在定理之后做了一些注释。

如果两个定理之间只有一个注释,则该注释不应该编号。

如果两个定理之间有多条注释,则应对其进行编号(并根据定理计数器重置计数器)。

我有两个环境来处理这个问题,rmkrmk*,但我可以只有一个吗?

(如果有人好奇,我正在排版欧拉的一些作品,他使用 Scholium 编号来完成这项工作。但我也在考虑用我自己的个人笔记来做这件事,这就是我要求一个强大的单一环境解决方案的原因......)

最小工作示例。对于我现在所做的,这是一个使用变通方法的最小工作示例。但当我向定理添加更多注释以记住将其更改为时,这很不rmk*愉快rmk

\documentclass{article}

\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\newtheorem{rmk}{Remark}[thm]
\newtheorem*{rmk*}{Remark}

\begin{document}
\begin{thm}
Lorem ipsum.
\end{thm}

% it would be really nice if these could just be "rmk" and
% magically unnumbered...
\begin{rmk*} % only one remark made, so don't number it
It is Latin for "I have boring examples".
\end{rmk*}

\begin{thm}
We see that $\pi$ is an interesting number.
\end{thm}

\begin{rmk} % Multiple remarks require numbering
It's the ratio of the circumference to the diameter of a circle.
\end{rmk}
\begin{rmk}
It's also used when I do my taxes.
\end{rmk}
% snip
\end{document}

答案1

如果只有一个实体,则以下示例修补程序\@thm将定义删除数字。amsthm

.aux如果定理实体已达到2个,则有多个项目,并使用定理名称和编号作为键将标签写入文件。

在下一次运行 LaTeX 时,将检查第一个项目是否存在此键,如果标签存在且有多个项目,则抑制数字。

\documentclass{article}

\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\newtheorem{rmk}{Remark}[thm]

\usepackage{etoolbox}
\usepackage{zref-base}
\makeatletter
\patchcmd\@thm{%
  \refstepcounter{#2}%
  \def\@tempa{\@oparg{\@begintheorem{#3}{\csname the#2\endcsname}}[]}%
}{%
  \refstepcounter{#2}%
  \def\@tempa{\@oparg{\@begintheorem{#3}{\csname the#2\endcsname}}[]}%
  % \in@{,#2,}{,...,}\ifin@...\fi select the theorems for this patch
  \in@{,#2,}{,rmk,}% list of theorems with "intelligent numbering"
  \ifin@
    \ifnum\value{#2}=2 %
      \if@filesw
        \zref@wrapper@immediate{%
          \zref@labelbyprops{IntNumTheo.#2@\csname the#2\endcsname}{}%
        }%
      \fi
    \fi
    \ifnum\value{#2}=1 %
      \stepcounter{#2}%
      \zref@ifrefundefined{IntNumTheo.#2@\csname the#2\endcsname}{%
        \def\@tempa{\@oparg{\@begintheorem{#3}{}}[]}%
      }{}%
      \addtocounter{#2}{-1}%
    \fi
  \fi
}{}{\errmessage{Patching \noexpand\@thm failed}}
\makeatother

\begin{document}
\begin{thm}
Lorem ipsum.
\end{thm}

\begin{rmk} % only one remark made, so don't number it
It is Latin for ``I have boring examples''.
\end{rmk}

\begin{thm}
We see that $\pi$ is an interesting number.
\end{thm}

\begin{rmk} % Multiple remarks require numbering
It's the ratio of the circumference to the diameter of a circle.
\end{rmk}
\begin{rmk}
It's also used when I do my taxes.
\end{rmk}
% snip
\end{document}

结果

答案2

有一个非官方软件包,其名称corollaries正是针对这种情况。我已经用了一年多了。它应该很快就会在 CTAN 上提出,但作者没有太多时间完成英文文档。目前文档是法语的(只有 1½ 页)。

它定义了三个新命令,newcorollary和 ,用于任意计数器(先前用 \newcounter 定义):DeclareCorollaryCounter\AddToCorollaryReset。在你的情况下,你应该只写,假设你还有一个 prop 环境:

\newcorollary{rmk}{Remark}[thm,prop]

这定义了一个计数器,1)每次OR计数器发生变化rmk时,该计数器设置为 0 ;2)不会显示单独的注释。thmprop

如果您要使用该ntheorem包,那么也会有\newframedcorollarynewshadedcorollary命令。

以下是该文档的摘录:

在此处输入图片描述

针对非法语读者的引言段落翻译:

推论包旨在允许自动对推论进行编号,例如采用布尔巴基数学论文的风格——换句话说,当一个定理或命题后面跟着一个推论时,它不会被编号,而如果有多个推论,则每个推论都有其编号。以下是一个例子:

您可以从以下位置下载此主题在法语帮助/论坛网站上mathematex.net。如果您有兴趣,请小心下载version 1.2

相关内容