5

The button [Go To Summary] should be a link to the summary page, and the [Go Back] button should perform the command to go back to the last position it was.

This is very useful for file navigation, as I can freely move from the summary to anywhere and from anywhere back to the summary or for whatever place I as before.

I created a minimal latex document to illustrate it:

\documentclass{article}

\usepackage{array}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\section{Fermat’s Principle}

    \label{sec:fermat}
    Fermat’s principle states that the path light takes from one point
    to another is not necessarily the one with the smallest distance,
    but rather the path which can be traversed in the shortest time.


\section{Geometrical Optics}

    Geometrical optics is an approximation for light propagation in
    cases where the wavelength is very small compared to the
    structures with which the light interacts. Snell’s Law, describing
    refraction, can be derived from Fermat’s principle
    (see section~\ref{sec:fermat}).

\end{document}

This is a illustrative picture within the [Go To Summary] | [Go Back] links. With summary I mean Table of Contents or just Contents as on the picture:

enter image description here

The go back is useful because most PDF views has a bad usability for their Go Back button, is it hard to find it and click on the in just one step. Also the [Go Back] link is necessary beyond the [Go To Summary] because you are not always coming form the summary, but from another part of the document which had a link to the current section, as taught on the question Making clickable links to sections with hyperref.


Update

As @Werner comment, seems not possible to do a [Go Back] link, therefore just the [Go To Summary] link would help a lot.

enter image description here

  • No information about the jump is kept, and since it should be dynamic based on where you are (inside a statically-created LaTeX document), that is not possible. Jumping to a know/fixed location (like the summary) should be okay though. – Werner May 2 '17 at 22:54
  • Thanks @Werner, I updated the question within this information. – user May 2 '17 at 23:51
  • @werner what about \Acrobatmenu{GoBack}{Go Back}? – touhami May 3 '17 at 10:19
  • Thanks @touhami, I found an answer on tex.stackexchange.com/questions/51320/… and it seems to be working on Sumatra PDF reader also. – user May 3 '17 at 14:06
4

The following example allows you to adapt the text to be displayed with each sectional unit and provides a one-way link back to the summary/top/ToC:

enter image description here

\documentclass{article}

\usepackage{xcolor}
\usepackage[colorlinks]{hyperref}

\newcommand{\goToSummaryText}{\hyperlink{summary}{\textcolor{green}{\small\mdseries [Go To Top]}}}

