I know there's an option in expl3, but how can I do the same in LaTeX2e (or TeX)?
\newenvironment*{myEnv}[1][]{}{}
\begin{myEnv}
I first need to pass this to this environment as an argument.
\end{myEnv}
I know there's an option in expl3, but how can I do the same in LaTeX2e (or TeX)?
\newenvironment*{myEnv}[1][]{}{}
\begin{myEnv}
I first need to pass this to this environment as an argument.
\end{myEnv}
The idea of 'collecting the body' is nowadays available in xparse
\documentclass{article}
\usepackage{xparse}
\begin{document}
\NewDocumentEnvironment{myEnv}{O{}+b}{The argument was '#2'}{}
\begin{myEnv}
I first need to pass this to this environment as an argument.
\end{myEnv}
\end{document}
Here, #2 is the second argument (the body).
As pointed out in comments, the long-standing environ package does the same but provides the result as \BODY.
\par tokens.
– Joseph Wright
Nov 17 '19 at 08:18
\BODY to \zStart as \zStart{\BODY} I don't get processed text, it's as if \zStart didn't work.
– bp2017
Nov 17 '19 at 08:20
\BODY. You'll need to expand it once: \expandafter\zStart\expandafter{\BODY}. TeX macros receive the tokens you pass as written, not the expansion of the tokens. I think that was mentioned in comments on the question.
– Joseph Wright
Nov 17 '19 at 08:23
environpackage does, the body of the environment is then stored in\BODY. – Nov 17 '19 at 07:31\makeatletterand\makeatother, of course). I do not know what defines an "official" package, butenvironis definitely a very nice and robust package that gets widely used. The source of the package is not very long, so you can have a look at it. – Nov 17 '19 at 07:38\documentclass{article} \usepackage{environ} \NewEnviron{myEnv}[1][]{\underline{\BODY}} \begin{document} \begin{myEnv} I first need to pass this to this environment as an argument. \end{myEnv} \end{document}– Nov 17 '19 at 07:40\MyCustomMacro{\BODY}by\edef\temp{\noexpand\MyCustomMacro{\BODY}}\temp, but really hard to say. – Nov 17 '19 at 07:55