diff options
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/environ/README | 20 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/environ/environ.pdf | bin | 97203 -> 132373 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/environ/environ.dtx | 313 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/environ/environ.ins | 1 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/environ/environ.cfg | 30 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/environ/environ.sty | 68 |
6 files changed, 355 insertions, 77 deletions
diff --git a/Master/texmf-dist/doc/latex/environ/README b/Master/texmf-dist/doc/latex/environ/README index 6fe3cb4b30b..5d61602e73c 100644 --- a/Master/texmf-dist/doc/latex/environ/README +++ b/Master/texmf-dist/doc/latex/environ/README @@ -1,10 +1,26 @@ ___________________ The ENVIRON package -v0.0 +v0.2 + +Provides two things: a new way of defining +environments that read their contents before +processing; and, a \long version of amsmath's +\collect@body macro called \Collect@Body. + +Here's an example: + + \NewEnviron{test}[3][]{"#1,#2,\BODY,#3"} + \begin{test}[zero]{one}{last} + three\par four + \end{test} + +Produces the equivalent of: + + "zero,one,three\par four,last" ______________ Will Robertson wspr 81 [at] gmail [dot] com -Copyright 2007 +Copyright 2007-2008 Distributed under the LaTeX Project Public License diff --git a/Master/texmf-dist/doc/latex/environ/environ.pdf b/Master/texmf-dist/doc/latex/environ/environ.pdf Binary files differindex dd5504dc2fc..c013a4e3e48 100644 --- a/Master/texmf-dist/doc/latex/environ/environ.pdf +++ b/Master/texmf-dist/doc/latex/environ/environ.pdf diff --git a/Master/texmf-dist/source/latex/environ/environ.dtx b/Master/texmf-dist/source/latex/environ/environ.dtx index f30120eb541..020e3ef87fc 100644 --- a/Master/texmf-dist/source/latex/environ/environ.dtx +++ b/Master/texmf-dist/source/latex/environ/environ.dtx @@ -5,13 +5,29 @@ %<*readme> ___________________ The ENVIRON package -v0.0 +v0.2 + +Provides two things: a new way of defining +environments that read their contents before +processing; and, a \long version of amsmath's +\collect@body macro called \Collect@Body. + +Here's an example: + + \NewEnviron{test}[3][]{"#1,#2,\BODY,#3"} + \begin{test}[zero]{one}{last} + three\par four + \end{test} + +Produces the equivalent of: + + "zero,one,three\par four,last" ______________ Will Robertson wspr 81 [at] gmail [dot] com -Copyright 2007 +Copyright 2007-2008 Distributed under the LaTeX Project Public License %</readme> %<*internal> @@ -49,14 +65,12 @@ This work consists of the file environ.dtx \endpostamble \askforoverwritefalse \generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}} -\generate{\file{\jobname.cfg}{\from{\jobname.dtx}{defaults}}} %</batchfile> %<batchfile>\endbatchfile %<*internal> \generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}} \nopreamble\nopostamble \generate{\file{README.txt}{\from{\jobname.dtx}{readme}}} -\generate{\file{prepare.sh}{\from{\jobname.dtx}{prepare}}} \generate{\file{dtx-style.sty}{\from{\jobname.dtx}{dtx-style}}} \endgroup \immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx} @@ -89,9 +103,26 @@ This work consists of the file environ.dtx % \maketitle % % \begin{abstract} -% This package provides two things, one for document authors and one for macro authors. For the document authors, a new method of defining environments that might be more convenient on occassion. And for the package writers, \pkg{amsmath}'s \cmd\collect@body\ command, and a long version of the same, \cmd\Collect@Body. +% \noindent This package provides two things, one for document authors and one for macro authors. For the document authors, a new method of defining environments that might be more convenient on occassion. And for the package writers, \pkg{amsmath}'s \cmd\collect@body\ command, and a long version of the same, \cmd\Collect@Body. % \end{abstract} % +% \section{Introduction} +% +% This packages provides new commands for defining environments. Here's a trivial example: +% \begin{example}{} +% \NewEnviron{test}{% +% \fbox{\parbox{1.5cm}{\BODY}} +% \color{red} +% \fbox{\parbox{1.5cm}{\BODY}}} +% +% \begin{test} +% par\par +% graf +% \end{test} +% \end{example} +% +% \cmd\RenewEnviron\ can be used with the same syntax to redefine a pre\"existing environment. +% % \section{For the document author} % % \LaTeX's standard method of defining environments looks like this (ignoring arguments for now): @@ -99,21 +130,101 @@ This work consists of the file environ.dtx % % The advantage to using environments is that their contents is not treated as a macro argument, so there are less restrictions on what can exist inside, and the processing can be more efficient for long pieces of document text. % -% The disadvantage of environments is that sometimes you really do want to collect up its body and apply some sort of command to the whole thing. -% This package provides a way to define such environments, -% \codeline \cmd\NewEnvironment\marg{name}\marg{macro code} ,\\ -% where \marg{macro code} has argument |#1| as everything inside the environment. \cmd\RenewEnvironment\ can be used to redefine a pre\"existing environment. +% The disadvantage of environments is that sometimes you really do want to collect up its body and apply some sort of command to the whole thing. This package provides a way to define such environments, and v0.2 of this package brings a new syntax: +% \codeline \cmd\NewEnviron\marg{name}\marg{macro code}\oarg{final code} .\\ +% You saw an example in the introduction; the body of the environment is contained within the macro |\BODY|, and \oarg{final code} is the code executed at |\end|\marg{name} (more on this later). +% +% \subsection{Environment arguments} % -% As an example, consider putting a box around an environment. This requires more than a one-line solution without this package \note{And there're packages to do things much more nicely than I'm showing here anyway.}, but now we can write +% If you want to use arguments to the environment, these are specified in the usual way: +% \codeline \cmd\NewEnviron\marg{name}\oarg{N.\,args}\oarg{opt.\,arg.}\marg{macro code}\oarg{final code} ,\\ +% where \marg{macro code} has arguments |#1|, |#2|, \dots, as per traditional \LaTeX\ environment mandatory and optional arguments. Here's an example with two arguments; one optional argument (|#1|, which is |\today| if omitted) and one mandatory argument (|#2|): % \begin{example}{} -% \NewEnvironment{test}{\fbox{\parbox{3cm}{#1}}} +% \NewEnviron{test}[2][\today]{% +% \fbox{\parbox{3cm}{% +% \textbf{#2}\\ +% \BODY\\ +% (#1)}}} +% +% \begin{test}{Title} +% par\par graf +% \end{test} +% +% \begin{test}[Yesterday]{Title} +% par\par graf +% \end{test} +% \end{example} +% +% \subsection{\oarg{final code}} +% This is the code executed at |\end|\marg{name} of the environment. +% For the purposes of this package it is only designed (but is very useful indeed) for cleanup code such as space gobbling in the input text. +% +% \DescribeMacro{\environfinalcode} +% This macro sets a default value for the \oarg{final code} (unless manually specified) in each subsequent environment created with \cmd\NewEnviron. The default is to define each new environment postfixed by \cmd\ignorespacesafterend, like this: +% \codeline |\environfinalcode{\ignorespacesafterend}| .\\ +% Here's a silly example: +% \begin{example}{} +% \environfinalcode{((finish))} +% \NewEnviron{test}{\fbox{\parbox{3cm}{\BODY}}} % \begin{test} % par\par % graf % \end{test} % \end{example} % -% Now, this kind of environment definition makes collecting arguments a little cumbersome, but it's certainly possible. Arguments are defined with a separate macro that `gobbles up' the arguments inside the environment before the body is passed to \marg{macro code}. +% Careful, \cmd\environfinalcode\ cannot contain square brackets without first protecting them with braces (\eg, +% \codeline |\environfinalcode{[end]}| \\ +% will not work but +% \codeline |\environfinalcode{{[end]}}| \\ +% will). This is because the optional argument to \cmd\NewEnviron\ itself uses square brackets as argument delimiters. +% +% \section{Test} +% +% Here's an example to ensure everything that you'd think should work, in fact, does: +% \begin{example}{} +% \NewEnviron{test}{% +% \fbox{\parbox{\linewidth- +% 0.1cm*\currentgrouplevel}{\BODY}} +% \setlength\fboxrule{2\fboxrule} +% \fbox{\parbox{\linewidth- +% 0.1cm*\currentgrouplevel}{``\BODY''}}} +% +% \begin{test} +% outer\par +% \def\tmp#1{*#1*}% +% \tmp{aa}\par +% \begin{test} +% inner\par +% \def\tmp#1{(#1)}\tmp{bb} +% \end{test} +% \end{test} +% \end{example} +% +% +% \section{Backwards compatibility} +% +% In v0.1 of this package, the \cmd\NewEnvironment\ macro was +% used instead (described below). There were a number of limitations with the different +% approach that it used, the main ones being: +% \begin{itemize} +% \item Option processing occured with \emph{every} instance of |#1| +% (which represented the environment body), +% \item Environment options were only available \emph{after} the first instance of |#1|. +% \end{itemize} +% Please, please, don't use \cmd\NewEnvironment. +% +% The code for this syntax is still loaded by this package for +% backwards compatibility, but in the next major release it will +% be moved to a conditional package option. Eventually, I'll +% probably delete it from the package altogether. +% +% \subsection{Previous code documentation} +% +% Just in case you need the documentation for the old syntax, here it is: +% \codeline \cmd\NewEnvironment\marg{name}\marg{macro code} ,\\ +% where \marg{macro code} has argument |#1| as everything inside the environment. +% +% Now, this kind of environment definition makes collecting arguments a little cumbersome. Arguments are defined with a separate macro that `gobbles up' the arguments inside the environment before the body is passed to \marg{macro code}. % \codeline \cmd\EnvironArgs\marg{name}\oarg{N.\ args}\oarg{opt. arg.}\marg{arg. macro code} \\ % This follows the same syntax of defining a macro with several arguments and a possible optional argument at the beginning. Here's an example: % \begin{example}{} @@ -128,13 +239,7 @@ This work consists of the file environ.dtx % % I've tried to ensure that whitespace is ignored at the appropriate places; without this additional code, there would be a space before `par' and after `graf' in the examples above. % -% Note that arguments to the environment have to be explicitly passed into the macro code defining what the environment actually does. This is a bit of a shame, and a more convenient syntax could be -% \begin{Verbatim}[gobble=4] -% \NewEnv{test}[2][before]{\EnvBody\par---#1/#2---} -% \end{Verbatim} -% This is a probable future addition I'll make to the package. -% -% Oh, one last thing. These environments are defined to be ended by \cmd\ignorespacesafterend, which means that if they're used in a paragraph then the |\end{...}| command will gobble space after it. Let me know if this is a problem. It's kind of the way I like to do things but it might not fit everyone. +% Environments created with \cmd\NewEnvironment\ are ended by the command \cmd\ignorespacesafterend, which means that if they're used in a paragraph then the |\end{...}| command will gobble space after it. (If the environment is a paragraph on its own, there will be no difference.) % % \newpage % \section{For the macro author} @@ -151,7 +256,7 @@ This work consists of the file environ.dtx % \end{test} % \end{example} % -% And here's an example with environment arguments: +% And here's a crude example with environment arguments: % % \begin{example}{} % \long\def\wrap#1{[\arg#1]} @@ -174,11 +279,55 @@ This work consists of the file environ.dtx % % This is the package. % \begin{macrocode} -\ProvidesPackage{environ}[2007/09/23 v0.1 A new environment syntax] +\ProvidesPackage{environ}[2008/06/18 v0.2 A new way to define environments] % \end{macrocode} % % \PrintChanges % +% \section{Begin} +% +% \begin{macro}{\environbodyname} +% \darg{control sequence} +% Changes the control sequence used to represent the environment body in its definition. Not to be used as a user command; but maybe one day it will be. Don't change this after defining any |\NewEnviron| environments! +% \begin{macrocode} +\def\environbodyname#1{\def\env@BODY{#1}} +\environbodyname\BODY +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\environfinalcode} +% \darg{code} +% This is the \marg{code} that's executed by default at \cs{end}\marg{env.\,name}: +% \begin{macrocode} +\def\environfinalcode#1{% + \def\env@finalcode{#1}} +\environfinalcode{\ignorespacesafterend} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\longdef@c} +% \LaTeX3-inspired shorthands. +% \begin{macrocode} +\def\longdef@c#1{% + \expandafter\long\expandafter\def\csname#1\endcsname} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\trim@spaces} +% \darg{tokens} Removes leading and trailing spaces from the (arbitrary) input. +% Thanks to Morten H\o gholm. +% \begin{macrocode} +\catcode`\Q=3 +\long\def\trim@spaces#1{\romannumeral-`\q\trim@trim@\noexpand#1Q Q} +\long\def\trim@trim@#1 Q{\trim@trim@@#1Q} +\long\def\trim@trim@@#1Q#2{#1} +\catcode`\Q=11 +% \end{macrocode} +% \changes{v0.2}{2008/06/16}{Added.} +% \end{macro} +% +% \section{\cs{collect@body}-related code} +% % \begin{macro}{\collect@body} % Now, \pkg{amsmath} defines \cmd\collect@body\ for us. But that package may not be loaded, and we don't want to have to load the whole thing just for this one macro. % \begin{macrocode} @@ -191,7 +340,8 @@ This work consists of the file environ.dtx \@envbody\@emptytoks \def\begin@stack{b}% \begingroup \expandafter\let\csname\@currenvir\endcsname\collect@@body - \edef\process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}% + \edef\process@envbody{% + \expandafter\noexpand\csname\@currenvir\endcsname}% \process@envbody } \def\push@begins#1\begin#2{% @@ -224,7 +374,8 @@ This work consists of the file environ.dtx \@envbody\@emptytoks \def\begin@stack{b}% \begingroup \expandafter\let\csname\@currenvir\endcsname\Collect@@Body - \edef\process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}% + \edef\process@envbody{% + \expandafter\noexpand\csname\@currenvir\endcsname}% \process@envbody } \long\def\Push@Begins#1\begin#2{% @@ -247,6 +398,97 @@ This work consists of the file environ.dtx % \end{macrocode} % \end{macro} % +% \section{User-level syntax} +% \begin{macro}{\NewEnviron} +% This is the new one. +% \begin{macrocode} +\def\NewEnviron{% + \let\env@newcommand\newcommand + \let\env@newenvironment\newenvironment + \env@NewEnviron} +\def\RenewEnviron{% + \let\env@newcommand\renewcommand + \let\env@newenvironment\renewenvironment + \env@NewEnviron} +% \end{macrocode} +% \paragraph{Input argument parsing} +% The first optional argument: +% \begin{macrocode} +\def\env@NewEnviron#1{% + \@ifnextchar[ + {\env@new@i{#1}} + {\env@new@iii{#1}{}}} +% \end{macrocode} +% And the second: +% \begin{macrocode} +\def\env@new@i#1[#2]{% + \@ifnextchar[ + {\env@new@ii{#1}[#2]} + {\env@new@iii{#1}{[#2]}}} +% \end{macrocode} +% And the second: (cont.) +% \begin{macrocode} +\def\env@new@ii#1[#2][#3]{% + \env@new@iii{#1}{[#2][#3]}} +% \end{macrocode} +% The final optional argument: +% \begin{macrocode} +\long\def\env@new@iii#1#2#3{% + \@temptokena={\env@new{#1}{#2}{#3}}% + \@ifnextchar[{% + \the\@temptokena + }{% + \expandafter\the\expandafter + \@temptokena\expandafter[\env@finalcode]% + }} +% \end{macrocode} +% \paragraph{Environment creation code} +% \begin{macro}{\env@new} +% \darg{name of the environment} +% \darg{possible optional args (either `\meta{empty}' or `\texttt{[N]}' or `\texttt{[N][default]}')} +% \darg{environment code} +% \doarg{final code} +% \begin{macrocode} +\long\def\env@new#1#2#3[#4]{% +% \end{macrocode} +% Define the new environment to Collect its body and execute |env@#1@parse| on it. +% \begin{macrocode} + \env@newenvironment{#1}{% + \expandafter\Collect@Body\csname env@#1@parse\endcsname + }{#4} +% \end{macrocode} +% |env@#1@parse| executes the body twice: the first time to save the body while ignoring the arguments; and the second time to process the environment definition itself while ignoring the environment body: +% \begin{macrocode} + \longdef@c{env@#1@parse}##1{% + \csname env@#1@save@env\endcsname##1\env@nil + \csname env@#1@process\endcsname##1\env@nil}% +% \end{macrocode} +% These must be defined on a per-environment basis in order to get the argument gobbling right: (because there are a variable number of arguments) +% \begin{macrocode} + \expandafter\env@newcommand + \csname env@#1@save@env\endcsname#2{\env@save}% + \expandafter\env@newcommand + \csname env@#1@process\endcsname#2{#3\env@ignore}} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\env@save} +% If \cmd{\env@BODY} were variable, this macro would have to be saved for every environment definition individually; at the moment we just use a global definition. +% Use \cmd\trim@spaces\ to remove surrounding space: +% \begin{macrocode} +\long\def\env@save#1\env@nil{% + \expandafter\edef\env@BODY{% + \unexpanded\expandafter + \expandafter\expandafter{\trim@spaces{#1}}}} +% \end{macrocode} +% \end{macro} +% This is the same as a \cmd\@gobblenil\ but long and less likely to exist in the environment body: +% \begin{macrocode} +\long\def\env@ignore#1\env@nil{} +% \end{macrocode} +% \changes{v0.2}{2008/06/16}{Added.} +% \end{macro} +% +% \section{Backwards compatibility} % \begin{macro}{\NewEnvironment} % \darg{Environment name} % \darg{Macro definition applied to env.\ body} @@ -276,20 +518,22 @@ This work consists of the file environ.dtx % \end{macrocode} % Now precede the env.\ body by the argument parsing command, which may or may not be defined in \cmd\EnvironArgs\ (and \cmd\unskip\ removes trailing space) % \begin{macrocode} - \expandafter\env@newcommand\csname env@@#1\endcsname[1]{% + \longdef@c{env@@#1}##1{% \csname env@@@#1\endcsname{% - \csname env@args@\@currenvir\endcsname##1\unskip}}% + \csname env@args@#1\endcsname##1\unskip}}% % \end{macrocode} % And then pass it all off to the environment macro (|#2|), % \begin{macrocode} - \expandafter\env@newcommand\csname env@@@#1\endcsname[1]{#2}} + \longdef@c{env@@@#1}##1{#2}} % \end{macrocode} +% \changes{v0.2}{2008/06/11}{Changed \cs{@currenv} to \texttt{\#1} to allow nesting.} +% \changes{v0.2}{2008/06/16}{Deprecated.} % \end{macro} % % \begin{macro}{\EnvironArgs} % \darg{Environment name} -% \oarg{Number of arguments} -% \oarg{Optional argument} +% \doarg{Number of arguments} +% \doarg{Optional argument} % \darg{Argument macro code} % Tedious argument parsing: % \begin{macrocode} @@ -442,12 +686,12 @@ This work consists of the file environ.dtx \g@addto@macro\endmacro{\setcounter{argument}{0}} \newcommand*\darg[1]{% \stepcounter{argument}% - {\ttfamily\char`\#\theargument~:~}#1\par\noindent\ignorespaces} + {\ttfamily\char`\{\char`\#\theargument\char`\}:~}#1\par\noindent\ignorespaces} \newcommand*\doarg[1]{% \stepcounter{argument}% - {\ttfamily\makebox[0pt][r]{[}\char`\#\theargument]:~}#1\par\noindent\ignorespaces} + {\ttfamily[\char`\#\theargument]:~}#1\par\noindent\ignorespaces} -\def\codeline{\par\hspace{\parindent}}% two \indents in total +\def\codeline{\par\hspace{0.5\parindent}} \newcommand\unichar[2]{\textsc{\MakeLowercase{u+#1: #2}}} @@ -455,13 +699,6 @@ This work consists of the file environ.dtx % \end{macrocode} %</dtx-style> -%<*prepare> -rm environ.zip -latex environ.dtx -mv README.txt README - -zip environ.zip environ.dtx environ.ins environ.pdf README -%</prepare> %\fi % % \typeout{*************************************************************} diff --git a/Master/texmf-dist/source/latex/environ/environ.ins b/Master/texmf-dist/source/latex/environ/environ.ins index 644b366eee6..135c6a9cebd 100644 --- a/Master/texmf-dist/source/latex/environ/environ.ins +++ b/Master/texmf-dist/source/latex/environ/environ.ins @@ -41,7 +41,6 @@ This work consists of the file environ.dtx \endpostamble \askforoverwritefalse \generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}} -\generate{\file{\jobname.cfg}{\from{\jobname.dtx}{defaults}}} \endbatchfile %% %% Copyright (C) 2007 by Will Robertson <wspr81@gmail.com> diff --git a/Master/texmf-dist/tex/latex/environ/environ.cfg b/Master/texmf-dist/tex/latex/environ/environ.cfg deleted file mode 100644 index 51638f6a061..00000000000 --- a/Master/texmf-dist/tex/latex/environ/environ.cfg +++ /dev/null @@ -1,30 +0,0 @@ -%% -%% This is file `environ.cfg', -%% generated with the docstrip utility. -%% -%% The original source files were: -%% -%% environ.dtx (with options: `defaults') -%% -%% __________________________________ -%% Copyright (C) 2007 Will Robertson -%% -%% License information appended. -%% -%% -%% Copyright (C) 2007 by Will Robertson <wspr81@gmail.com> -%% -%% Distributable under the LaTeX Project Public License, -%% version 1.3c or higher (your choice). The latest version of -%% this license is at: http://www.latex-project.org/lppl.txt -%% -%% This work is "maintained" (as per LPPL maintenance status) -%% by Will Robertson. -%% -%% This work consists of the file environ.dtx -%% and the derived files environ.pdf, -%% environ.sty, and -%% environ.ins. -%% -%% -%% End of file `environ.cfg'. diff --git a/Master/texmf-dist/tex/latex/environ/environ.sty b/Master/texmf-dist/tex/latex/environ/environ.sty index 99469eb1f6b..6a576bf1a66 100644 --- a/Master/texmf-dist/tex/latex/environ/environ.sty +++ b/Master/texmf-dist/tex/latex/environ/environ.sty @@ -11,7 +11,19 @@ %% %% License information appended. %% -\ProvidesPackage{environ}[2007/09/23 v0.1 A new environment syntax] +\ProvidesPackage{environ}[2008/06/18 v0.2 A new way to define environments] +\def\environbodyname#1{\def\env@BODY{#1}} +\environbodyname\BODY +\def\environfinalcode#1{% + \def\env@finalcode{#1}} +\environfinalcode{\ignorespacesafterend} +\def\longdef@c#1{% + \expandafter\long\expandafter\def\csname#1\endcsname} +\catcode`\Q=3 +\long\def\trim@spaces#1{\romannumeral-`\q\trim@trim@\noexpand#1Q Q} +\long\def\trim@trim@#1 Q{\trim@trim@@#1Q} +\long\def\trim@trim@@#1Q#2{#1} +\catcode`\Q=11 \unless\ifdefined\collect@body \newtoks\@emptytoks \newtoks\@envbody @@ -21,7 +33,8 @@ \@envbody\@emptytoks \def\begin@stack{b}% \begingroup \expandafter\let\csname\@currenvir\endcsname\collect@@body - \edef\process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}% + \edef\process@envbody{% + \expandafter\noexpand\csname\@currenvir\endcsname}% \process@envbody } \def\push@begins#1\begin#2{% @@ -48,7 +61,8 @@ \@envbody\@emptytoks \def\begin@stack{b}% \begingroup \expandafter\let\csname\@currenvir\endcsname\Collect@@Body - \edef\process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}% + \edef\process@envbody{% + \expandafter\noexpand\csname\@currenvir\endcsname}% \process@envbody } \long\def\Push@Begins#1\begin#2{% @@ -68,6 +82,48 @@ \Addto@Envbody{#1\end{#2}}% \fi \process@envbody} +\def\NewEnviron{% + \let\env@newcommand\newcommand + \let\env@newenvironment\newenvironment + \env@NewEnviron} +\def\RenewEnviron{% + \let\env@newcommand\renewcommand + \let\env@newenvironment\renewenvironment + \env@NewEnviron} +\def\env@NewEnviron#1{% + \@ifnextchar[ + {\env@new@i{#1}} + {\env@new@iii{#1}{}}} +\def\env@new@i#1[#2]{% + \@ifnextchar[ + {\env@new@ii{#1}[#2]} + {\env@new@iii{#1}{[#2]}}} +\def\env@new@ii#1[#2][#3]{% + \env@new@iii{#1}{[#2][#3]}} +\long\def\env@new@iii#1#2#3{% + \@temptokena={\env@new{#1}{#2}{#3}}% + \@ifnextchar[{% + \the\@temptokena + }{% + \expandafter\the\expandafter + \@temptokena\expandafter[\env@finalcode]% + }} +\long\def\env@new#1#2#3[#4]{% + \env@newenvironment{#1}{% + \expandafter\Collect@Body\csname env@#1@parse\endcsname + }{#4} + \longdef@c{env@#1@parse}##1{% + \csname env@#1@save@env\endcsname##1\env@nil + \csname env@#1@process\endcsname##1\env@nil}% + \expandafter\env@newcommand + \csname env@#1@save@env\endcsname#2{\env@save}% + \expandafter\env@newcommand + \csname env@#1@process\endcsname#2{#3\env@ignore}} +\long\def\env@save#1\env@nil{% + \expandafter\edef\env@BODY{% + \unexpanded\expandafter + \expandafter\expandafter{\trim@spaces{#1}}}} +\long\def\env@ignore#1\env@nil{} \newcommand\NewEnvironment{% \let\env@newenvironment\newenvironment \let\env@newcommand\newcommand @@ -80,10 +136,10 @@ \expandafter\let\csname env@args@#1\endcsname\ignorespaces \env@newenvironment{#1}{% \expandafter\Collect@Body\csname env@@#1\endcsname}{\ignorespacesafterend}% - \expandafter\env@newcommand\csname env@@#1\endcsname[1]{% + \longdef@c{env@@#1}##1{% \csname env@@@#1\endcsname{% - \csname env@args@\@currenvir\endcsname##1\unskip}}% - \expandafter\env@newcommand\csname env@@@#1\endcsname[1]{#2}} + \csname env@args@#1\endcsname##1\unskip}}% + \longdef@c{env@@@#1}##1{#2}} \newcommand\EnvironArgs[1]{% \@ifnextchar[ {\Env@Args{#1}} |