I have a problem with the listings and the mdframed package together. The following code compiles with errors, but the only info I managed to get about it is that it was fatal.
\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{mdframed}
\usepackage{listings}
\newmdenv[linecolor=red,frametitle=Infobox]{infoboxmd}
\makeatletter
\def\@noargument{noargument}
\newenvironment{infobox}[1][noargument]
{\def\@opt@arg{#1}% Caption optional argument
\infoboxmd}
{\endinfoboxmd\par\nobreak%
\ifx\@opt@arg\@noargument\else\centering\@opt@arg\par\fi}%
\makeatother
\lstnewenvironment{codetext}[1]{
Something.
#1
\infobox[#1]
Some text.
}{
Some text.
\endinfobox
Something.
}
%\BeforeBeginEnvironment{codetext}{\begin{infobox}[myonlycaption]}
%\AfterEndEnvironment{codetext}{\end{infobox}}
\begin{document}
\begin{codetext}{caption}
Some code.
\end{codetext}
Some text.
\end{document}
If I use the (commented out) \BeforeBeginEnvironment command instead of \infobox it works, but I can't specify the parameter that way.
Associated thread: mdframed captioning thread

\begin{codetext}, so with a non-interactive compilation TeX exits. With an interactive run (from the command line) the input prompt appears, but of course no command can be recognized and forcing exit is the only escape. – egreg Oct 04 '13 at 15:12mdframed(I guess). I tried the following modified MWE:\documentclass{article} \usepackage[a6paper]{geometry} \usepackage{listings} \makeatletter \lstnewenvironment{codetext}[1]{ \begin{lrbox}{\@tempboxa} }{% \end{lrbox}% \fbox{\usebox\@tempboxa}% } \begin{document} \begin{codetext}{caption} Some code. \end{codetext} \end{document}– Marco Daniel Oct 04 '13 at 19:52mdframed's base environment but not with an environment newly defined with\newmdenv... – cgnieder Oct 06 '13 at 10:43\newmdenv:\renewcommand\newmdenv[2][]{\newenvironment{#2}\mdfsetup{#1}\mdframed}{\endmdframed}}– cgnieder Oct 06 '13 at 15:19\newenvironment{#2}. :) To enable copy/paste of your code:\renewcommand\newmdenv[2][]{\newenvironment{#2}{\mdfsetup{#1}\mdframed}{\endmdframed}}– masu Oct 06 '13 at 16:04