ref takes reader to incorrect section

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












Context



In the document I'm writing, I have redefined each environment and have included a new counter, called counter, to help with the numbering of the environments. My intention is for each definition, proposition, theorem, and so on to all use the same counter, which displays the section and then the counter number with the counter reset for each section. For example, in Section 2, the first definition reads "Definition 2.1", and the following proposition then reads "Proposition 2.2".



The counter has been defined as follows.



newcountercounter
renewcommandthecounterthesection.arabiccounter


The environments have been defined similarly to the following.



newenvironmentdefinition[1]%
refstepcountercounter%
textscDefinition~thecounter. #1
%
%


Each environment has label after begin<environment> to insert the anchor.



To reset the counter for each section, I have included setcountercounter0 after section. Redefining thecounter to include thesection meant that cross-referencing with ref displayed the correct section with each number, and all the environments themselves display the correct numbering.



The Issue



The issue I have is that when I click on the link for Environment 2.X, I am taken to Environment 1.X, and similarly for Environment 3.X. The reference does not seem to be reading the section anchor, even though it displays the number for the environment with the correct section.



My guess is that the redefining of thecounter is causing the issue. How can I fix this?







share|improve this question


























    up vote
    5
    down vote

    favorite
    1












    Context



    In the document I'm writing, I have redefined each environment and have included a new counter, called counter, to help with the numbering of the environments. My intention is for each definition, proposition, theorem, and so on to all use the same counter, which displays the section and then the counter number with the counter reset for each section. For example, in Section 2, the first definition reads "Definition 2.1", and the following proposition then reads "Proposition 2.2".



    The counter has been defined as follows.



    newcountercounter
    renewcommandthecounterthesection.arabiccounter


    The environments have been defined similarly to the following.



    newenvironmentdefinition[1]%
    refstepcountercounter%
    textscDefinition~thecounter. #1
    %
    %


    Each environment has label after begin<environment> to insert the anchor.



    To reset the counter for each section, I have included setcountercounter0 after section. Redefining thecounter to include thesection meant that cross-referencing with ref displayed the correct section with each number, and all the environments themselves display the correct numbering.



    The Issue



    The issue I have is that when I click on the link for Environment 2.X, I am taken to Environment 1.X, and similarly for Environment 3.X. The reference does not seem to be reading the section anchor, even though it displays the number for the environment with the correct section.



    My guess is that the redefining of thecounter is causing the issue. How can I fix this?







    share|improve this question
























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      Context



      In the document I'm writing, I have redefined each environment and have included a new counter, called counter, to help with the numbering of the environments. My intention is for each definition, proposition, theorem, and so on to all use the same counter, which displays the section and then the counter number with the counter reset for each section. For example, in Section 2, the first definition reads "Definition 2.1", and the following proposition then reads "Proposition 2.2".



      The counter has been defined as follows.



      newcountercounter
      renewcommandthecounterthesection.arabiccounter


      The environments have been defined similarly to the following.



      newenvironmentdefinition[1]%
      refstepcountercounter%
      textscDefinition~thecounter. #1
      %
      %


      Each environment has label after begin<environment> to insert the anchor.



      To reset the counter for each section, I have included setcountercounter0 after section. Redefining thecounter to include thesection meant that cross-referencing with ref displayed the correct section with each number, and all the environments themselves display the correct numbering.



      The Issue



      The issue I have is that when I click on the link for Environment 2.X, I am taken to Environment 1.X, and similarly for Environment 3.X. The reference does not seem to be reading the section anchor, even though it displays the number for the environment with the correct section.



      My guess is that the redefining of thecounter is causing the issue. How can I fix this?







      share|improve this question














      Context



      In the document I'm writing, I have redefined each environment and have included a new counter, called counter, to help with the numbering of the environments. My intention is for each definition, proposition, theorem, and so on to all use the same counter, which displays the section and then the counter number with the counter reset for each section. For example, in Section 2, the first definition reads "Definition 2.1", and the following proposition then reads "Proposition 2.2".



      The counter has been defined as follows.



      newcountercounter
      renewcommandthecounterthesection.arabiccounter


      The environments have been defined similarly to the following.



      newenvironmentdefinition[1]%
      refstepcountercounter%
      textscDefinition~thecounter. #1
      %
      %


      Each environment has label after begin<environment> to insert the anchor.



      To reset the counter for each section, I have included setcountercounter0 after section. Redefining thecounter to include thesection meant that cross-referencing with ref displayed the correct section with each number, and all the environments themselves display the correct numbering.



      The Issue



      The issue I have is that when I click on the link for Environment 2.X, I am taken to Environment 1.X, and similarly for Environment 3.X. The reference does not seem to be reading the section anchor, even though it displays the number for the environment with the correct section.



      My guess is that the redefining of thecounter is causing the issue. How can I fix this?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 9 at 20:20









      Werner

      418k579081572




      418k579081572










      asked Aug 9 at 20:09









      Bill Wallis

      1547




      1547




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Your problem here should be solved using



          newcountercounter[section]


          which links the counter counter to the section counter, making it reset (be set to 0) with every step of the section counter (at section...).



          Here is a complete example of the code that provides the correct jumps:



          documentclassarticle

          usepackagehyperref

          newcountercounter[section]
          renewcommandthecounterthesection.arabiccounter

          newenvironmentdefinition[1]%
          refstepcountercounter%
          noindenttextscDefinition~thecounter. #1
          %
          par%

          begindocument

          See Definitions~refdef:first, refdef:second, refdef:third and refdef:last.

          sectionFirst section
          begindefinitionlabeldef:firstSome definitionenddefinition
          begindefinitionSome definitionenddefinition
          begindefinitionSome definitionenddefinition

          sectionSecond section
          begindefinitionlabeldef:secondSome definitionenddefinition
          begindefinitionSome definitionenddefinition
          begindefinitionSome definitionenddefinition

          sectionThird section
          begindefinitionlabeldef:thirdSome definitionenddefinition
          begindefinitionSome definitionenddefinition
          begindefinitionSome definitionenddefinition

          sectionLast section
          begindefinitionlabeldef:lastSome definitionenddefinition
          begindefinitionSome definitionenddefinition
          begindefinitionSome definitionenddefinition

          enddocument





          share|improve this answer




















          • Awesome, an easy fix! Thanks.
            – Bill Wallis
            Aug 9 at 20:24

















          up vote
          6
          down vote













          Use a more standard framework, which is supported by hyperref out of the box.



          documentclassarticle
          usepackageamsmath,amsthm
          usepackagehyperref

          usepackagelipsum % for context

          newtheoremstylewallisdefinition
          0pt % ABOVESPACE
          0pt % BELOWSPACE
          upshape % BODYFONT
          0pt % INDENT (empty value is the same as 0pt)
          upshape % HEADFONT
          % HEADPUNCT
          % HEADSPACE
          % CUSTOM-HEAD-SPEC follows
          thmnametextsc#1thmnumber #2.thmnote #3

          theoremstylewallisdefinition
          newtheoremdefinitionDefinition[section]

          begindocument

          sectionTest

          See definition~refdef:foo.

          clearpage

          lipsum[2]

          begindefinition[Attribution]labeldef:foo
          A emphfoo is something very useful. We will use foos all the
          time in this paper. This should be enough to wrap.
          enddefinition

          lipsum[3]

          enddocument


          I'd add some vertical space, though.



          documentclassarticle
          usepackageamsmath,amsthm
          usepackagehyperref

          usepackagelipsum % for context

          newtheoremstylewallisdefinition
          topsep % ABOVESPACE
          topsep % BELOWSPACE
          upshape % BODYFONT
          0pt % INDENT (empty value is the same as 0pt)
          upshape % HEADFONT
          % HEADPUNCT
          % HEADSPACE
          % CUSTOM-HEAD-SPEC follows
          thmnametextsc#1thmnumber #2.thmnote #3

          theoremstylewallisdefinition
          newtheoremdefinitionDefinition[section]

          begindocument

          sectionTest

          See definition~refdef:foo.

          clearpage

          lipsum[2]

          begindefinition[Attribution]labeldef:foo
          A emphfoo is something very useful. We will use foos all the
          time in this paper. This should be enough to wrap.
          enddefinition

          lipsum[3]

          enddocument





          share|improve this answer



























            up vote
            5
            down vote













            Use the optional argument of newcounter if you want a counter to reset with another. This here works fine:



            documentclassarticle

            newcountercounter[section]
            renewcommandthecounterthesection.arabiccounter
            newenvironmentdefinition[1]%
            refstepcountercounter%
            textscDefinition~thecounter. #1
            %
            %
            usepackagehyperref
            begindocument
            sectionabc


            begindefinition
            labela
            abc
            enddefinition


            newpage
            sectionb
            begindefinition
            labelb
            abc
            enddefinition

            newpage
            refa refb

            enddocument





            share|improve this answer



























              up vote
              1
              down vote













              Let's go through your posting:




              In the document I'm writing, I have redefined each environment and
              have included a new counter, called counter, to help with the
              numbering of the environments. My intention is for each definition,
              proposition, theorem, and so on to all use the same counter, which
              displays the section and then the counter number with the counter
              reset for each section. For example, in Section 2, the first
              definition reads "Definition 2.1", and the following proposition then
              reads "Proposition 2.2".




              Instead of doing this, you could define your environments in terms of newtheorem.

              Syntax of newtheorem is:



              newtheorem&langle;Name of the environment and — in case no already
              existing counter is to be used — name of
              newly to allocate underlying counter.&rangle;
              %
              [&langle;Name of already existing counter to be used for
              numbering the environment.&rangle;
              ]%
              &langle;Textual phrase denoting the title/heading/the kind of
              item of sectioning produced by an instance of the
              environment.&rangle;
              %
              [&langle;Name of superordinate sectioning counter whose value is
              part of the number of the sectioning-item provided by
              this environment, and whose incrementing via `refstepcounter`
              triggers resetting the counter in use for numbering the
              environment.&rangle;
              ]


              Thus you could, e.g., do:



              newtheoremtheoremTheorem[section]%
              newtheoremproposition[theorem]Proposition%
              newtheoremdefinition[theorem]Definition%


              If with this approach you wish to also use the hyperref package and to use its autoref-feature, you need to also load the aliascnt package and do:



              documentclass...
              ...
              usepackagehyperref
              usepackagealiascnt
              ...
              newtheoremtheoremTheorem[section]%
              %
              newaliascntpropositiontheorem
              newtheoremproposition[proposition]Proposition%
              aliascntresettheproposition
              newcommandpropositionautorefnameProposition
              %
              newaliascntdefinitiontheorem
              newtheoremdefinition[definition]Definition%
              aliascntresetthedefinition
              newcommanddefinitionnautorefnameDefinition


              Beneath other things, the aliascnt-package solves problems related to the autoref-feature of the hyperref-package.
              Also it provides the possibility of having different anchor-name-patterns for hyperlinks. (More information about this can be found in the manual of the hyperref package, section 4: additional user macros, autoref.)



              E.g., the name of the anchor of theorem 2.4 will not be #counter.2.4 but #theorem.2.4.

              E.g., the name of the anchor of proposition 2.5 will not be #counter.2.5 but #proposition.2.5.

              E.g., the name of the anchor of definition 2.6 will not be #counter.2.6 but #definition.2.6.




              The counter has been defined as follows.



              newcountercounter
              renewcommandthecounterthesection.arabiccounter



              If you wish the counter counter to be reset to the value 0 whenever the counter section is incremented via refstepcounter, which in turn is used by the sectioning-command section, apply newcounter as follows:



              newcountercounter[section]



              Each environment has label after begin<environment> to
              insert the anchor.




              The assumption that the label-command would place an anchor is a common misunderstanding.



              Anchors are placed by sectioning-commands like section or begintheorem or item (of an enumerate-environment). They internally use refstepcounter as you did with your environments.



              refstepcounter does



              • increment the counter,


              • create an anchor-name,


              • place an anchor of that name,


              • make the name of that just placed anchor available to the label-macro as the expansion of the macro @currentHref,


              • make the value of the just incremented counter availabe to the label-macro as the expansion of the macro @currentlabel.


              label itself does neither create anchor names nor place anchors. label only writes information that is provided by sectioning-commands in terms of redefining macros of specific names (@currentlabel, @currentHref, ...) into the .aux-file in terms of these nice newlabel-entries.



              In case I wouldn't care about anchor-names for hyperlinks and the autoref-feature, I would probably do it as follows:



              documentclassarticle
              usepackagehyperref
              newcountercounter[section]
              renewcommandthecounterthesection.arabiccounter
              renewcommandtheHcountertheHsection.arabiccounter

              newcommandunderlyingformatting[1]%
              refstepcountercounter%
              parnoindent
              textsc#1~thecounter. #1
              %

              newcommandcounterautorefnameTheorem/Definition/Proposition

              newenvironmenttheorem[1]underlyingformattingTheorem%

              newenvironmentdefinition[1]underlyingformattingDefinition%

              newenvironmentproposition[1]underlyingformattingProposition%

              begindocument

              sectionA section

              refthm1

              autorefthm1

              refdef1

              autorefdef1

              refpro1

              autorefpro1

              refthm2

              autorefthm2

              refdef2

              autorefdef2

              refpro2

              autorefpro2

              begintheoremlabelthm1
              A theorem
              endtheorem

              begindefinitionlabeldef1
              A definition
              enddefinition

              beginpropositionlabelpro1
              A proposition
              endproposition

              begintheoremlabelthm2
              Another theorem
              endtheorem

              begindefinitionlabeldef2
              Another definition
              enddefinition

              beginpropositionlabelpro2
              Another proposition
              endproposition

              enddocument


              In case of caring about anchor-names and autoref and the like, I would do it as follows—I "borrowed" the theoremstyle-code from egreg ;-) :



              documentclassarticle
              usepackageamsmath,amsthm
              usepackagehyperref
              usepackagealiascnt

              usepackagelipsum % for context

              newtheoremstylewallisdefinition
              topsep % ABOVESPACE
              topsep % BELOWSPACE
              upshape % BODYFONT
              0pt % INDENT (empty value is the same as 0pt)
              upshape % HEADFONT
              % HEADPUNCT
              % HEADSPACE
              % CUSTOM-HEAD-SPEC follows
              thmnametextsc#1thmnumber #2.thmnote #3

              theoremstylewallisdefinition
              newtheoremtheoremTheorem[section]%

              newaliascntpropositiontheorem
              newtheoremproposition[proposition]Proposition%
              aliascntresettheproposition
              newcommandpropositionautorefnameProposition

              newaliascntdefinitiontheorem
              newtheoremdefinition[definition]Definition%
              aliascntresetthedefinition
              newcommanddefinitionautorefnameDefinition

              begindocument

              sectionTest

              See definition~refdef:foo.

              See autorefdef:foo.

              See theorem~refthm:foo.

              See autorefthm:foo.

              See proposition~refprp:foo.

              See autorefprp:foo.

              See definition~refdef:bar.

              See autorefdef:bar.

              See theorem~refthm:bar.

              See autorefthm:bar.

              See proposition~refprp:bar.

              See autorefprp:bar.

              clearpage

              lipsum[2]

              begindefinition[(Foo-attribution.)]labeldef:foo
              A emphfoo is something very useful. Therefore we will not use
              foos all the time in this paper. This should be enough to wrap.
              enddefinition

              lipsum[3]

              begintheorem[(Foo's bar-associativity.)]labelthm:foo
              Foo is bar-associative. The proof is left to a drunken monkey.
              endtheorem

              lipsum[4]

              beginproposition[(Foo's foobar-associativity.)]labelprp:foo
              Foo is also foobar-associative. Before the break we announce proving
              after the break. After the break we proclaim having proven just
              before the break and continue with other things.
              endproposition

              lipsum[5]

              begindefinition[(Bar-attribution.)]labeldef:bar
              A emphbar is something very useful but we will never really
              use bars in this paper. This should be enough to wrap.
              enddefinition

              lipsum[6]

              begintheorem[(Bar's foo-associativity.)]labelthm:bar
              Bar is foo-associative. The proof is left to a drunken donkey.
              endtheorem

              lipsum[7]

              beginproposition[(Bar's barfoo-assoviativity.)]labelprp:bar
              Bar is also barfoo-associative. We proclaim that this is obvious
              and cause fear of attracting attention in an embarrassing way on
              the side of those people that don't agree.
              endproposition

              enddocument





              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',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                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%2f445377%2fref-takes-reader-to-incorrect-section%23new-answer', 'question_page');

                );

                Post as a guest






























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                4
                down vote



                accepted










                Your problem here should be solved using



                newcountercounter[section]


                which links the counter counter to the section counter, making it reset (be set to 0) with every step of the section counter (at section...).



                Here is a complete example of the code that provides the correct jumps:



                documentclassarticle

                usepackagehyperref

                newcountercounter[section]
                renewcommandthecounterthesection.arabiccounter

                newenvironmentdefinition[1]%
                refstepcountercounter%
                noindenttextscDefinition~thecounter. #1
                %
                par%

                begindocument

                See Definitions~refdef:first, refdef:second, refdef:third and refdef:last.

                sectionFirst section
                begindefinitionlabeldef:firstSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionSecond section
                begindefinitionlabeldef:secondSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionThird section
                begindefinitionlabeldef:thirdSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionLast section
                begindefinitionlabeldef:lastSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                enddocument





                share|improve this answer




















                • Awesome, an easy fix! Thanks.
                  – Bill Wallis
                  Aug 9 at 20:24














                up vote
                4
                down vote



                accepted










                Your problem here should be solved using



                newcountercounter[section]


                which links the counter counter to the section counter, making it reset (be set to 0) with every step of the section counter (at section...).



                Here is a complete example of the code that provides the correct jumps:



                documentclassarticle

                usepackagehyperref

                newcountercounter[section]
                renewcommandthecounterthesection.arabiccounter

                newenvironmentdefinition[1]%
                refstepcountercounter%
                noindenttextscDefinition~thecounter. #1
                %
                par%

                begindocument

                See Definitions~refdef:first, refdef:second, refdef:third and refdef:last.

                sectionFirst section
                begindefinitionlabeldef:firstSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionSecond section
                begindefinitionlabeldef:secondSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionThird section
                begindefinitionlabeldef:thirdSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionLast section
                begindefinitionlabeldef:lastSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                enddocument





                share|improve this answer




















                • Awesome, an easy fix! Thanks.
                  – Bill Wallis
                  Aug 9 at 20:24












                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                Your problem here should be solved using



                newcountercounter[section]


                which links the counter counter to the section counter, making it reset (be set to 0) with every step of the section counter (at section...).



                Here is a complete example of the code that provides the correct jumps:



                documentclassarticle

                usepackagehyperref

                newcountercounter[section]
                renewcommandthecounterthesection.arabiccounter

                newenvironmentdefinition[1]%
                refstepcountercounter%
                noindenttextscDefinition~thecounter. #1
                %
                par%

                begindocument

                See Definitions~refdef:first, refdef:second, refdef:third and refdef:last.

                sectionFirst section
                begindefinitionlabeldef:firstSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionSecond section
                begindefinitionlabeldef:secondSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionThird section
                begindefinitionlabeldef:thirdSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionLast section
                begindefinitionlabeldef:lastSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                enddocument





                share|improve this answer












                Your problem here should be solved using



                newcountercounter[section]


                which links the counter counter to the section counter, making it reset (be set to 0) with every step of the section counter (at section...).



                Here is a complete example of the code that provides the correct jumps:



                documentclassarticle

                usepackagehyperref

                newcountercounter[section]
                renewcommandthecounterthesection.arabiccounter

                newenvironmentdefinition[1]%
                refstepcountercounter%
                noindenttextscDefinition~thecounter. #1
                %
                par%

                begindocument

                See Definitions~refdef:first, refdef:second, refdef:third and refdef:last.

                sectionFirst section
                begindefinitionlabeldef:firstSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionSecond section
                begindefinitionlabeldef:secondSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionThird section
                begindefinitionlabeldef:thirdSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                sectionLast section
                begindefinitionlabeldef:lastSome definitionenddefinition
                begindefinitionSome definitionenddefinition
                begindefinitionSome definitionenddefinition

                enddocument






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 9 at 20:19









                Werner

                418k579081572




                418k579081572











                • Awesome, an easy fix! Thanks.
                  – Bill Wallis
                  Aug 9 at 20:24
















                • Awesome, an easy fix! Thanks.
                  – Bill Wallis
                  Aug 9 at 20:24















                Awesome, an easy fix! Thanks.
                – Bill Wallis
                Aug 9 at 20:24




                Awesome, an easy fix! Thanks.
                – Bill Wallis
                Aug 9 at 20:24










                up vote
                6
                down vote













                Use a more standard framework, which is supported by hyperref out of the box.



                documentclassarticle
                usepackageamsmath,amsthm
                usepackagehyperref

                usepackagelipsum % for context

                newtheoremstylewallisdefinition
                0pt % ABOVESPACE
                0pt % BELOWSPACE
                upshape % BODYFONT
                0pt % INDENT (empty value is the same as 0pt)
                upshape % HEADFONT
                % HEADPUNCT
                % HEADSPACE
                % CUSTOM-HEAD-SPEC follows
                thmnametextsc#1thmnumber #2.thmnote #3

                theoremstylewallisdefinition
                newtheoremdefinitionDefinition[section]

                begindocument

                sectionTest

                See definition~refdef:foo.

                clearpage

                lipsum[2]

                begindefinition[Attribution]labeldef:foo
                A emphfoo is something very useful. We will use foos all the
                time in this paper. This should be enough to wrap.
                enddefinition

                lipsum[3]

                enddocument


                I'd add some vertical space, though.



                documentclassarticle
                usepackageamsmath,amsthm
                usepackagehyperref

                usepackagelipsum % for context

                newtheoremstylewallisdefinition
                topsep % ABOVESPACE
                topsep % BELOWSPACE
                upshape % BODYFONT
                0pt % INDENT (empty value is the same as 0pt)
                upshape % HEADFONT
                % HEADPUNCT
                % HEADSPACE
                % CUSTOM-HEAD-SPEC follows
                thmnametextsc#1thmnumber #2.thmnote #3

                theoremstylewallisdefinition
                newtheoremdefinitionDefinition[section]

                begindocument

                sectionTest

                See definition~refdef:foo.

                clearpage

                lipsum[2]

                begindefinition[Attribution]labeldef:foo
                A emphfoo is something very useful. We will use foos all the
                time in this paper. This should be enough to wrap.
                enddefinition

                lipsum[3]

                enddocument





                share|improve this answer
























                  up vote
                  6
                  down vote













                  Use a more standard framework, which is supported by hyperref out of the box.



                  documentclassarticle
                  usepackageamsmath,amsthm
                  usepackagehyperref

                  usepackagelipsum % for context

                  newtheoremstylewallisdefinition
                  0pt % ABOVESPACE
                  0pt % BELOWSPACE
                  upshape % BODYFONT
                  0pt % INDENT (empty value is the same as 0pt)
                  upshape % HEADFONT
                  % HEADPUNCT
                  % HEADSPACE
                  % CUSTOM-HEAD-SPEC follows
                  thmnametextsc#1thmnumber #2.thmnote #3

                  theoremstylewallisdefinition
                  newtheoremdefinitionDefinition[section]

                  begindocument

                  sectionTest

                  See definition~refdef:foo.

                  clearpage

                  lipsum[2]

                  begindefinition[Attribution]labeldef:foo
                  A emphfoo is something very useful. We will use foos all the
                  time in this paper. This should be enough to wrap.
                  enddefinition

                  lipsum[3]

                  enddocument


                  I'd add some vertical space, though.



                  documentclassarticle
                  usepackageamsmath,amsthm
                  usepackagehyperref

                  usepackagelipsum % for context

                  newtheoremstylewallisdefinition
                  topsep % ABOVESPACE
                  topsep % BELOWSPACE
                  upshape % BODYFONT
                  0pt % INDENT (empty value is the same as 0pt)
                  upshape % HEADFONT
                  % HEADPUNCT
                  % HEADSPACE
                  % CUSTOM-HEAD-SPEC follows
                  thmnametextsc#1thmnumber #2.thmnote #3

                  theoremstylewallisdefinition
                  newtheoremdefinitionDefinition[section]

                  begindocument

                  sectionTest

                  See definition~refdef:foo.

                  clearpage

                  lipsum[2]

                  begindefinition[Attribution]labeldef:foo
                  A emphfoo is something very useful. We will use foos all the
                  time in this paper. This should be enough to wrap.
                  enddefinition

                  lipsum[3]

                  enddocument





                  share|improve this answer






















                    up vote
                    6
                    down vote










                    up vote
                    6
                    down vote









                    Use a more standard framework, which is supported by hyperref out of the box.



                    documentclassarticle
                    usepackageamsmath,amsthm
                    usepackagehyperref

                    usepackagelipsum % for context

                    newtheoremstylewallisdefinition
                    0pt % ABOVESPACE
                    0pt % BELOWSPACE
                    upshape % BODYFONT
                    0pt % INDENT (empty value is the same as 0pt)
                    upshape % HEADFONT
                    % HEADPUNCT
                    % HEADSPACE
                    % CUSTOM-HEAD-SPEC follows
                    thmnametextsc#1thmnumber #2.thmnote #3

                    theoremstylewallisdefinition
                    newtheoremdefinitionDefinition[section]

                    begindocument

                    sectionTest

                    See definition~refdef:foo.

                    clearpage

                    lipsum[2]

                    begindefinition[Attribution]labeldef:foo
                    A emphfoo is something very useful. We will use foos all the
                    time in this paper. This should be enough to wrap.
                    enddefinition

                    lipsum[3]

                    enddocument


                    I'd add some vertical space, though.



                    documentclassarticle
                    usepackageamsmath,amsthm
                    usepackagehyperref

                    usepackagelipsum % for context

                    newtheoremstylewallisdefinition
                    topsep % ABOVESPACE
                    topsep % BELOWSPACE
                    upshape % BODYFONT
                    0pt % INDENT (empty value is the same as 0pt)
                    upshape % HEADFONT
                    % HEADPUNCT
                    % HEADSPACE
                    % CUSTOM-HEAD-SPEC follows
                    thmnametextsc#1thmnumber #2.thmnote #3

                    theoremstylewallisdefinition
                    newtheoremdefinitionDefinition[section]

                    begindocument

                    sectionTest

                    See definition~refdef:foo.

                    clearpage

                    lipsum[2]

                    begindefinition[Attribution]labeldef:foo
                    A emphfoo is something very useful. We will use foos all the
                    time in this paper. This should be enough to wrap.
                    enddefinition

                    lipsum[3]

                    enddocument





                    share|improve this answer












                    Use a more standard framework, which is supported by hyperref out of the box.



                    documentclassarticle
                    usepackageamsmath,amsthm
                    usepackagehyperref

                    usepackagelipsum % for context

                    newtheoremstylewallisdefinition
                    0pt % ABOVESPACE
                    0pt % BELOWSPACE
                    upshape % BODYFONT
                    0pt % INDENT (empty value is the same as 0pt)
                    upshape % HEADFONT
                    % HEADPUNCT
                    % HEADSPACE
                    % CUSTOM-HEAD-SPEC follows
                    thmnametextsc#1thmnumber #2.thmnote #3

                    theoremstylewallisdefinition
                    newtheoremdefinitionDefinition[section]

                    begindocument

                    sectionTest

                    See definition~refdef:foo.

                    clearpage

                    lipsum[2]

                    begindefinition[Attribution]labeldef:foo
                    A emphfoo is something very useful. We will use foos all the
                    time in this paper. This should be enough to wrap.
                    enddefinition

                    lipsum[3]

                    enddocument


                    I'd add some vertical space, though.



                    documentclassarticle
                    usepackageamsmath,amsthm
                    usepackagehyperref

                    usepackagelipsum % for context

                    newtheoremstylewallisdefinition
                    topsep % ABOVESPACE
                    topsep % BELOWSPACE
                    upshape % BODYFONT
                    0pt % INDENT (empty value is the same as 0pt)
                    upshape % HEADFONT
                    % HEADPUNCT
                    % HEADSPACE
                    % CUSTOM-HEAD-SPEC follows
                    thmnametextsc#1thmnumber #2.thmnote #3

                    theoremstylewallisdefinition
                    newtheoremdefinitionDefinition[section]

                    begindocument

                    sectionTest

                    See definition~refdef:foo.

                    clearpage

                    lipsum[2]

                    begindefinition[Attribution]labeldef:foo
                    A emphfoo is something very useful. We will use foos all the
                    time in this paper. This should be enough to wrap.
                    enddefinition

                    lipsum[3]

                    enddocument






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 9 at 21:46









                    egreg

                    676k8318003043




                    676k8318003043




















                        up vote
                        5
                        down vote













                        Use the optional argument of newcounter if you want a counter to reset with another. This here works fine:



                        documentclassarticle

                        newcountercounter[section]
                        renewcommandthecounterthesection.arabiccounter
                        newenvironmentdefinition[1]%
                        refstepcountercounter%
                        textscDefinition~thecounter. #1
                        %
                        %
                        usepackagehyperref
                        begindocument
                        sectionabc


                        begindefinition
                        labela
                        abc
                        enddefinition


                        newpage
                        sectionb
                        begindefinition
                        labelb
                        abc
                        enddefinition

                        newpage
                        refa refb

                        enddocument





                        share|improve this answer
























                          up vote
                          5
                          down vote













                          Use the optional argument of newcounter if you want a counter to reset with another. This here works fine:



                          documentclassarticle

                          newcountercounter[section]
                          renewcommandthecounterthesection.arabiccounter
                          newenvironmentdefinition[1]%
                          refstepcountercounter%
                          textscDefinition~thecounter. #1
                          %
                          %
                          usepackagehyperref
                          begindocument
                          sectionabc


                          begindefinition
                          labela
                          abc
                          enddefinition


                          newpage
                          sectionb
                          begindefinition
                          labelb
                          abc
                          enddefinition

                          newpage
                          refa refb

                          enddocument





                          share|improve this answer






















                            up vote
                            5
                            down vote










                            up vote
                            5
                            down vote









                            Use the optional argument of newcounter if you want a counter to reset with another. This here works fine:



                            documentclassarticle

                            newcountercounter[section]
                            renewcommandthecounterthesection.arabiccounter
                            newenvironmentdefinition[1]%
                            refstepcountercounter%
                            textscDefinition~thecounter. #1
                            %
                            %
                            usepackagehyperref
                            begindocument
                            sectionabc


                            begindefinition
                            labela
                            abc
                            enddefinition


                            newpage
                            sectionb
                            begindefinition
                            labelb
                            abc
                            enddefinition

                            newpage
                            refa refb

                            enddocument





                            share|improve this answer












                            Use the optional argument of newcounter if you want a counter to reset with another. This here works fine:



                            documentclassarticle

                            newcountercounter[section]
                            renewcommandthecounterthesection.arabiccounter
                            newenvironmentdefinition[1]%
                            refstepcountercounter%
                            textscDefinition~thecounter. #1
                            %
                            %
                            usepackagehyperref
                            begindocument
                            sectionabc


                            begindefinition
                            labela
                            abc
                            enddefinition


                            newpage
                            sectionb
                            begindefinition
                            labelb
                            abc
                            enddefinition

                            newpage
                            refa refb

                            enddocument






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 9 at 20:19









                            Ulrike Fischer

                            177k7278645




                            177k7278645




















                                up vote
                                1
                                down vote













                                Let's go through your posting:




                                In the document I'm writing, I have redefined each environment and
                                have included a new counter, called counter, to help with the
                                numbering of the environments. My intention is for each definition,
                                proposition, theorem, and so on to all use the same counter, which
                                displays the section and then the counter number with the counter
                                reset for each section. For example, in Section 2, the first
                                definition reads "Definition 2.1", and the following proposition then
                                reads "Proposition 2.2".




                                Instead of doing this, you could define your environments in terms of newtheorem.

                                Syntax of newtheorem is:



                                newtheorem&langle;Name of the environment and — in case no already
                                existing counter is to be used — name of
                                newly to allocate underlying counter.&rangle;
                                %
                                [&langle;Name of already existing counter to be used for
                                numbering the environment.&rangle;
                                ]%
                                &langle;Textual phrase denoting the title/heading/the kind of
                                item of sectioning produced by an instance of the
                                environment.&rangle;
                                %
                                [&langle;Name of superordinate sectioning counter whose value is
                                part of the number of the sectioning-item provided by
                                this environment, and whose incrementing via `refstepcounter`
                                triggers resetting the counter in use for numbering the
                                environment.&rangle;
                                ]


                                Thus you could, e.g., do:



                                newtheoremtheoremTheorem[section]%
                                newtheoremproposition[theorem]Proposition%
                                newtheoremdefinition[theorem]Definition%


                                If with this approach you wish to also use the hyperref package and to use its autoref-feature, you need to also load the aliascnt package and do:



                                documentclass...
                                ...
                                usepackagehyperref
                                usepackagealiascnt
                                ...
                                newtheoremtheoremTheorem[section]%
                                %
                                newaliascntpropositiontheorem
                                newtheoremproposition[proposition]Proposition%
                                aliascntresettheproposition
                                newcommandpropositionautorefnameProposition
                                %
                                newaliascntdefinitiontheorem
                                newtheoremdefinition[definition]Definition%
                                aliascntresetthedefinition
                                newcommanddefinitionnautorefnameDefinition


                                Beneath other things, the aliascnt-package solves problems related to the autoref-feature of the hyperref-package.
                                Also it provides the possibility of having different anchor-name-patterns for hyperlinks. (More information about this can be found in the manual of the hyperref package, section 4: additional user macros, autoref.)



                                E.g., the name of the anchor of theorem 2.4 will not be #counter.2.4 but #theorem.2.4.

                                E.g., the name of the anchor of proposition 2.5 will not be #counter.2.5 but #proposition.2.5.

                                E.g., the name of the anchor of definition 2.6 will not be #counter.2.6 but #definition.2.6.




                                The counter has been defined as follows.



                                newcountercounter
                                renewcommandthecounterthesection.arabiccounter



                                If you wish the counter counter to be reset to the value 0 whenever the counter section is incremented via refstepcounter, which in turn is used by the sectioning-command section, apply newcounter as follows:



                                newcountercounter[section]



                                Each environment has label after begin<environment> to
                                insert the anchor.




                                The assumption that the label-command would place an anchor is a common misunderstanding.



                                Anchors are placed by sectioning-commands like section or begintheorem or item (of an enumerate-environment). They internally use refstepcounter as you did with your environments.



                                refstepcounter does



                                • increment the counter,


                                • create an anchor-name,


                                • place an anchor of that name,


                                • make the name of that just placed anchor available to the label-macro as the expansion of the macro @currentHref,


                                • make the value of the just incremented counter availabe to the label-macro as the expansion of the macro @currentlabel.


                                label itself does neither create anchor names nor place anchors. label only writes information that is provided by sectioning-commands in terms of redefining macros of specific names (@currentlabel, @currentHref, ...) into the .aux-file in terms of these nice newlabel-entries.



                                In case I wouldn't care about anchor-names for hyperlinks and the autoref-feature, I would probably do it as follows:



                                documentclassarticle
                                usepackagehyperref
                                newcountercounter[section]
                                renewcommandthecounterthesection.arabiccounter
                                renewcommandtheHcountertheHsection.arabiccounter

                                newcommandunderlyingformatting[1]%
                                refstepcountercounter%
                                parnoindent
                                textsc#1~thecounter. #1
                                %

                                newcommandcounterautorefnameTheorem/Definition/Proposition

                                newenvironmenttheorem[1]underlyingformattingTheorem%

                                newenvironmentdefinition[1]underlyingformattingDefinition%

                                newenvironmentproposition[1]underlyingformattingProposition%

                                begindocument

                                sectionA section

                                refthm1

                                autorefthm1

                                refdef1

                                autorefdef1

                                refpro1

                                autorefpro1

                                refthm2

                                autorefthm2

                                refdef2

                                autorefdef2

                                refpro2

                                autorefpro2

                                begintheoremlabelthm1
                                A theorem
                                endtheorem

                                begindefinitionlabeldef1
                                A definition
                                enddefinition

                                beginpropositionlabelpro1
                                A proposition
                                endproposition

                                begintheoremlabelthm2
                                Another theorem
                                endtheorem

                                begindefinitionlabeldef2
                                Another definition
                                enddefinition

                                beginpropositionlabelpro2
                                Another proposition
                                endproposition

                                enddocument


                                In case of caring about anchor-names and autoref and the like, I would do it as follows—I "borrowed" the theoremstyle-code from egreg ;-) :



                                documentclassarticle
                                usepackageamsmath,amsthm
                                usepackagehyperref
                                usepackagealiascnt

                                usepackagelipsum % for context

                                newtheoremstylewallisdefinition
                                topsep % ABOVESPACE
                                topsep % BELOWSPACE
                                upshape % BODYFONT
                                0pt % INDENT (empty value is the same as 0pt)
                                upshape % HEADFONT
                                % HEADPUNCT
                                % HEADSPACE
                                % CUSTOM-HEAD-SPEC follows
                                thmnametextsc#1thmnumber #2.thmnote #3

                                theoremstylewallisdefinition
                                newtheoremtheoremTheorem[section]%

                                newaliascntpropositiontheorem
                                newtheoremproposition[proposition]Proposition%
                                aliascntresettheproposition
                                newcommandpropositionautorefnameProposition

                                newaliascntdefinitiontheorem
                                newtheoremdefinition[definition]Definition%
                                aliascntresetthedefinition
                                newcommanddefinitionautorefnameDefinition

                                begindocument

                                sectionTest

                                See definition~refdef:foo.

                                See autorefdef:foo.

                                See theorem~refthm:foo.

                                See autorefthm:foo.

                                See proposition~refprp:foo.

                                See autorefprp:foo.

                                See definition~refdef:bar.

                                See autorefdef:bar.

                                See theorem~refthm:bar.

                                See autorefthm:bar.

                                See proposition~refprp:bar.

                                See autorefprp:bar.

                                clearpage

                                lipsum[2]

                                begindefinition[(Foo-attribution.)]labeldef:foo
                                A emphfoo is something very useful. Therefore we will not use
                                foos all the time in this paper. This should be enough to wrap.
                                enddefinition

                                lipsum[3]

                                begintheorem[(Foo's bar-associativity.)]labelthm:foo
                                Foo is bar-associative. The proof is left to a drunken monkey.
                                endtheorem

                                lipsum[4]

                                beginproposition[(Foo's foobar-associativity.)]labelprp:foo
                                Foo is also foobar-associative. Before the break we announce proving
                                after the break. After the break we proclaim having proven just
                                before the break and continue with other things.
                                endproposition

                                lipsum[5]

                                begindefinition[(Bar-attribution.)]labeldef:bar
                                A emphbar is something very useful but we will never really
                                use bars in this paper. This should be enough to wrap.
                                enddefinition

                                lipsum[6]

                                begintheorem[(Bar's foo-associativity.)]labelthm:bar
                                Bar is foo-associative. The proof is left to a drunken donkey.
                                endtheorem

                                lipsum[7]

                                beginproposition[(Bar's barfoo-assoviativity.)]labelprp:bar
                                Bar is also barfoo-associative. We proclaim that this is obvious
                                and cause fear of attracting attention in an embarrassing way on
                                the side of those people that don't agree.
                                endproposition

                                enddocument





                                share|improve this answer


























                                  up vote
                                  1
                                  down vote













                                  Let's go through your posting:




                                  In the document I'm writing, I have redefined each environment and
                                  have included a new counter, called counter, to help with the
                                  numbering of the environments. My intention is for each definition,
                                  proposition, theorem, and so on to all use the same counter, which
                                  displays the section and then the counter number with the counter
                                  reset for each section. For example, in Section 2, the first
                                  definition reads "Definition 2.1", and the following proposition then
                                  reads "Proposition 2.2".




                                  Instead of doing this, you could define your environments in terms of newtheorem.

                                  Syntax of newtheorem is:



                                  newtheorem&langle;Name of the environment and — in case no already
                                  existing counter is to be used — name of
                                  newly to allocate underlying counter.&rangle;
                                  %
                                  [&langle;Name of already existing counter to be used for
                                  numbering the environment.&rangle;
                                  ]%
                                  &langle;Textual phrase denoting the title/heading/the kind of
                                  item of sectioning produced by an instance of the
                                  environment.&rangle;
                                  %
                                  [&langle;Name of superordinate sectioning counter whose value is
                                  part of the number of the sectioning-item provided by
                                  this environment, and whose incrementing via `refstepcounter`
                                  triggers resetting the counter in use for numbering the
                                  environment.&rangle;
                                  ]


                                  Thus you could, e.g., do:



                                  newtheoremtheoremTheorem[section]%
                                  newtheoremproposition[theorem]Proposition%
                                  newtheoremdefinition[theorem]Definition%


                                  If with this approach you wish to also use the hyperref package and to use its autoref-feature, you need to also load the aliascnt package and do:



                                  documentclass...
                                  ...
                                  usepackagehyperref
                                  usepackagealiascnt
                                  ...
                                  newtheoremtheoremTheorem[section]%
                                  %
                                  newaliascntpropositiontheorem
                                  newtheoremproposition[proposition]Proposition%
                                  aliascntresettheproposition
                                  newcommandpropositionautorefnameProposition
                                  %
                                  newaliascntdefinitiontheorem
                                  newtheoremdefinition[definition]Definition%
                                  aliascntresetthedefinition
                                  newcommanddefinitionnautorefnameDefinition


                                  Beneath other things, the aliascnt-package solves problems related to the autoref-feature of the hyperref-package.
                                  Also it provides the possibility of having different anchor-name-patterns for hyperlinks. (More information about this can be found in the manual of the hyperref package, section 4: additional user macros, autoref.)



                                  E.g., the name of the anchor of theorem 2.4 will not be #counter.2.4 but #theorem.2.4.

                                  E.g., the name of the anchor of proposition 2.5 will not be #counter.2.5 but #proposition.2.5.

                                  E.g., the name of the anchor of definition 2.6 will not be #counter.2.6 but #definition.2.6.




                                  The counter has been defined as follows.



                                  newcountercounter
                                  renewcommandthecounterthesection.arabiccounter



                                  If you wish the counter counter to be reset to the value 0 whenever the counter section is incremented via refstepcounter, which in turn is used by the sectioning-command section, apply newcounter as follows:



                                  newcountercounter[section]



                                  Each environment has label after begin<environment> to
                                  insert the anchor.




                                  The assumption that the label-command would place an anchor is a common misunderstanding.



                                  Anchors are placed by sectioning-commands like section or begintheorem or item (of an enumerate-environment). They internally use refstepcounter as you did with your environments.



                                  refstepcounter does



                                  • increment the counter,


                                  • create an anchor-name,


                                  • place an anchor of that name,


                                  • make the name of that just placed anchor available to the label-macro as the expansion of the macro @currentHref,


                                  • make the value of the just incremented counter availabe to the label-macro as the expansion of the macro @currentlabel.


                                  label itself does neither create anchor names nor place anchors. label only writes information that is provided by sectioning-commands in terms of redefining macros of specific names (@currentlabel, @currentHref, ...) into the .aux-file in terms of these nice newlabel-entries.



                                  In case I wouldn't care about anchor-names for hyperlinks and the autoref-feature, I would probably do it as follows:



                                  documentclassarticle
                                  usepackagehyperref
                                  newcountercounter[section]
                                  renewcommandthecounterthesection.arabiccounter
                                  renewcommandtheHcountertheHsection.arabiccounter

                                  newcommandunderlyingformatting[1]%
                                  refstepcountercounter%
                                  parnoindent
                                  textsc#1~thecounter. #1
                                  %

                                  newcommandcounterautorefnameTheorem/Definition/Proposition

                                  newenvironmenttheorem[1]underlyingformattingTheorem%

                                  newenvironmentdefinition[1]underlyingformattingDefinition%

                                  newenvironmentproposition[1]underlyingformattingProposition%

                                  begindocument

                                  sectionA section

                                  refthm1

                                  autorefthm1

                                  refdef1

                                  autorefdef1

                                  refpro1

                                  autorefpro1

                                  refthm2

                                  autorefthm2

                                  refdef2

                                  autorefdef2

                                  refpro2

                                  autorefpro2

                                  begintheoremlabelthm1
                                  A theorem
                                  endtheorem

                                  begindefinitionlabeldef1
                                  A definition
                                  enddefinition

                                  beginpropositionlabelpro1
                                  A proposition
                                  endproposition

                                  begintheoremlabelthm2
                                  Another theorem
                                  endtheorem

                                  begindefinitionlabeldef2
                                  Another definition
                                  enddefinition

                                  beginpropositionlabelpro2
                                  Another proposition
                                  endproposition

                                  enddocument


                                  In case of caring about anchor-names and autoref and the like, I would do it as follows—I "borrowed" the theoremstyle-code from egreg ;-) :



                                  documentclassarticle
                                  usepackageamsmath,amsthm
                                  usepackagehyperref
                                  usepackagealiascnt

                                  usepackagelipsum % for context

                                  newtheoremstylewallisdefinition
                                  topsep % ABOVESPACE
                                  topsep % BELOWSPACE
                                  upshape % BODYFONT
                                  0pt % INDENT (empty value is the same as 0pt)
                                  upshape % HEADFONT
                                  % HEADPUNCT
                                  % HEADSPACE
                                  % CUSTOM-HEAD-SPEC follows
                                  thmnametextsc#1thmnumber #2.thmnote #3

                                  theoremstylewallisdefinition
                                  newtheoremtheoremTheorem[section]%

                                  newaliascntpropositiontheorem
                                  newtheoremproposition[proposition]Proposition%
                                  aliascntresettheproposition
                                  newcommandpropositionautorefnameProposition

                                  newaliascntdefinitiontheorem
                                  newtheoremdefinition[definition]Definition%
                                  aliascntresetthedefinition
                                  newcommanddefinitionautorefnameDefinition

                                  begindocument

                                  sectionTest

                                  See definition~refdef:foo.

                                  See autorefdef:foo.

                                  See theorem~refthm:foo.

                                  See autorefthm:foo.

                                  See proposition~refprp:foo.

                                  See autorefprp:foo.

                                  See definition~refdef:bar.

                                  See autorefdef:bar.

                                  See theorem~refthm:bar.

                                  See autorefthm:bar.

                                  See proposition~refprp:bar.

                                  See autorefprp:bar.

                                  clearpage

                                  lipsum[2]

                                  begindefinition[(Foo-attribution.)]labeldef:foo
                                  A emphfoo is something very useful. Therefore we will not use
                                  foos all the time in this paper. This should be enough to wrap.
                                  enddefinition

                                  lipsum[3]

                                  begintheorem[(Foo's bar-associativity.)]labelthm:foo
                                  Foo is bar-associative. The proof is left to a drunken monkey.
                                  endtheorem

                                  lipsum[4]

                                  beginproposition[(Foo's foobar-associativity.)]labelprp:foo
                                  Foo is also foobar-associative. Before the break we announce proving
                                  after the break. After the break we proclaim having proven just
                                  before the break and continue with other things.
                                  endproposition

                                  lipsum[5]

                                  begindefinition[(Bar-attribution.)]labeldef:bar
                                  A emphbar is something very useful but we will never really
                                  use bars in this paper. This should be enough to wrap.
                                  enddefinition

                                  lipsum[6]

                                  begintheorem[(Bar's foo-associativity.)]labelthm:bar
                                  Bar is foo-associative. The proof is left to a drunken donkey.
                                  endtheorem

                                  lipsum[7]

                                  beginproposition[(Bar's barfoo-assoviativity.)]labelprp:bar
                                  Bar is also barfoo-associative. We proclaim that this is obvious
                                  and cause fear of attracting attention in an embarrassing way on
                                  the side of those people that don't agree.
                                  endproposition

                                  enddocument





                                  share|improve this answer
























                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    Let's go through your posting:




                                    In the document I'm writing, I have redefined each environment and
                                    have included a new counter, called counter, to help with the
                                    numbering of the environments. My intention is for each definition,
                                    proposition, theorem, and so on to all use the same counter, which
                                    displays the section and then the counter number with the counter
                                    reset for each section. For example, in Section 2, the first
                                    definition reads "Definition 2.1", and the following proposition then
                                    reads "Proposition 2.2".




                                    Instead of doing this, you could define your environments in terms of newtheorem.

                                    Syntax of newtheorem is:



                                    newtheorem&langle;Name of the environment and — in case no already
                                    existing counter is to be used — name of
                                    newly to allocate underlying counter.&rangle;
                                    %
                                    [&langle;Name of already existing counter to be used for
                                    numbering the environment.&rangle;
                                    ]%
                                    &langle;Textual phrase denoting the title/heading/the kind of
                                    item of sectioning produced by an instance of the
                                    environment.&rangle;
                                    %
                                    [&langle;Name of superordinate sectioning counter whose value is
                                    part of the number of the sectioning-item provided by
                                    this environment, and whose incrementing via `refstepcounter`
                                    triggers resetting the counter in use for numbering the
                                    environment.&rangle;
                                    ]


                                    Thus you could, e.g., do:



                                    newtheoremtheoremTheorem[section]%
                                    newtheoremproposition[theorem]Proposition%
                                    newtheoremdefinition[theorem]Definition%


                                    If with this approach you wish to also use the hyperref package and to use its autoref-feature, you need to also load the aliascnt package and do:



                                    documentclass...
                                    ...
                                    usepackagehyperref
                                    usepackagealiascnt
                                    ...
                                    newtheoremtheoremTheorem[section]%
                                    %
                                    newaliascntpropositiontheorem
                                    newtheoremproposition[proposition]Proposition%
                                    aliascntresettheproposition
                                    newcommandpropositionautorefnameProposition
                                    %
                                    newaliascntdefinitiontheorem
                                    newtheoremdefinition[definition]Definition%
                                    aliascntresetthedefinition
                                    newcommanddefinitionnautorefnameDefinition


                                    Beneath other things, the aliascnt-package solves problems related to the autoref-feature of the hyperref-package.
                                    Also it provides the possibility of having different anchor-name-patterns for hyperlinks. (More information about this can be found in the manual of the hyperref package, section 4: additional user macros, autoref.)



                                    E.g., the name of the anchor of theorem 2.4 will not be #counter.2.4 but #theorem.2.4.

                                    E.g., the name of the anchor of proposition 2.5 will not be #counter.2.5 but #proposition.2.5.

                                    E.g., the name of the anchor of definition 2.6 will not be #counter.2.6 but #definition.2.6.




                                    The counter has been defined as follows.



                                    newcountercounter
                                    renewcommandthecounterthesection.arabiccounter



                                    If you wish the counter counter to be reset to the value 0 whenever the counter section is incremented via refstepcounter, which in turn is used by the sectioning-command section, apply newcounter as follows:



                                    newcountercounter[section]



                                    Each environment has label after begin<environment> to
                                    insert the anchor.




                                    The assumption that the label-command would place an anchor is a common misunderstanding.



                                    Anchors are placed by sectioning-commands like section or begintheorem or item (of an enumerate-environment). They internally use refstepcounter as you did with your environments.



                                    refstepcounter does



                                    • increment the counter,


                                    • create an anchor-name,


                                    • place an anchor of that name,


                                    • make the name of that just placed anchor available to the label-macro as the expansion of the macro @currentHref,


                                    • make the value of the just incremented counter availabe to the label-macro as the expansion of the macro @currentlabel.


                                    label itself does neither create anchor names nor place anchors. label only writes information that is provided by sectioning-commands in terms of redefining macros of specific names (@currentlabel, @currentHref, ...) into the .aux-file in terms of these nice newlabel-entries.



                                    In case I wouldn't care about anchor-names for hyperlinks and the autoref-feature, I would probably do it as follows:



                                    documentclassarticle
                                    usepackagehyperref
                                    newcountercounter[section]
                                    renewcommandthecounterthesection.arabiccounter
                                    renewcommandtheHcountertheHsection.arabiccounter

                                    newcommandunderlyingformatting[1]%
                                    refstepcountercounter%
                                    parnoindent
                                    textsc#1~thecounter. #1
                                    %

                                    newcommandcounterautorefnameTheorem/Definition/Proposition

                                    newenvironmenttheorem[1]underlyingformattingTheorem%

                                    newenvironmentdefinition[1]underlyingformattingDefinition%

                                    newenvironmentproposition[1]underlyingformattingProposition%

                                    begindocument

                                    sectionA section

                                    refthm1

                                    autorefthm1

                                    refdef1

                                    autorefdef1

                                    refpro1

                                    autorefpro1

                                    refthm2

                                    autorefthm2

                                    refdef2

                                    autorefdef2

                                    refpro2

                                    autorefpro2

                                    begintheoremlabelthm1
                                    A theorem
                                    endtheorem

                                    begindefinitionlabeldef1
                                    A definition
                                    enddefinition

                                    beginpropositionlabelpro1
                                    A proposition
                                    endproposition

                                    begintheoremlabelthm2
                                    Another theorem
                                    endtheorem

                                    begindefinitionlabeldef2
                                    Another definition
                                    enddefinition

                                    beginpropositionlabelpro2
                                    Another proposition
                                    endproposition

                                    enddocument


                                    In case of caring about anchor-names and autoref and the like, I would do it as follows—I "borrowed" the theoremstyle-code from egreg ;-) :



                                    documentclassarticle
                                    usepackageamsmath,amsthm
                                    usepackagehyperref
                                    usepackagealiascnt

                                    usepackagelipsum % for context

                                    newtheoremstylewallisdefinition
                                    topsep % ABOVESPACE
                                    topsep % BELOWSPACE
                                    upshape % BODYFONT
                                    0pt % INDENT (empty value is the same as 0pt)
                                    upshape % HEADFONT
                                    % HEADPUNCT
                                    % HEADSPACE
                                    % CUSTOM-HEAD-SPEC follows
                                    thmnametextsc#1thmnumber #2.thmnote #3

                                    theoremstylewallisdefinition
                                    newtheoremtheoremTheorem[section]%

                                    newaliascntpropositiontheorem
                                    newtheoremproposition[proposition]Proposition%
                                    aliascntresettheproposition
                                    newcommandpropositionautorefnameProposition

                                    newaliascntdefinitiontheorem
                                    newtheoremdefinition[definition]Definition%
                                    aliascntresetthedefinition
                                    newcommanddefinitionautorefnameDefinition

                                    begindocument

                                    sectionTest

                                    See definition~refdef:foo.

                                    See autorefdef:foo.

                                    See theorem~refthm:foo.

                                    See autorefthm:foo.

                                    See proposition~refprp:foo.

                                    See autorefprp:foo.

                                    See definition~refdef:bar.

                                    See autorefdef:bar.

                                    See theorem~refthm:bar.

                                    See autorefthm:bar.

                                    See proposition~refprp:bar.

                                    See autorefprp:bar.

                                    clearpage

                                    lipsum[2]

                                    begindefinition[(Foo-attribution.)]labeldef:foo
                                    A emphfoo is something very useful. Therefore we will not use
                                    foos all the time in this paper. This should be enough to wrap.
                                    enddefinition

                                    lipsum[3]

                                    begintheorem[(Foo's bar-associativity.)]labelthm:foo
                                    Foo is bar-associative. The proof is left to a drunken monkey.
                                    endtheorem

                                    lipsum[4]

                                    beginproposition[(Foo's foobar-associativity.)]labelprp:foo
                                    Foo is also foobar-associative. Before the break we announce proving
                                    after the break. After the break we proclaim having proven just
                                    before the break and continue with other things.
                                    endproposition

                                    lipsum[5]

                                    begindefinition[(Bar-attribution.)]labeldef:bar
                                    A emphbar is something very useful but we will never really
                                    use bars in this paper. This should be enough to wrap.
                                    enddefinition

                                    lipsum[6]

                                    begintheorem[(Bar's foo-associativity.)]labelthm:bar
                                    Bar is foo-associative. The proof is left to a drunken donkey.
                                    endtheorem

                                    lipsum[7]

                                    beginproposition[(Bar's barfoo-assoviativity.)]labelprp:bar
                                    Bar is also barfoo-associative. We proclaim that this is obvious
                                    and cause fear of attracting attention in an embarrassing way on
                                    the side of those people that don't agree.
                                    endproposition

                                    enddocument





                                    share|improve this answer














                                    Let's go through your posting:




                                    In the document I'm writing, I have redefined each environment and
                                    have included a new counter, called counter, to help with the
                                    numbering of the environments. My intention is for each definition,
                                    proposition, theorem, and so on to all use the same counter, which
                                    displays the section and then the counter number with the counter
                                    reset for each section. For example, in Section 2, the first
                                    definition reads "Definition 2.1", and the following proposition then
                                    reads "Proposition 2.2".




                                    Instead of doing this, you could define your environments in terms of newtheorem.

                                    Syntax of newtheorem is:



                                    newtheorem&langle;Name of the environment and — in case no already
                                    existing counter is to be used — name of
                                    newly to allocate underlying counter.&rangle;
                                    %
                                    [&langle;Name of already existing counter to be used for
                                    numbering the environment.&rangle;
                                    ]%
                                    &langle;Textual phrase denoting the title/heading/the kind of
                                    item of sectioning produced by an instance of the
                                    environment.&rangle;
                                    %
                                    [&langle;Name of superordinate sectioning counter whose value is
                                    part of the number of the sectioning-item provided by
                                    this environment, and whose incrementing via `refstepcounter`
                                    triggers resetting the counter in use for numbering the
                                    environment.&rangle;
                                    ]


                                    Thus you could, e.g., do:



                                    newtheoremtheoremTheorem[section]%
                                    newtheoremproposition[theorem]Proposition%
                                    newtheoremdefinition[theorem]Definition%


                                    If with this approach you wish to also use the hyperref package and to use its autoref-feature, you need to also load the aliascnt package and do:



                                    documentclass...
                                    ...
                                    usepackagehyperref
                                    usepackagealiascnt
                                    ...
                                    newtheoremtheoremTheorem[section]%
                                    %
                                    newaliascntpropositiontheorem
                                    newtheoremproposition[proposition]Proposition%
                                    aliascntresettheproposition
                                    newcommandpropositionautorefnameProposition
                                    %
                                    newaliascntdefinitiontheorem
                                    newtheoremdefinition[definition]Definition%
                                    aliascntresetthedefinition
                                    newcommanddefinitionnautorefnameDefinition


                                    Beneath other things, the aliascnt-package solves problems related to the autoref-feature of the hyperref-package.
                                    Also it provides the possibility of having different anchor-name-patterns for hyperlinks. (More information about this can be found in the manual of the hyperref package, section 4: additional user macros, autoref.)



                                    E.g., the name of the anchor of theorem 2.4 will not be #counter.2.4 but #theorem.2.4.

                                    E.g., the name of the anchor of proposition 2.5 will not be #counter.2.5 but #proposition.2.5.

                                    E.g., the name of the anchor of definition 2.6 will not be #counter.2.6 but #definition.2.6.




                                    The counter has been defined as follows.



                                    newcountercounter
                                    renewcommandthecounterthesection.arabiccounter



                                    If you wish the counter counter to be reset to the value 0 whenever the counter section is incremented via refstepcounter, which in turn is used by the sectioning-command section, apply newcounter as follows:



                                    newcountercounter[section]



                                    Each environment has label after begin<environment> to
                                    insert the anchor.




                                    The assumption that the label-command would place an anchor is a common misunderstanding.



                                    Anchors are placed by sectioning-commands like section or begintheorem or item (of an enumerate-environment). They internally use refstepcounter as you did with your environments.



                                    refstepcounter does



                                    • increment the counter,


                                    • create an anchor-name,


                                    • place an anchor of that name,


                                    • make the name of that just placed anchor available to the label-macro as the expansion of the macro @currentHref,


                                    • make the value of the just incremented counter availabe to the label-macro as the expansion of the macro @currentlabel.


                                    label itself does neither create anchor names nor place anchors. label only writes information that is provided by sectioning-commands in terms of redefining macros of specific names (@currentlabel, @currentHref, ...) into the .aux-file in terms of these nice newlabel-entries.



                                    In case I wouldn't care about anchor-names for hyperlinks and the autoref-feature, I would probably do it as follows:



                                    documentclassarticle
                                    usepackagehyperref
                                    newcountercounter[section]
                                    renewcommandthecounterthesection.arabiccounter
                                    renewcommandtheHcountertheHsection.arabiccounter

                                    newcommandunderlyingformatting[1]%
                                    refstepcountercounter%
                                    parnoindent
                                    textsc#1~thecounter. #1
                                    %

                                    newcommandcounterautorefnameTheorem/Definition/Proposition

                                    newenvironmenttheorem[1]underlyingformattingTheorem%

                                    newenvironmentdefinition[1]underlyingformattingDefinition%

                                    newenvironmentproposition[1]underlyingformattingProposition%

                                    begindocument

                                    sectionA section

                                    refthm1

                                    autorefthm1

                                    refdef1

                                    autorefdef1

                                    refpro1

                                    autorefpro1

                                    refthm2

                                    autorefthm2

                                    refdef2

                                    autorefdef2

                                    refpro2

                                    autorefpro2

                                    begintheoremlabelthm1
                                    A theorem
                                    endtheorem

                                    begindefinitionlabeldef1
                                    A definition
                                    enddefinition

                                    beginpropositionlabelpro1
                                    A proposition
                                    endproposition

                                    begintheoremlabelthm2
                                    Another theorem
                                    endtheorem

                                    begindefinitionlabeldef2
                                    Another definition
                                    enddefinition

                                    beginpropositionlabelpro2
                                    Another proposition
                                    endproposition

                                    enddocument


                                    In case of caring about anchor-names and autoref and the like, I would do it as follows—I "borrowed" the theoremstyle-code from egreg ;-) :



                                    documentclassarticle
                                    usepackageamsmath,amsthm
                                    usepackagehyperref
                                    usepackagealiascnt

                                    usepackagelipsum % for context

                                    newtheoremstylewallisdefinition
                                    topsep % ABOVESPACE
                                    topsep % BELOWSPACE
                                    upshape % BODYFONT
                                    0pt % INDENT (empty value is the same as 0pt)
                                    upshape % HEADFONT
                                    % HEADPUNCT
                                    % HEADSPACE
                                    % CUSTOM-HEAD-SPEC follows
                                    thmnametextsc#1thmnumber #2.thmnote #3

                                    theoremstylewallisdefinition
                                    newtheoremtheoremTheorem[section]%

                                    newaliascntpropositiontheorem
                                    newtheoremproposition[proposition]Proposition%
                                    aliascntresettheproposition
                                    newcommandpropositionautorefnameProposition

                                    newaliascntdefinitiontheorem
                                    newtheoremdefinition[definition]Definition%
                                    aliascntresetthedefinition
                                    newcommanddefinitionautorefnameDefinition

                                    begindocument

                                    sectionTest

                                    See definition~refdef:foo.

                                    See autorefdef:foo.

                                    See theorem~refthm:foo.

                                    See autorefthm:foo.

                                    See proposition~refprp:foo.

                                    See autorefprp:foo.

                                    See definition~refdef:bar.

                                    See autorefdef:bar.

                                    See theorem~refthm:bar.

                                    See autorefthm:bar.

                                    See proposition~refprp:bar.

                                    See autorefprp:bar.

                                    clearpage

                                    lipsum[2]

                                    begindefinition[(Foo-attribution.)]labeldef:foo
                                    A emphfoo is something very useful. Therefore we will not use
                                    foos all the time in this paper. This should be enough to wrap.
                                    enddefinition

                                    lipsum[3]

                                    begintheorem[(Foo's bar-associativity.)]labelthm:foo
                                    Foo is bar-associative. The proof is left to a drunken monkey.
                                    endtheorem

                                    lipsum[4]

                                    beginproposition[(Foo's foobar-associativity.)]labelprp:foo
                                    Foo is also foobar-associative. Before the break we announce proving
                                    after the break. After the break we proclaim having proven just
                                    before the break and continue with other things.
                                    endproposition

                                    lipsum[5]

                                    begindefinition[(Bar-attribution.)]labeldef:bar
                                    A emphbar is something very useful but we will never really
                                    use bars in this paper. This should be enough to wrap.
                                    enddefinition

                                    lipsum[6]

                                    begintheorem[(Bar's foo-associativity.)]labelthm:bar
                                    Bar is foo-associative. The proof is left to a drunken donkey.
                                    endtheorem

                                    lipsum[7]

                                    beginproposition[(Bar's barfoo-assoviativity.)]labelprp:bar
                                    Bar is also barfoo-associative. We proclaim that this is obvious
                                    and cause fear of attracting attention in an embarrassing way on
                                    the side of those people that don't agree.
                                    endproposition

                                    enddocument






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Aug 10 at 15:51

























                                    answered Aug 10 at 9:48









                                    Ulrich Diez

                                    2,735313




                                    2,735313






















                                         

                                        draft saved


                                        draft discarded


























                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f445377%2fref-takes-reader-to-incorrect-section%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        這個網誌中的熱門文章

                                        Is there any way to eliminate the singular point to solve this integral by hand or by approximations?

                                        Why am i infinitely getting the same tweet with the Twitter Search API?

                                        Carbon dioxide