# ! Paragraph ended before \lst@next was complete: Using lstlisting in itemize

I want to print a piece of verbatim within an item of an itemize environment, as below:

\documentclass[letter, 11pt]{article}
\usepackage{enumitem}
\usepackage{pifont}
\usepackage{listings}

\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}

\begin{document}

\section*{Problem \#1}
\Question{content
}

\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{lstlisting}
G = VVVVVVVVVVVVVVVVVVVVVVVVVVV

PROJ = PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{itemize}
}
\end{document}


But there is an error:

! Paragraph ended before \lst@next was complete.

I did even try the frame solution, presented here, but it does still not work:

\documentclass[letter, 11pt]{article}
\usepackage{enumitem}
\usepackage{pifont}
\usepackage{listings}

\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}

\begin{document}

\section*{Problem \#1}
\Question{content
}

\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{frame}[fragile]
\begin{lstlisting}
G = VVVVVVVVVVVVVVVVVVVVVVVVVVV

PROJ = PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{frame}
\end{itemize}
}
\end{document}

• Crosspost – Johannes_B Oct 18 '16 at 19:30
• @Johannes_B: I sent that question there, because no one declared any idea, here. – Roboticist Oct 18 '16 at 19:32
• Well, maybe that happened because you did not listen to helpers advice. You got two answers for the no line to end question, both of hem saying that an environment would be better suited for what you are trying to do. And here again, commands instead of environments. – Johannes_B Oct 18 '16 at 19:38
• @Johannes_B: I remember your advice within my question, considerably. The problem is that this code is a part of a big project and many people are working on that. For the sake of uniformity, we must use the commands, as they are defined, not to improve them. That is the reason behind not to applying your advice to use environment, instead of command. Actually, I need a way to handle the problem within this command form. Is it possible, at all? – Roboticist Oct 18 '16 at 19:45
• @Roboticist Did you ever resolve this? – Greg Hilston Aug 6 '19 at 2:54

Since there seem to be an absolute No way for code improvement (including a change of macros) and manually doing stuff anyways, including numbering, there is nothing much that can be done.

\documentclass[letter, 11pt]{article}
\usepackage{enumitem}
\usepackage{pifont}
\usepackage{listings}

\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}

\begin{document}

\section*{Problem \#1}
\Question{content
}

\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{lstlisting}
G =
VVVVVVVVVVVVVVVVVVVVVVVVVVV

PROJ
=
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{itemize}
}
\end{document}


What can you control, here?

The issue is with a verbatim environment as the argument to a command. From this question, one solution is to use cprotect:

\documentclass[letter, 11pt]{article}
\usepackage{enumitem,cprotect}
\usepackage{pifont}
\usepackage{listings}

\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}

\begin{document}

\section*{Problem \#1}
\Question{content
}

\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{lstlisting}
G = VVVVVVVVVVVVVVVVVVVVVVVVVVV

PROJ = PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{itemize}
}
\end{document}


The workaround with \input also worked in my case.

I encountered the same error message when trying to use lstlistings within the multiaudience package:


\usepackage{multiaudience}
\SetNewAudience{guests}

\begin{shownto}{guests}
\begin{indentcode}
\begin{lstlisting}
some text
\end{lstlisting}
\end{indentcode}
\end{shownto}

~~~~~~~   example which works   ~~~~~~~~~

\usepackage{multiaudience}
\SetNewAudience{guests}

\begin{shownto}{guests}
\begin{indentcode}
\input{folder/newfile}
\end{indentcode}
\end{shownto}

with the content of newfile.tex being saved in the 'folder':
\begin{lstlisting}
some text
\end{lstlisting}


• could you please add a fully compilable answer to check the validity? Right now, it does not fully answer this question. – Raaja_is_at_topanswers.xyz May 3 '19 at 12:43
• Thanks. I have this issue with baposter class, moving the code out and using \input works! – Emit Taste Aug 24 at 15:02

Not an answer to OP's question, but I got to this question when I forgot to add [fragile] to my frame when adding lstlisting code.

Example:

Broken

\begin{frame}
\begin{lstlisting}[language=Java]
// single line comment
\end{lstlisting}
\end{frame}


Fixed

\begin{frame}[fragile]
\begin{lstlisting}[language=Java]
// single line comment
\end{lstlisting}
\end{frame}