I don't know why, but I tried to follow https://tex.stackexchange.com/a/286089/116348 to redefine an environment like:
\let\answers\questions
\let\endanswers\endquestions
in order to save and restore an environment.
I tried to do:
\documentclass[]{article}
\begin{document}
\NewDocumentEnvironment{mydummyenv}{m}{I will print #1 before. ``}{'' And I will print #1 after.}
\begin{mydummyenv}{MyArg}
Hey
\end{mydummyenv}
%%% Overwrite the env and store the old version
\let\mydummyenvOrig\mydummyenv
\let\endmydummyenvOrig\endmydummyenv
\DeclareDocumentEnvironment{mydummyenv}{D<>{}}{
I replace the dummy environment, see my value #1.
}{}
%% Restore the env
\let\mydummyenv\mydummyenvOrig
\let\endmydummyenv\endmydummyenvOrig
\begin{mydummyenv}{MyArg}
Hey
\end{mydummyenv}
\end{document}
But sadly the old environment is used:
Do you have a solution to save and later restore an arbitrary environment? Ideally, this solution should only depend on the name of the environment (I don't want to make any assumption on how the original argument was made, as I only know the definition of the new environment).
PS: in practice my issue is more complicated as it is part of my robust-externalize library and involves rescan… so just wrapping the redefined environment in a group as a workaround would not work for my actual problem.

\NewDocumentEnvironmentisn't stored in the macro of that environment directly (that holds the argument pattern). Use\NewEnvironmentCopyand\DeclareEnvironmentCopyinstead of\let. – Skillmon Sep 07 '23 at 12:55\NewDocumentEnvironmentso that all the submacros remain intact. – John Kormylo Sep 07 '23 at 13:53