Article View: comp.text
Article #943Re: LaTeX environments and macros
From: Friedrich Haubensak
Date: Fri, 29 Sep 1989 11:22
Date: Fri, 29 Sep 1989 11:22
83 lines
3384 bytes
3384 bytes
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
Technical Details
Message-ID:
<556@infko.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!unido!infko!hskReferences:
<941@sbsvax.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!unido!infko!hsk From: hsk@infko.UUCP (Friedrich Haubensak) Newsgroups: comp.text Subject: Re: LaTeX environments and macros Summary: here are the macros Keywords: LaTeX, TeX, environments, macros, delimited parameters Message-ID: <556@infko.UUCP> Date: 29 Sep 89 11:22:10 GMT References: <941@sbsvax.UUCP> Organization: University of Koblenz (EWH), West Germany Lines: 83