# Two attempts which not worked

Herein there are 2 examples which did not work. Each attempt has written over it % Not works:

\PassOptionsToPackage{brazil,main=english}{babel}
\documentclass[10pt,a5paper,twoside]{abntex2}
\pdfstringdefDisableCommands{\let\uppercase\relax}

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

\usepackage[
style=abnt,
language=english,
backref=true,
backend=biber,
citecounter=true
]{biblatex}
\usepackage{csquotes}

\makeatletter
\let\orig@listi\@listi
\def\@listi{\orig@listi\topsep=0pt} % Not works
\makeatother

\begin{document}

Test
\begin{citacao}\setlength{\topsep}{0pt} % Not works
Test
\end{citacao}
Test

\end{document}


The citacao environment is implemented at:

1. https://github.com/abntex/abntex2/blob/8f2109ac2ef986b15d97d0bfc489b251918f1761/tex/latex/abntex2/abntex2.cls#L961-L978

\newenvironment*{citacao}[1][default]{%
\list{}%
\ABNTEXfontereduzida%
\item[]%
\begin{SingleSpace}%
\ifthenelse{\not\equal{#1}{default}}{\itshape\selectlanguage{#1}}{}%
}{%
\end{SingleSpace}%
\endlist}%
% ---


# Two attempts which worked

Herein there are 2 examples which did worked.The first is by renewing the environment, the other opening the abntex2 files on my computer and changing the implementation.

1. I could just change its implementation adding {\topsep=0pt} as in:

\newenvironment*{citacao}[1][default]{%
\list{}{\topsep=0pt}%
\ABNTEXfontereduzida%
\item[]%
\begin{SingleSpace}%
\ifthenelse{\not\equal{#1}{default}}{\itshape\selectlanguage{#1}}{}%
}{%
\end{SingleSpace}%
\endlist}%

2. Or renew the environment in my document as in:

\renewenvironment*{citacao}[1][default]{%
\list{}{\topsep=0pt}%
\ABNTEXfontereduzida%
\item[]%
\begin{SingleSpace}%
\ifthenelse{\not\equal{#1}{default}}{\itshape\selectlanguage{#1}}{}%
}{%
\end{SingleSpace}%
\endlist}%


# The question

But I would like to not hardly copy their implementation, neither am interested in doing a pull request for adding {\topsep=0pt}. May I do something like this bellow, patching the environment?

\pretocmd{\citacao}{\let\oldtopsep\topsep \setlength{\topsep}{0pt}}{}{}
\xapptocmd{\citacaoend}{\let\topsep\oldtopsep}{}{}


Why this is not on my code on the beginning of the post?

Because I could not make it work patching it manually, by adding \setlength{\topsep}{0pt}, therefore loading xpatch will do no help if I do not know how to patch. None of these worked:

% First attempt
\makeatletter
\let\orig@listi\@listi
\def\@listi{\orig@listi\topsep=0pt} % Not works
\makeatother

...
% Second attempt
\begin{citacao}\setlength{\topsep}{0pt} % Not works
Test
\end{citacao}


Related questions:

• Did you try it? What happened? Can you put your fragments together into a single, (non-)compilable example? – cfr Sep 17 '17 at 1:00
• @cfr, I provided 2 examples which work, 1 by renewing the environment, the other opening the abntex2 files on my computer and changing the implementation. I also provided 2 examples which did not work. They are the first code on the post, and each attempt has written over it % Not works. I will update the post with this information. – user Sep 17 '17 at 1:13
• But what does 'not working' mean? You don't say. Do you get an error? Do you get output you don't expect? – cfr Sep 17 '17 at 3:00
• You need to patch it and not just append to the command. That is, you need \patchcmd and search for \list{} and replace with the line you want there instead. – cfr Sep 17 '17 at 3:03
• @cfr, with not work I mean the \topsep=0pt is not applied, i.e., it is ignored. I also just tried to do \xpatchcmd{\citacao}{\list{}}{\list{}{\topsep=0pt}}{}{} and it worked, but if some day they decide to add some argument to the \citation \list{}{}, it would stop working. That is why I thought about trying to use \xapptocmd and \pretocmd. – user Sep 17 '17 at 4:42

Not only is \topsep setting hard-coded in standard list environments (itemize, enumerate, description), from inside such environment it is too late to correct the top use, and changing \topsep will not influence the bottom use.

Assuming one can not customize directly the \list usage, one can attempt this:

\documentclass{article}

\usepackage{color}
\begin{document}

\setlength{\topsep}{40pt}% useless

BEFORE

\begin{itemize}
\item \the\topsep
\item A
\item B
\item C
\end{itemize}

AFTER

\color{blue}

BEFORE

\begin{itemize}\kern-\topsep