# Using minted inside listing causes Problems

I am farly new to LateX, so please be kind ;-). I am using minted to show off some code I wrote. I want the code to have a caption and label so i can refer to it from the text and have it appear in the "List of Listings" at the bottom of my document. Thats why I put minted inside this listing thing.

This is my definition for minted - so i dont need to specify everything mutliple times:

\usepackage[chapter]{minted}
\newminted{glsl}{
mathescape,
linenos,
numbersep=5pt,
gobble=2,
frame=lines,
framesep=2mm}


And this is the code inside my Text.

\begin{listing}[H]
\caption{Berechnung der Runlength für einen bestimmten Pixel}
\begin{glslcode}
void getRlHor() {
for(int j=1; j < maxSize; j++) {
int xRunlength = px + j;
if(xRunlength > imgWidth)
break;
nextGreyV = getGreyValue(xRunlength, py);
if(currentGreyV == nextGreyV) {
rlHor++;
}else{
break;
}
}
}
\end{glslcode}
\label{lis:getRlHor}
\end{listing}


I am using \begin{listing} because i saw it on multiple examples with minted. But this is giving me the trouble.

Here is the error report i am getting: There are always these 8 lines that pop off.

Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }
Something's wrong--perhaps a missing \item. \addvspace {10\p@ }


It seems when i delete the main.lol file. I can compile once without an error. If i write another sentence and then compile again, i get these errors mentioned above. But thats a buggy workarround.

Help is appreciated!!

Edit: I feel a bit dump for not realising this. When i open the main.lol file, here is what it shows

\addvspace {10\p@ }
\contentsline {listing}{\numberline {3.1}{\ignorespaces Spezialf\"alle     abfangen und Randbedingungen setzen}}{8}{listing.3.1}%
\contentsline {listing}{\numberline {3.2}{\ignorespaces Berechnung der              Runlength f\"ur einen bestimmten Pixel}}{8}{listing.3.2}%


The bottom 8 of these (\addvspace {10\p@ }) show red after i compile. I thought it came from the code i put in, since the error started occuring after i put the code it. I cant really post the whole document, since i had to post like 8 whole files here.

• please make a small document that shows the problem, it is hard to debug a fragment, and the error appears to be in the frontmatter list of listings which you have not shown. – David Carlisle Jun 18 at 13:16

This document runs without error, so the error you show must be generated by code you have not shown. please edit the question to have a complete document as below which generates the error shown.

\documentclass{report}

\usepackage{float}
\usepackage[chapter]{minted}
\newminted{glsl}{
mathescape,
linenos,
numbersep=5pt,
gobble=2,
frame=lines,
framesep=2mm}

\begin{document}

\listoflistings

\begin{listing}[H]
\caption{Berechnung der Runlength für einen bestimmten Pixel}
\begin{glslcode}
void getRlHor() {
for(int j=1; j < maxSize; j++) {
int xRunlength = px + j;
if(xRunlength > imgWidth)
break;
nextGreyV = getGreyValue(xRunlength, py);
if(currentGreyV == nextGreyV) {
rlHor++;
}else{
break;
}
}
}
\end{glslcode}
\label{lis:getRlHor}
\end{listing}
\end{document}


Following the edit, this document produces the error shown, on line 15

\documentclass{article}

\begin{document}

\makeatletter

\contentsline {listing}{\numberline {3.1}{\ignorespaces Spezialf\"alle     abfangen und Randbedingungen setzen}}{8}{listing.3.1}%
\contentsline {listing}{\numberline {3.2}{\ignorespaces Berechnung der              Runlength f\"ur einen bestimmten Pixel}}{8}{listing.3.2}%
\end{document}


It can be fixed by adding a blank line as in:

\documentclass{article}

\begin{document}

\makeatletter

\contentsline {listing}{\numberline {3.1}{\ignorespaces Spezialf\"alle     abfangen und Randbedingungen setzen}}{8}{listing.3.1}%
\contentsline {listing}{\numberline {3.2}{\ignorespaces Berechnung der              Runlength f\"ur einen bestimmten Pixel}}{8}{listing.3.2}%

\end{document}


So the error is in code you have not shown that is writing

 \addvspace {10\p@ }


to the lol file. Either it should not be written at all (which is the default behaviour) or it should write a blank like or \par to make sure it is in vertical mode before adding vertical space.

• I edited the question to put more information in it. I sadly cannot post a whole working thing because its split up in more then 8 files.. – Chris Jun 19 at 8:39
• Does it help if i post my header file? There are all the declarations about packages and stuff – Chris Jun 19 at 8:39
• @Chris you do not need to post the original project, start from a copy of the source, can you still show the problem if you only input one of the files? if so can you remove all the text apart from a listing, then can you remove all packages not used in the remaining example. then you can post the example. If you remove something and the problem goes, then you have solved the problem yourself.... – David Carlisle Jun 19 at 9:38
• When i comment the minted part out. The error is gone. I will use something else to promote my code. Or maybe I have the power to dig deeper into this some time later on. Thank u very much for trying to help me, I really appreciate people like you helping out on Forums!!!. Have a nice day – Chris Jun 19 at 10:23
• @Chris I added some code to show how to remove the error but I can't tell you where to make the fix as it is in code you have not shown. – David Carlisle Jun 19 at 10:26