Recently, when I've been working with environments with an optional argument, I've noticed that the behavior changes when I introduce a set of square braces, even when there is nothing inside them. For instance:
\documentclass{article}
\usepackage{fancyvrb}
\newenvironment{exer}[1][]
{
do the following exercise from #1
\VerbatimOut{\jobname.exer}%
}
{
\endVerbatimOut%
\input{\jobname.exer}%
}
\begin{document}
\begin{exer}[]
some text
\end{exer}
\end{document}
It will compile a pdf with "some text" as well as a .exer file, but if I replace the exer environment with
\begin{exer}
some text
\end{exer}
it will throw the following error:
! FancyVerb Error:
Extraneous input `some text' between \begin{exer}[<key=value>] and line end
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}
l.16 some text
So I have two questions: first, why does the environment behave differently even when I pass in the default optional argument, and second, is there any way to patch or address this behavior?
Many thanks.