I am trying to use the proof environment that comes with the amsthm package. And I would like the proof environment to be numbered, such as the theorem environment for the sake of adding a label, so I have added a custom counter in the preamble and changed the embedded \proofname in the proof environment. It all works well and displays my counters correctly in the text. However, when I try to reference my proofs, only the proof counter gets displayed instead of the full counter.
My code is below:
\documentclass[12pt,letterpaper]{article}
\usepackage{amsthm}
\usepackage{hyperref}
\newcounter{proof}[section] % adds a new counter for the proof environment included in the amsthm package that restarts for every new section
\renewcommand{\theproof}{\thesection.\arabic{proof}} % adds the section number before your proof counters
\renewcommand{\proofname}{\refstepcounter{proof}Proof \theproof} % the \proofname was embedded in your proof environment to output the italicized 'Proof', which is displayed at the beginning of every proof. This changes the \proofname to print 'Proof' and \theproof, which we defined as the section-proof counter above. This adds a counter to your proofs so you can hyperref them.
\newtheorem{definition}{Definition}[section]
\begin{document}
\section{One}
\begin{proof}
\label{p1}
this is proof one.
\end{proof}
This should reference proof \ref{p1}, which should display as proof 1.1.
\begin{definition}
\label{d1}
this is definition one.
\end{definition}
As we can see, this is not a problem when I reference definition \ref{d1}.
\section{Two}
\begin{proof}
\label{p2}
this is proof two.
\end{proof}
This should reference proof \ref{p2}, which should display as proof 2.1.
\begin{definition}
\label{d2}
this is definition two.
\end{definition}
As we can see, this is not a problem when I reference definition \ref{d2}.
\end{document}
But this is the result I get:





\refstepcounterto the beginning of\proof. BTW,\proofnameis expanded inside inside a savebox, hence the local definition of\@currentlabel. Interestingly, the etoolbox\patchcmddidn't work on\proof. – John Kormylo Sep 08 '19 at 15:59\patchcmddoesn't work on commands that have an optional argument. Thexpatchpackage was written for the purpose in order to avoid things such as\expandafter\patchcmd\csname\string\proof\endcsnamefor the particular case. – egreg Sep 08 '19 at 21:26