0

I am using this customization How to automatically put a [Go To Summary] | [Go Back] on each section?, but when I load it together with abntex2 class, my go back buttons are put on the next line for the \chapter{} command. Everything works fine for \section{} and others:

enter image description here

If I remove the following code from the abntex2 class, then, it is fixed:

https://github.com/abntex/abntex2/blob/15a981c300198ca59920eea17f02893490adf878/tex/latex/abntex2/abntex2.cls#L603-L614

  \def\printchaptertitle##1{%
    \chaptitlefont%
    \ifthenelse{\boolean{abntex@innonumchapter}}{\centering\ABNTEXchapterupperifneeded{##1}}{%
    \ifthenelse{\boolean{abntex@apendiceousecao}}{%
        \centering%
        \settowidth{\chapternamenumlength}{\printchaptername\printchapternum\afterchapternum}%
        \ABNTEXchapterupperifneeded{##1}%
      }{%
        \settowidth{\chapternamenumlength}{\printchaptername\printchapternum\afterchapternum}%
        \parbox[t]{\columnwidth-\chapternamenumlength}{\ABNTEXchapterupperifneeded{##1}}}%
     }
  }

enter image description here


This is my minimal example:

\documentclass[
10pt,
a5paper
]{abntex2}

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

\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{amssymb}
\newcommand{\goToSummaryText}
{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}
\makeatletter
    \newif\ifismemoirloaded\ismemoirloadedfalse
    \@ifclassloaded{memoir}
    {%
        \ismemoirloadedtrue
    }{}
    \newcommand{\addGoToSummary}
    {%
        \renewcommand{\Sectionformat}[2]{##1 \protect\goToSummaryText}
        \ifismemoirloaded
            \let\oldprintchaptertitle\printchaptertitle
            \renewcommand{\printchaptertitle}[1]{\oldprintchaptertitle{##1} \protect\goToSummaryText}
        \else\fi
    }
    \newcommand{\removeGoToSummary}
    {%
        \renewcommand{\Sectionformat}[2]{##1}
        \ifismemoirloaded
            \let\printchaptertitle\oldprintchaptertitle
        \else\fi
    }
\makeatother
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}
{%
    \hypertarget{summary}%
    \oldtableofcontents%
}

\begin{document}
    \addGoToSummary
    \chapter{Section contents}
    thing2.
\end{document}

How can I patch abntex2 class or my command to fix this issue?

References:

  1. What is the equivalent to `\Sectionformat` on memoir class for `\Chapterformat`?
  2. How can the go to summary be fixed so the \section[Some]{Some more} does not throw all these errors?
user
  • 4,745

1 Answers1

1

I managed to fix it by checking whether the abntex2 is loaded and patching directly \ABNTEXchapterupperifneeded.

If someone knows a better or more general answer, please share it!

\documentclass[
10pt,
a5paper
]{memoir}

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

\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{xpatch}
\RequirePackage{amssymb}
\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}
    \addGoToSummary
    \part{My}
    \chapter{Chapter title}
    thing1.
    \removeGoToSummary
    \section{Section title}
    thing2.
    \addGoToSummary
    \section{Section title}
    thing3.
\end{document}

References:

  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