Received: by nummer-3.proteosys id <01C19442.D39D129C@nummer-3.proteosys>; Thu, 3 Jan 2002 11:38:48 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C19442.D39D129C" x-vm-v5-data: ([nil nil nil nil nil nil nil t nil][nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil]) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message Subject: environ.sty Date: Wed, 22 Aug 1990 10:39:12 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: From: To: "Rainer Schoepf" Reply-To: "LaTeX-L Mailing list" Status: R X-Status: X-Keywords: X-UID: 227 This is a multi-part message in MIME format. ------_=_NextPart_001_01C19442.D39D129C Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable % **************************************** % * ENVIRONMENTS * % **************************************** % % % \begin{foo} and \end{foo} are used to delimit environment foo. % \begin{foo} starts a group and calls \foo if it is defined, otherwise % it does nothing. \end{foo} checks to see that it matches the % corresponding \begin and if so, it calls \endfoo and does an % \endgroup. Otherwise, \end{foo} tries the following recovery: % % 1) if \end{foo} is unknown we assume that the user misspelled the % name and recover by replacing \end{foo} with \end{} % % 2) if \end{foo} is a legitime end command we check whether there % exists any unresolved \begin{foo}. % % a) if so, the currently open environment (\end{} is % closed. Afterwards \end{foo} is tried again. % This mechanism will close all open enviroments until the % correct one is found. % % b) if there is no open \begin{foo} we simply ignore the \end tag. % % % If \end{foo} needs to ignore blanks after it, then \endfoo should % globally set the @ignore switch true with \global\@ignoretrue. % % %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z %% Digits \0\1\2\3\4\5\6\7\8\9 %% Exclamation \! Double quote \" Hash (number) \# %% Dollar \$ Percent \% Ampersand \& %% Acute accent \' Left paren \( Right paren \) %% Asterisk \* Plus \+ Comma \, %% Minus \- Point \. Solidus \/ %% Colon \: Semicolon \; Less than \< %% Equals \=3D Greater than \> Question mark \? %% Commercial at \@ Left bracket \[ Backslash \\ %% Right bracket \] Circumflex \^ Underscore \_ %% Grave accent \` Left brace \{ Vertical bar \| %% Right brace \} Tilde \~} % First some stuff which is necessary if the macros are used as a % substitute for LaTeX's environments part in latex.tex. % \addto@hook\everyjob{\typeout{environ: new error recovery for % missplaced \string\end.}} \catcode`\_=3D11 \catcode`\0=3D11 \makeatletter % to allow using \input in test files \def\inner_begin#1{% \ifx#1\relax \@latexerr{Environment \expandafter\@gobble\string#1 undefined}\@eha \else \begingroup \@endpefalse \@aligningfalse % not in \halign by default \expandafter \xdef\csname l_\the\env_level\endcsname {\expandafter\@gobble\string#1,% \csname l_\the\env_level\endcsname}% \expandafter #1\fi % put \fi out of the way in case the env has = args. } % \begin is supposed to get all attributes and then calls \inner_begin % at the moment it only calls it. \def\begin#1{% \expandafter\inner_begin\csname #1\endcsname } \def\@gobblefour#1#2#3#4{} \newcount\env_level \def\l_0{GROUND} \def\separate_stack{% \global\advance\env_level\@ne \expandafter\gdef \csname l_\the\env_level\endcsname {}% } \def\combine_stack#1{% \count@\env_level \global\advance\env_level\m@ne \expandafter \xdef\csname l_\the\env_level\endcsname {\expandafter\@gobble\string#1,% \csname l_\the\count@\endcsname \expandafter\expandafter\expandafter \gobble_to_comma %remove old top entry from = begin \csname l_\the\env_level\endcsname}% % \expandafter\show\csname l_\the\env_level\endcsname } \def\gobble_to_comma#1,{} \def\end#1{\expandafter\inner_end \csname end#1\endcsname} \def\hidden_crcr{\crcr\noalign\bgroup \let\test_undefined\undefined} % hide \crcr in skipped conditional text. To make the next macro faster % we also put some other stuff into it. \def\inner_end#1{% % % The next lines place everything which is not expandable inside a % \noalign group if we are ending an \halign environment. Of course such % environments have to set the switch. % \if@aligning \hidden_crcr\fi \edef\@tempa{\expandafter\@gobblefour\string#1}% \expandafter\expandafter\expandafter \pop_stack\csname l_\the\env_level\endcsname\@nil % \typeout{\showmeaning\@tempa}% % \typeout{\showmeaning\cur_envir}% \ifx \@tempa\cur_envir \global\let\end_env_game\normal_game \else \expandafter \xdef\csname l_\the\env_level\endcsname {\cur_envir,\csname l_\the\env_level\endcsname}% \ifx#1\test_undefined \@latexerr{\string\begin{\cur_envir} ended by \string\end{\@tempa} which is undefined}% {Your command was replaced by \string\end{\cur_envir}.}% \gdef\end_env_game{\end\cur_envir\@gobble}\else \if_on_stack\@tempa {\err_warn{\string\begin{\cur_envir} ended by \ifx#1\dummy a right brace\else \string\end{\@tempa}\fi}% {An \string\end{\cur_envir} tag was added.}% \gdef\end_env_game{\end\cur_envir \inner_end}}% {\@latexerr{\string\begin{\cur_envir} ended by \string\end{\@tempa} which was never opened}% {The offending \string\end{\@tempa} tag was = ignored.}% \global\let\end_env_game\@gobble}% \fi \fi \if@aligning \egroup \fi \end_env_game#1} \let\test_undefined\relax % during if@aligning this has to be = *undefined* % At the moment only a warning % \def\err_warn#1#2{\typeout{Warning: #1!^^J\@spaces\@spaces\space#2}} \def\omitendtags{\let\err_warn\@gobbletwo} % Using \newif will alway define three control sequences even if we need % only two of them, so we better define them directly. This would save % a lot of macro names in \LaTeX{}, we can also omit the equal sign % in the definition of \..true: \let\if@aligning\iffalse \def\@aligningtrue{\let\if@aligning\iftrue} \def\@aligningfalse{\let\if@aligning\iffalse} % Another point worth considering is to define \newglobalif to omit the % \global\..true etc. in many places of \LaTeX{}. \long\def\normal_game#1{#1% \if@endpe\aftergroup\@doendpe\fi \endgroup \if@ignore \global\@ignorefalse \ignorespaces\fi} % Here the test macros for looking at the stack, the \in@ macro % is coming from the AMS-TeX implementation. We have to use \@tempb % \@tempa is already used above % \def\pop_stack#1,#2\@nil{\gdef\cur_envir{#1}% \expandafter \gdef\csname l_\the\env_level\endcsname{#2}} \def\if_on_stack#1#2#3{% \edef\@tempb{\noexpand\in@{#1,}{\l_0,}}% \@tempb \ifin@ #2\else #3\fi}% \def\in@#1#2{% \def\in@@##1#1##2##3\in@@{% \ifx\in@##2\in@false\else\in@true\fi}% \in@@#2#1\in@\in@@} \newif\ifin@ \def\showstack{\show\l_0} \catcode`\0=3D12 \def\newenvironment#1{\@ifnextchar [{\@newenv{#1}}{\@newenv{#1}[0]}} \long\def\@newenv#1[#2]#3#4{\expandafter\newcommand \csname #1\endcsname[#2]{\separate_stack#3% \expandafter\combine_stack\csname#1\endcsname}% \long\expandafter\def\csname end#1\endcsname{#4}} % this is a very simple test for checking the catcodes of a list of = characters % containing no braces maybe somebody can spend some thoughts on writing % a complete test using some sort of \futurelet mechanism. \def\showmeaning#1{\expandafter\show@meaning#1\@nil} \def\show@meaning#1{\ifx\@nil#1\else \string#1 (\ifnum\the\catcode\expandafter`\csname\string#1\endcsname<10 0\fi \the\catcode\expandafter`\csname\string#1\endcsname) \expandafter\show@meaning\fi} %%%%%%%%%%%%%%%%%%%% \def\@tabarray{\@aligningtrue\@ifnextchar[{\@array}{\@array[c]}} %the math envs have to be handled similar \def\eqnarray{\stepcounter{equation}\let\@currentlabel=3D\theequation \global\@eqnswtrue \@aligningtrue \global\@eqcnt\z@\tabskip\@centering\let\\=3D\@eqncr $$\halign to \displaywidth\bgroup\@eqnsel\hskip\@centering $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne \hskip 2\arraycolsep \hfil${##}$\hfil &\global\@eqcnt\tw@ \hskip 2\arraycolsep = $\displaystyle\tabskip\z@{##}$\hfil \tabskip\@centering&\llap{##}\tabskip\z@\cr} % We also have to restore if@aligning inside parboxes etc. \catcode`\_=3D8 \endinput ------_=_NextPart_001_01C19442.D39D129C Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable environ.sty

