\def \WhizzyEnvlimit #1#2{\expandafter \def \csname wiz@#1@#2\endcsname}
\newcount\whizzy@envno
\def \whizzy@envin{in}
\def \whizzy@envout{out}
\def \whizzy@envlimit@waux {\whizzy@aux {\string 
      \WhizzyEnvlimit {\@currenvir}{\the\whizzy@envno}{\the\inputlineno}}}
\def \whizzy@ignoreenv[3][]{}
\@ifundefined{whizzy@line}
{\def \WhizzyInsideEnvironment #1\whizzy@ignoreenv}
{\def \WhizzyInsideEnvironment #1{%
  \expandafter \let \expandafter \@aux \csname #1\endcsname
  \expandafter \let \csname out@#1\endcsname \@aux
  \expandafter \let \expandafter \@aux \csname end#1\endcsname
  \expandafter \let \csname endout@#1\endcsname \@aux
  \expandafter \def \csname #1\endcsname {%
    \advance \whizzy@envno by \@ne 
    \let \whizzy@envinout \whizzy@envout
    \expandafter \let \expandafter \@aux
       \csname wiz@#1@\the\whizzy@envno\endcsname
    \ifx \@aux \relax \else
      \ifnum \the\inputlineno<\whizzy@line
        \ifnum \whizzy@line<\@aux \let \whizzy@envinout \whizzy@envin
    \fi \fi \fi
    \csname \whizzy@envinout @#1\endcsname
  }%
  \expandafter \def \csname end#1\endcsname {\whizzy@envlimit@waux
    \csname end\whizzy@envinout @#1\endcsname 
  }%
  \newenvironment{in@#1}}}


