Back link all headings with respective TOC entry











up vote
0
down vote

favorite












I came across a PDF which mutually links TOC entries and the headings present in the text body. It was created using Adobe Indesign. If I am reading the book and need to take a look at the TOC I can easily click the heading itself to see it in TOC. This will be a helpfull feature if content has many sub-headings. Are there any packages to achieve this functionality. Please guide.










share|improve this question


















  • 1




    Do yiu really need it ? IMo the bookmarks created by hyperref in conjonction with pdflatex do provide already similar fonctionality, don't they?
    – Jhor
    yesterday










  • Yes I need it. It will be helpfull to see larger picture when many sub-topics are discussed. We need to create a label each time for each subheading and refer to it, becomes messy when many headings are involved. I dont know whether a package exists for this purpose.
    – Ramaprakasha
    yesterday

















up vote
0
down vote

favorite












I came across a PDF which mutually links TOC entries and the headings present in the text body. It was created using Adobe Indesign. If I am reading the book and need to take a look at the TOC I can easily click the heading itself to see it in TOC. This will be a helpfull feature if content has many sub-headings. Are there any packages to achieve this functionality. Please guide.










share|improve this question


















  • 1




    Do yiu really need it ? IMo the bookmarks created by hyperref in conjonction with pdflatex do provide already similar fonctionality, don't they?
    – Jhor
    yesterday










  • Yes I need it. It will be helpfull to see larger picture when many sub-topics are discussed. We need to create a label each time for each subheading and refer to it, becomes messy when many headings are involved. I dont know whether a package exists for this purpose.
    – Ramaprakasha
    yesterday















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I came across a PDF which mutually links TOC entries and the headings present in the text body. It was created using Adobe Indesign. If I am reading the book and need to take a look at the TOC I can easily click the heading itself to see it in TOC. This will be a helpfull feature if content has many sub-headings. Are there any packages to achieve this functionality. Please guide.










share|improve this question













I came across a PDF which mutually links TOC entries and the headings present in the text body. It was created using Adobe Indesign. If I am reading the book and need to take a look at the TOC I can easily click the heading itself to see it in TOC. This will be a helpfull feature if content has many sub-headings. Are there any packages to achieve this functionality. Please guide.







packages links






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Ramaprakasha

315110




315110








  • 1




    Do yiu really need it ? IMo the bookmarks created by hyperref in conjonction with pdflatex do provide already similar fonctionality, don't they?
    – Jhor
    yesterday










  • Yes I need it. It will be helpfull to see larger picture when many sub-topics are discussed. We need to create a label each time for each subheading and refer to it, becomes messy when many headings are involved. I dont know whether a package exists for this purpose.
    – Ramaprakasha
    yesterday
















  • 1




    Do yiu really need it ? IMo the bookmarks created by hyperref in conjonction with pdflatex do provide already similar fonctionality, don't they?
    – Jhor
    yesterday










  • Yes I need it. It will be helpfull to see larger picture when many sub-topics are discussed. We need to create a label each time for each subheading and refer to it, becomes messy when many headings are involved. I dont know whether a package exists for this purpose.
    – Ramaprakasha
    yesterday










1




1




Do yiu really need it ? IMo the bookmarks created by hyperref in conjonction with pdflatex do provide already similar fonctionality, don't they?
– Jhor
yesterday




Do yiu really need it ? IMo the bookmarks created by hyperref in conjonction with pdflatex do provide already similar fonctionality, don't they?
– Jhor
yesterday












Yes I need it. It will be helpfull to see larger picture when many sub-topics are discussed. We need to create a label each time for each subheading and refer to it, becomes messy when many headings are involved. I dont know whether a package exists for this purpose.
– Ramaprakasha
yesterday






Yes I need it. It will be helpfull to see larger picture when many sub-topics are discussed. We need to create a label each time for each subheading and refer to it, becomes messy when many headings are involved. I dont know whether a package exists for this purpose.
– Ramaprakasha
yesterday












1 Answer
1






active

oldest

votes

















up vote
1
down vote













First, using etoolbox's patchcmd, one can add to the TOC filling a command for the creation of an hypertarget :



patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
{{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
{typeout{*patch success}}{typeout{*patch failure}}


Here I have chosen to alter directly the addcontentsline command as it is still called by the LaTeX @startsection (actually @sect) after its modification by hyperref. This enable to affect all the titles in the TOC.



Second, one has to add the hyperlink on the sectioning titles. In both article and book standard classes, this is achieved by redefinition of the Sectionformat introduced in @sect by hyperref:



AtBeginDocument{renewcommand{Sectionformat}[2]%
{ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}


Finally an MWE is:



% !TEX encoding = UTF-8
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{etoolbox}
usepackage{blindtext}
usepackage{hyperref}
makeatletter
patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
{{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
{typeout{*patch success}}{typeout{*patch failure}}
AtBeginDocument{renewcommand{Sectionformat}[2]%
{ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}
makeatother

begin{document}
tableofcontents
clearpage
Blinddocument
Blinddocument
Blinddocument
Blinddocument
Blinddocument
Blinddocument
end{document}


Of course the ugly link appearance can be improved with the suitable hypersetup{...}



Some caveats :




  • This code is rather simple, but will likely conflict with any other classes or packages modifying titles and/or tableofcontents, namely the popular titlesec and titletoc packages, or etoc or tocloft, etc.

  • Nevertheless, it can surely be adapted to other situations, by looking as the content of the sectioning macro by using meaning

  • In this spirit, the same procedure can be surely be used to modify the chapters in the book class, it will require to patch the @makechapterhead macro.

  • There is still a small default: the backlink opens the TOC page but the upper visible line is not the linked one, but the one just followingit.






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
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460688%2fback-link-all-headings-with-respective-toc-entry%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













    First, using etoolbox's patchcmd, one can add to the TOC filling a command for the creation of an hypertarget :



    patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
    {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
    {typeout{*patch success}}{typeout{*patch failure}}


    Here I have chosen to alter directly the addcontentsline command as it is still called by the LaTeX @startsection (actually @sect) after its modification by hyperref. This enable to affect all the titles in the TOC.



    Second, one has to add the hyperlink on the sectioning titles. In both article and book standard classes, this is achieved by redefinition of the Sectionformat introduced in @sect by hyperref:



    AtBeginDocument{renewcommand{Sectionformat}[2]%
    {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}


    Finally an MWE is:



    % !TEX encoding = UTF-8
    documentclass{article}
    usepackage[utf8]{inputenc}
    usepackage{etoolbox}
    usepackage{blindtext}
    usepackage{hyperref}
    makeatletter
    patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
    {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
    {typeout{*patch success}}{typeout{*patch failure}}
    AtBeginDocument{renewcommand{Sectionformat}[2]%
    {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}
    makeatother

    begin{document}
    tableofcontents
    clearpage
    Blinddocument
    Blinddocument
    Blinddocument
    Blinddocument
    Blinddocument
    Blinddocument
    end{document}


    Of course the ugly link appearance can be improved with the suitable hypersetup{...}



    Some caveats :




    • This code is rather simple, but will likely conflict with any other classes or packages modifying titles and/or tableofcontents, namely the popular titlesec and titletoc packages, or etoc or tocloft, etc.

    • Nevertheless, it can surely be adapted to other situations, by looking as the content of the sectioning macro by using meaning

    • In this spirit, the same procedure can be surely be used to modify the chapters in the book class, it will require to patch the @makechapterhead macro.

    • There is still a small default: the backlink opens the TOC page but the upper visible line is not the linked one, but the one just followingit.






    share|improve this answer



























      up vote
      1
      down vote













      First, using etoolbox's patchcmd, one can add to the TOC filling a command for the creation of an hypertarget :



      patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
      {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
      {typeout{*patch success}}{typeout{*patch failure}}


      Here I have chosen to alter directly the addcontentsline command as it is still called by the LaTeX @startsection (actually @sect) after its modification by hyperref. This enable to affect all the titles in the TOC.



      Second, one has to add the hyperlink on the sectioning titles. In both article and book standard classes, this is achieved by redefinition of the Sectionformat introduced in @sect by hyperref:



      AtBeginDocument{renewcommand{Sectionformat}[2]%
      {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}


      Finally an MWE is:



      % !TEX encoding = UTF-8
      documentclass{article}
      usepackage[utf8]{inputenc}
      usepackage{etoolbox}
      usepackage{blindtext}
      usepackage{hyperref}
      makeatletter
      patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
      {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
      {typeout{*patch success}}{typeout{*patch failure}}
      AtBeginDocument{renewcommand{Sectionformat}[2]%
      {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}
      makeatother

      begin{document}
      tableofcontents
      clearpage
      Blinddocument
      Blinddocument
      Blinddocument
      Blinddocument
      Blinddocument
      Blinddocument
      end{document}


      Of course the ugly link appearance can be improved with the suitable hypersetup{...}



      Some caveats :




      • This code is rather simple, but will likely conflict with any other classes or packages modifying titles and/or tableofcontents, namely the popular titlesec and titletoc packages, or etoc or tocloft, etc.

      • Nevertheless, it can surely be adapted to other situations, by looking as the content of the sectioning macro by using meaning

      • In this spirit, the same procedure can be surely be used to modify the chapters in the book class, it will require to patch the @makechapterhead macro.

      • There is still a small default: the backlink opens the TOC page but the upper visible line is not the linked one, but the one just followingit.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        First, using etoolbox's patchcmd, one can add to the TOC filling a command for the creation of an hypertarget :



        patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
        {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
        {typeout{*patch success}}{typeout{*patch failure}}


        Here I have chosen to alter directly the addcontentsline command as it is still called by the LaTeX @startsection (actually @sect) after its modification by hyperref. This enable to affect all the titles in the TOC.



        Second, one has to add the hyperlink on the sectioning titles. In both article and book standard classes, this is achieved by redefinition of the Sectionformat introduced in @sect by hyperref:



        AtBeginDocument{renewcommand{Sectionformat}[2]%
        {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}


        Finally an MWE is:



        % !TEX encoding = UTF-8
        documentclass{article}
        usepackage[utf8]{inputenc}
        usepackage{etoolbox}
        usepackage{blindtext}
        usepackage{hyperref}
        makeatletter
        patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
        {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
        {typeout{*patch success}}{typeout{*patch failure}}
        AtBeginDocument{renewcommand{Sectionformat}[2]%
        {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}
        makeatother

        begin{document}
        tableofcontents
        clearpage
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        end{document}


        Of course the ugly link appearance can be improved with the suitable hypersetup{...}



        Some caveats :




        • This code is rather simple, but will likely conflict with any other classes or packages modifying titles and/or tableofcontents, namely the popular titlesec and titletoc packages, or etoc or tocloft, etc.

        • Nevertheless, it can surely be adapted to other situations, by looking as the content of the sectioning macro by using meaning

        • In this spirit, the same procedure can be surely be used to modify the chapters in the book class, it will require to patch the @makechapterhead macro.

        • There is still a small default: the backlink opens the TOC page but the upper visible line is not the linked one, but the one just followingit.






        share|improve this answer














        First, using etoolbox's patchcmd, one can add to the TOC filling a command for the creation of an hypertarget :



        patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
        {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
        {typeout{*patch success}}{typeout{*patch failure}}


        Here I have chosen to alter directly the addcontentsline command as it is still called by the LaTeX @startsection (actually @sect) after its modification by hyperref. This enable to affect all the titles in the TOC.



        Second, one has to add the hyperlink on the sectioning titles. In both article and book standard classes, this is achieved by redefinition of the Sectionformat introduced in @sect by hyperref:



        AtBeginDocument{renewcommand{Sectionformat}[2]%
        {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}


        Finally an MWE is:



        % !TEX encoding = UTF-8
        documentclass{article}
        usepackage[utf8]{inputenc}
        usepackage{etoolbox}
        usepackage{blindtext}
        usepackage{hyperref}
        makeatletter
        patchcmd{addcontentsline}{{#2}{#3}{thepage }}%
        {{#2}{#3}{protecthypertarget{back@currentHref}{}thepage }}%
        {typeout{*patch success}}{typeout{*patch failure}}
        AtBeginDocument{renewcommand{Sectionformat}[2]%
        {ifnum #2>c@secnumdepth {#1}elsehyperlink{back@currentHref}{#1}fi}}
        makeatother

        begin{document}
        tableofcontents
        clearpage
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        end{document}


        Of course the ugly link appearance can be improved with the suitable hypersetup{...}



        Some caveats :




        • This code is rather simple, but will likely conflict with any other classes or packages modifying titles and/or tableofcontents, namely the popular titlesec and titletoc packages, or etoc or tocloft, etc.

        • Nevertheless, it can surely be adapted to other situations, by looking as the content of the sectioning macro by using meaning

        • In this spirit, the same procedure can be surely be used to modify the chapters in the book class, it will require to patch the @makechapterhead macro.

        • There is still a small default: the backlink opens the TOC page but the upper visible line is not the linked one, but the one just followingit.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Jhor

        2,0661014




        2,0661014






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460688%2fback-link-all-headings-with-respective-toc-entry%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