# Minted listings spanning across multiple pages with caption

I'm using the lncs class and I'm trying to have long code highlighted with minted to span across multiple pages with a caption. According to the minted documentation, a new environment is needed. I'm using the caption package. It works perfectly with a document class such as article, but not with the lncs class.

This is what I have so far:

\documentclass{llncs}

\usepackage{caption}

\newenvironment{longlisting}{\captionsetup{type=listing}}{}
\usepackage[cache=false,outputdir=../build]{minted}

\begin{document}
%
\title{Contribution Title\thanks{Supported by the Machine Learning teaching team.}}
%
\author{The author\orcidID{123456}}
%
\authorrunning{F. Author et al.}
%
\institute{An Institute\\
\email{\{someone,anotherone\}@fantasy.com}}
%
\maketitle              % typeset the header of the contribution
%
\begin{abstract}
The abstract
\keywords{First keyword  \and Second keyword \and Another keyword.}
\end{abstract}
%
\section{First Section}
%
\begin{longlisting}
\begin{minted}{python}
# This program does amazing stuff!
import numpy as np
print('Hello, world!')
\end{minted}
\caption{This is the caption}
\label{lst:long}
\end{longlisting}
\end{document}


When I compile, I get the following error messages:

Unsupported document class (or package) detected, (caption)
usage of the caption package is not recommended. See the caption package documentation for explanation.

Package caption Warning: \caption will not be redefined since it's already (caption) redefined by a document class or package which is (caption) unknown to the caption package. See the caption package documentation for explanation.

I tried with the option

\captionsetup{compatibility=false}


but then I get the warning message:

Package caption Warning: Forced redefinition of \caption since the (caption) unsupported(!) package option compatibility=false' (caption) was given. See the caption package documentation for explanation.

Is there any solution to this?

• It appears the caption package is incompatible (forbidden) with llncs. All you really need is \expandafter\def\csname @captype\endcsname{listings} or \makeatletter \def\@captype{listings} \makeatother`. This assumes that the float class listings exists (not a minted user). – John Kormylo Feb 23 '20 at 16:59
• I relatively new to LaTeX. Could you please explain me how to use the concepts above and the difference between them? – matteo-gambarutti Feb 24 '20 at 10:37
• The @ symbol is used to protect system commands etc. from being used by the unwashed masses. \makeatletter removes that constraint, and \makeatother restores it. \csname ...\endcsname can also use @ symbols, although that is not its primary function. The \expandafter allows \csname to expand before \def. – John Kormylo Feb 24 '20 at 13:40