I managed to put both listings and minted codes in a single list of codes called LISTINGS. However, the entries of the minted package on the list of codes are shorted on the distance between the listing name and the listing title.
This causes two problems.
The first problem is that when I have more than 10 items, they are eaten by the hyphen of the minted code environment, instead of expanding to hold the hyphen. On my thesis, this problems happens right after the 10th item, as showed on the next figure:
However, when I tried to create a minimal example, it only happened after 1000th item, as showed on the next figure:
First problem minimal example
\documentclass[english,12pt,a4paper,twoside,chapter=TITLE,section=TITLE,]{abntex2}
\usepackage{caption,listings}
\usepackage[newfloat,chapter,outputdir=F:/SublimeText/Data/Cache/LaTeXTools/b98d701d6340232fe19ea13f16f5a620]{minted}
% https://tex.stackexchange.com/questions/320185/adjust-vertical-spacing-between-caption-and-listing-in-koma-scrartcl
\captionsetup[listing]{position=top,skip=0pt}
\newenvironment{code}{\captionsetup{type=listing}}{}
% https://tex.stackexchange.com/questions/26220/control-spacing-around-table-caption
\AtBeginEnvironment{code}{\setcounter{listing}{\value{lstlisting}}
\setlength{\abovecaptionskip}{0pt}
\setlength{\belowcaptionskip}{10pt}
\setlength{\parskip}{0pt}
\captionsetup{skip=0pt}
}
\AtEndEnvironment{code}{\stepcounter{lstlisting}}
% https://tex.stackexchange.com/questions/269491/mixing-minted-with-lstlisting
\AtBeginEnvironment{listing}{\setcounter{listing}{\value{lstlisting}}}
\AtEndEnvironment{listing}{\stepcounter{lstlisting}}
\makeatletter
\newlength\mylen
\begingroup
\let\newcounter\@gobble\let\setcounter\@gobbletwo
\globaldefs\@ne \let\c@loldepth\@ne
\newlistof{listings}{lol}{\lstlistlistingname}
\newlistof{lstlistoflistings}{lol}{\lstlistlistingname}
\newlistentry{lstlisting}{lol}{0}
\endgroup
% Why the empty space size is increasing each call to my calculate listing header command?
% https://tex.stackexchange.com/questions/388411/why-the-empty-space-size-is-increasing-each-call
\newlength\cftlstlistingoldnumwidth
\setlength\cftlstlistingoldnumwidth{\cftlstlistingnumwidth}
% Calculate the size of the header
%
% What is the use of percent signs (%) at the end of lines?
% https://tex.stackexchange.com/questions/7453/what-is-the-use-of-percent-signs-at-the-end-of-lines
\newcommand{\calculatelisteningsheader}
{%
\renewcommand\cftlstlistingpresnum{\lstlistingname~}%
\settowidth\mylen{\cftlstlistingpresnum\cftlstlistingaftersnum}%
\setlength\cftlstlistingnumwidth{\dimexpr\cftlstlistingoldnumwidth+\mylen}%
\renewcommand\cftlstlistingaftersnum{\hfill\textendash\hfill}%
}
% Ensure it is called at least one time
\calculatelisteningsheader
% https://tex.stackexchange.com/questions/14135/how-to-automatically-add-text-immediately-after-begindocument
\AtBeginDocument{\calculatelisteningsheader}
\makeatother
\begin{document}
% https://tex.stackexchange.com/questions/511519/latex-keeps-showing-minted-environment-as-figures-instead-of-listening
{\renewcommand{\cftfigurename}{\listingname\space}
\lstlistoflistings
}
% \newpage
\begin{code}
\caption{Code}
\begin{minted}{text}
$ python3 unit_tests.py
OK
\end{minted}
\end{code}
% \newpage
% ... more 1892 items equal
\begin{code}
\caption{Code}
\begin{minted}{text}
$ python3 unit_tests.py
OK
\end{minted}
\end{code}
% \newpage
\end{document}
The second problem is that when I use both listings and minted codes, they became unaligned on list of codes (See figure).
Second problem minimal example
\documentclass[english,12pt,a4paper,twoside,chapter=TITLE,section=TITLE,]{abntex2}
\usepackage{caption,listings}
\usepackage[newfloat,chapter,outputdir=F:/SublimeText/Data/Cache/LaTeXTools/b98d701d6340232fe19ea13f16f5a620]{minted}
% https://tex.stackexchange.com/questions/320185/adjust-vertical-spacing-between-caption-and-listing-in-koma-scrartcl
\captionsetup[listing]{position=top,skip=0pt}
\newenvironment{code}{\captionsetup{type=listing}}{}
% https://tex.stackexchange.com/questions/26220/control-spacing-around-table-caption
\AtBeginEnvironment{code}{\setcounter{listing}{\value{lstlisting}}
\setlength{\abovecaptionskip}{0pt}
\setlength{\belowcaptionskip}{10pt}
\setlength{\parskip}{0pt}
\captionsetup{skip=0pt}
}
\AtEndEnvironment{code}{\stepcounter{lstlisting}}
% https://tex.stackexchange.com/questions/269491/mixing-minted-with-lstlisting
\AtBeginEnvironment{listing}{\setcounter{listing}{\value{lstlisting}}}
\AtEndEnvironment{listing}{\stepcounter{lstlisting}}
\makeatletter
\newlength\mylen
\begingroup
\let\newcounter\@gobble\let\setcounter\@gobbletwo
\globaldefs\@ne \let\c@loldepth\@ne
\newlistof{listings}{lol}{\lstlistlistingname}
\newlistof{lstlistoflistings}{lol}{\lstlistlistingname}
\newlistentry{lstlisting}{lol}{0}
\endgroup
% Why the empty space size is increasing each call to my calculate listing header command?
% https://tex.stackexchange.com/questions/388411/why-the-empty-space-size-is-increasing-each-call
\newlength\cftlstlistingoldnumwidth
\setlength\cftlstlistingoldnumwidth{\cftlstlistingnumwidth}
% Calculate the size of the header
%
% What is the use of percent signs (%) at the end of lines?
% https://tex.stackexchange.com/questions/7453/what-is-the-use-of-percent-signs-at-the-end-of-lines
\newcommand{\calculatelisteningsheader}
{%
\renewcommand\cftlstlistingpresnum{\lstlistingname~}%
\settowidth\mylen{\cftlstlistingpresnum\cftlstlistingaftersnum}%
\setlength\cftlstlistingnumwidth{\dimexpr\cftlstlistingoldnumwidth+\mylen}%
\renewcommand\cftlstlistingaftersnum{\hfill\textendash\hfill}%
}
% Ensure it is called at least one time
\calculatelisteningsheader
% https://tex.stackexchange.com/questions/14135/how-to-automatically-add-text-immediately-after-begindocument
\AtBeginDocument{\calculatelisteningsheader}
\makeatother
\begin{document}
% https://tex.stackexchange.com/questions/511519/latex-keeps-showing-minted-environment-as-figures-instead-of-listening
{\renewcommand{\cftfigurename}{\listingname\space}
\lstlistoflistings
}
% \newpage
\begin{lstlisting}[caption={Listing}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}
% \newpage
\begin{code}
\caption{Code}
\label{unitTestsResults}
\begin{minted}{text}
$ python3 unit_tests.py
OK
\end{minted}
\end{code}
% \newpage
\begin{lstlisting}[caption={Listing}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}
% \newpage
\begin{code}
\caption{Code}
\label{unitTestsResults}
\begin{minted}{text}
$ python3 unit_tests.py
OK
\end{minted}
\end{code}
% \newpage
\end{document}
Related questions:


