Problem with fancyvrb and optional environment argument



I have the following sample code where I use Verbatim within an
environment with an optional argument:

\documentclass{book}
\usepackage{fancyvrb}
\newenvironment{dialogue}[1][Label]{
#1
\VerbatimEnvironment
\begin{Verbatim}
}
{\end{Verbatim}}

\begin{document}
\begin{dialogue}
Line 1
Line 2
\end{dialogue}
\end{document}

This fails with:
! FancyVerb Error:
Extraneous input `Line 1' between \begin{dialogue}[<key=value>] and
line end
..
\FV@Error ... {FancyVerb Error:
\space \space #1
}

If I change the call to \begin{dialogue}[Label] then the code works.
I've tried tracing macros, but I can't figure out what's wrong.

Anyone else have an idea why the optional argument breaks the code?

.



Relevant Pages

  • Re: Verbatim and tabular
    ... how to insert a verbatim environment into a tabular one. ... command, which is forbidden. ... You must instead define an environment. ... But I don't see that it saves you much typing. ...
    (comp.text.tex)
  • Verbatim and tabular
    ... how to insert a verbatim environment into a tabular one. ... command, which is forbidden. ... You must instead define an environment. ... But I don't see that it saves you much typing. ...
    (comp.text.tex)
  • Re: Why doesnt esizebox work with a verbatim env.?
    ... argument to a command. ... at the fancyvrb for other "verbatim" tricks. ... environment; otherwise try and split them to fit the lines. ...
    (comp.text.tex)
  • Re: Problem with enumitem and hyperref
    ... Write the content of your answer-environment verbatim to the ... environment. ... When reading the aux-file at the end of document-processing ... First it expands some number-values so that ...
    (comp.text.tex)
  • Re: Problem with fancyvrb and optional environment argument
    ... You can't generally put verbatim in the argument to another command. ... Read the fancyvrb documentation for how it implements defining new ... environment as such, I want to add stuff outside it in my environment. ...
    (comp.text.tex)