summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gmutils/gmenvir.sty
blob: 347198ceacf032ba804f17281c4398e455573125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
%% 
%% \iffalse ^^A we skip the debug setting
\IfFileExists{\string~/bin/gen_and_xela}{\errorcontextlines=1000 }{}
%% \fi
%% ^^A $Id: TheUltimateMaster.gmd,v 0.352 2011/10/12 15:19:42 natror Exp natror $
%% This is file “gmenvir.sty” generated with the DocStrip utility.
%% 
%%
%% The original source files were:
%%
%% gmutils/gmutils.gmd  (with options: `envir')
%%
%% 
%% Copyright ©  
%% by Grzegorz ‘Natror’ Murzynowski
%% natror (at) gmail (dot) com
%% 
%% This program is subject to the LaTeX Project Public License.
%% See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html
%% for the details of that license.
%%
%% LPPL status: "author-maintained".
%%
%% 
%% 
%% For documentation please refer to the file(s)
%% gmutils.{gmd,pdf}.
%% 
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gmenvir}
    [2011/10/12 v0.996 redefinition of \string \begin \space and \string \end  (GM)]


%%
%%
%%     ^^A\typeout{\unexpanded{#4}}%%

\RequirePackage{gmbase, gmampulex} % the low-level macros



\emptify\@envirstack

\def\@pushenvir{%
  %^^V\edef\@currenvir{\@currenvir}% is already expanded.
  \xdef\@envirstack{%
    {\@xa\detokenize\@xa{\@currenvir}}%
    {\the\currentgrouplevel}%
    {\@currenvline}%
    \@envirstack
  }%
}

\def\@popenvir #1#2#3{%
  \@XA{\@popenvir@ #1#2#3}\@envirstack\@nil
}

\def\@popenvir@ #1#2#3#4#5#6#7\@nil{%
  \gdef #1{#4}% |#1| carries last envir name
  \gdef #2{#5}% |#2| carries last envir level
  \gdef #3{#6}% |#3| carries last envir beginnig line
  \gdef\@envirstack{#7}% and we update the stack
}

\long\def\@begnamedgroup#1{%
  \edef\@prevgrouplevel{\the\currentgrouplevel}% added 2009/03/24 to
  % handle special pseudo-environments that don't increase
  % \incmd\currentgrouplevel (such as \inenv{document}). Note it's
  % |\edef|ed \emph{outside} the environment's group.
  \@ignorefalse% not to ignore blanks after group
  \begingroup\@endpefalse
  \edef\@prevenvir{\@currenvir}% Note we |\edef| it inside the group
  % (for obvious reason), unlike the ‘previous’ grouplevel.
  \edef\@currenvir{#1}% We could do recatcoding
  % through\inverb|\string| or \nlperc\cmd\detokenize\ but all the name
  % `other' and 10 could affect
  % a~thousand packages so we don't do that and we'll recatcode in
  % a~testing macro, see line \ref{@ifenvir}.
  \edef\@currenvline{\on@line}%
  \@pushenvir % we put current envir to |\@envirstack|.
  \csname #1\endcsname}% if the argument is a~command's name (an

\def\begin{\gmu@ifstar{\@begnamedgroup}{%
      \@begnamedgroup@ifcs}}

\def\@begnamedgroup@ifcs#1{%
  \ifcsname#1\endcsname\afterfi{\@begnamedgroup{#1}}%
  \else\afterfi{\@latex@error{Environment #1 undefined}\@eha}%
  \fi}%


\long\def\@fourthofmany#1#2#3#4#5\@nil{#4}%

\lpdef\@ifprevenvir#1{%\label{@ifenvir}\
  \gmu@ifedetokens
  {\@xa\@fourthofmany\@envirstack\relax\relax\relax\relax\@nil}%
  {#1}%
}


\def\@checkend#1{%
  \@ifenvir{#1}%
  {}%
  {\@badend{#1}}%
}

\ampulexdef\end[#1][#1]\endcsname\@checkend{%
\endcsname
\@xa\gmu@ifempty\@xa{\@envirstack}%
{%
  \PackageError {gmutils/base}%
  {There's no environment to pop!}{Oy vey, gefeelte fish!}%
}%
{\@popenvir\gmu@drain\gmu@drain\gmu@drain }%
\@checkend
}

\pdef\@endif#1{\@ifenvir{#1}{\end{#1}}{}}

\pdef\@endifprev#1{\@ifprevenvir{#1}{\end{#1}}{}}

\newcount\c@EnvirInterruption

\lpdef\gmu@InterruptEnvir
#1% the contents of interruption.
{%
  \global  \advance\c@EnvirInterruption\@ne
  \Name \@popenvir
  {gmu@InterruptCurrenv \the\c@EnvirInterruption}\gmu@drain\gmu@drain
  \endgroup
  #1%
  \begingroup
  \@XA {\let\@currenvir}%
  \csname gmu@InterruptCurrenv \the\c@EnvirInterruption \endcsname
  \@pushenvir
  \global  \advance\c@EnvirInterruption\m@ne
}


\endinput
%%
%% End of file `gmenvir.sty'.