I've been under, apparently, the misapprehension that if you have defined an environment called <env_name> then \begin<env_name> and \<env_name> accomplish the same thing. But considering @egreg 's admonishment and my attempts to implement his suggestion, I see that I'm quite wrong.
Occasionally I want to define a new environment, or a command that invokes an environment, in a manner where too early expansion of \begin{<env_name>} will result in errors. Here's a MWE of what I'm thinking of:
\documentclass{article}
\usepackage{pgfkeys}
\usepackage{fancyvrb}
\makeatletter
\pgfkeys
{
/ae/mwe/.is family,
/ae/mwe,
usegobble/.initial=,
gobble/.style = { usegobble={gobble=#1,} },
}
\newenvironment{aetestingmwe}[1][]
{%%'
\pgfqkeys{/ae/mwe}{#1}%%'
\edef\ae@begin@verbatim
{%%'
\noexpand\Verbatim[\pgfkeysvalueof{/ae/mwe/usegobble}]}%%'
\ae@begin@verbatim
}
{
\endVerbatim
}
\makeatother
\pagestyle{empty}
\begin{document}
\begin{aetestingmwe}
[
gobble=2,
]
\textbf{Random stuff}
This line will get decapitated!
\end{aetestingmwe}
\end{document}
If I try to define the environment as
\newenvironment{aetestingmwe}[1][]
{%%'
\pgfqkeys{/ae/mwe}{#1}%%'
\begin{Verbatim}[\pgfkeysvalueof{/ae/mwe/usegobble}]
}
{
\end{Verbatim}
}
I'll get an error:
! Package keyval Error: gobble=2, undefined.
See the keyval package documentation for explanation.
Type H <return> for immediate help.
...
l.27 ]
?
So it seems that it is sometimes necessary to use \<env_name> in place of \begin{<env_name>}.
How do I know when it's safe to assume these two are the same? When are they different? Does it matter whether the environment was defined using low level commands or LaTeX's \newenvironment? What about environments created using xparse?
documentandlrboxthat, for different reasons, issue\endgroupin the starting part and\begingroupin the finishing part. Verbatim environment definitions should never use\beginand\endin their arguments. – egreg Jul 29 '13 at 21:58