6

I'm trying to create a new environment on top of tcblisting (from tcolorbox package) using environ package. Getting weird error about Runaway argument. The MWE:

\documentclass{book}
\usepackage{tcolorbox}
\usepackage{environ}

\tcbuselibrary{listings}

\NewEnviron{CodeListing}[2][]{%
  \begin{tcblisting}{listing only}
    \BODY
  \end{tcblisting}
}

\begin{document}
\begin{CodeListing}
  bool someVar;
\end{CodeListing}
\end{document}

The error is

Runaway argument?
! File ended while scanning use of \next.
<inserted text> 
                \par 
<*> mwe.tex

If I remove the tcblisting environment in the new environment, Everything is fine. What is going wrong here ?

2
  • I'm getting similar error when I try to create new command and use tcblisting environment inside the new command. – Surya Aug 25 '13 at 4:23
  • 2
    Verbatim material (as the one in tcblisting) can't be placed in a macro argument. See this related thread: tex.stackexchange.com/q/86705/27635. – karlkoeller Aug 25 '13 at 5:39
5

Why the combination of tcblisting and environ does not work, was explained in the comments. But it is possible to create a new environment using \newtcblisting:

\documentclass{book}
\usepackage{tcolorbox}

\tcbuselibrary{listings}

\newtcblisting{CodeListing}[2][]{listing only}

\begin{document}
\begin{CodeListing}{something for the mandatory argument}
  bool someVar;
\end{CodeListing}
\end{document}

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.