# How to automatically put a [Go To Summary] | [Go Back] on each section?

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:

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.

• 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

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:

\documentclass{article}

\usepackage{xcolor}

\makeatletter
\makeatother

\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
\oldtableofcontents}

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

\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

\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{ultramarine}{RGB}{0,32,96}
\RequirePackage{xpatch}
\RequirePackage{amssymb}
\newcommand{\goToSummaryText}{{%
\small\mdseries
\hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
{$|$}
\Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}}
\makeatletter
}{}
}{}
{%
\@ifundefined{printparttitle}{\message{printparttitle patch for addGoToSummary could NOT
be applied because there is no printparttitle command available!^^J}}{%
\xapptocmd{\printparttitle}{~\protect\goToSummaryText}{}{}
}
\@ifundefined{Sectionformat}{\message{Sectionformat patch for addGoToSummary could NOT
be applied because there is no Sectionformat command available!^^J}}{%
\xapptocmd{\Sectionformat}{~\protect\goToSummaryText}{}{}
}
\xapptocmd{\ABNTEXchapterupperifneeded}{~\protect\goToSummaryText}{}{}
\else
\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}}{%
\xapptocmd{\Chapterformat}{~\protect\goToSummaryText}{}{}
}
\fi
}
\newcommand{\removeGoToSummary}
{%
\else
\fi
\else
\fi
}
\makeatother
\renewcommand{\tableofcontents}{%
\hypertarget{summary}%
}

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


Which produces this PDF: