2

On the question How to automatically put a [Go To Summary] | [Go Back] on each section? I learned how to create a go to summary on each section on the text. However now I am having a errors when I change this:

\documentclass[10pt,a5paper,twoside]{abntex2}

To this:

\documentclass[10pt,a5paper,twoside,chapter=TITLE,section=TITLE]{abntex2}

Also the errors are fixed when I remove the go to summary section command.

This is an example with errors, i.e., using chapter=TITLE,section=TITLE

\documentclass[10pt,a5paper,twoside,chapter=TITLE,section=TITLE]{abntex2}

% Incompatible color definition when using tikz with color package
% https://tex.stackexchange.com/questions/150369/incompatible-color-definition-when-using-tikz-with-color-package
\usepackage{xcolor}

\definecolor{darkblue}{RGB}{26,13,178}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\hypersetup{colorlinks,linkcolor=darkblue,citecolor=darkgreen}

% How to automatically put a [Go To Summary] | [Go Back] on each section?
% https://tex.stackexchange.com/questions/367859/how-to-automatically-put-a-go-to-summary-go-back-on-each-section
\definecolor{ultramarine}{RGB}{0,32,96}

\makeatletter
\newcommand{\goToSummaryText}
{
    \hyperlink{summary} {\textcolor{ultramarine}{\small\mdseries [Go To Top]}}
    {\small\mdseries |}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{\small\mdseries [Go Back]}}
}
\newcommand{\addGoToSummary}{\renewcommand{\Sectionformat}[2]{##1 \goToSummaryText}}
\newcommand{\removeGoToSummary}{\renewcommand{\Sectionformat}[2]{##1}}

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

\tableofcontents*
\addGoToSummary

\chapter[Nullam]{Nullam elementum}
Nullam elementum

\section[Some encoding tests]{showfont}
\end{document}

Just by running this simple example only with one command \section I got several errors:

! Undefined control sequence.
\hyper@@link ->\let \Hy@reserved@a 
                                   \relax \@ifnextchar [{\hyper@link@ }{\hyp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Use of \hyper@link@ doesn't match its definition.
<argument> \def 

l.41 \section[Some encoding tests]{showfont}

If you say, e.g., `\def\a1{...}', then you must always
put `1' after `\a', since control sequence names are
made up of letters only. The macro here has not been
followed by the required stuff, so I'm ignoring it.

! Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next 
                                                  {\calc@error #1}\fi \fi \f...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<argument> \Hy@phantomsection 

l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@RemoveLeft ...{}{}\GTS@Nil }\edef \GTS@Token 
                                                  {\the \toks@ }\GTS@Predefi...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\GTS@TestLeft #1#2->\def \GTS@temp 
                                   {#1}\ifx \GTS@temp \GTS@Token \toks@ \exp...
l.41 \section[Some encoding tests]{showfont}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Running the example above removing the chapter=TITLE,section=TITLE correctly generates the document as follows:

enter image description here enter image description here

How can the go to summary be fixed so the chapter=TITLE,section=TITLE does not throw all these errors?


Update

I failed to create a minimal example before posting this question. Now I am going to dig on my main document to find out how to reproduce the problem correctly.

I already fixed the question with the real error/problem.

user
  • 4,745
  • 1
    Why do you want a \showfont in a section heading? – TeXnician Aug 24 '17 at 17:48
  • For anything in special. But would be welcome to not have a command use limitation on my sections headers, as introduced by the go to summary feature. – user Aug 24 '17 at 17:50
  • 2
    I agree with @TeXnician, but your missing effectively the \makeatother after the \showfont definition, remove the 'intermediate' one before \showfont, the first one causes jumping out of the @ catcode regime –  Aug 24 '17 at 17:51
  • Thanks @ChristianHupfer, this this the problem on my example. But on my main document is giving other errors other than this. I failed to create a minimal example of the problem. I need to go back to my main document do look what is missing. – user Aug 24 '17 at 17:56
  • @ChristianHupfer, I already fixed the question/minimal example. Now the error is cause by the chapter=TITLE,section=TITLE. – user Aug 24 '17 at 18:21
  • 1
    @user: I've to fight through your setup. You redefine \tableofcontents but use \tableofcontents, so the \hypertarget{summary} is never set yet –  Aug 24 '17 at 18:29
  • @ChristianHupfer, sorry for the mess. It redefines the tableofcontents to add a link to it. But I use the \tableofcontents* on my document. The document is compilling if I remove the chapter=TITLE,section=TITLE. – user Aug 24 '17 at 18:36
  • @user: I meant \tableofcontents* above -- a typo –  Aug 24 '17 at 20:55
  • Your code has showfont but the error has \showfont at that place. (Not the error, but the context.) Is that error produced from the code you posted *exactly*? – cfr Aug 24 '17 at 23:01
  • Off-topic: your commands are probably introducing spurious spaces. At least, if they aren't, that is going to be down to the good wishes of Lady Luck and not a result of any care on your part in coding them. – cfr Aug 24 '17 at 23:04
  • @cfr, I had copied the log from an old version of the minimal example. I just copied the current minimal example and generated a new log which is updated on the main post. The code is pretty simple, the errors are because there are some spaces on the code? – user Aug 25 '17 at 02:58
  • I said it was off-topic. No. the spaces aren't responsible for this problem (that I know of), but you may not want to be inserting spaces when you use these commands. Why do you need font commands in the argument of \hyperlink? – cfr Aug 25 '17 at 04:04
  • @cfr, I do not understand exactly what font commands you noticed. The only one I think I am using are the \small\mdseries and \textcolor{ultramarine}. But I added those to make the document more beauty. – user Aug 25 '17 at 15:41

2 Answers2

1
\documentclass[10pt,a5paper,twoside,chapter=TITLE,section=TITLE]{abntex2}
% https://tex.stackexchange.com/questions/150369/incompatible-color-definition-when-using-tikz-with-color-package
\usepackage{xcolor}
\definecolor{darkblue}{RGB}{26,13,178}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\hypersetup{colorlinks,linkcolor=darkblue,citecolor=darkgreen}
% https://tex.stackexchange.com/questions/367859/how-to-automatically-put-a-go-to-summary-go-back-on-each-section
\definecolor{ultramarine}{RGB}{0,32,96}
\newcommand{\goToSummaryText}
{%
  \small\mdseries%
  \hyperlink{summary} { \textcolor{ultramarine}{[Go To Top]}}%
  |%
  \Acrobatmenu{GoBack}{ \textcolor{ultramarine}{[Go Back]}}%
}
\newcommand{\addGoToSummary}{\renewcommand{\Sectionformat}[2]{##1 \protect\goToSummaryText}}
\newcommand{\removeGoToSummary}{\renewcommand{\Sectionformat}[2]{##1}}
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}
{%
    \hypertarget{summary}%
    \oldtableofcontents
}
\begin{document}
\tableofcontents*
\addGoToSummary
\chapter[Nullam]{Nullam elementum}
Nullam elementum
\section[Some encoding tests]{showfont}
\end{document}

I don't know where all the arrows come into it, but I don't see them.

cfr
  • 198,882
  • Thanks! It is fixed. I compared your code with mime, you added \protect before \goToSummaryText on the command \addGoToSummary changes image. You also fixed inconsistencies I had on defining \small\mdseries multiple times, instead of only one as you did. – user Aug 25 '17 at 15:34
0

Here is my minimal example fixed with @cfr help on the other answer, but replacing the text [Go To Top] and [Go Back] with arrows $\leftleftarrows$ and $\leftarrow$ respectively:

\documentclass[10pt,a5paper,twoside,chapter=TITLE,section=TITLE]{abntex2}

% Incompatible color definition when using tikz with color package
% https://tex.stackexchange.com/questions/150369/incompatible-color-definition
\usepackage{xcolor}

\definecolor{darkblue}{RGB}{26,13,178}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\hypersetup{colorlinks,linkcolor=darkblue,citecolor=darkgreen}

% How to automatically put a [Go To Summary] on each section?
% https://tex.stackexchange.com/questions/367859/how-to-automatically-put-a-go-to
\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{xpatch}

% The Comprehensive LATEX Symbol List
% http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf
\RequirePackage{MnSymbol}
\RequirePackage{hyperref}
\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

\chapter[Nullam]{Nullam elementum}
Nullam elementum

\section[Some encoding tests]{showfont}
\end{document}

enter image description here enter image description here


Related questions to the \protect fix used:

  1. Minimal \protected@edef example
  2. What is the purpose of \protect?
  3. What is the difference between Fragile and Robust commands?

Related questions:

  1. Why abntex2 class is inserting a new line after the chapter title?
  2. How to automatically put a [Go To Summary] | [Go Back] on each section?
  3. How can the go to summary be fixed so the \section[Some]{Some more} does not throw all these errors?
  4. What is the equivalent to `\Sectionformat` on memoir class for `\Chapterformat`?
  5. Why xapptocmd is reducing the vertical space between \partname and \parttile?
user
  • 4,745