Say that we have an environment that is used like this:
\begin{foo}
... code in here
\end{foo}
And, without changing the above syntax in our document, we would like to redefine what the foo environment does.
For example, say we want to wrap foo in a bar, so that the effect of the above code would be like this:
\begin{bar}
\begin{foo}
... code in here
\end{foo}
\end{bar}
For example, as suggested in this post we can do the following:
\let\OldFoo\foo
% in the minimal redefinition case
\renewcommand{\foo}[1]{\OldFoo#1\endfoo}
% in the wrapping w/ bar case
\renewcommand{\foo}[1]{\begin{bar}\OldFoo#1\endfoo}\end{bar}}
And this would allow us to do the following:
\foo{ ... code in here }
However, that's not the syntax we want - it's essentially a new \foo command, not redefining \begin{foo}...\end{foo}
My attempt is the following:
\let\origfoo\foo
\let\origendfoo\endfoo
\renewcommand{\foo}[1]{
\begin{bar}
\origfoo{#1}
}
\renewcommand{\endfoo}[0]{
\origendfoo
\end{bar}
}
... but it doesn't seem to work.
Any thoughts on how to do this?
P.S. Bonus Q: I don't understand where \endfoo is coming from. Is \end{foo} a syntax shorthand for \endfoo in LaTeX?

\end{foo}expands to\endfooand some other things. Could please show us a concrete example? It will be much easier than trying to guess whatfoodoes. Depending on the environment, the approach is different. – Phelype Oleinik Sep 05 '18 at 20:51\begin{foo}...\end{foo}to\foo{...}when wrappingfoowithin some other environment. See this example. – Werner Sep 05 '18 at 21:24