This is an attempt to make clear what happened in this question of xport (now deleted, sorry). The now deleted question included code that tried to make my answer to this question of xport work for optional arguments, but the code failed. A shorter illustration: The following code doesn't compile if one removes the [optional argument]
.
\documentclass{minimal}
\usepackage{listings,fancyvrb}
\newenvironment{Row}[1][]
{\VerbatimEnvironment
\begin{VerbatimOut}{\jobname.tmp}}
{\end{VerbatimOut}\lstinputlisting{\jobname.tmp}}
\begin{document}
\begin{Row}[optional argument]
\relax
\end{Row}
\end{document}
The error message says
! FancyVerb Error:
Extraneous input `\relax ' between \begin{Row}[<key=value>] and line end
Of course, the optional argument (and in fact the whole construction) is utterly pointless here, but hey, it's a minimal example. To make the example in xport's question also work for optional arguments is quite interesting, I think.
The question: What exactly is happening here, and how can one fix the code?
(What I found out so far: \begin{VerbatimOut}{\jobname.tmp}}
wants to see a linebreak immediately after it (try putting a %
), and this somehow gets messed up by \begin{Row}
looking for the optional argument.)