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 ?

karlkoeller
  • 124,410
Surya
  • 709
  • 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 04:23
  • 2
    Verbatim material (as the one in tcblisting) can't be placed in a macro argument. See this related thread: http://tex.stackexchange.com/q/86705/27635. – karlkoeller Aug 25 '13 at 05:39

1 Answers1

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}