yxoc@sbsvax.UUCP (Ralf Treinen) (09/27/89)
Hi, I would like to define an environment that passes all its input text as a parameter to a macro. An application of this is an environment that prints its input text twice. The best thing I could do was \def\doubleenv{\double} \def\double#1\enddoubleenv{#1\par#1\par\end{doubleenv}} \let\enddoubleenv\relax so that I can write normal textline \begin{doubleenv} This line to be printed twice \enddoubleenv normal textline This solution has to drawbacks: 1.) it is not possible to use \end{doubleenv} since it seems not to be possible to include a begin group character in the parameter delimeter text. I don't want to change the catcodes of { and } as it is done in LaTeX's verbatim environment. 2.) it is not possible to use nested doubleenv environments since there is no matching of nested parameter delimeters. I would appreciate any solution Ralf -- ------------------------------------------------------------------------------ EAN :treinen%fb10vax.informatik.uni-saarland.dbp.de (preferred!) UUCP : ...!uunet!unido!sbsvax!treinen | Ralf Treinen or treinen@sbsvax.UUCP | Universitaet des Saarlandes CSNET: treinen%sbsvax.uucp@Germany.CSnet| FB 10 - Informatik (Dept. of CS) ARPA : treinen%sbsvax.uucp@uunet.UU.NET | Bau 36, Im Stadtwald 15 Phone: +49 681 302 2065 | D-6600 Saarbruecken 11, West Germany ------------------------------------------------------------------------------
hsk@infko.UUCP (Friedrich Haubensak) (09/29/89)
Hello, why not use a macro instead of an environment? It would be *much* easier. (If I had known before, I wouldn't have tackled the problem :-) Anyway, here are macros that generate an environment that passes all its input to a macro (actually, this macro is \fhenvwhattodo, see below). The environment stores all its input in a token list register, which then is referenced within the \end...-macro of the environment. You can't define an \end...-macro that has an argument (unless you change code from latex.tex, of course :-). The macros keep track of the \begin's and \end's within the environment so that nesting is no problem. You can give a name of your taste to this environment by redefining the macro \fhenvname, and you can change what is to be done at completion of the environment by redefining macro \fhenvwhattodo. The latter must have 1 parameter. Hope it works! (:-) %% macros for an environment that passes its input to a macro %% (C) Friedrich Haubensak, Uni Koblenz 28. 9. 89 \def\fhenvname{doubleenv}% how the environment should be named \def\fhenvwhattodo#1{% what's to be done with the stuff \par#1\par#1\par} \makeatletter \newtoks\@fh@envtoks\newcount\@fh@envcount \newenvironment{\fhenvname}{\@fh@envtoks{}\@fh@envcount\z@\x@fh@env}% {\expandafter\fhenvwhattodo\expandafter{\the\@fh@envtoks}} \long\def\x@fh@env#1\end#2{% \y@fh@env#1\begin\@fh@etx\end{#2}} \long\def\y@fh@env#1\begin#2\end#3{% \@fh@envtoks\expandafter{\the\@fh@envtoks#1}% \ifx\@fh@etx#2% \ifnum\@fh@envcount=\z@ \def\@fh@nxt{\end{#3}}% \else \@fh@envtoks\expandafter{\the\@fh@envtoks\end{#3}}% \advance\@fh@envcount\m@ne \def\@fh@nxt{\x@fh@env}% \fi \else \advance\@fh@envcount\@ne \def\@fh@nxt{\z@fh@env#2\end{#3}}% \fi \@fh@nxt} \long\def\z@fh@env#1\begin#2\end#3{% \ifx\@fh@etx#2% \@fh@envtoks\expandafter{\the\@fh@envtoks\begin#1\end{#3}}% \advance\@fh@envcount\m@ne \def\@fh@nxt{\x@fh@env}% \else \advance\@fh@envcount\@ne \@fh@envtoks\expandafter{\the\@fh@envtoks\begin#1}% \def\@fh@nxt{\z@fh@env#2\end{#3}}% \fi \@fh@nxt} \makeatother %% end of macros % example: ordinary text \begin{doubleenv} first line within doubleenv \begin{quote} quote one \end{quote} \begin{doubleenv} line of doublenv within doubleenv \end{doubleenv} \end{doubleenv} go on with ordinary text - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | | L i f e |___ ___ | / would be so much easier, | | |___ |\/ | | ___| | \ if everyone read the manual. Friedrich Haubensak, Uni Koblenz (EWH), W. Germany ---- ...!unido!infko!hsk