summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gmutils/gmampulex.sty
blob: 9ae544868e6137fac064c7dde9493d67626c834b (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
%% 
%% \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 “gmampulex.sty” generated with the DocStrip utility.
%% 
%%
%% The original source files were:
%%
%% gmutils/gmutils.gmd  (with options: `ampulex')
%%
%% 
%% 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{gmampulex}
    [2011/10/12 v0.996 Ampulex Compressa-like modifier of macros (GM)]


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

\RequirePackage{gmcommand}

\DeclareCommand\ampulexlet\long
{Q{\outer\long\global\protected}{} % (1)  (optional) prefix\:(es);
  % allowed is any sequence of them in any order, just like for the
  % original \TeX's \incmd\def.
  T{\def\edef\gdef\xdef\pdef}{\def} % (2) (optional) kind of definition; if
  % not specified, \incmd\def\ will be used.
  m % (3)  macro to be let to,
  m % (4) macro to provide the definition,
  O{} % (5) \cs{def}'s parameters string; empty by default,
  O{} % (6) definition body's parameters to be taken in a~one-step
  % expansion of the redefined macro; empty by default; the
  % undelimited parameters should be double-braced here.
  m % (7) start token(s),
  m % (8) end token(s)
  m % (9) the replacement of |#7|, |#8| and whatever between them.
}{%^^B
  % \changes{v0.93}{2008/08/29}{added}
  % \changes{v0.94}{2008/09/07}{made \pk{xparse}-ish and
  %   \cs{ampulexset} removed}
  % \chgs{2008/12/7 v0.98 first argument (the prefix) made of the
  %   \env{Q} type}
  % For the example of usage see \ref{ampulexset}. \HideDef
  %
  \long\def\gmu@ampulexlet@resa
  ##1#7% we put |#7| as a delimiter
  ##2#8% we put |#8| as a delimiter
  ##3\gmu@AmpulexDelimiter{%
    % We use a special (undefined) \CS  |\gmu@AmpulexDelimiter| as
    % the final delimiter because standard \LaTeX's |\@nil| isn't
    % probably a good idea since we
    % want to ampulex deep \LaTeX's macros and other |\gmu@›…|
    % macros too.
    \gmu@ifempty{##3}%
  }%
  % Now |\gmu@ampulexlet@resa| is redefined to produce an open |\gmu@ifempty|
  % depending on whether the start and end token(s) are found in the
  % meaning of \inverb|#4|.
  %
  % Before we proceed, we deal with a difficulty with a special case
  % when |#6| is “|#1|”, which occurs because of stripping braces of a
  % single-brace argument.
  \gmu@ifutokens{#6}{##1}%
  {\def\ampulex@Args{{%
          ####1}}%
  }%
  {\edef\ampulex@Args{\@nx\unexpanded{%
        \unexpanded{#6}}}}%
  \long  \def\gmu@ampulexlet@resc##1{%
    \@xa\@xa\@xa\@xa      \@xa\@xa\@xa\gmu@ampulexlet@resa
    \@xa\@xa\@xa#4%
    \ampulex@Args
    ##1% this parameter will be substituted with |#7#8| in
       % line~\ref{resc1} and with emptiness in line~\ref{resc2}.
    \gmu@AmpulexDelimiter
  }%
  %
  \gmu@ampulexlet@resc{#7#8}%\label{resc1}   % ^^V   \gmu@ampulexlet@resb
  % We've just applied the checker and it produces an open
  % |\gmu@ifempty{⁄<some tokens>}|
  %  if the delimiters are found in the meaning of |#4|
  % so, if \<some tokens> are none, we issue a warning
  {%
    \PackageWarning{gmampulex}{%
      \@nx#4 doesn't contain tokens
      \detokenize{#7} nor \detokenize{#8}. You better check if this is
      what you want to redefine.^^J%
      \@nx#4 is^^J%
      \meaning#4^^J%
    }}%
  % and we proceed if they are really some
  {%
  % We define a~temporary
  % macro with the parameters delimited with the `start' and `end' parameters
  % of \incs{ampulexdef}. It has to stand a double |\edef|.
  \edef\gmu@ampulexlet@resa{%
    \long\def\@nx\gmu@ampulexlet@resa
    ####1\unexpanded{#7}%
    ####2\unexpanded{#8}%
    ####3\@nx\gmu@AmpulexDelimiter{%
      \@nx\unexpanded{####1}%
      % we drop the part between the |#7| and |#8| delimiters
      % (including delimiters)
      \unexpanded{\unexpanded{#9}}% we replace the part of the
      % redefined macro's meaning with the replacement text.
      \@nx\unexpanded{####3}%
    }% of inner |\gmu@ampulexlet@resa|
  }% of outer |\gmu@ampulexlet@resa|
  \gmu@ampulexlet@resa
  % Now |\gmu@ampulexlet@resa| carries the modifier of |#4|'s
  % definition.
  %
  %
\unless\ifx\czat#4%
   \edef\gmu@ampulexlet@resb{% double definition for double hashes of expanded
     % |\unexpanded{#1›…}|
     #1#2%
     \@nx#3\unexpanded{#5}{%
       \gmu@ampulexlet@resc{}%\label{resc2}
 % Here we are sure the tokens sequences
 % |#7| and |#8| are in the one-level expansion of |#4| so we don't pass them
 % as sentinels (which \ac{BTW} would totally spoil the redefinition, what it
 % did indeed 2010/6/23).
     }% of |#3|'s definition body
   }% of inner |\gmu@ampulexlet@resb|
   \gmu@ampulexlet@resb
\else
    \gmu@ifxany#2{\gdef\xdef}{\global}{}%
    #1\edef#3#5{\gmu@ampulexlet@resc{}}%\label{resc2}
\fi
  }% of if the delimiters were found in the meaning.
}% of |\ampulexlet|

\DeclareCommand\ampulexdef\long{%
  % \chgs{2010/04/22 v0.994 rewritten not to use the arguments 7–9
  %   explicitly not to wrap them in a temporary macros, and to accept
  %   single hashes (instead of quadruple) in arguments 5 and 6. The
  %   temporary macros renamed
  %   to \cmd\gmu@reserveda and \cmd\gmu@reservedb. The body moved to
  %   \cmd\ampulexlet with adding another \CS argument to let let a
  %   macro not necessarily redefine it itself and this command made a
  %   particular case of that new one}
#1  Q{\outer\long\global\protected}{} % (1) as |\ampulexlet|
#2  T{\def\edef\gdef\xdef\pdef}{\def} % (2) ad |\ampulexlet|
#3  m % (3)  macro to be redefined,
#4  O{} % (4) as |\ampulexlet|'s |#5|, i.e., \cs{def}'s parameters string; empty by default,
#5  O{} % (5) as |\ampulexlet|'s |#6|, i.e., definition body's
 % parameters to be taken in a~one-step expansion of the redefined
 % macro; empty by default; the undelimited parameters should be
 % double-braced here (but not doubled).
#6  m % (6) start token(s),
#7  m % (7) end token(s),
#8  m % (8) the replacement
}{%
  \DCUse\ampulexlet{#1}{#2}{#3}{#3}{#4}{#5}{#6}{#7}{#8}%
}



\def\gmu@ENumLoop#1#2{% this is a~fully expandable loop generating |#2|${}-{}$|#1|
  % space tokens (cf. The  % \eTeX\ Manual p.~9).
  \ifnum#1<#2 %
    \gmu@tempa
    \@xa\gmu@ENumLoop
    \@xa{\number\numexpr#1+1\@xa}%
    \@xa{\number#2\@xa}%
  \fi}% of |\gmu@hashes|.

\long\def\defENumLoop
#1% the loop macro's name
#2% the replacement of |\gmu@tempa|
{%
  \ampulexlet#1\gmu@ENumLoop
  [##1##2][{##1}{##2}]%
  \gmu@tempa\@xa{#2\@xa}%
  %
  \ampulexdef#1%
  [##1##2][{##1}{##2}]%
  \gmu@ENumLoop\@xa{#1\@xa}%
}

\edef\GenericInfoToTerminal{%
  \unexpanded{%
    \@XA{\ampulexlet\protected\long\GenericInfo}\csname
    GenericInfo \endcsname[#1#2][{#1}{#2}]%
    \write\m@ne % we replace the token between these with:
    {\write\ifnum\tracingonline>\z@ \@unused\else\m@ne\fi}%
  }%
}

\ampulexdef\@starttoc[#1][#1]\makeatletter\@input{\makeatletter\NamedInput}


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