[EDITED to show where I actually want to use the optional argument]
This question may be answered at How to pass an optional argument to an environment with verbatim content?, but I'm having a hard time trying to apply that answer to my problem. I will delete this query if it is deemed duplicative.
When I utilize a verbatim-like environment that takes an optional argument (vb in the MWE below), then for cases where no optional argument is specified the first token in the environment is sometimes excuted outside of the environment.
\documentclass{article}
\usepackage{verbatim}
\parskip 1ex\parindent 0em
\makeatletter
\newenvironment{va}{%
\def\verbatim@processline{%
{\setbox0=\hbox{\the\verbatim@line}%
\hsize=\wd0 \the\verbatim@line\par}}%
\setbox0=\vbox\bgroup \verbatim
}
{%
\endverbatim
\unskip\setbox0=\lastbox %
\egroup
\usebox0
}
\newenvironment{vb}[1][]{%
\def\verbatim@processline{%
{\setbox0=\hbox{\the\verbatim@line}%
\hsize=\wd0 \the\verbatim@line\par}}%
\setbox0=\vbox\bgroup #1 \verbatim
}
{%
\endverbatim
\unskip\setbox0=\lastbox %
\egroup
\usebox0
}
\makeatother
\begin{document}
I created two environments based on \verb|boxedverbatim| environment.
Environment \verb|va| takes no arguments. Environment \verb|vb| is
identical but takes an optional argument (which is not actually used for
anything in this MWE). In all the following cases, no optional argument
is actually passed to the \verb|vb| environment
Starting either environment with a letter works:
\begin{va}I will set \def\x{1}\end{va}
\begin{vb}I will set \def\x{1}\end{vb}
But if I start the environments with a command like \verb|\Huge|, the
\verb|vb| environment executes that command outside the environment, even
though it was not in brackets:
\begin{va}\Huge I will set \def\x{1}\end{va}
\begin{vb}\Huge I will set \def\x{1}\end{vb}
If I start the verbatim with a \verb|\def|, the \verb|vb|
environment breaks
\begin{va}\def\x{1}\end{va}
%\begin{vb}\def\x{1}\end{vb}
\end{document}

xparse's\NewDocumentEnvironment{vc}{ o }{<begin>}{<end>}works, since it uses a different method/technique for picking up arguments (I think). Lots of uncertainty on my end; a heavy-weight can chip in. – Werner Apr 15 '13 at 19:35