# mixing minted with lstlisting

I have a List of Listings that looks like this:

The first listing, which is correct, uses lstlisting. 3.1 is the correct chapter.

The second listing uses minted. Somehow it shows 1 as chapter, which should actually be 3.2.

This is my command for the List of Listings:

\renewcommand{\lstlistlistingname}{List of Listings}
\listof{listing}{\listoflistingscaption}%


This is the first code:

\begin{lstlisting}[language=xml, frame=single, caption={"Segment of the XML input file"}, label={lst:xmlfile}]
some code
\end{lstlisting}


This is the second:

\begin{listing}[H]
\begin{minted}{c++}
some code
\end{minted}
\caption{"Conversion functions for DirID and ID"}
\label{lst:conversion}
\end{listing}


What do I need to change here so that it shows up correctly with the right chapter number?

The first thing you need is \usepackage[chapter]{minted}. This sets minted to use <chapter>.<listing> style numbering in the list of listings.
At this point, listings from the two packages will have the same format in the list of listings, but each will be using its own number scheme. They need to share a common counter to fix this. A simple solution is to modify the listing environment from minted so that it actually uses the lstlisting counter. This relies on the etoolbox package, which is automatically loaded by recent versions of minted. The code can be inserted in the preamble after minted is loaded.
\AtBeginEnvironment{listing}{\setcounter{listing}{\value{lstlisting}}}

• Only adding [chapter] did not work for me, however I got it working when I included etoolbox and added the two lines you mentioned. There is one error though: The captions both say "Listing 3.1 ..." even though the second one should say "Listing 3.2 ..." and in the list of listings it shows correctly. – gartenriese Sep 26 '15 at 16:34