The \newenvironment command allows the environment to take arguments:
\begin{article}
\newenvironment{preecho}[1]{#1}{}
\begin{document}
\begin{preecho}{Hi!}\end{preecho} % => Hi!
\end{document}
However, this argument cannot be accessed in the destructor:
\begin{article}
\newenvironment{postecho}[1]{}{#1} % => Illegal parameter number #1 in definition of \endpostecho.
\begin{document}
\begin{postecho}{Hi!}\end{postecho}
\end{document}
The error message makes it clear why this is happening. However:
Is this behaviour intentional?
Is there a
\newenvironment-type command that makes the argument accessible in the destructor?
\NewDocumentEnvironmentinstead, but the argument should be specified differently:\NewDocumentEnvironment{echo}{m}{}{#1}– egreg Jan 22 '22 at 21:19