[Tex/LaTex] “Figure” as name of listings in listoflistings with minted and newfloat

classicthesislistingsminted

The following MWE gives me a List of Listings with "Figure" as name of listings.

\documentclass{scrreprt}
\usepackage{classicthesis}    
\usepackage[newfloat]{minted}

\begin{document}
\listoflistings
\begin{listing}
\begin{minted}{sql}
Test
\end{minted}
\caption{My Listing}
\end{listing}
\end{document}

output

If I remove the newfloat option from minted, the "Figure"-String disappears. However, the desired behaviour would be to include something like "Listing" in front of every entry.

Best Answer

You should load minted before classicthesis, otherwise you get a

pdfTeX warning (ext4): destination with the same identifier 
(name{figure.0.1}) has been already used, duplicate ignored

warning, with incorrect hyperlinks.

Then you can make \l@listing the same as \l@figure, which is what newfloat does anyway, but after classicthesis has modified the standard meaning of \l@figure. You can use a hook, usually empty, for locally changing \figurename to “Listing” and, possibly, for changing some of the indentation parameters.

\documentclass{scrreprt}

\usepackage[newfloat]{minted}
\usepackage{classicthesis}

\makeatletter
\let\l@listing\l@figure
\def\newfloat@listoflisting@hook{\let\figurename\listingname}
\makeatother

\begin{document}

\listoflistings

\begin{listing}
\begin{minted}{sql}
Test
\end{minted}
\caption{My Listing}
\end{listing}
\end{document}

enter image description here

With babel it seems that some timing problems arise. Here's a different workaround, including the change to the labels.

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[newfloat]{minted}
\usepackage{classicthesis}
\usepackage{etoolbox}

\addto\captionsngerman{%
  \renewcommand{\listlistingname}{Quellcodeverzeichnis}%
  \renewcommand{\listingname}{Listing}%
}

\makeatletter
\let\l@listing\l@figure
\patchcmd{\l@listing}{\cftfigpresnum}{\cftlistingpresnum}{}{}
\newcommand\cftlistingpresnum{\listingname~}
\makeatother

\begin{document}

\listoflistings

\begin{listing}
\begin{minted}{sql}
Test
\end{minted}
\caption{My Listing}
\end{listing}
\end{document}

enter image description here