How to display chapter/section counter value?











up vote
2
down vote

favorite












I'm building a documentclass[...]{book} latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise command. In the preamble I did:



newcommand{exercise}{
paragraph{Exercício x}
}


How can I set x = chapter . section . mycounter?



The mycounter counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).



Thanks in advance.










share|improve this question







New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • thechapter.thesection.themycounter? or better define themycounter as renecommand{thechapter.thesection.arabic{mycounter}} . welcome to tex.se!
    – Zarko
    2 days ago












  • @Zarko Under normal circumstances thesection already prints the chapter number, so thechapter.thesection would duplicate the chapter number.
    – Phelype Oleinik
    2 days ago










  • @PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
    – Zarko
    2 days ago










  • @Zarko I completely agree :-)
    – Phelype Oleinik
    2 days ago















up vote
2
down vote

favorite












I'm building a documentclass[...]{book} latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise command. In the preamble I did:



newcommand{exercise}{
paragraph{Exercício x}
}


How can I set x = chapter . section . mycounter?



The mycounter counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).



Thanks in advance.










share|improve this question







New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • thechapter.thesection.themycounter? or better define themycounter as renecommand{thechapter.thesection.arabic{mycounter}} . welcome to tex.se!
    – Zarko
    2 days ago












  • @Zarko Under normal circumstances thesection already prints the chapter number, so thechapter.thesection would duplicate the chapter number.
    – Phelype Oleinik
    2 days ago










  • @PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
    – Zarko
    2 days ago










  • @Zarko I completely agree :-)
    – Phelype Oleinik
    2 days ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm building a documentclass[...]{book} latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise command. In the preamble I did:



newcommand{exercise}{
paragraph{Exercício x}
}


How can I set x = chapter . section . mycounter?



The mycounter counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).



Thanks in advance.










share|improve this question







New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm building a documentclass[...]{book} latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise command. In the preamble I did:



newcommand{exercise}{
paragraph{Exercício x}
}


How can I set x = chapter . section . mycounter?



The mycounter counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).



Thanks in advance.







counters






share|improve this question







New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Enrique René

134




134




New contributor




Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Enrique René is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • thechapter.thesection.themycounter? or better define themycounter as renecommand{thechapter.thesection.arabic{mycounter}} . welcome to tex.se!
    – Zarko
    2 days ago












  • @Zarko Under normal circumstances thesection already prints the chapter number, so thechapter.thesection would duplicate the chapter number.
    – Phelype Oleinik
    2 days ago










  • @PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
    – Zarko
    2 days ago










  • @Zarko I completely agree :-)
    – Phelype Oleinik
    2 days ago


















  • thechapter.thesection.themycounter? or better define themycounter as renecommand{thechapter.thesection.arabic{mycounter}} . welcome to tex.se!
    – Zarko
    2 days ago












  • @Zarko Under normal circumstances thesection already prints the chapter number, so thechapter.thesection would duplicate the chapter number.
    – Phelype Oleinik
    2 days ago










  • @PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
    – Zarko
    2 days ago










  • @Zarko I completely agree :-)
    – Phelype Oleinik
    2 days ago
















thechapter.thesection.themycounter? or better define themycounter as renecommand{thechapter.thesection.arabic{mycounter}} . welcome to tex.se!
– Zarko
2 days ago






thechapter.thesection.themycounter? or better define themycounter as renecommand{thechapter.thesection.arabic{mycounter}} . welcome to tex.se!
– Zarko
2 days ago














@Zarko Under normal circumstances thesection already prints the chapter number, so thechapter.thesection would duplicate the chapter number.
– Phelype Oleinik
2 days ago




@Zarko Under normal circumstances thesection already prints the chapter number, so thechapter.thesection would duplicate the chapter number.
– Phelype Oleinik
2 days ago












@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago




@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago












@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago




@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You have to define a counter exercise with newcounter{exercise}, then you say that it restarts at every section with counterwithin{exercise}{section}.



To make thesection (which prints the value of the section) to be chapter.section.exercise you can use thesection.arabic{exercise} because thesection is already defined to print chapter.section. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.



Finally, at each exercise you use refstepcounter{exercise} to add one to it, and print theexercise.




enter image description here




documentclass{book}

usepackage{lipsum}