\makeatletter
\newcommand{\addGoToSummary}{\renewcommand{\Sectionformat}[2]{##1 \goToSummaryText}}
\newcommand{\removeGoToSummary}{\renewcommand{\Sectionformat}[2]{##1}}
\makeatother

\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
  \hypertarget{summary}% Insert internal document link
  \oldtableofcontents}

\begin{document}

\tableofcontents

\addGoToSummary% Add "Go To Summary" to each section

\section{Fermat's Principle}\label{sec:fermat}
Fermat's principle states that the path light takes from one point
to another is not necessarily the one with the smallest distance,
but rather the path which can be traversed in the shortest time.

\removeGoToSummary% Remove "Go To Summary" from each section

\section{Geometrical Optics}
Geometrical optics is an approximation for light propagation in
cases where the wavelength is very small compared to the
structures with which the light interacts. Snell's Law, describing
refraction, can be derived from Fermat's principle
(see section~\ref{sec:fermat}).

\end{document}
  • You need to add \protect before \goToSummaryText on the command \addGoToSummary, otherwise there will be a pile of errors on some document classes with option which change the section. See the question: tex.stackexchange.com/questions/388045/… – user Aug 25 '17 at 16:01
4

Combining @Werner answer, @touhami comment and with the answers:

  1. Going "back" when using hyperref
  2. How to change color for a block of texts?
  3. What point (pt) font size are \Large etc.?
  4. How to insert pipe symbol in (La)TeX?
  5. Why abntex2 class is inserting a new line after the chapter title?
  6. How can the go to summary be fixed so the \section[Some]{Some more} does not throw all these errors?
  7. What is the equivalent to `\Sectionformat` on memoir class for `\Chapterformat`?
  8. Why xapptocmd is reducing the vertical space between \partname and \parttile?

I added this:

\definecolor{ultramarine}{RGB}{0,32,96}

\newcommand{\goToSummaryText}{{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}}

This is a full example:

\documentclass{article}
\usepackage{xcolor}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\definecolor{link_color}{RGB}{26,13,178}
\usepackage[backref,colorlinks,linkcolor=link_color]{hyperref}

\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{xpatch}
\RequirePackage{amssymb}
\newcommand{\goToSummaryText}{{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}}
\makeatletter
    \newif\ifismemoirloaded\ismemoirloadedfalse
    \newif\ifisabntexloaded\isabntexloadedfalse
    \@ifclassloaded{memoir}{%
        \ismemoirloadedtrue%
    }{}
    \@ifclassloaded{abntex2}{%
        \isabntexloadedtrue%
    }{}
    \newcommand{\addGoToSummary}
    {%
        \@ifundefined{printparttitle}{\message{printparttitle patch for addGoToSummary could NOT
                    be applied because there is no printparttitle command available!^^J}}{%
            \let\oldAddGoToprintparttitle\printparttitle
            \xapptocmd{\printparttitle}{~\protect\goToSummaryText}{}{}
        }
        \@ifundefined{Sectionformat}{\message{Sectionformat patch for addGoToSummary could NOT
                    be applied because there is no Sectionformat command available!^^J}}{%
            \let\oldAddGoToSectionformat\Sectionformat
            \xapptocmd{\Sectionformat}{~\protect\goToSummaryText}{}{}
        }
        \ifismemoirloaded
            \ifisabntexloaded
                \let\oldAddGoToABNTEXchapterupperifneeded\ABNTEXchapterupperifneeded
                \xapptocmd{\ABNTEXchapterupperifneeded}{~\protect\goToSummaryText}{}{}
            \else
                \let\oldAddGoToprintchaptertitle\printchaptertitle
                \xapptocmd{\printchaptertitle}{~\protect\goToSummaryText}{}{}
            \fi
        \else
            \@ifundefined{Chapterformat}{\message{Chapterformat patch for addGoToSummary could NOT
                        be applied because there is no Chapterformat command available!^^J}}{%
                \let\oldAddGoToChapterformat\Chapterformat
                \xapptocmd{\Chapterformat}{~\protect\goToSummaryText}{}{}
            }
        \fi
    }
    \newcommand{\removeGoToSummary}
    {%
        \@ifundefined{oldAddGoToprintparttitle}{}{\let\printparttitle\oldAddGoToprintparttitle}
        \@ifundefined{oldAddGoToSectionformat}{}{\let\Sectionformat\oldAddGoToSectionformat}
        \ifismemoirloaded
            \ifisabntexloaded
                \@ifundefined{oldAddGoToABNTEXchapterupperifneeded}{}{\let\ABNTEXchapterupperifneeded\oldAddGoToABNTEXchapterupperifneeded}
            \else
                \@ifundefined{oldAddGoToprintchaptertitle}{}{\let\printchaptertitle\oldAddGoToprintchaptertitle}
            \fi
        \else
            \@ifundefined{oldAddGoToChapterformat}{}{\let\Chapterformat\oldAddGoToChapterformat}
        \fi
    }
\makeatother
\let\oldAddGoTotableofcontents\tableofcontents
% Insert internal document link
\renewcommand{\tableofcontents}{%
    \hypertarget{summary}%
    \oldAddGoTotableofcontents%
}

\begin{document}

\tableofcontents
\addGoToSummary

\section{Fermat’s Principle}

    \label{sec:fermat}
    Fermat’s principle states that the path light takes from one point
    to another is not necessarily the one with the smallest distance,
    but rather the path which can be traversed in the shortest time.


\section{Geometrical Optics}

    Geometrical optics is an approximation for light propagation in
    cases where the wavelength is very small compared to the
    structures with which the light interacts. Snell’s Law, describing
    refraction, can be derived from Fermat’s principle
    (see section~\ref{sec:fermat}).

\end{document}

Which produces this PDF:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.