|
Packit |
90a5c9 |
% atbeginend.sty
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
% contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
% this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
% The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
% (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
% the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
% distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
% See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
% limitations under the License.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
% defines
|
|
Packit |
90a5c9 |
% \BeforeBegin{environment}{code-to-execute}
|
|
Packit |
90a5c9 |
% \BeforeEnd {environment}{code-to-execute}
|
|
Packit |
90a5c9 |
% \AfterBegin {environment}{code-to-execute}
|
|
Packit |
90a5c9 |
% \AfterEnd {environment}{code-to-execute}
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% Save \begin and \end to \BeginEnvironment and \EndEnvironment
|
|
Packit |
90a5c9 |
\let\BeginEnvironment=\begin
|
|
Packit |
90a5c9 |
\let\EndEnvironment=\end
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
\def\IfUnDef#1{\expandafter\ifx\csname#1\endcsname\relax}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
% Null command needed to for \nothing{something}=.nothing.
|
|
Packit |
90a5c9 |
\def\NullCom#1{}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
\def\begin#1{%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% if defined \BeforeBeg for this environment, execute it
|
|
Packit |
90a5c9 |
\IfUnDef{BeforeBeg#1}\else\csname BeforeBeg#1\endcsname\fi%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
\IfUnDef{AfterBeg#1}% This is done to skip the command for environments
|
|
Packit |
90a5c9 |
% which can take arguments, like multicols; YOU MUST NOT
|
|
Packit |
90a5c9 |
% USE \AfterBegin{...}{...} for such environments!
|
|
Packit |
90a5c9 |
\let\SaveBegEng=\BeginEnvironment%
|
|
Packit |
90a5c9 |
\else%
|
|
Packit |
90a5c9 |
% Start this environment
|
|
Packit |
90a5c9 |
\BeginEnvironment{#1}%
|
|
Packit |
90a5c9 |
% and execute code after \begin{environment}
|
|
Packit |
90a5c9 |
\csname AfterBeg#1\endcsname%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
\let\SaveBegEng=\NullCom%
|
|
Packit |
90a5c9 |
\fi%
|
|
Packit |
90a5c9 |
\SaveBegEng{#1}%
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
\def\end#1{%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% execute code before \end{environment}
|
|
Packit |
90a5c9 |
\IfUnDef{BeforeEnd#1}\else\csname BeforeEnd#1\endcsname\fi%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% close this environment
|
|
Packit |
90a5c9 |
\EndEnvironment{#1}%
|
|
Packit |
90a5c9 |
%
|
|
Packit |
90a5c9 |
% and execute code after \begin{environment}
|
|
Packit |
90a5c9 |
\IfUnDef{AfterEnd#1}\else\csname AfterEnd#1\endcsname\fi%
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
%% Now, define commands
|
|
Packit |
90a5c9 |
% \BeforeBegin{environment}{code-to-execute}
|
|
Packit |
90a5c9 |
% \BeforeEnd {environment}{code-to-execute}
|
|
Packit |
90a5c9 |
% \AfterBegin {environment}{code-to-execute}
|
|
Packit |
90a5c9 |
% \AfterEnd {environment}{code-to-execute}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
\def\BeforeBegin#1#2{\expandafter\gdef\csname BeforeBeg#1\endcsname
|
|
Packit |
90a5c9 |
{#2}}
|
|
Packit |
90a5c9 |
\def\BeforeEnd #1#2{\expandafter\gdef\csname BeforeEnd#1\endcsname
|
|
Packit |
90a5c9 |
{#2}}
|
|
Packit |
90a5c9 |
\def\AfterBegin #1#2{\expandafter\gdef\csname AfterBeg#1\endcsname {#2}}
|
|
Packit |
90a5c9 |
\def\AfterEnd #1#2{\expandafter\gdef\csname AfterEnd#1\endcsname{#2}}
|