%          = ****************************************
%          = *            = ENVIRONMENTS          &= nbsp;   *
%          = ****************************************
%
%
%  \begin{foo} and \end{foo} are used to delimit = environment foo.
%  \begin{foo} starts a group and calls \foo if = it is defined, otherwise
%  it does nothing.  \end{foo} checks to = see that it matches the
%  corresponding \begin and if so, it calls = \endfoo and does an
%  \endgroup.  Otherwise, \end{foo} tries = the following recovery:
%
%  1) if \end{foo} is unknown we assume that the = user misspelled the
%     name and recover by = replacing \end{foo} with \end{<currenvir>}
%
%  2) if \end{foo} is a legitime end command we = check whether there
%     exists any unresolved = \begin{foo}.
%
%     a) if so, the currently = open environment (\end{<currenvir>} is
%        closed. = Afterwards \end{foo} is tried again.
%        This = mechanism will close all open enviroments until the
%        correct = one is found.
%
%     b) if there is no open = \begin{foo} we simply ignore the \end tag.
%
%
%  If \end{foo} needs to ignore blanks after it, = then \endfoo should
%  globally set the @ignore switch true with = \global\@ignoretrue.
%
%
%% \CharacterTable
%%  {Upper-case    = \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    = \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   = Digits        = \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   = \!     Double quote  = \"     Hash (number) \#
%%   = Dollar        = \$     Percent       = \%     Ampersand     = \&
%%   Acute accent  = \'     Left paren    = \(     Right paren   \)
%%   Asterisk      = \*     = Plus          = \+     = Comma         \,
%%   = Minus         = \-     = Point         = \.     Solidus       = \/
%%   = Colon         = \:     Semicolon     = \;     Less than     = \<
%%   = Equals        = \=3D     Greater than  = \>     Question mark \?
%%   Commercial at = \@     Left bracket  \[     = Backslash     \\
%%   Right bracket = \]     Circumflex    = \^     Underscore    \_
%%   Grave accent  = \`     Left brace    = \{     Vertical bar  \|
%%   Right brace   = \}     = Tilde         \~}


% First some stuff which is necessary if the macros = are used as a
% substitute for LaTeX's environments part in = latex.tex.

% \addto@hook\everyjob{\typeout{environ: new error = recovery for
%          &nb= sp;           &nbs= p;        missplaced = \string\end.}}

\catcode`\_=3D11
\catcode`\0=3D11
\makeatletter % to allow using \input in test = files


\def\inner_begin#1{%
  \ifx#1\relax
    \@latexerr{Environment = \expandafter\@gobble\string#1 undefined}\@eha
  \else
    \begingroup
     \@endpefalse
     \@aligningfalse  % not = in \halign by default
     \expandafter
     \xdef\csname = l_\the\env_level\endcsname
      = {\expandafter\@gobble\string#1,%
       \csname = l_\the\env_level\endcsname}%
     \expandafter = #1\fi   % put \fi out of the way in case the env has = args.
}


% \begin is supposed to get all attributes and then = calls \inner_begin
% at the moment it only calls it.

\def\begin#1{%
 \expandafter\inner_begin\csname = #1\endcsname
}

\def\@gobblefour#1#2#3#4{}


\newcount\env_level

\def\l_0{GROUND}

\def\separate_stack{%
   \global\advance\env_level\@ne
   \expandafter\gdef
     \csname = l_\the\env_level\endcsname
     {}%
}


\def\combine_stack#1{%
  \count@\env_level
  \global\advance\env_level\m@ne
  \expandafter
  \xdef\csname l_\the\env_level\endcsname
    = {\expandafter\@gobble\string#1,%
     \csname = l_\the\count@\endcsname
     = \expandafter\expandafter\expandafter
     = \gobble_to_comma         &nb= sp;           &nbs= p; %remove old top entry from begin
     \csname = l_\the\env_level\endcsname}%
%  \expandafter\show\csname = l_\the\env_level\endcsname
}

\def\gobble_to_comma#1,{}


\def\end#1{\expandafter\inner_end
           = \csname end#1\endcsname}


\def\hidden_crcr{\crcr\noalign\bgroup
          &nbs= p; \let\test_undefined\undefined}
% hide \crcr in skipped conditional text. To make the = next macro faster
% we also put some other stuff into it.

\def\inner_end#1{%
%
% The next lines place everything which is not = expandable inside a
% \noalign group if we are ending an \halign = environment. Of course such
% environments have to set the switch.
%
    \if@aligning = \hidden_crcr\fi
      = \edef\@tempa{\expandafter\@gobblefour\string#1}%
      = \expandafter\expandafter\expandafter
         = \pop_stack\csname l_\the\env_level\endcsname\@nil
%    = \typeout{\showmeaning\@tempa}%
%    = \typeout{\showmeaning\cur_envir}%
    \ifx  = \@tempa\cur_envir
      = \global\let\end_env_game\normal_game
    \else
      \expandafter
      \xdef\csname = l_\the\env_level\endcsname
        = {\cur_envir,\csname l_\the\env_level\endcsname}%
      = \ifx#1\test_undefined
         = \@latexerr{\string\begin{\cur_envir} ended by
          &nbs= p;          = \string\end{\@tempa} which is undefined}%
          &nbs= p;         {Your command was = replaced by
          &nbs= p;          = \string\end{\cur_envir}.}%
         = \gdef\end_env_game{\end\cur_envir\@gobble}\else
         = \if_on_stack\@tempa
          &nbs= p;  {\err_warn{\string\begin{\cur_envir} ended by
          &nbs= p;            = ; \ifx#1\dummy a right brace\else
          &nbs= p;            = ;   \string\end{\@tempa}\fi}%
          &nbs= p;         {An = \string\end{\cur_envir} tag was
          &nbs= p;          added.}%
          &nbs= p;   \gdef\end_env_game{\end\cur_envir
          &nbs= p;            = ;     \inner_end}}%
          &nbs= p;  {\@latexerr{\string\begin{\cur_envir} ended by
          &nbs= p;          = \string\end{\@tempa} which was never opened}%
          &nbs= p;         {The offending = \string\end{\@tempa} tag was ignored.}%
          &nbs= p;   \global\let\end_env_game\@gobble}%
       \fi
    \fi
    \if@aligning \egroup \fi
    \end_env_game#1}

\let\test_undefined\relax % during if@aligning this = has to be *undefined*



% At the moment only a warning
%
\def\err_warn#1#2{\typeout{Warning: = #1!^^J\@spaces\@spaces\space#2}}

\def\omitendtags{\let\err_warn\@gobbletwo}


% Using \newif will alway define three control = sequences even if we need
% only two of them, so we better define them = directly. This would save
% a lot of macro names in \LaTeX{}, we can also omit = the equal sign
% in the definition of \..true:

\let\if@aligning\iffalse = \def\@aligningtrue{\let\if@aligning\iftrue}
\def\@aligningfalse{\let\if@aligning\iffalse}

% Another point worth considering is to define = \newglobalif to omit the
% \global\..true etc. in many places of = \LaTeX{}.

\long\def\normal_game#1{#1%
      = \if@endpe\aftergroup\@doendpe\fi
    \endgroup
    \if@ignore = \global\@ignorefalse
          &nbs= p;           = \ignorespaces\fi}


% Here the test macros for looking at the stack, the = \in@ macro
% is coming from the AMS-TeX implementation. We have = to use \@tempb
% \@tempa is already used above
%

\def\pop_stack#1,#2\@nil{\gdef\cur_envir{#1}%
      \expandafter
      \gdef\csname = l_\the\env_level\endcsname{#2}}

\def\if_on_stack#1#2#3{%
  = \edef\@tempb{\noexpand\in@{#1,}{\l_0,}}%
  \@tempb \ifin@ #2\else #3\fi}%


\def\in@#1#2{%
  \def\in@@##1#1##2##3\in@@{%
    = \ifx\in@##2\in@false\else\in@true\fi}%
  \in@@#2#1\in@\in@@}

\newif\ifin@

\def\showstack{\show\l_0}

\catcode`\0=3D12


\def\newenvironment#1{\@ifnextchar
     = [{\@newenv{#1}}{\@newenv{#1}[0]}}

\long\def\@newenv#1[#2]#3#4{\expandafter\newcommand
     \csname = #1\endcsname[#2]{\separate_stack#3%
       = \expandafter\combine_stack\csname#1\endcsname}%
     \long\expandafter\def\csname = end#1\endcsname{#4}}

% this is a very simple test for checking the catcodes = of a list of characters
% containing no braces maybe somebody can spend some = thoughts on writing
% a complete test using  some sort of \futurelet = mechanism.

\def\showmeaning#1{\expandafter\show@meaning#1\@nil}
\def\show@meaning#1{\ifx\@nil#1\else
  \string#1
    = (\ifnum\the\catcode\expandafter`\csname\string#1\endcsname<10 = 0\fi
    = \the\catcode\expandafter`\csname\string#1\endcsname)
  \expandafter\show@meaning\fi}

%%%%%%%%%%%%%%%%%%%%



\def\@tabarray{\@aligningtrue\@ifnextchar[{\@array}{\@array[c]}}=

%the math envs have to be handled similar

\def\eqnarray{\stepcounter{equation}\let\@currentlabel=3D\theequ= ation
\global\@eqnswtrue
\@aligningtrue
\global\@eqcnt\z@\tabskip\@centering\let\\=3D\@eqncr
$$\halign to = \displaywidth\bgroup\@eqnsel\hskip\@centering
  = $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne
  \hskip 2\arraycolsep \hfil${##}$\hfil
  &\global\@eqcnt\tw@ \hskip 2\arraycolsep = $\displaystyle\tabskip\z@{##}$\hfil
   = \tabskip\@centering&\llap{##}\tabskip\z@\cr}

% We also have to restore if@aligning inside parboxes = etc.



\catcode`\_=3D8

\endinput

------_=_NextPart_001_01C19442.D39D129C--