newcounter{exercise}
counterwithin{exercise}{section}
renewcommandtheexercise{%
thesection.arabic{exercise}%
}
newcommand{exercise}{%
refstepcounter{exercise}%
paragraph{Exercício~theexercise}
}

begin{document}

chapter{I don't care about}

section{This section}

exercise lipsum[1]

exercise lipsum[2]

section{Another section}

exercise lipsum[3]

end{document}





share|improve this answer





















    Your Answer








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

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

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


    }
    });






    Enrique René is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460488%2fhow-to-display-chapter-section-counter-value%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    You have to define a counter exercise with newcounter{exercise}, then you say that it restarts at every section with counterwithin{exercise}{section}.



    To make thesection (which prints the value of the section) to be chapter.section.exercise you can use thesection.arabic{exercise} because thesection is already defined to print chapter.section. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.



    Finally, at each exercise you use refstepcounter{exercise} to add one to it, and print theexercise.




    enter image description here




    documentclass{book}

    usepackage{lipsum}

    newcounter{exercise}
    counterwithin{exercise}{section}
    renewcommandtheexercise{%
    thesection.arabic{exercise}%
    }
    newcommand{exercise}{%
    refstepcounter{exercise}%
    paragraph{Exercício~theexercise}
    }

    begin{document}

    chapter{I don't care about}

    section{This section}

    exercise lipsum[1]

    exercise lipsum[2]

    section{Another section}

    exercise lipsum[3]

    end{document}





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      You have to define a counter exercise with newcounter{exercise}, then you say that it restarts at every section with counterwithin{exercise}{section}.



      To make thesection (which prints the value of the section) to be chapter.section.exercise you can use thesection.arabic{exercise} because thesection is already defined to print chapter.section. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.



      Finally, at each exercise you use refstepcounter{exercise} to add one to it, and print theexercise.




      enter image description here




      documentclass{book}

      usepackage{lipsum}

      newcounter{exercise}
      counterwithin{exercise}{section}
      renewcommandtheexercise{%
      thesection.arabic{exercise}%
      }
      newcommand{exercise}{%
      refstepcounter{exercise}%
      paragraph{Exercício~theexercise}
      }

      begin{document}

      chapter{I don't care about}

      section{This section}

      exercise lipsum[1]

      exercise lipsum[2]

      section{Another section}

      exercise lipsum[3]

      end{document}





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        You have to define a counter exercise with newcounter{exercise}, then you say that it restarts at every section with counterwithin{exercise}{section}.



        To make thesection (which prints the value of the section) to be chapter.section.exercise you can use thesection.arabic{exercise} because thesection is already defined to print chapter.section. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.



        Finally, at each exercise you use refstepcounter{exercise} to add one to it, and print theexercise.




        enter image description here




        documentclass{book}

        usepackage{lipsum}

        newcounter{exercise}
        counterwithin{exercise}{section}
        renewcommandtheexercise{%
        thesection.arabic{exercise}%
        }
        newcommand{exercise}{%
        refstepcounter{exercise}%
        paragraph{Exercício~theexercise}
        }

        begin{document}

        chapter{I don't care about}

        section{This section}

        exercise lipsum[1]

        exercise lipsum[2]

        section{Another section}

        exercise lipsum[3]

        end{document}





        share|improve this answer












        You have to define a counter exercise with newcounter{exercise}, then you say that it restarts at every section with counterwithin{exercise}{section}.



        To make thesection (which prints the value of the section) to be chapter.section.exercise you can use thesection.arabic{exercise} because thesection is already defined to print chapter.section. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.



        Finally, at each exercise you use refstepcounter{exercise} to add one to it, and print theexercise.




        enter image description here




        documentclass{book}

        usepackage{lipsum}

        newcounter{exercise}
        counterwithin{exercise}{section}
        renewcommandtheexercise{%
        thesection.arabic{exercise}%
        }
        newcommand{exercise}{%
        refstepcounter{exercise}%
        paragraph{Exercício~theexercise}
        }

        begin{document}

        chapter{I don't care about}

        section{This section}

        exercise lipsum[1]

        exercise lipsum[2]

        section{Another section}

        exercise lipsum[3]

        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Phelype Oleinik

        20.2k54277




        20.2k54277






















            Enrique René is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Enrique René is a new contributor. Be nice, and check out our Code of Conduct.













            Enrique René is a new contributor. Be nice, and check out our Code of Conduct.












            Enrique René is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460488%2fhow-to-display-chapter-section-counter-value%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt