Consider this example:
\documentclass{article}
\newcommand{\baz}{}
\newenvironment{foo}[1]{#1}{\makeatletter\g@addto@macro\baz{#1}\makeatother}
\begin{document}
\begin{foo}{bar}
\end{foo}
\end{document}
The example does not work. What I am aiming to achieve is concatenating all parameters used with foo, so I can output them at the end of the document. What is the correct approach for that?
\newenvironment. – Display Name Jun 07 '11 at 00:08\makeatletteretc. inside command arguments because they are parsed when they are read, not when they are executed. – Philipp Jun 07 '11 at 05:08\newenvironment, with\NewDocumentEnvironment{myenv}{m}{}{#1}the end-code argument can refer to the arguments#1,#2, etc. – Daniel Diniz Nov 10 '22 at 22:52