atbeginend.sty revision 3fa58e00171aebf3b2cfa90035ed530f5b1f651d
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \BeforeBegin{environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \BeforeEnd {environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \AfterBegin {environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \AfterEnd {environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% Save \begin and \end to \BeginEnvironment and \EndEnvironment
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\let\BeginEnvironment=\begin
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\let\EndEnvironment=\end
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\IfUnDef#1{\expandafter\ifx\csname#1\endcsname\relax}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% Null command needed to for \nothing{something}=.nothing.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\NullCom#1{}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\begin#1{%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% if defined \BeforeBeg for this environment, execute it
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\IfUnDef{BeforeBeg#1}\else\csname BeforeBeg#1\endcsname\fi%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\IfUnDef{AfterBeg#1}% This is done to skip the command for environments
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive % which can take arguments, like multicols; YOU MUST NOT
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive % USE \AfterBegin{...}{...} for such environments!
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive \let\SaveBegEng=\BeginEnvironment%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive % Start this environment
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive \BeginEnvironment{#1}%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive % and execute code after \begin{environment}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive \csname AfterBeg#1\endcsname%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive \let\SaveBegEng=\NullCom%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\SaveBegEng{#1}%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\end#1{%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% execute code before \end{environment}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\IfUnDef{BeforeEnd#1}\else\csname BeforeEnd#1\endcsname\fi%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% close this environment
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\EndEnvironment{#1}%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% and execute code after \begin{environment}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\IfUnDef{AfterEnd#1}\else\csname AfterEnd#1\endcsname\fi%
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive%% Now, define commands
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \BeforeBegin{environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \BeforeEnd {environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \AfterBegin {environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive% \AfterEnd {environment}{code-to-execute}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\BeforeBegin#1#2{\expandafter\gdef\csname BeforeBeg#1\endcsname
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\BeforeEnd #1#2{\expandafter\gdef\csname BeforeEnd#1\endcsname
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\AfterBegin #1#2{\expandafter\gdef\csname AfterBeg#1\endcsname {#2}}
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive\def\AfterEnd #1#2{\expandafter\gdef\csname AfterEnd#1\endcsname{#2}}