2

In this question I asked to achieve a local equation numbering for equations which appear only inside proofs and to have a global counter for equations outside of proofs. I prefer the style where equations inside proofs are numbered with a star, i.e. (1*),(2*) or (3*a) and so on. This can be managed in the following way:

%
% Local equation numbering inside proofs
%

\newcounter{equationstore}
\AtBeginEnvironment{proof}{\setcounter{equationstore}{\value{equation}}
\setcounter{equation}{0}\renewcommand{\theequation}{\arabic{equation}${}^\ast$}}
\AtEndEnvironment{proof}{\setcounter{equation}{\value{equationstore}}}

As you can see there exist two equation counter. Before entering the proof environment, the global counter is stored, then switched to another local counter, which starts from zero for each proof environment. After exiting the proof environment the global equation counter is loaded.

I would like to know if it is possible to show only those equations inside proofs which one refers to inside a proof. Equations inside proofs will be only referenced from the same proof. A solution should respect that I use hyperref. cleveref is NO longer necessary for me.

3
  • 2
    I could look into that later today I think; there's mathtools' showonlyrefs (see mathtools documentation), but AFAIK this change is global. Have you got a MWE to spare please?
    – yo'
    Sep 19, 2016 at 13:32
  • @yo' -- The showonlyrefs option of the mathtools package is seriously incompatible with cleveref. :-(
    – Mico
    Sep 19, 2016 at 13:48
  • @yo'-- A MWE can be taken from Andrew Swann right here: tex.stackexchange.com/a/290019/97026
    – varsop
    Sep 19, 2016 at 14:01

1 Answer 1

3

The hyperref solution I gave to the other question works fine with mathtools' option showonlyrefs provided you drop cleveref, which is a standard caveat for this option of mathtools:

Sample output

\documentclass{article}

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

\mathtoolsset{showonlyrefs}

\newtheorem{theorem}{Theorem}

\newcounter{equationstore}
\newcounter{proofnum}

\AtBeginEnvironment{proof}{\setcounter{equationstore}{\value{equation}}
\refstepcounter{proofnum}
\setcounter{equation}{0}\renewcommand{\theequation}{\arabic{equation}$^*$}
\renewcommand{\theHequation}{\arabic{proofnum}.\arabic{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.
\end{proof}

\begin{equation}
  \label{eq:two}
  z = 2
\end{equation}
Refer to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p}.


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

\begin{proof}
  Proof
  \begin{equation}
    \label{eq:p2}
    a = b
  \end{equation}
  refers to \eqref{eq:one}, \eqref{eq:two} and gives
  \begin{equation}
    \label{eq:q2}
    c = d.
  \end{equation}
  \eqref{eq:q2} is the required result.
\end{proof}

\end{document}

For your new request of applying the reference-use check only to equations inside proofs, you can adjust the above code to

\newcounter{equationstore}
\newcounter{proofnum}

\AtBeginEnvironment{proof}{\mathtoolsset{showonlyrefs}%
\setcounter{equationstore}{\value{equation}}
\refstepcounter{proofnum}
\setcounter{equation}{0}\renewcommand{\theequation}{\arabic{equation}$^*$}
\renewcommand{\theHequation}{\arabic{proofnum}.\arabic{equation}$^*$}}
\AtEndEnvironment{proof}{\setcounter{equation}{\value{equationstore}}%
\mathtoolsset{showonlyrefs=false}}
4
  • I have to uncheck this answer, since finally I came a across a misbehavior of the solution. What I want is to have showonlyrefs for referenced equations inside proofs, with a new counter for every proof, but on the opposite to display all equation numbers outside proof-environments (includes the non-referenced ones). I could use \noeqref for all equations outside proof-environments, but this is merely a workaround.
    – varsop
    May 9, 2017 at 14:29
  • EDIT: Maybe one can switch on 'showonlyrefs' when entering a proof and switch it off at the end?
    – varsop
    May 9, 2017 at 14:38
  • Is this okay? \newcounter{equationstore} \newcounter{proofnum} \AtBeginEnvironment{proof}{\mathtoolsset{showonlyrefs=true}\setcounter{equationstore}{\value{equation}} \refstepcounter{proofnum} \setcounter{equation}{0}\renewcommand{\theequation}{\arabic{equation}$^*$} \renewcommand{\theHequation}{\arabic{proofnum}.\arabic{equation}$^*$}} \AtEndEnvironment{proof}{\mathtoolsset{showonlyrefs=false}\setcounter{equation}{\value{equationstore}}}
    – varsop
    May 9, 2017 at 14:43
  • Yes, that works. I'll mention it in my answer. May 9, 2017 at 14:56

You must log in to answer this question.

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