1

According to the question asked here and a possible suggestion to the problem which equations should be numbered given here I want to ask following question;

I find it a good solution to number all equations outside a proof-environment for a later reference option. I also share the opinion that equations inside a proof only have a local character, which do not need a global numbering. But I think one is limited to manually use \tag{$\ast$} on those equations inside a proof which one refers to. In case one restructures a proof, one has to manually change all tags and on the other hand I think it looks silly to have an equation tagged with (****).

Therefore I would like to know if it is possible to have a local equation numbering only for the proof-environment, i.e. to achieve a local numbering inside proofs for equations for which one refers to inside a proof. The numbering should start for every proof from the beginning in alphabetical style (a), (b), (c) and so on and to have a global counter outside proofs.

I guess there might exist some complications since I use cleverref. So it would be good to have a solution to this problem compatible to cleverref. Furthermore I would like to use all typical formula environments like equation, align, gather etc. just with a local counter inside proofs.

  • So you'll never refer to an equation inside a proof from outside the proof? – Werner Jan 29 '16 at 8:13
  • If one I want to refer to an equation inside a proof from outside a proof I make it a global statement. Thus reference from outside of proofs should not happen. – varsop Jan 29 '16 at 8:19
  • Are you using any package to create your proofs? Like amsthm? What about hyperref? – Werner Jan 29 '16 at 8:20
  • I am using amsthmto create proofs and hyperrefas well. – varsop Jan 29 '16 at 8:25
2

You can make temporary redefitions at the beginning and end of environment with the help of hooks provided by the etoolbox package. So a first attempt is:

Sample output

\documentclass{article}

\usepackage{mathtools,amsthm,etoolbox,cleveref}

\newtheorem{theorem}{Theorem}

\newcounter{equationstore}
\AtBeginEnvironment{proof}{\setcounter{equationstore}{\value{equation}}
\setcounter{equation}{0}\renewcommand{\theequation}{\alph{equation}}}
\AtEndEnvironment{proof}{\setcounter{equation}{\value{equationstore}}}

\begin{document}

\begin{equation}
  \label{eq:one}
  x = 1
\end{equation}

\begin{theorem}
  A theorem.
\end{theorem}

\begin{proof}
  Proof
  \begin{equation}
    \label{eq:p}
    a = b
  \end{equation}
  refers to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p} and gives
  \begin{equation}
    \label{eq:q}
    c = d
  \end{equation}
  as required.  Note the cleveref references are \cref{eq:one},
  \cref{eq:two} and \cref{eq:p}.
\end{proof}

\begin{equation}
  \label{eq:two}
  z = 2
\end{equation}
Refer to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p}.  Note the
cleveref references are \cref{eq:one}, \cref{eq:two} and \cref{eq:p}.


\end{document}

This needs to be adjusted depending on you equation labelling scheme.

If you are using hyperref you can avoid messages about duplicate labels either by disabling the hypertextnames option or as follows, where the \theHequation is also redefined in a way that includes a unique number for the current proof:

\documentclass{article}

\usepackage{mathtools,amsthm,etoolbox}
\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}

\newcounter{equationstore}
\newcounter{proofnum}

\AtBeginEnvironment{proof}{\setcounter{equationstore}{\value{equation}}
\refstepcounter{proofnum}
\setcounter{equation}{0}\renewcommand{\theequation}{\alph{equation}}
\renewcommand{\theHequation}{\arabic{proofnum}.\alph{equation}}}
\AtEndEnvironment{proof}{\setcounter{equation}{\value{equationstore}}}

\begin{document}

\begin{equation}
  \label{eq:one}
  x = 1
\end{equation}

\begin{theorem}
  A theorem.
\end{theorem}

\begin{proof}
  Proof
  \begin{equation}
    \label{eq:p}
    a = b
  \end{equation}
  refers to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p} and gives
  \begin{equation}
    \label{eq:q}
    c = d
  \end{equation}
  as required.  Note the cleveref references are \cref{eq:one},
  \cref{eq:two} and \cref{eq:p}.
\end{proof}

\begin{equation}
  \label{eq:two}
  z = 2
\end{equation}
Refer to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p}.  Note the
cleveref references are \cref{eq:one}, \cref{eq:two} and \cref{eq:p}.


\end{document}
  • If I take your MWE and load the following packages in this order, \usepackage{mathtools,amsthm,etoolbox}, \usepackage{hyperref}\usepackage{cleveref} and compile it with pdflatex, then I obtain following error: pdfTeX warning (ext4): destination with the same identifier (name{equation.0.2}) has been already used, duplicate ignored. I guess hyperref makes some trouble. I still obtain this error commenting out the cleveref-part. Moreover the reference-system seems to be disturbed in the final pdf-document. – varsop Jan 29 '16 at 11:22
  • OK. That info was not in your question. See my update to my answer to cover this. – Andrew Swann Jan 29 '16 at 13:14
  • Works for my thesis-project with \usepackage[hypertexnames=false]{hyperref}, no errors. But with errors enabling hypertexnames. In the MWE it works with enabling hypertexnames as well. So I would say my problem is solved, but is there something dangerous about loading hyperref in this way? – varsop Jan 29 '16 at 13:30
  • hypertextnames=false is not dangerous, but it just means the internal links names no longer have obvious meaning to a human (they may show up when you hover over them with a mouse). Redefining \theH... make a more comprehensible version and avoids the problem. – Andrew Swann Jan 29 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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