2

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}}}
\newcommand{\Answer}[1]{\noindent\ding{51}: #1}

\begin{document}

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

\Answer{
\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}}}
\newcommand{\Answer}[1]{\noindent\ding{51}: #1}

\begin{document}

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

\Answer{
\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 at 2:54
1

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}}}
\newcommand{\Answer}{\noindent\ding{51}: }

\begin{document}

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

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

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

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}}}
\newcommand{\Answer}[1]{\noindent\ding{51}: #1}

\begin{document}

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

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

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

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}

  • 3
    could you please add a fully compilable answer to check the validity? Right now, it does not fully answer this question. – Raaja May 3 at 12:43
0

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.