7

My goal is to get a new claim environment which automatically numbers. This is fine - I can make a counter, define a claim environment and claimproof environment which number automatically, and this is all fine.

However, I would like the numbering to start at one for each proof, which means I need to reset the counter at the beginning of each proof. I can do this by defining a new environment, "myproof" or so on, which is a wrapper for proof, but I would like it to automatically work on existing LaTeX code.

So how can I "redefine" the proof environment without rewriting the proof environment from scratch?

4
  • Could you provide the community with an example?
    – Werner
    Dec 17, 2015 at 3:21
  • It's not clear what example would be useful here. I think the description is fairly clear. If you can tell me specifically what sort of example would be useful, I'd be glad to add one. Dec 17, 2015 at 4:01
  • Does the current answer answer your question? If not, then it's clear that there could be some ambiguity in terms of what you want.
    – Werner
    Dec 17, 2015 at 4:02
  • It does. I don't know the custom here, so I thought I would wait to see votes, other answers, etc. and then pick the apparent best. But this answer looks perfect. Dec 17, 2015 at 4:03

2 Answers 2

6

There are numerous ways to achieve the desired behavior. A relatively clean (and general) way is to use \AtBeginEnvironment from the etoolbox package to reset the counter associated with your claim environment at the beginning of the proof environment.

For example:

\documentclass{article}
\usepackage{amsthm}
\newcounter{claimcount}
\setcounter{claimcount}{0}
\newenvironment{claim}{\refstepcounter{claimcount}\textbf{Claim \arabic{claimcount}:}}{}

\usepackage{etoolbox}
\AtBeginEnvironment{proof}{\setcounter{claimcount}{0}}
\begin{document}
text
\begin{proof}
test proof
\begin{claim}
a claim
\end{claim}
\end{proof}
more text
\begin{proof}
test proof
\begin{claim}
a claim
\end{claim}
\end{proof}
\end{document}

Result:

result

1
  • 2
    Thanks! The real magic is the "AtBeginEnvironment" command - I had never heard of it. Dec 17, 2015 at 17:52
0

Guho's answer is correct, but for sake of posterity, here is the code I went with:

\newcounter{claimCount}
\setcounter{claimCount}{0}
\newenvironment{claim}{\medskip

    \noindent\refstepcounter{claimCount}\textbf{Claim~\arabic{claimCount}.}}{

    \medskip}
\newenvironment{claimproof}{\noindent\textit{Proof of Claim~\arabic{claimCount}.}}{\hfill\ensuremath{\qedsymbol} \tiny{Claim~\arabic{claimCount}}

    \medskip}

\AtBeginEnvironment{proof}{\setcounter{claimCount}{0}}

I often look for copy/paste code on this site, so I thought I'd contribute some. This automatically numbers claims and (assuming the claim's proof follows the claim before a new claim is written) the claim proofs are properly labeled. Also the QED at the end of the claim's proof is clearly marked as such, to distinguish it from the QED at the end of the full proof (another pet peeve of mine).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .