When I want to globally modify a command in my document, I will often use a duplicated version of the original in the stencil, with the help of the \let
macro. For example, if I wanted to do something every time I created a section, I might say:
\let\svsection\section
\renewcommand\section[1]{\mychanges\svsection{#1}}
It just dawned on me that I don't know how or if something similar can be done for environments. What I would hope for is something like (I'm omitting arguments for the sake of simplicity, don't focus on that):
\let\svfigure\figure
\renewenvironment{figure}{\blahblah\begin{svfigure}}
{\end{svfigure}\moreblah}
Of course, this syntax won't work because \figure
isn't a command.
But, I was hoping that the creation of environment abc
would always be accompanied by the creation of associated constructed commands, for example, \start@abc
and \end@abc
, such that these associated commands could be \let
to duplicate the original environment.
I also realize that one approach may be to "patch" the original environment, but I don't think that is really what I'm asking, since I'm not sure a patch can be easily undone, whereas redoing a \let
in the opposite direction (e.g., \let\section\svsection
) will totally undo the effects of redefinition.
It would be a handy feature to know how to duplicate an environment, so that the original copy can be \renew
ed in the fashion I describe.
Best Answer
When you define an environment with
what happens internally (after some checking for optional arguments, testing if the environment exists, and taking care of a possible star argument to
\newenvironment
) essentially boils down toThis means if the environment has no optional arguments
copies the environment
{foo}
as environment{myfoo}
. (If it has an optional argument\LetLtxMacro
should be used instead of\let
, see When to use \LetLtxMacro?.)In the
article
class the{figure}
environment is defined asso saying
works:
Some environments like
{verbatim}
or AMSmath's{align}
cannot be copied this way since they need to find\end{verbatim}
or\end{align}
, respectively, exactly.