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}
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI 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 8: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 8: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 8:23
environ
package does, the body of the environment is then stored in\BODY
. – user194703 Nov 17 '19 at 7:31\makeatletter
and\makeatother
, of course). I do not know what defines an "official" package, butenviron
is 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. – user194703 Nov 17 '19 at 7: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}
– user194703 Nov 17 '19 at 7:40\MyCustomMacro{\BODY}
by\edef\temp{\noexpand\MyCustomMacro{\BODY}}\temp
, but really hard to say. – user194703 Nov 17 '19 at 7:55