How do I reference a custom counter that shows the section number?custom counter and cross-referencingnameref...

How to say "In Japan, I want to ..."?

How can Schrödinger's cat be both dead and alive?

Why is it that I have to play this note on the piano as A sharp?

If every star in the universe except the Sun were destroyed, would we die?

When does order matter in probability?

Are programming languages necessary/useful for operations research practitioner?

Gap in tcolorbox after title

How invisible hand adjusts stock prices if company is listed on multiple exchanges, under multiple currencies, and one of the currencies plunges?

Walking on an infinite grid

Are there any space probes or landers which regained communication after being lost?

When calculating averages, why can we treat exploding die as if they're independent?

How strong is aircraft-grade spruce?

Contractor cut joist hangers to make them fit

LGPL HDL in larger FPGA design

What is the difference between tl_to_str:V and tl_to_str:N?

What makes an ending "happy"?

How to set any file manager in Linux to show the duration like the Length feature in Windows Explorer?

The meaning of "offing" in "an agreement in the offing"

Contour plot of a sequence of spheres with increasing radius

What makes things real?

When did computers stop checking memory on boot?

How do Scrum teams manage their dependencies on other teams?

After a few interviews, What should I do after told to wait?

Isn't that (two voices leaping to C like this) a breaking of the rules of four-part harmony?



How do I reference a custom counter that shows the section number?


custom counter and cross-referencingnameref : how to get counter's label value instead of section nameMaking an “auto-counter” command - test whether a reference marker already exists?Reference to section where is labelHow to customize cross-reference numbering of custom environments?Referencing Definition by Name and Optional ArgumentCleveref reference name depending on label instead of counter?Setting the enumi counter under custom enumeration with enumitemNumber only referenced equations for local equation numberingUltimate proof at the end/in appendix: different sections, with references to proof/theorem, restate, and synctex






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5















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:



Enter image description here










