Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Problem. I am using the amsthm package, and have remarks after theorems.

If there is only one remark between two theorems, the remark should not be numbered.

If there are multiple remarks between two theorems, they should be numbered (with the counter reset with respect to the theorem counter).

I have two environments to handle this, rmk and rmk*, but can I have only one?

(If anyone is curious, I'm typesetting some work by Euler, and he does this with Scholium numbering. But I'm also thinking about doing this with my own personal notes, which is why I ask for a robust single environment solution...)

Minimal Working Example. For what I do now, here's a minimal working example using a workaround. But it's unpleasant when I add more remarks to a theorem to remember to change rmk* to 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}
share|improve this question
    
For an alternative approach to the already posted answers, you could have a look at thmtools and its numbered=unless unique option. This doesn't work out of the box, because in the above example, you have indeed 3 remarks, they aren't "unique". However, I suspect the underlying macros can be adapted to this case. The documentation even mention a very similar usecase (legal documents, where paragraphs within a section are numbered starting at the second), without solving it. –  T. Verron Apr 19 at 20:03
    
@T.Verron Hmm, I'll look into thmtools a bit more. And thanks for the edit, btw, I knew I forgot some key detail :) –  Alex Nelson Apr 20 at 16:23

2 Answers 2

up vote 8 down vote accepted

The following example patches \@thm that is defined by amsthm to remove the number, if there is only one entity.

If the theorem entity has reached number 2, then there are multiple items and a label is written to the .aux file using the theorem name and number as key.

In the next LaTeX run, the existence of this key is checked for the first item and the number is suppressed, if the label exists and there are multiple items.

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

Result

share|improve this answer

There exists an unofficial package named corollaries exactly for such a case. I've been using it for more than a year. It should soon be proposed on CTAN, but author doesn't have much time to finish the doc in English. For the moment the documentation is in French (1½ page only).

It defines three new commands, newcorollary , and for arbitrary counters (previously defined with \newcounter): DeclareCorollaryCounter and \AddToCorollaryReset. In your case, you should just write, supposing you also have a prop environment:

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

This defines a rmk counter which 1) is set to 0 each time the thm OR prop counter change; 2) is not displayed for a lonely remark.

If you would use the ntheorem package, there are also \newframedcorollary and newshadedcorollary commands.

Here is an excerpt from the doc:

enter image description here

Translation of the introductory paragraph for non-French speaking readers:

The corollaries package aims at allowing automatic numbering of corollaries in the style of, for instance, Bourbaki's mathematics treatise — in other words, when a single corollary follows a theorem or a proposition, it is not numbered while if there are several ones, each has its number. Here is an example:

You can download it from this thread on the french help/forum site mathematex.net. If you're interested, be careful to download version 1.2.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.