share|improve this question

































    5















    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:



    Enter image description here










    share|improve this question





























      5












      5








      5








      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:



      Enter image description here










      share|improve this question
















      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:



      Enter image description here







      hyperref cross-referencing labels proof-package






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 51 mins ago









      Peter Mortensen

      5643 silver badges7 bronze badges




      5643 silver badges7 bronze badges










      asked 13 hours ago









      Carina ChenCarina Chen

      363 bronze badges




      363 bronze badges

























          3 Answers
          3






          active

          oldest

          votes


















          3
















          You can manually set the label value by defining @currentlabel at the start of the proof environment.



          Adding something to the start of a command can be done using the xpatch package which provides the xpretocmd (xpatch pre to command) macro. This works the same for environments, an environment like proof defines two commands, one that is executed with begin{proof} which is internally called proof, and one that is executed with end{proof} which is internally called endproof.



          Patching the environment allows you to use the normal label command instead of a newly defined labelling command.



          Because @currentlabel has an @ symbol in the name the redefinition should be enclosed in makeatletter and makeatother.



          MWE:



          documentclass[12pt,letterpaper]{article}

          usepackage{amsthm}
          usepackage{xpatch}
          usepackage{hyperref}
          makeatletter
          xpretocmd{proof}{def@currentlabel{theproof}}{}{}
          makeatother

          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}


          Result:



          enter image description here






          share|improve this answer





















          • 1





            You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

            – John Kormylo
            5 hours ago











          • @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

            – egreg
            29 mins ago





















          2
















          Here is an approach that works, but I am not sure what is going on behind the scenes. I adapted the accepted answer from this question, though copying it verbatim increased the counter proof once when the environment began, and once when the label was defined, resulting in offset numbering, so I just decreased the counter every time the label is called.



          After you define the counter proof, add the the following line:



          newcommand{prooflabel}[1]{addtocounter{proof}{-1}refstepcounter{proof}label{#1}}


          Then whenever you have a proof, instead of label, use prooflabel as below.



          section{One}
          begin{proof}
          prooflabel{p1}
          this is proof one.
          end{proof}

          This should reference proof ref{p1}, which should display as proof 1.1.


          This is the result:



          enter image description here



          Perhaps someone more knowledgeable than me can adjust the prooflabel and other definitions so that there isn't this back and forth couting, but it seems to work as you would like it to work.






          share|improve this answer

































            0
















            Your refstepcounter is issued inside the optional argument to item and the corresponding value of @currentlabel gets forgotten as soon as item is processed, so you actually get references to the section number. You can check it by clicking on the reference.



            A possible solution is to patch proof (the command executed upon entering the proof environment) to issue refstepcounter after trivlist and before item.



            documentclass[12pt,letterpaper]{article}

            usepackage{amsthm}
            usepackage{xpatch}
            usepackage{hyperref}

            newcounter{proof}[section]
            renewcommand{theproof}{thesection.arabic{proof}}
            renewcommand{proofname}{Proof theproof}

            xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

            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}


            enter image description here



            You can also define a proof* environment for unnumbered proofs by saving a copy of proof before patching it.



            documentclass[12pt,letterpaper]{article}

            usepackage{amsthm}
            usepackage{xpatch}
            usepackage{hyperref}

            % save proof
            letunnumberedproofproof
            newenvironment{proof*}
            {renewcommandproofname{Proof}unnumberedproof}
            {endproof}

            newcounter{proof}[section]
            renewcommand{theproof}{thesection.arabic{proof}}
            renewcommand{proofname}{Proof theproof}

            xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

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

            begin{proof*}
            An unnumbered proof.
            end{proof*}

            end{document}





            share|improve this answer






























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "85"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });















              draft saved

              draft discarded
















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f507464%2fhow-do-i-reference-a-custom-counter-that-shows-the-section-number%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3
















              You can manually set the label value by defining @currentlabel at the start of the proof environment.



              Adding something to the start of a command can be done using the xpatch package which provides the xpretocmd (xpatch pre to command) macro. This works the same for environments, an environment like proof defines two commands, one that is executed with begin{proof} which is internally called proof, and one that is executed with end{proof} which is internally called endproof.



              Patching the environment allows you to use the normal label command instead of a newly defined labelling command.



              Because @currentlabel has an @ symbol in the name the redefinition should be enclosed in makeatletter and makeatother.



              MWE:



              documentclass[12pt,letterpaper]{article}

              usepackage{amsthm}
              usepackage{xpatch}
              usepackage{hyperref}
              makeatletter
              xpretocmd{proof}{def@currentlabel{theproof}}{}{}
              makeatother

              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}


              Result:



              enter image description here






              share|improve this answer





















              • 1





                You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

                – John Kormylo
                5 hours ago











              • @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

                – egreg
                29 mins ago


















              3
















              You can manually set the label value by defining @currentlabel at the start of the proof environment.



              Adding something to the start of a command can be done using the xpatch package which provides the xpretocmd (xpatch pre to command) macro. This works the same for environments, an environment like proof defines two commands, one that is executed with begin{proof} which is internally called proof, and one that is executed with end{proof} which is internally called endproof.



              Patching the environment allows you to use the normal label command instead of a newly defined labelling command.



              Because @currentlabel has an @ symbol in the name the redefinition should be enclosed in makeatletter and makeatother.



              MWE:



              documentclass[12pt,letterpaper]{article}

              usepackage{amsthm}
              usepackage{xpatch}
              usepackage{hyperref}
              makeatletter
              xpretocmd{proof}{def@currentlabel{theproof}}{}{}
              makeatother

              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}


              Result:



              enter image description here






              share|improve this answer





















              • 1





                You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

                – John Kormylo
                5 hours ago











              • @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

                – egreg
                29 mins ago
















              3














              3










              3









              You can manually set the label value by defining @currentlabel at the start of the proof environment.



              Adding something to the start of a command can be done using the xpatch package which provides the xpretocmd (xpatch pre to command) macro. This works the same for environments, an environment like proof defines two commands, one that is executed with begin{proof} which is internally called proof, and one that is executed with end{proof} which is internally called endproof.



              Patching the environment allows you to use the normal label command instead of a newly defined labelling command.



              Because @currentlabel has an @ symbol in the name the redefinition should be enclosed in makeatletter and makeatother.



              MWE:



              documentclass[12pt,letterpaper]{article}

              usepackage{amsthm}
              usepackage{xpatch}
              usepackage{hyperref}
              makeatletter
              xpretocmd{proof}{def@currentlabel{theproof}}{}{}
              makeatother

              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}


              Result:



              enter image description here






              share|improve this answer













              You can manually set the label value by defining @currentlabel at the start of the proof environment.



              Adding something to the start of a command can be done using the xpatch package which provides the xpretocmd (xpatch pre to command) macro. This works the same for environments, an environment like proof defines two commands, one that is executed with begin{proof} which is internally called proof, and one that is executed with end{proof} which is internally called endproof.



              Patching the environment allows you to use the normal label command instead of a newly defined labelling command.



              Because @currentlabel has an @ symbol in the name the redefinition should be enclosed in makeatletter and makeatother.



              MWE:



              documentclass[12pt,letterpaper]{article}

              usepackage{amsthm}
              usepackage{xpatch}
              usepackage{hyperref}
              makeatletter
              xpretocmd{proof}{def@currentlabel{theproof}}{}{}
              makeatother

              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}


              Result:



              enter image description here







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 12 hours ago









              MarijnMarijn

              12.3k1 gold badge7 silver badges41 bronze badges




              12.3k1 gold badge7 silver badges41 bronze badges











              • 1





                You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

                – John Kormylo
                5 hours ago











              • @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

                – egreg
                29 mins ago
















              • 1





                You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

                – John Kormylo
                5 hours ago











              • @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

                – egreg
                29 mins ago










              1




              1





              You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

              – John Kormylo
              5 hours ago





              You could have just moved refstepcounter to the beginning of proof. BTW, proofname is expanded inside inside a savebox, hence the local definition of @currentlabel. Interestingly, the etoolbox patchcmd didn't work on proof.

              – John Kormylo
              5 hours ago













              @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

              – egreg
              29 mins ago







              @JohnKormylo patchcmd doesn't work on commands that have an optional argument. The xpatch package was written for the purpose in order to avoid things such as expandafterpatchcmdcsnamestringproofendcsname for the particular case.

              – egreg
              29 mins ago















              2
















              Here is an approach that works, but I am not sure what is going on behind the scenes. I adapted the accepted answer from this question, though copying it verbatim increased the counter proof once when the environment began, and once when the label was defined, resulting in offset numbering, so I just decreased the counter every time the label is called.



              After you define the counter proof, add the the following line:



              newcommand{prooflabel}[1]{addtocounter{proof}{-1}refstepcounter{proof}label{#1}}


              Then whenever you have a proof, instead of label, use prooflabel as below.



              section{One}
              begin{proof}
              prooflabel{p1}
              this is proof one.
              end{proof}

              This should reference proof ref{p1}, which should display as proof 1.1.


              This is the result:



              enter image description here



              Perhaps someone more knowledgeable than me can adjust the prooflabel and other definitions so that there isn't this back and forth couting, but it seems to work as you would like it to work.






              share|improve this answer






























                2
















                Here is an approach that works, but I am not sure what is going on behind the scenes. I adapted the accepted answer from this question, though copying it verbatim increased the counter proof once when the environment began, and once when the label was defined, resulting in offset numbering, so I just decreased the counter every time the label is called.



                After you define the counter proof, add the the following line:



                newcommand{prooflabel}[1]{addtocounter{proof}{-1}refstepcounter{proof}label{#1}}


                Then whenever you have a proof, instead of label, use prooflabel as below.



                section{One}
                begin{proof}
                prooflabel{p1}
                this is proof one.
                end{proof}

                This should reference proof ref{p1}, which should display as proof 1.1.


                This is the result:



                enter image description here



                Perhaps someone more knowledgeable than me can adjust the prooflabel and other definitions so that there isn't this back and forth couting, but it seems to work as you would like it to work.






                share|improve this answer




























                  2














                  2










                  2









                  Here is an approach that works, but I am not sure what is going on behind the scenes. I adapted the accepted answer from this question, though copying it verbatim increased the counter proof once when the environment began, and once when the label was defined, resulting in offset numbering, so I just decreased the counter every time the label is called.



                  After you define the counter proof, add the the following line:



                  newcommand{prooflabel}[1]{addtocounter{proof}{-1}refstepcounter{proof}label{#1}}


                  Then whenever you have a proof, instead of label, use prooflabel as below.



                  section{One}
                  begin{proof}
                  prooflabel{p1}
                  this is proof one.
                  end{proof}

                  This should reference proof ref{p1}, which should display as proof 1.1.


                  This is the result:



                  enter image description here



                  Perhaps someone more knowledgeable than me can adjust the prooflabel and other definitions so that there isn't this back and forth couting, but it seems to work as you would like it to work.






                  share|improve this answer













                  Here is an approach that works, but I am not sure what is going on behind the scenes. I adapted the accepted answer from this question, though copying it verbatim increased the counter proof once when the environment began, and once when the label was defined, resulting in offset numbering, so I just decreased the counter every time the label is called.



                  After you define the counter proof, add the the following line:



                  newcommand{prooflabel}[1]{addtocounter{proof}{-1}refstepcounter{proof}label{#1}}


                  Then whenever you have a proof, instead of label, use prooflabel as below.



                  section{One}
                  begin{proof}
                  prooflabel{p1}
                  this is proof one.
                  end{proof}

                  This should reference proof ref{p1}, which should display as proof 1.1.


                  This is the result:



                  enter image description here



                  Perhaps someone more knowledgeable than me can adjust the prooflabel and other definitions so that there isn't this back and forth couting, but it seems to work as you would like it to work.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 12 hours ago









                  Jānis LazovskisJānis Lazovskis

                  3,55912 silver badges32 bronze badges




                  3,55912 silver badges32 bronze badges


























                      0
















                      Your refstepcounter is issued inside the optional argument to item and the corresponding value of @currentlabel gets forgotten as soon as item is processed, so you actually get references to the section number. You can check it by clicking on the reference.



                      A possible solution is to patch proof (the command executed upon entering the proof environment) to issue refstepcounter after trivlist and before item.



                      documentclass[12pt,letterpaper]{article}

                      usepackage{amsthm}
                      usepackage{xpatch}
                      usepackage{hyperref}

                      newcounter{proof}[section]
                      renewcommand{theproof}{thesection.arabic{proof}}
                      renewcommand{proofname}{Proof theproof}

                      xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

                      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}


                      enter image description here



                      You can also define a proof* environment for unnumbered proofs by saving a copy of proof before patching it.



                      documentclass[12pt,letterpaper]{article}

                      usepackage{amsthm}
                      usepackage{xpatch}
                      usepackage{hyperref}

                      % save proof
                      letunnumberedproofproof
                      newenvironment{proof*}
                      {renewcommandproofname{Proof}unnumberedproof}
                      {endproof}

                      newcounter{proof}[section]
                      renewcommand{theproof}{thesection.arabic{proof}}
                      renewcommand{proofname}{Proof theproof}

                      xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

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

                      begin{proof*}
                      An unnumbered proof.
                      end{proof*}

                      end{document}





                      share|improve this answer
































                        0
















                        Your refstepcounter is issued inside the optional argument to item and the corresponding value of @currentlabel gets forgotten as soon as item is processed, so you actually get references to the section number. You can check it by clicking on the reference.



                        A possible solution is to patch proof (the command executed upon entering the proof environment) to issue refstepcounter after trivlist and before item.



                        documentclass[12pt,letterpaper]{article}

                        usepackage{amsthm}
                        usepackage{xpatch}
                        usepackage{hyperref}

                        newcounter{proof}[section]
                        renewcommand{theproof}{thesection.arabic{proof}}
                        renewcommand{proofname}{Proof theproof}

                        xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

                        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}


                        enter image description here



                        You can also define a proof* environment for unnumbered proofs by saving a copy of proof before patching it.



                        documentclass[12pt,letterpaper]{article}

                        usepackage{amsthm}
                        usepackage{xpatch}
                        usepackage{hyperref}

                        % save proof
                        letunnumberedproofproof
                        newenvironment{proof*}
                        {renewcommandproofname{Proof}unnumberedproof}
                        {endproof}

                        newcounter{proof}[section]
                        renewcommand{theproof}{thesection.arabic{proof}}
                        renewcommand{proofname}{Proof theproof}

                        xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

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

                        begin{proof*}
                        An unnumbered proof.
                        end{proof*}

                        end{document}





                        share|improve this answer






























                          0














                          0










                          0









                          Your refstepcounter is issued inside the optional argument to item and the corresponding value of @currentlabel gets forgotten as soon as item is processed, so you actually get references to the section number. You can check it by clicking on the reference.



                          A possible solution is to patch proof (the command executed upon entering the proof environment) to issue refstepcounter after trivlist and before item.



                          documentclass[12pt,letterpaper]{article}

                          usepackage{amsthm}
                          usepackage{xpatch}
                          usepackage{hyperref}

                          newcounter{proof}[section]
                          renewcommand{theproof}{thesection.arabic{proof}}
                          renewcommand{proofname}{Proof theproof}

                          xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

                          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}


                          enter image description here



                          You can also define a proof* environment for unnumbered proofs by saving a copy of proof before patching it.



                          documentclass[12pt,letterpaper]{article}

                          usepackage{amsthm}
                          usepackage{xpatch}
                          usepackage{hyperref}

                          % save proof
                          letunnumberedproofproof
                          newenvironment{proof*}
                          {renewcommandproofname{Proof}unnumberedproof}
                          {endproof}

                          newcounter{proof}[section]
                          renewcommand{theproof}{thesection.arabic{proof}}
                          renewcommand{proofname}{Proof theproof}

                          xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

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

                          begin{proof*}
                          An unnumbered proof.
                          end{proof*}

                          end{document}





                          share|improve this answer















                          Your refstepcounter is issued inside the optional argument to item and the corresponding value of @currentlabel gets forgotten as soon as item is processed, so you actually get references to the section number. You can check it by clicking on the reference.



                          A possible solution is to patch proof (the command executed upon entering the proof environment) to issue refstepcounter after trivlist and before item.



                          documentclass[12pt,letterpaper]{article}

                          usepackage{amsthm}
                          usepackage{xpatch}
                          usepackage{hyperref}

                          newcounter{proof}[section]
                          renewcommand{theproof}{thesection.arabic{proof}}
                          renewcommand{proofname}{Proof theproof}

                          xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

                          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}


                          enter image description here



                          You can also define a proof* environment for unnumbered proofs by saving a copy of proof before patching it.



                          documentclass[12pt,letterpaper]{article}

                          usepackage{amsthm}
                          usepackage{xpatch}
                          usepackage{hyperref}

                          % save proof
                          letunnumberedproofproof
                          newenvironment{proof*}
                          {renewcommandproofname{Proof}unnumberedproof}
                          {endproof}

                          newcounter{proof}[section]
                          renewcommand{theproof}{thesection.arabic{proof}}
                          renewcommand{proofname}{Proof theproof}

                          xpatchcmd{proof}{trivlist}{trivlistrefstepcounter{proof}}{}{}

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

                          begin{proof*}
                          An unnumbered proof.
                          end{proof*}

                          end{document}






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 30 mins ago

























                          answered 37 mins ago









                          egregegreg

                          767k91 gold badges2002 silver badges3358 bronze badges




                          767k91 gold badges2002 silver badges3358 bronze badges


































                              draft saved

                              draft discarded



















































                              Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f507464%2fhow-do-i-reference-a-custom-counter-that-shows-the-section-number%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                              Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                              Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...