source: docs/Working/re/etoolbox.sty @ 3664

Last change on this file since 3664 was 3624, checked in by cameron, 6 years ago

Formats for PACT

File size: 40.2 KB
Line 
1% $Id: etoolbox.sty,v 2.1 2011/01/03 19:14:10 lehman stable $
2
3% Copyright (c) 2007-2011 Philipp Lehman.
4%
5% Permission is granted to copy, distribute and/or modify this
6% software under the terms of the LaTeX Project Public License
7% (LPPL), version 1.3.
8%
9% The LPPL maintenance status of this software is
10% 'author-maintained'.
11%
12% This software is provided 'as is', without warranty of any kind,
13% either expressed or implied, including, but not limited to, the
14% implied warranties of merchantability and fitness for a
15% particular purpose.
16
17\def\etb@rcsid$#1: #2 #3 #4 #5${#4 v#3}
18
19\NeedsTeXFormat{LaTeX2e}
20\ProvidesPackage{etoolbox}
21[\etb@rcsid $Id: etoolbox.sty,v 2.1 2011/01/03 19:14:10 lehman stable $
22 e-TeX tools for LaTeX]
23
24\begingroup
25\@ifundefined{eTeXversion}
26  {\PackageError{etoolbox}
27     {Not running under e-TeX}
28     {This package requires e-TeX. Try compiling the document
29      with\MessageBreak 'elatex' instead of 'latex'. When using
30      pdfTeX, try 'pdfelatex'\MessageBreak instead of 'pdflatex'.
31      This is a fatal error. I'm aborting now.}%
32   \aftergroup\endinput}
33  {}
34\endgroup
35
36\RequirePackage{etex}
37
38\def\etb@catcodes{\do\&\do\|\do\:\do\-\do\=\do\<\do\>}
39\def\do#1{\catcode\number`#1=\the\catcode`#1\relax}
40\edef\etb@catcodes{\etb@catcodes}
41\let\do\noexpand
42\AtEndOfPackage{\etb@catcodes\undef\etb@catcodes}
43
44\catcode`\&=3
45\catcode`\|=3
46\@makeother\:
47\@makeother\-
48\@makeother\=
49\@makeother\<
50\@makeother\>
51
52\protected\def\etb@error{\PackageError{etoolbox}}
53\protected\def\etb@warning{\PackageWarning{etoolbox}}
54\protected\def\etb@info{\PackageInfo{etoolbox}}
55\newcount\etb@tempcnta
56
57% {<cstoken>}[<arguments>][<optarg default>]{<definition>}
58
59\newcommand*{\newrobustcmd}{}
60\protected\def\newrobustcmd{\@star@or@long\etb@new@command}
61
62\def\etb@new@command#1{\@testopt{\etb@newcommand#1}0}
63
64\def\etb@newcommand#1[#2]{%
65  \@ifnextchar[%]
66    {\etb@xargdef#1[#2]}
67    {\ifx\l@ngrel@x\relax
68       \let\l@ngrel@x\protected
69     \else
70       \protected\def\l@ngrel@x{\protected\long}%
71     \fi
72     \@argdef#1[#2]}}
73
74\long\def\etb@xargdef#1[#2][#3]#4{%
75  \@ifdefinable#1{%
76    \expandafter\protected
77    \expandafter\def
78    \expandafter#1%
79    \expandafter{%
80      \expandafter\@testopt
81      \csname\string#1\endcsname{#3}}%
82    \expandafter\@yargdef\csname\string#1\endcsname\tw@{#2}{#4}}}
83
84% {<cstoken>}[<arguments>][<optarg default>]{<definition>}
85
86\newrobustcmd*{\renewrobustcmd}{\@star@or@long\etb@renew@command}
87
88\def\etb@renew@command#1{%
89  \ifundef{#1}
90     {\etb@error{\string#1 undefined}\@ehc}
91     {}%
92  \let\@ifdefinable\@rc@ifdefinable
93  \etb@new@command#1}
94
95% {<cstoken>}[<arguments>][<optarg default>]{<definition>}
96
97\newrobustcmd*{\providerobustcmd}{\@star@or@long\etb@provide@command}
98
99\def\etb@provide@command#1{%
100  \ifundef{#1}
101    {\def\reserved@a{\etb@new@command#1}}
102    {\def\reserved@a{\etb@renew@command\reserved@a}}%
103  \reserved@a}
104
105% {<csname>}
106
107\newrobustcmd*{\csshow}[1]{%
108  \begingroup\expandafter\endgroup
109  \expandafter\show\csname#1\endcsname}
110
111% {<cstoken>}{<true>}{<false>}
112
113\newcommand{\ifdef}[1]{%
114  \ifdefined#1%
115    \expandafter\@firstoftwo
116  \else
117    \expandafter\@secondoftwo
118  \fi}
119
120% {<cstoken>}{<true>}{<false>}
121
122\newcommand{\ifundef}[1]{%
123  \ifdefined#1%
124    \ifx#1\relax
125      \expandafter\expandafter
126      \expandafter\@firstoftwo
127    \else
128      \expandafter\expandafter
129      \expandafter\@secondoftwo
130    \fi
131  \else
132    \expandafter\@firstoftwo
133  \fi}
134
135% {<csname>}{<true>}{<false>}
136
137\newcommand*{\ifcsdef}[1]{%
138  \ifcsname#1\endcsname
139    \expandafter\@firstoftwo
140  \else
141    \expandafter\@secondoftwo
142  \fi}
143
144% {<csname>}{<true>}{<false>}
145
146\newcommand*{\ifcsundef}[1]{%
147  \ifcsname#1\endcsname
148    \expandafter\ifx\csname#1\endcsname\relax
149      \expandafter\expandafter
150      \expandafter\@firstoftwo
151    \else
152      \expandafter\expandafter
153      \expandafter\@secondoftwo
154    \fi
155  \else
156    \expandafter\@firstoftwo
157  \fi}
158
159% {<cstoken>}{<true}{<false>}
160
161\newcommand{\ifdefmacro}{}
162\long\edef\ifdefmacro#1{%
163  \noexpand\expandafter\noexpand\etb@ifdefmacro
164  \noexpand\meaning#1\detokenize{macro}:&}
165\edef\etb@ifdefmacro{%
166  \def\noexpand\etb@ifdefmacro##1\detokenize{macro}:##2&}
167\etb@ifdefmacro{\notblank{#2}}
168
169% {<csname>}{<true>}{<false>}
170
171\newcommand*{\ifcsmacro}[1]{%
172  \ifcsdef{#1}
173    {\expandafter\ifdefmacro\csname#1\endcsname}
174    {\@secondoftwo}}
175
176% {<cstoken>}{<true}{<false>}
177
178\newcommand{\ifdefprefix}[1]{%
179  \ifdefmacro{#1}
180    {\etb@ifdefprefix{#1}}
181    {\@secondoftwo}}
182\long\edef\etb@ifdefprefix#1{%
183  \noexpand\expandafter\noexpand\etb@ifdefprefix@i
184  \noexpand\meaning#1\detokenize{macro}:&}
185\edef\etb@ifdefprefix@i{%
186  \def\noexpand\etb@ifdefprefix@i##1\detokenize{macro}:##2&}
187\etb@ifdefprefix@i{\notblank{#1}}
188
189% {<csname>}{<true>}{<false>}
190
191\newcommand*{\ifcsprefix}[1]{%
192  \ifcsdef{#1}
193    {\expandafter\ifdefprefix\csname#1\endcsname}
194    {\@secondoftwo}}
195
196% {<cstoken>}{<true}{<false>}
197
198\newcommand{\ifdefparam}{}
199\long\edef\ifdefparam#1{%
200  \noexpand\expandafter\noexpand\etb@ifdefparam
201  \noexpand\meaning#1\detokenize{macro}:->&}
202\edef\etb@ifdefparam{%
203  \def\noexpand\etb@ifdefparam##1\detokenize{macro}:##2->##3&}
204\etb@ifdefparam{\notblank{#2}}
205
206% {<csname>}{<true>}{<false>}
207
208\newcommand*{\ifcsparam}[1]{%
209  \ifcsdef{#1}
210    {\expandafter\ifdefparam\csname#1\endcsname}
211    {\@secondoftwo}}
212
213% {<cstoken>}{<true}{<false>}
214
215\newcommand{\ifdefprotected}{}
216\long\edef\ifdefprotected#1{%
217  \noexpand\expandafter\noexpand\etb@ifdefprotected
218  \noexpand\meaning#1\string\protected&}
219\edef\etb@ifdefprotected{%
220  \def\noexpand\etb@ifdefprotected##1\string\protected##2&}
221\etb@ifdefprotected{\notblank{#2}}
222
223% {<csname>}{<true>}{<false>}
224
225\newcommand*{\ifcsprotected}[1]{%
226  \ifcsdef{#1}
227    {\expandafter\ifdefprotected\csname#1\endcsname}
228    {\@secondoftwo}}
229
230% {<cstoken>}{<true}{<false>}
231
232\newrobustcmd{\ifdefltxprotect}[1]{%
233  \begingroup
234  \edef\etb@resrvda{%
235    \noexpand\protect\expandafter\noexpand
236    \csname\expandafter\@gobble\string#1 \endcsname}%
237  \expandafter\endgroup\ifx#1\etb@resrvda
238    \expandafter\@firstoftwo
239  \else
240    \expandafter\@secondoftwo
241  \fi}
242
243% {<csname>}{<true>}{<false>}
244
245\newrobustcmd*{\ifcsltxprotect}[1]{%
246  \ifcsdef{#1}
247    {\expandafter\ifdefltxprotect\csname#1\endcsname}
248    {\@secondoftwo}}
249
250% {<cstoken>}{<true>}{<false>}
251
252\newcommand{\ifdefempty}[1]{%
253  \ifundef{#1}
254    {\@secondoftwo}
255    {\ifdefmacro{#1}
256       {\ifdefparam{#1}
257          {\@secondoftwo}
258          {\etb@ifdefempty{#1}}}
259       {\@secondoftwo}}}
260
261\def\etb@ifdefempty#1{%
262  \expandafter\expandafter
263  \expandafter\ifblank
264  \expandafter\expandafter
265  \expandafter{%
266  \expandafter\strip@prefix\meaning#1}}
267
268% {<csname>}{<true>}{<false>}
269
270\newcommand*{\ifcsempty}[1]{%
271  \ifcsundef{#1}
272    {\@secondoftwo}
273    {\expandafter\ifdefparam\csname#1\endcsname
274       {\@secondoftwo}
275       {\expandafter\etb@ifdefempty\csname#1\endcsname}}}
276
277% {<cstoken>}{<true>}{<false>}
278
279\newcommand{\ifdefvoid}[1]{%
280  \ifundef{#1}
281    {\@firstoftwo}
282    {\ifdefmacro{#1}
283       {\ifdefparam{#1}
284          {\@secondoftwo}
285          {\etb@ifdefempty{#1}}}
286       {\@secondoftwo}}}
287
288% {<csname>}{<true>}{<false>}
289
290\newcommand*{\ifcsvoid}[1]{%
291  \ifcsundef{#1}
292    {\@firstoftwo}
293    {\expandafter\ifdefparam\csname#1\endcsname
294       {\@secondoftwo}
295       {\expandafter\etb@ifdefempty\csname#1\endcsname}}}
296
297% {<cstoken1>}{<cstoken2>}{<true>}{<false>}
298
299\newcommand{\ifdefequal}[2]{%
300  \ifundef{#1}
301    {\@secondoftwo}
302    {\ifundef{#2}
303       {\@secondoftwo}
304       {\ifx#1#2%
305          \expandafter\@firstoftwo
306        \else
307          \expandafter\@secondoftwo
308        \fi}}}
309
310% {<csname1>}{<csname2>}{<true>}{<false>}
311
312\newcommand*{\ifcsequal}[2]{%
313  \ifcsundef{#1}
314    {\@secondoftwo}
315    {\ifcsundef{#2}
316       {\@secondoftwo}
317       {\expandafter\ifx
318        \csname#1\expandafter\endcsname
319        \csname#2\endcsname
320          \expandafter\@firstoftwo
321        \else
322          \expandafter\@secondoftwo
323        \fi}}}
324
325% {<cstoken1>}{<cstoken2>}{<true>}{<false>}
326
327\newrobustcmd{\ifdefstrequal}[2]{%
328  \ifdefmacro{#1}
329    {\ifdefmacro{#2}
330       {\begingroup
331        \edef\etb@tempa{\expandafter\strip@prefix\meaning#1}%
332        \edef\etb@tempb{\expandafter\strip@prefix\meaning#2}%
333        \ifx\etb@tempa\etb@tempb
334          \aftergroup\@firstoftwo
335        \else
336          \aftergroup\@secondoftwo
337        \fi
338        \endgroup}
339       {\@secondoftwo}}
340    {\@secondoftwo}}
341
342% {<csname1>}{<csname2>}{<true>}{<false>}
343
344\newcommand*{\ifcsstrequal}[2]{%
345  \ifcsundef{#1}
346    {\@secondoftwo}
347    {\ifcsundef{#2}
348       {\@secondoftwo}
349       {\expandafter\ifdefstrequal
350        \csname#1\expandafter\endcsname
351        \csname#2\endcsname}}}
352
353% {<cstoken>}{<string>}{<true>}{<false>}
354
355\newrobustcmd{\ifdefstring}[2]{%
356  \ifdefmacro{#1}
357    {\begingroup
358     \edef\etb@tempa{\expandafter\strip@prefix\meaning#1}%
359     \edef\etb@tempb{\detokenize{#2}}%
360     \ifx\etb@tempa\etb@tempb
361       \aftergroup\@firstoftwo
362     \else
363       \aftergroup\@secondoftwo
364     \fi
365     \endgroup}
366    {\@secondoftwo}}
367
368% {<csname>}{<string>}{<true>}{<false>}
369
370\newrobustcmd{\ifcsstring}[2]{%
371  \ifcsundef{#1}
372    {\@secondoftwo}
373    {\expandafter\ifdefstring\csname#1\endcsname{#2}}}
374
375% {<cstoken>}{<true}{<false>}
376
377\newcommand{\ifdefcounter}[1]{\etb@ifcounter#1&}
378\long\def\etb@ifcounter#1#2&{%
379  \ifx\count#1%
380    \expandafter\@secondoftwo
381  \else
382    \expandafter\etb@ifcounter@i\meaning#1:%
383  \fi}
384\edef\etb@ifcounter@i#1:#2\fi{\noexpand\fi
385  \noexpand\etb@ifcounter@ii#1\string\count&}
386\edef\etb@ifcounter@ii{%
387  \def\noexpand\etb@ifcounter@ii##1\string\count##2&}
388\etb@ifcounter@ii{\ifblank{#1}}
389
390% {<csname>}{<true>}{<false>}
391
392\newcommand*{\ifcscounter}[1]{%
393  \ifcsdef{#1}
394    {\expandafter\ifdefcounter\csname#1\endcsname}
395    {\@secondoftwo}}
396
397% {<name>}{<true>}{<false>}
398
399\newcommand*{\ifltxcounter}[1]{%
400  \ifcsdef{c@#1}
401    {\expandafter\ifdefcounter\csname c@#1\endcsname}
402    {\@secondoftwo}}
403
404% {<cstoken>}{<true}{<false>}
405
406\newcommand{\ifdeflength}[1]{\etb@iflength#1&}
407\long\def\etb@iflength#1#2&{%
408  \ifx\skip#1%
409    \expandafter\@secondoftwo
410  \else
411    \expandafter\etb@iflength@i\meaning#1:%
412  \fi}
413\edef\etb@iflength@i#1:#2\fi{\noexpand\fi
414  \noexpand\etb@iflength@ii#1\string\skip&}
415\edef\etb@iflength@ii{%
416  \def\noexpand\etb@iflength@ii##1\string\skip##2&}
417\etb@iflength@ii{\ifblank{#1}}
418
419% {<csname>}{<true>}{<false>}
420
421\newcommand*{\ifcslength}[1]{%
422  \ifcsdef{#1}
423    {\expandafter\ifdeflength\csname#1\endcsname}
424    {\@secondoftwo}}
425
426% {<cstoken>}{<true}{<false>}
427
428\newcommand{\ifdefdimen}[1]{\etb@ifdimen#1&}
429\long\def\etb@ifdimen#1#2&{%
430  \ifx\dimen#1%
431    \expandafter\@secondoftwo
432  \else
433    \expandafter\etb@ifdimen@i\meaning#1:%
434  \fi}
435\edef\etb@ifdimen@i#1:#2\fi{\noexpand\fi
436  \noexpand\etb@ifdimen@ii#1\string\dimen&}
437\edef\etb@ifdimen@ii{%
438  \def\noexpand\etb@ifdimen@ii##1\string\dimen##2&}
439\etb@ifdimen@ii{\ifblank{#1}}
440
441% {<csname>}{<true>}{<false>}
442
443\newcommand*{\ifcsdimen}[1]{%
444  \ifcsdef{#1}
445    {\expandafter\ifdefdimen\csname#1\endcsname}
446    {\@secondoftwo}}
447
448% {<string1>}{<string2>}{<true>}{<false>}
449
450\newrobustcmd{\ifstrequal}[2]{%
451  \begingroup
452  \edef\etb@tempa{\detokenize{#1}}%
453  \edef\etb@tempb{\detokenize{#2}}%
454  \ifx\etb@tempa\etb@tempb
455    \aftergroup\@firstoftwo
456  \else
457    \aftergroup\@secondoftwo
458  \fi
459  \endgroup}
460
461% {<string>}{<true>}{<false>}
462
463\newcommand{\ifstrempty}[1]{%
464  \expandafter\ifx\expandafter&\detokenize{#1}&%
465    \expandafter\@firstoftwo
466  \else
467    \expandafter\@secondoftwo
468  \fi}
469
470% {<string>}{<true>}{<false>}
471
472\newcommand{\ifblank}[1]{% from url.sty
473  \etb@ifblank@i#1&&\@secondoftwo\@firstoftwo:}
474\long\def\etb@ifblank@i#1#2&#3#4#5:{#4}
475
476\newcommand{\notblank}[1]{%
477  \etb@ifblank@i#1&&\@firstoftwo\@secondoftwo:}
478
479% {<numexpr>}{<comp>}{<numexpr>}{<true>}{<false>}
480
481\newcommand*{\ifnumcomp}[3]{%
482  \ifnum\numexpr#1\relax#2\numexpr#3\relax
483    \expandafter\@firstoftwo
484  \else
485    \expandafter\@secondoftwo
486  \fi}
487
488% {<numexpr>}{<numexpr>}{<true>}{<false>}
489
490\newcommand*{\ifnumequal}[1]{%
491  \ifnumcomp{#1}=}
492
493\newcommand*{\ifnumgreater}[1]{%
494  \ifnumcomp{#1}>}
495
496\newcommand*{\ifnumless}[1]{%
497  \ifnumcomp{#1}<}
498
499% {<numexpr>}{<true>}{<false>}
500
501\newcommand*{\ifnumodd}[1]{%
502  \ifodd\numexpr#1\relax
503    \expandafter\@firstoftwo
504  \else
505    \expandafter\@secondoftwo
506  \fi}
507
508% {<dimexpr>}{<comp>}{<dimexpr>}{<true>}{<false>}
509
510\newcommand*{\ifdimcomp}[3]{%
511  \ifdim\dimexpr#1\relax#2\dimexpr#3\relax
512    \expandafter\@firstoftwo
513  \else
514    \expandafter\@secondoftwo
515  \fi}
516
517% {<dimexpr>}{<dimexpr>}{<true>}{<false>}
518
519\newcommand*{\ifdimequal}[1]{%
520  \ifdimcomp{#1}=}
521
522\newcommand*{\ifdimgreater}[1]{%
523  \ifdimcomp{#1}>}
524
525\newcommand*{\ifdimless}[1]{%
526  \ifdimcomp{#1}<}
527
528% {<expr>}{<true>}{<false>}
529
530\newcommand{\ifboolexpe}[1]{%
531  \etb@be@beg\etb@be@bgroup#1(&\etb@be@end}
532
533\let\etb@be@true\@empty
534\def\etb@be@false{-\@ne}
535
536\def\etb@be@beg{%
537  \ifnum\numexpr\z@\ifnum\numexpr\z@}
538
539\def\etb@be@end{%
540  <\z@
541    \expandafter\etb@be@false
542  \fi
543  <\z@
544    \expandafter\@secondoftwo
545  \else
546    \expandafter\@firstoftwo
547  \fi}
548
549\long\def\etb@be@bgroup#1(#2&{%
550  \etb@be@egroup#1)&%
551  \ifblank{#2}
552    {}
553    {\etb@be@beg
554     \etb@be@bgroup#2&}}
555
556\long\def\etb@be@egroup#1)#2&{%
557  \etb@be@and#1and&%
558  \ifblank{#2}
559    {}
560    {\etb@be@end\etb@be@true\etb@be@false
561     \etb@be@egroup#2&}}
562
563\long\def\etb@be@and#1and#2&{%
564  \etb@be@or#1or&%
565  \ifblank{#2}
566    {}
567    {<\z@
568       \expandafter\@firstofone
569     \else
570       \expandafter\@gobble
571     \fi
572     {=\z@\fi\ifnum\numexpr\m@ne}%
573     \ifnum\numexpr\z@
574     \etb@be@and#2&}}
575
576\long\def\etb@be@or#1or#2&{%
577  \etb@be@not#1not&%
578  \ifblank{#2}
579    {}
580    {<\z@
581       \expandafter\@secondoftwo
582     \else
583       \expandafter\@firstoftwo
584     \fi
585     {=\z@\fi\ifnum\numexpr\z@
586      \ifnum\numexpr\@ne}
587     {=\z@\fi\ifnum\numexpr\z@
588      \ifnum\numexpr\z@}%
589     \etb@be@or#2&}}
590
591\long\def\etb@be@not#1not#2&{%
592  \etb@be@togl#1togl&%
593  \ifblank{#2}
594    {}
595    {>\z@
596       \expandafter\@firstoftwo
597     \else
598       \expandafter\@secondoftwo
599     \fi
600     {\unless\ifnum\numexpr\m@ne}
601     {\unless\ifnum\numexpr\z@}%
602     \etb@be@not#2&}}
603
604\long\def\etb@be@togl#1togl#2&{%
605  \etb@be@bool#1bool&%
606  \ifblank{#2}
607    {}
608    {\etb@be@togl@i#2&}}
609
610\long\def\etb@be@togl@i#1#2&{%
611  \ifcsdef{etb@tgl@#1}
612    {\csname etb@tgl@#1\endcsname\etb@be@true\etb@be@false}
613    {\etb@be@err{Toggle '#1' undefined}{}}%
614  \etb@be@togl#2&}
615
616\long\def\etb@be@bool#1bool#2&{%
617  \etb@be@test#1test&%
618  \ifblank{#2}
619    {}
620    {\etb@be@bool@i#2&}}
621
622\long\def\etb@be@bool@i#1#2&{%
623  \ifcsundef{if#1}
624    {\etb@be@err{Boolean '#1' undefined}{}}
625    {\csname if#1\endcsname
626     \else
627       \etb@be@false
628     \fi}%
629  \etb@be@bool#2&}
630
631\long\def\etb@be@test#1test#2&{%
632  \ifblank{#1}
633    {}
634    {\etb@be@err{The invalid part is: '\detokenize{#1}'}{}}%
635  \ifblank{#2}
636    {}
637    {\etb@be@test@i#2&}}
638
639\long\def\etb@be@test@i#1#2&{%
640  #1\etb@be@true\etb@be@false
641  \etb@be@test#2&}
642
643\long\def\etb@be@err#1#2{%
644  \expandafter\ifnum\the\numexpr
645    \expandafter\ifnum\the\currentiftype=-3
646      \expandafter\thr@@
647    \else
648      \expandafter\currentiftype
649    \fi
650  =\thr@@
651    \expandafter\@firstoftwo
652  \else
653    \expandafter\@secondoftwo
654  \fi
655  {=\z@\fi
656   \etb@be@err{#1}{#2\ifnum\numexpr\m@ne}}
657  {\etb@err@expr{#1}#2}}
658
659% {<expr>}{<true>}{<false>}
660
661\newrobustcmd{\ifboolexpr}[1]{\etb@boolexpr{#1}}
662
663\long\def\etb@boolexpr#1{%
664  \begingroup
665  \let\etb@br@neg\@firstoftwo
666  \etb@tempcnta\z@
667  \etb@br@beg
668  \etb@br@bgroup#1(&%
669  \etb@br@end
670  \etb@br@eval}
671
672\def\etb@br@beg{%
673  \begingroup
674  \let\etb@br@neg\@firstoftwo
675  \etb@tempcnta\z@}
676
677\def\etb@br@end{%
678  \etb@br@eval\etb@br@true\etb@br@false}
679
680\def\etb@br@eval{%
681  \ifnum\etb@tempcnta<\z@
682    \aftergroup\@secondoftwo
683  \else
684    \aftergroup\@firstoftwo
685  \fi
686  \endgroup}
687
688\def\etb@br@true{%
689  \advance\etb@tempcnta\etb@br@neg\z@\m@ne
690  \let\etb@br@neg\@firstoftwo}
691
692\def\etb@br@false{%
693  \advance\etb@tempcnta\etb@br@neg\m@ne\z@
694  \let\etb@br@neg\@firstoftwo}
695
696\long\def\etb@br@bgroup#1(#2&{%
697  \etb@br@egroup#1)&%
698  \ifblank{#2}
699    {}
700    {\etb@br@beg
701     \etb@br@bgroup#2&}}
702
703\long\def\etb@br@egroup#1)#2&{%
704  \etb@br@and#1and&%
705  \ifblank{#2}
706    {}
707    {\etb@br@end
708     \etb@br@egroup#2&}}
709
710\long\def\etb@br@and#1and#2&{%
711  \etb@br@or#1or&%
712  \ifblank{#2}
713    {}
714    {\ifnum\etb@tempcnta<\z@
715       \etb@tempcnta\m@ne
716     \else
717       \etb@tempcnta\z@
718     \fi
719     \etb@br@and#2&}}
720
721\long\def\etb@br@or#1or#2&{%
722  \etb@br@not#1not&%
723  \ifblank{#2}
724    {}
725    {\ifnum\etb@tempcnta<\z@
726       \etb@tempcnta\z@
727     \else
728       \etb@tempcnta\@ne
729     \fi
730     \etb@br@or#2&}}
731
732\long\def\etb@br@not#1not#2&{%
733  \etb@br@togl#1togl&%
734  \ifblank{#2}
735    {}
736    {\let\etb@br@neg\@secondoftwo
737     \etb@br@not#2&}}
738
739\long\def\etb@br@togl#1togl#2&{%
740  \etb@br@bool#1bool&%
741  \ifblank{#2}
742    {}
743    {\etb@br@togl@i#2&}}
744
745\long\def\etb@br@togl@i#1#2&{%
746  \ifcsdef{etb@tgl@#1}
747    {\csname etb@tgl@#1\endcsname\etb@br@true\etb@br@false}
748    {\etb@err@expr{Toggle '#1' undefined}\etb@br@false}%
749  \etb@br@togl#2&}
750
751\long\def\etb@br@bool#1bool#2&{%
752  \etb@br@test#1test&%
753  \ifblank{#2}
754    {}
755    {\etb@br@bool@i#2&}}
756
757\long\def\etb@br@bool@i#1#2&{%
758  \ifcsundef{if#1}
759    {\etb@err@expr{Boolean '#1' undefined}\etb@br@false}
760    {\csname if#1\endcsname
761       \etb@br@true
762     \else
763       \etb@br@false
764     \fi}%
765  \etb@br@bool#2&}
766
767\long\def\etb@br@test#1test#2&{%
768  \ifblank{#1}
769    {}
770    {\etb@err@expr{The invalid part is: '\detokenize{#1}'}}%
771  \ifblank{#2}
772    {}
773    {\etb@br@test@i#2&}}
774
775\long\def\etb@br@test@i#1#2&{%
776  \ignorespaces#1\etb@br@true\etb@br@false
777  \etb@br@test#2&}
778
779\long\def\etb@err@expr#1{%
780  \etb@error
781    {Invalid boolean expression}
782    {#1.}}
783
784% {<expr>}{<code>}
785
786\newrobustcmd{\whileboolexpr}[2]{%
787  \etb@boolexpr{#1}{#2\whileboolexpr{#1}{#2}}{}}
788
789% {<expr>}{<code>}
790
791\newrobustcmd{\unlessboolexpr}[2]{%
792  \etb@boolexpr{#1}{}{#2\unlessboolexpr{#1}{#2}}}
793
794% {<cstoken>}
795
796\newcommand{\expandonce}[1]{%
797  \unexpanded\expandafter{#1}}
798
799% {<csname>}
800
801\newcommand*{\csexpandonce}[1]{%
802  \expandafter\expandonce\csname#1\endcsname}
803
804% {<code>}
805
806\newcommand*{\protecting}{}
807\def\protecting#{%
808  \ifx\protect\@typeset@protect
809    \etb@protecting\@firstofone
810  \fi
811  \ifx\protect\@unexpandable@protect
812    \etb@protecting\etb@unexpandable
813  \fi
814  \ifx\protect\noexpand
815    \etb@protecting\unexpanded
816  \fi
817  \ifx\protect\string
818    \etb@protecting\detokenize
819  \fi
820  \relax\@firstofone}
821
822\def\etb@protecting#1#2\relax\@firstofone{\fi#1}
823\long\def\etb@unexpandable#1{\unexpanded{\protecting{#1}}}
824
825% {<csname>}
826
827\newrobustcmd*{\csdef}[1]{\expandafter\def\csname#1\endcsname}
828\newrobustcmd*{\csedef}[1]{\expandafter\edef\csname#1\endcsname}
829\newrobustcmd*{\csgdef}[1]{\expandafter\gdef\csname#1\endcsname}
830\newrobustcmd*{\csxdef}[1]{\expandafter\xdef\csname#1\endcsname}
831\newrobustcmd*{\protected@csedef}{\etb@protected\csedef}
832\newrobustcmd*{\protected@csxdef}{\etb@protected\csxdef}
833
834\def\etb@protected{%
835  \let\@@protect\protect
836  \let\protect\@unexpandable@protect
837  \afterassignment\restore@protect}
838
839% {<csname>}{<cstoken>}
840
841\newrobustcmd{\cslet}[2]{%
842  \expandafter\let\csname#1\endcsname#2}
843
844% {<cstoken>}{<csname>}
845
846\newrobustcmd{\letcs}[2]{%
847  \ifcsdef{#2}
848    {\expandafter\let\expandafter#1\csname#2\endcsname}
849    {\undef#1}}
850
851% {<csname>}{<csname>}
852
853\newrobustcmd*{\csletcs}[2]{%
854  \ifcsdef{#2}
855    {\expandafter\let
856     \csname#1\expandafter\endcsname
857     \csname#2\endcsname}
858    {\csundef{#1}}}
859
860% {<csname>}
861
862\newcommand*{\csuse}[1]{%
863  \ifcsname#1\endcsname
864    \csname#1\expandafter\endcsname
865  \fi}
866
867% {<cstoken>}
868
869\newrobustcmd{\undef}[1]{\let#1\etb@undefined}
870
871% {<csname>}
872
873\newrobustcmd*{\csundef}[1]{\cslet{#1}\etb@undefined}
874
875% {<cstoken>}{<code>}
876
877\newrobustcmd{\appto}[2]{%
878  \ifundef{#1}
879    {\edef#1{\unexpanded{#2}}}
880    {\edef#1{\expandonce#1\unexpanded{#2}}}}
881\newrobustcmd{\eappto}[2]{%
882  \ifundef{#1}
883    {\edef#1{#2}}
884    {\edef#1{\expandonce#1#2}}}
885\newrobustcmd{\gappto}[2]{%
886  \ifundef{#1}
887    {\xdef#1{\unexpanded{#2}}}
888    {\xdef#1{\expandonce#1\unexpanded{#2}}}}
889\newrobustcmd{\xappto}[2]{%
890  \ifundef{#1}
891    {\xdef#1{#2}}
892    {\xdef#1{\expandonce#1#2}}}
893
894\newrobustcmd*{\protected@eappto}{\etb@protected\eappto}
895\newrobustcmd*{\protected@xappto}{\etb@protected\xappto}
896
897% {<cstoken>}{<code>}
898
899\newrobustcmd{\preto}[2]{%
900  \ifundef{#1}
901    {\edef#1{\unexpanded{#2}}}
902    {\edef#1{\unexpanded{#2}\expandonce#1}}}
903\newrobustcmd{\epreto}[2]{%
904  \ifundef{#1}
905    {\edef#1{#2}}
906    {\edef#1{#2\expandonce#1}}}
907\newrobustcmd{\gpreto}[2]{%
908  \ifundef{#1}
909    {\xdef#1{\unexpanded{#2}}}
910    {\xdef#1{\unexpanded{#2}\expandonce#1}}}
911\newrobustcmd{\xpreto}[2]{%
912  \ifundef{#1}
913    {\xdef#1{#2}}
914    {\xdef#1{#2\expandonce#1}}}
915
916\newrobustcmd*{\protected@epreto}{\etb@protected\epreto}
917\newrobustcmd*{\protected@xpreto}{\etb@protected\xpreto}
918
919% {<csname>}{<code>}
920
921\newrobustcmd*{\csappto}[1]{\expandafter\appto\csname#1\endcsname}
922\newrobustcmd*{\cseappto}[1]{\expandafter\eappto\csname#1\endcsname}
923\newrobustcmd*{\csgappto}[1]{\expandafter\gappto\csname#1\endcsname}
924\newrobustcmd*{\csxappto}[1]{\expandafter\xappto\csname#1\endcsname}
925\newrobustcmd*{\protected@cseappto}{\etb@protected\cseappto}
926\newrobustcmd*{\protected@csxappto}{\etb@protected\csxappto}
927
928% {<csname>}{<code>}
929
930\newrobustcmd*{\cspreto}[1]{\expandafter\preto\csname#1\endcsname}
931\newrobustcmd*{\csepreto}[1]{\expandafter\epreto\csname#1\endcsname}
932\newrobustcmd*{\csgpreto}[1]{\expandafter\gpreto\csname#1\endcsname}
933\newrobustcmd*{\csxpreto}[1]{\expandafter\xpreto\csname#1\endcsname}
934\newrobustcmd*{\protected@csepreto}{\etb@protected\csepreto}
935\newrobustcmd*{\protected@csxpreto}{\etb@protected\csxpreto}
936
937% {<cstoken>}{<numexpr>}
938
939\newrobustcmd*{\numdef}[2]{%
940  \ifundef#1{\let#1\z@}{}%
941  \edef#1{\the\numexpr#2}}
942\newrobustcmd*{\numgdef}[2]{%
943  \ifundef#1{\let#1\z@}{}%
944  \xdef#1{\the\numexpr#2}}
945
946% {<csname>}{<numexpr>}
947
948\newrobustcmd*{\csnumdef}[1]{%
949  \expandafter\numdef\csname#1\endcsname}
950\newrobustcmd*{\csnumgdef}[1]{%
951  \expandafter\numgdef\csname#1\endcsname}
952
953% {<cstoken>}{<dimexpr>}
954
955\newrobustcmd*{\dimdef}[2]{%
956  \ifundef#1{\let#1\z@}{}%
957  \edef#1{\the\dimexpr#2}}
958\newrobustcmd*{\dimgdef}[2]{%
959  \ifundef#1{\let#1\z@}{}%
960  \xdef#1{\the\dimexpr#2}}
961
962% {<csname>}{<dimexpr>}
963
964\newrobustcmd*{\csdimdef}[1]{%
965  \expandafter\dimdef\csname#1\endcsname}
966\newrobustcmd*{\csdimgdef}[1]{%
967  \expandafter\dimgdef\csname#1\endcsname}
968
969% {<cstoken>}{<glueexpr>}
970
971\newrobustcmd*{\gluedef}[2]{%
972  \ifundef#1{\let#1\z@skip}{}%
973  \edef#1{\the\glueexpr#2}}
974\newrobustcmd*{\gluegdef}[2]{%
975  \ifundef#1{\let#1\z@skip}{}%
976  \xdef#1{\the\glueexpr#2}}
977
978% {<csname>}{<glueexpr>}
979
980\newrobustcmd*{\csgluedef}[1]{%
981  \expandafter\gluedef\csname#1\endcsname}
982\newrobustcmd*{\csgluegdef}[1]{%
983  \expandafter\gluegdef\csname#1\endcsname}
984
985% {<cstoken>}{<muexpr>}
986
987\newrobustcmd*{\mudef}[2]{%
988  \ifundef#1{\def#1{0mu}}{}%
989  \edef#1{\the\muexpr#2}}
990\newrobustcmd*{\mugdef}[2]{%
991  \ifundef#1{\let#1\z@}{}%
992  \xdef#1{\the\muexpr#2}}
993
994% {<csname>}{<muexpr>}
995
996\newrobustcmd*{\csmudef}[1]{%
997  \expandafter\mudef\csname#1\endcsname}
998\newrobustcmd*{\csmugdef}[1]{%
999  \expandafter\mugdef\csname#1\endcsname}
1000
1001% {<counter>}{<numexpr>}
1002
1003\newrobustcmd*{\defcounter}[2]{%
1004  \ifcsundef{c@#1}
1005    {\etb@noglobal\@nocounterr{#1}}%
1006    {\csname c@#1\endcsname\numexpr#2\relax}}
1007
1008% {<length>}{<glueexpr>}
1009
1010\newrobustcmd*{\deflength}[2]{%
1011  \ifundef{#1}
1012    {\etb@noglobal\etb@err@nolen{#1}}%
1013    {#1\glueexpr#2\relax}}
1014
1015\protected\def\etb@err@nolen#1{%
1016  \etb@error{Length '\string#1' undefined}\@eha}
1017
1018% {<name>}
1019
1020\newrobustcmd*{\newbool}[1]{%
1021  \expandafter\@ifdefinable\csname if#1\endcsname{%
1022    \expandafter\newif\csname if#1\endcsname}}
1023
1024% {<name>}
1025
1026\newrobustcmd*{\providebool}[1]{%
1027  \ifcsundef{if#1}
1028    {\expandafter\newif\csname if#1\endcsname}
1029    {\begingroup
1030     \edef\@tempa{\expandafter\meaning\csname if#1\endcsname}%
1031     \ifx\@tempa\etb@isfalse
1032     \else
1033       \ifx\@tempa\etb@istrue
1034       \else
1035         \etb@error{\@backslashchar if#1 not a boolean}\@eha
1036       \fi
1037     \fi
1038     \endgroup}}
1039
1040% {<name>}{<true>|<false>}
1041
1042\newrobustcmd*{\setbool}[2]{%
1043  \ifcsundef{if#1}
1044    {\etb@noglobal\etb@err@nobool{#1}}
1045    {\ifcsundef{#1#2}
1046       {\etb@noglobal\etb@err@boolval{#2}}
1047       {\csname#1#2\endcsname}}}
1048
1049% {<name>}
1050
1051\newrobustcmd*{\booltrue}[1]{%
1052  \ifcsundef{if#1}
1053    {\etb@noglobal\etb@err@nobool{#1}}
1054    {\csname#1true\endcsname}}
1055
1056% {<name>}
1057
1058\newrobustcmd*{\boolfalse}[1]{%
1059  \ifcsundef{if#1}
1060    {\etb@noglobal\etb@err@nobool{#1}}
1061    {\csname#1false\endcsname}}
1062
1063\edef\etb@istrue{\meaning\iftrue}
1064\edef\etb@isfalse{\meaning\iffalse}
1065\protected\def\etb@noglobal{\let\relax\relax}
1066
1067% {<name>}{<true}{<false>}
1068
1069\newcommand*{\ifbool}[1]{%
1070  \ifcsundef{if#1}
1071    {\etb@err@nobool{#1}\@gobbletwo}
1072    {\csname if#1\endcsname
1073       \expandafter\@firstoftwo
1074     \else
1075       \expandafter\@secondoftwo
1076     \fi}}
1077
1078% {<name>}{<not true}{<not false>}
1079
1080\newcommand*{\notbool}[1]{%
1081  \ifcsundef{if#1}
1082    {\etb@err@nobool{#1}\@gobbletwo}
1083    {\csname if#1\endcsname
1084       \expandafter\@secondoftwo
1085     \else
1086       \expandafter\@firstoftwo
1087     \fi}}
1088
1089\protected\def\etb@err@nobool#1{%
1090  \etb@error{Boolean '\@backslashchar if#1' undefined}\@eha}
1091
1092\def\etb@err@boolval#1{%
1093  \etb@error
1094    {Invalid boolean value '#1'}
1095    {Valid boolean values are 'true' and 'false'.}}
1096
1097% {<name>}
1098
1099\newrobustcmd*{\newtoggle}[1]{%
1100  \ifcsdef{etb@tgl@#1}
1101    {\etb@error{Toggle '#1' already defined}\@eha}
1102    {\cslet{etb@tgl@#1}\@secondoftwo}}
1103
1104% {<name>}
1105
1106\newrobustcmd*{\providetoggle}[1]{%
1107  \ifcsdef{etb@tgl@#1}
1108    {}
1109    {\cslet{etb@tgl@#1}\@secondoftwo}}
1110
1111% {<name>}{<true>|<false>}
1112
1113\newrobustcmd*{\settoggle}[2]{%
1114  \ifcsdef{etb@tgl@#1}
1115    {\ifcsdef{etb@toggle#2}
1116       {\csletcs{etb@tgl@#1}{etb@toggle#2}}
1117       {\etb@noglobal\etb@err@boolval{#2}}}
1118    {\etb@noglobal\etb@err@notoggle{#1}}}
1119
1120% {<name>}
1121
1122\newrobustcmd*{\toggletrue}[1]{%
1123  \ifcsdef{etb@tgl@#1}
1124    {\cslet{etb@tgl@#1}\etb@toggletrue}
1125    {\etb@noglobal\etb@err@notoggle{#1}}}
1126
1127% {<name>}
1128
1129\newrobustcmd*{\togglefalse}[1]{%
1130  \ifcsdef{etb@tgl@#1}
1131    {\cslet{etb@tgl@#1}\etb@togglefalse}
1132    {\etb@noglobal\etb@err@notoggle{#1}}}
1133
1134\let\etb@toggletrue\@firstoftwo
1135\let\etb@togglefalse\@secondoftwo
1136
1137% {<name>}{<true}{<false>}
1138
1139\newcommand*{\iftoggle}[1]{%
1140  \ifcsdef{etb@tgl@#1}
1141    {\csname etb@tgl@#1\endcsname}
1142    {\etb@err@notoggle{#1}\@gobbletwo}}
1143
1144% {<name>}{<not true}{<not false>}
1145
1146\newcommand*{\nottoggle}[1]{%
1147  \ifcsdef{etb@tgl@#1}
1148    {\csname etb@tgl@#1\endcsname\@secondoftwo\@firstoftwo}
1149    {\etb@err@notoggle{#1}\@gobbletwo}}
1150
1151\protected\def\etb@err@notoggle#1{%
1152  \etb@error{Toggle '#1' undefined}\@eha}
1153
1154% {<cstoken>}{<true}{<false>}
1155
1156\protected\def\etb@ifscanable#1{%
1157  \begingroup
1158  \edef\etb@resrvda{%
1159    \def\noexpand\etb@resrvda####1\detokenize{macro}:####2->####3&{%
1160      ####1\def\string\etb@resrvda####2{####3}}%
1161    \edef\noexpand\etb@resrvda{\noexpand\etb@resrvda\meaning#1&}}%
1162  \etb@resrvda
1163  \makeatletter
1164  \scantokens\expandafter{\etb@resrvda}%
1165  \expandafter\endgroup\ifx#1\etb@resrvda
1166    \expandafter\@firstoftwo
1167  \else
1168    \expandafter\@secondoftwo
1169  \fi}
1170
1171% {<cstoken>}{<search>}{<true}{<false>}
1172
1173\protected\long\def\etb@ifpattern#1#2{%
1174  \begingroup
1175  \edef\etb@resrvda{%
1176    \def\noexpand\etb@resrvda####1\detokenize{#2}####2&{%
1177      \endgroup\noexpand\noexpand\noexpand\ifblank{####2}}%
1178    \edef\noexpand\etb@resrvda{\noexpand\etb@resrvda
1179      \expandafter\strip@prefix\meaning#1\detokenize{#2}&}%
1180    \noexpand\etb@resrvda}
1181  \etb@resrvda\@secondoftwo\@firstoftwo}
1182
1183% {<string>}{<true}{<false>}
1184
1185\protected\long\def\etb@ifhashcheck#1{%
1186  \begingroup
1187  \edef\etb@resrvda{\detokenize{#1}}%
1188  \expandafter\endgroup
1189  \expandafter\etb@ifhashcheck@i\meaning\etb@resrvda&}
1190
1191\edef\etb@ifhashcheck@i#1&{%
1192  \noexpand\expandafter
1193  \noexpand\etb@ifhashcheck@ii
1194  \noexpand\strip@prefix#1\string#\string#&}
1195
1196\edef\etb@ifhashcheck@ii{%
1197  \def\noexpand\etb@ifhashcheck@ii##1\string#\string###2&}
1198\etb@ifhashcheck@ii{\ifblank{#2}}
1199
1200% {<cstoken>}
1201
1202\newrobustcmd*{\robustify}[1]{%
1203  \ifundef{#1}
1204    {\etb@error{\string#1 undefined}\@eha}
1205    {\ifdefmacro{#1}
1206       {\ifdefltxprotect{#1}
1207          {\letcs\etb@resrvda{\expandafter\@gobble\string#1 }%
1208           \@tempswatrue}
1209          {\let\etb@resrvda#1%
1210           \@tempswafalse}%
1211        \ifdefparam\etb@resrvda
1212          {\etb@ifscanable\etb@resrvda
1213             {\etb@robustify\etb@resrvda
1214              \let#1\etb@resrvda}
1215             {\etb@error{Failed to robustify \string#1}
1216                {The command is special and cannot be
1217                 handled by \string\robustify.}%
1218              \@tempswafalse}}
1219          {\protected\edef#1{\expandonce\etb@resrvda}}
1220        \if@tempswa
1221          \ifcsdef{\string#1 }
1222            {}
1223            {\csundef{\expandafter\@gobble\string#1 }}%
1224        \fi
1225        \undef\etb@resrvda}
1226       {\etb@error{\string#1 not a macro}\@eha}}}
1227
1228\def\etb@robustify#1{%
1229  \begingroup
1230  \edef\etb@resrvdb{%
1231    \def\noexpand\etb@resrvdb####1\detokenize{macro}:####2->####3&{%
1232      \protected####1\def\string#1\space####2{####3}}%
1233    \edef\noexpand\etb@resrvdb{%
1234      \noexpand\etb@resrvdb\meaning#1&}}%
1235  \etb@resrvdb
1236  \etb@patchcmd@scantoks\etb@resrvdb}
1237
1238%  {<cstoken>}{<search>}{<true}{<false>}
1239% *{<cstoken>}{<true}{<false>}
1240
1241\newrobustcmd{\ifpatchable}{%
1242  \etb@dbg@trce\ifpatchable
1243  \begingroup
1244  \@makeother\#%
1245  \@ifstar\etb@ifpatchable@i\etb@ifpatchable}
1246
1247\long\def\etb@ifpatchable#1#2{%
1248  \endgroup
1249  \etb@dbg@init#1%
1250  \ifundef{#1}
1251    {\etb@dbg@fail{def}\@secondoftwo}
1252    {\etb@dbg@info{def}%
1253     \ifdefmacro{#1}
1254       {\etb@dbg@info{mac}%
1255        \etb@ifscanable{#1}
1256          {\etb@ifhashcheck{#2}
1257             {\etb@dbg@info{tok}%
1258              \etb@ifpattern#1{#2}
1259                 {\etb@dbg@info{pat}%
1260                  \etb@dbg@info{pos}\@firstoftwo}
1261                 {\etb@dbg@fail{pat}\@secondoftwo}}
1262             {\etb@dbg@fail{hsh}\@secondoftwo}}
1263          {\etb@dbg@fail{tok}\@secondoftwo}}
1264       {\etb@dbg@fail{mac}\@secondoftwo}}}
1265
1266\long\def\etb@ifpatchable@i#1{%
1267  \endgroup
1268  \etb@dbg@init#1%
1269  \ifundef{#1}
1270    {\etb@dbg@fail{def}\@secondoftwo}
1271    {\etb@dbg@info{def}%
1272     \ifdefmacro{#1}
1273       {\etb@dbg@info{mac}%
1274        \ifdefparam{#1}
1275          {\etb@dbg@info{prm}%
1276           \etb@ifscanable{#1}
1277             {\etb@dbg@info{tok}%
1278              \etb@dbg@info{pos}\@firstoftwo}
1279             {\etb@dbg@fail{tok}\@secondoftwo}}
1280          {\etb@dbg@info{prl}%
1281           \ifdefprotected{#1}
1282             {\etb@dbg@info{pro}}
1283             {}%
1284           \etb@dbg@info{pos}\@firstoftwo}}
1285       {\etb@dbg@fail{mac}\@secondoftwo}}}
1286
1287% [<prefix>]{<cstoken>}{<search>}{<replace>}{<success>}{<failure>}
1288
1289\newrobustcmd*{\patchcmd}{%
1290  \etb@dbg@trce\patchcmd
1291  \begingroup
1292  \@makeother\#%
1293  \etb@patchcmd}
1294
1295\newcommand{\etb@patchcmd}[4][########1]{%
1296  \etb@ifpatchable#2{#3}
1297    {\etb@dbg@succ{ret}%
1298     \begingroup
1299     \edef\etb@resrvda{%
1300       \def\noexpand\etb@resrvda####1\detokenize{macro:}####2->####3&{%
1301         #1\def\string\etb@resrvda\space####2{\noexpand\etb@resrvdb####3&}}%
1302       \def\noexpand\etb@resrvdb####1\detokenize{#3}####2&{%
1303         ####1\detokenize{#4}####2}%
1304       \edef\noexpand\etb@resrvda{%
1305         \noexpand\etb@resrvda\meaning#2&}}%
1306     \etb@resrvda
1307     \etb@patchcmd@scantoks\etb@resrvda
1308     \let#2\etb@resrvda
1309     \undef\etb@resrvda
1310     \@firstoftwo}
1311    {\@secondoftwo}}
1312
1313\def\etb@patchcmd@scantoks#1{%
1314  \edef\etb@resrvda{\endgroup
1315    \unexpanded{\makeatletter\scantokens}{#1}%
1316    \catcode\number`\@=\the\catcode`\@\relax}%
1317  \etb@resrvda}
1318
1319% {<cstoken>}{<code>}{<success>}{<failure>}
1320
1321\newrobustcmd*{\apptocmd}{%
1322  \etb@dbg@trce\apptocmd
1323  \begingroup
1324  \@makeother\#%
1325  \etb@hooktocmd\etb@append}
1326
1327\newrobustcmd*{\pretocmd}{%
1328  \etb@dbg@trce\pretocmd
1329  \begingroup
1330  \@makeother\#%
1331  \etb@hooktocmd\etb@prepend}
1332
1333\long\def\etb@hooktocmd#1#2#3{%
1334  \endgroup
1335  \etb@dbg@init#2%
1336  \ifundef{#2}
1337    {\etb@dbg@fail{def}\@secondoftwo}
1338    {\etb@dbg@info{def}%
1339     \ifdefmacro{#2}
1340       {\etb@dbg@info{mac}%
1341        \ifdefparam{#2}
1342          {\etb@dbg@info{prm}%
1343           \etb@ifscanable{#2}
1344             {\etb@ifhashcheck{#3}
1345                {\etb@dbg@info{tok}%
1346                 \etb@dbg@succ{ret}%
1347                 \etb@hooktocmd@i#1#2{#3}%
1348                 \@firstoftwo}
1349                {\etb@dbg@fail{hsh}\@secondoftwo}}
1350             {\etb@dbg@fail{tok}\@secondoftwo}}
1351          {\etb@dbg@info{prl}%
1352           \ifdefprotected{#2}
1353             {\etb@dbg@info{pro}%
1354              \etb@dbg@succ{red}%
1355              \protected}
1356             {\etb@dbg@succ{red}}%
1357           \edef#2{#1{\expandonce#2}{\unexpanded{#3}}}%
1358           \@firstoftwo}}
1359       {\etb@dbg@fail{mac}\@secondoftwo}}}
1360
1361\long\def\etb@hooktocmd@i#1#2#3{%
1362  \begingroup
1363  \edef\etb@resrvda{%
1364    \def\noexpand\etb@resrvda####1\detokenize{macro}:####2->####3&{%
1365      ####1\def\string\etb@resrvda\space####2{#1{####3}{\detokenize{#3}}}}%
1366    \edef\noexpand\etb@resrvda{%
1367      \noexpand\etb@resrvda\meaning#2&}}%
1368  \etb@resrvda
1369  \etb@patchcmd@scantoks\etb@resrvda
1370  \let#2\etb@resrvda
1371  \undef\etb@resrvda}
1372
1373\long\def\etb@append#1#2{#1#2}
1374\long\def\etb@prepend#1#2{#2#1}
1375
1376\newrobustcmd*{\tracingpatches}{%
1377  \etb@info{Enabling tracing}%
1378  \input{etoolbox.def}%
1379  \global\let\tracingpatches\relax}
1380\@onlypreamble\tracingpatches
1381
1382\let\etb@dbg@trce\@gobble
1383\let\etb@dbg@init\@gobble
1384\let\etb@dbg@info\@gobble
1385\let\etb@dbg@succ\@gobble
1386\let\etb@dbg@fail\@gobble
1387
1388% {<numeral>}
1389
1390\newcommand{\rmntonum}[1]{%
1391  \ifblank{#1}
1392    {}
1393    {\expandafter\etb@rti@end\number\numexpr
1394     \expandafter\etb@rti@prs\detokenize{#1}&\relax}}
1395
1396\def\etb@rti@prs#1#2{%
1397  \ifx&#1%
1398    \expandafter\@firstoftwo
1399  \else
1400    \expandafter\@secondoftwo
1401  \fi
1402  {#1#2}
1403  {\ifx&#2%
1404     \expandafter\@firstoftwo
1405   \else
1406     \expandafter\@secondoftwo
1407   \fi
1408   {\etb@rti@chk#1+\etb@rti@num#1#2}
1409   {\etb@rti@chk#1\etb@rti@chk#2%
1410    \ifnum\etb@rti@num#1<\etb@rti@num#2 %
1411      \expandafter\@firstoftwo
1412    \else
1413      \expandafter\@secondoftwo
1414    \fi
1415    {+\etb@rti@num#2-\etb@rti@num#1\etb@rti@prs}
1416    {+\etb@rti@num#1\etb@rti@prs#2}}}}
1417
1418\def\etb@rti@chk#1{%
1419  \ifcsname etb@rmn@#1\endcsname
1420  \else
1421    \expandafter\etb@rti@brk
1422  \fi}
1423
1424\def\etb@rti@brk#1&{+\z@&-1}
1425\def\etb@rti@end#1&#2\relax{\ifblank{#2}{#1}{#2}}
1426\def\etb@rti@num#1{\csname etb@rmn@#1\endcsname}
1427
1428\chardef\etb@rmn@i=1
1429\chardef\etb@rmn@I=1
1430\chardef\etb@rmn@v=5
1431\chardef\etb@rmn@V=5
1432\chardef\etb@rmn@x=10
1433\chardef\etb@rmn@X=10
1434\chardef\etb@rmn@l=50
1435\chardef\etb@rmn@L=50
1436\chardef\etb@rmn@c=100
1437\chardef\etb@rmn@C=100
1438\mathchardef\etb@rmn@d=500
1439\mathchardef\etb@rmn@D=500
1440\mathchardef\etb@rmn@m=1000
1441\mathchardef\etb@rmn@M=1000
1442
1443% {<numeral>}{<true>}{<false>}
1444
1445\newcommand{\ifrmnum}[1]{%
1446  \ifblank{#1}
1447    {\@secondoftwo}
1448    {\expandafter\etb@ifr@prs\detokenize{#1}\relax}}
1449
1450\def\etb@ifr@prs#1{%
1451  \ifx\relax#1%
1452    \expandafter\@firstoftwo
1453  \else
1454    \ifcsname etb@rmn@#1\endcsname
1455      \expandafter\expandafter
1456      \expandafter\etb@ifr@prs
1457    \else
1458      \expandafter\expandafter
1459      \expandafter\etb@ifr@brk
1460    \fi
1461  \fi}
1462
1463\def\etb@ifr@brk#1\relax{\@secondoftwo}
1464
1465% <*>{<command>}{<separator>}
1466
1467\newrobustcmd*{\DeclareListParser}{%
1468  \@ifstar
1469    {\etb@defparser\etb@defparser@arg}
1470    {\etb@defparser\etb@defparser@do}}
1471
1472\def\etb@defparser#1#2#3{%
1473  \@ifdefinable#2{#1{#2}{#3}}}
1474
1475\def\etb@defparser@do#1#2{%
1476  \begingroup
1477  \edef\@tempa{\endgroup
1478    \long\def\noexpand#1####1{%
1479      \expandafter\noexpand
1480      \csname etb@lst@\expandafter\@gobble\string#1\endcsname
1481      \space####1\noexpand#2&}%
1482    \long\csdef{etb@lst@\expandafter\@gobble\string#1}####1\noexpand#2####2&{%
1483      \noexpand\etb@listitem\noexpand\do{####1}%
1484      \noexpand\ifblank{####2}
1485        {\noexpand\listbreak}
1486        {\expandafter\noexpand
1487         \csname etb@lst@\expandafter\@gobble\string#1\endcsname
1488         \space####2}&}}%
1489  \@tempa}
1490
1491\def\etb@defparser@arg#1#2{%
1492  \begingroup
1493  \edef\@tempa{\endgroup
1494    \long\def\noexpand#1####1####2{%
1495      \expandafter\noexpand
1496      \csname etb@lst@\expandafter\@gobble\string#1\endcsname
1497      {####1}\space####2\noexpand#2&}%
1498    \long\csdef{etb@lst@\expandafter\@gobble\string#1}####1####2\noexpand#2####3&{%
1499      \noexpand\etb@listitem{####1}{####2}%
1500      \noexpand\ifblank{####3}
1501        {\noexpand\listbreak}
1502        {\expandafter\noexpand
1503         \csname etb@lst@\expandafter\@gobble\string#1\endcsname
1504         {####1}\space####3}&}}%
1505  \@tempa}
1506
1507\long\def\etb@listitem#1#2{%
1508  \ifblank{#2}
1509    {}
1510    {\expandafter\etb@listitem@i
1511     \expandafter{\@firstofone#2}{#1}}}
1512\long\def\etb@listitem@i#1#2{#2{#1}}
1513
1514\newcommand*{\listbreak}{}
1515\long\def\listbreak#1&{}
1516
1517% {<item1>,<item2>,...} => \do{<item1>}\do{<item2>}...
1518
1519\DeclareListParser{\docsvlist}{,}
1520
1521% {<handler>}{<item1>,<item2>,...} => <handler>{<item1>}<handler>{<item2>}...
1522
1523\DeclareListParser*{\forcsvlist}{,}
1524
1525% {<listmacro>}{<string>}
1526
1527\newrobustcmd{\listadd}[2]{%
1528  \ifblank{#2}{}{\appto#1{#2|}}}
1529\newrobustcmd{\listeadd}[2]{%
1530  \begingroup
1531  \edef\etb@tempa{\endgroup\noexpand\ifblank{#2}}%
1532  \etb@tempa{}{\eappto#1{#2|}}}
1533\newrobustcmd{\listgadd}[2]{%
1534  \ifblank{#2}{}{\gappto#1{#2|}}}
1535\newrobustcmd{\listxadd}[2]{%
1536  \begingroup
1537  \edef\etb@tempa{\endgroup\noexpand\ifblank{#2}}%
1538  \etb@tempa{}{\xappto#1{#2|}}}
1539
1540% {<listcsname>}{<string>}
1541
1542\newrobustcmd{\listcsadd}[1]{%
1543  \expandafter\listadd\csname#1\endcsname}
1544\newrobustcmd{\listcseadd}[1]{%
1545  \expandafter\listeadd\csname#1\endcsname}
1546\newrobustcmd{\listcsgadd}[1]{%
1547  \expandafter\listgadd\csname#1\endcsname}
1548\newrobustcmd{\listcsxadd}[1]{%
1549  \expandafter\listxadd\csname#1\endcsname}
1550
1551% {<string>}{<listmacro>}{<true>}{<false>}
1552
1553\newrobustcmd{\ifinlist}[2]{%
1554  \begingroup
1555  \def\etb@tempa##1|#1|##2&{\endgroup
1556    \ifblank{##2}\@secondoftwo\@firstoftwo}%
1557  \expandafter\etb@tempa\expandafter|#2|#1|&}
1558
1559\newrobustcmd{\xifinlist}[1]{%
1560  \begingroup
1561  \edef\etb@tempa{\endgroup\ifinlist{#1}}%
1562  \etb@tempa}
1563
1564% {<string>}{<listcsname>}{<true>}{<false>}
1565
1566\newrobustcmd{\ifinlistcs}[2]{%
1567  \expandafter\etb@ifinlistcs@i\csname #2\endcsname{#1}}
1568\long\def\etb@ifinlistcs@i#1#2{\ifinlist{#2}{#1}}
1569
1570\newrobustcmd{\xifinlistcs}[1]{%
1571  \begingroup
1572  \edef\etb@tempa{\endgroup\ifinlistcs{#1}}%
1573  \etb@tempa}
1574
1575% {<handler>}{<listmacro>} => <handler>{<item1>}<handler>{<item2>}...
1576
1577\newcommand*{\forlistloop}[2]{%
1578  \expandafter\etb@forlistloop\expandafter{#2}{#1}}
1579
1580\long\def\etb@forlistloop#1#2{\etb@forlistloop@i{#2}#1|&}
1581
1582\long\def\etb@forlistloop@i#1#2|#3&{%
1583  \ifblank{#2}
1584    {}
1585    {#1{#2}}%
1586  \ifblank{#3}
1587    {\listbreak}
1588    {\etb@forlistloop@i{#1}#3}%
1589  &}
1590
1591% {<handler>}{<listcsname>} => <handler>{<item1>}<handler>{<item2>}...
1592
1593\newcommand*{\forlistcsloop}[2]{%
1594  \expandafter\expandafter\expandafter\etb@forlistloop
1595  \expandafter\expandafter\expandafter{\csname#2\endcsname}{#1}}
1596
1597% {<listmacro>} => \do{<item1>}\do{<item2>}...
1598
1599\newcommand*{\dolistloop}{\forlistloop\do}
1600
1601% {<listcsname>} => \do{<item1>}\do{<item2>}...
1602
1603\newcommand*{\dolistcsloop}{\forlistcsloop\do}
1604
1605% {<code>}
1606
1607\newrobustcmd*{\AtEndPreamble}{\gappto\@endpreamblehook}
1608\newcommand*{\@endpreamblehook}{}
1609
1610\preto\document{%
1611  \endgroup
1612  \let\AtEndPreamble\@firstofone
1613  \@endpreamblehook
1614  \protected\def\AtEndPreamble{\@notprerr\@gobble}%
1615  \undef\@endpreamblehook
1616  \begingroup}
1617
1618% {<code>}
1619
1620\newrobustcmd*{\AfterPreamble}{\AtBeginDocument}
1621\AtEndPreamble{\let\AfterPreamble\@firstofone}
1622
1623% {<code>}
1624
1625\newrobustcmd*{\AfterEndPreamble}{\gappto\@afterendpreamblehook}
1626\newcommand*{\@afterendpreamblehook}{}
1627
1628\appto\document{%
1629  \let\AfterEndPreamble\@firstofone
1630  \@afterendpreamblehook
1631  \protected\def\AfterEndPreamble{\@notprerr\@gobble}%
1632  \undef\@afterendpreamblehook
1633  \ignorespaces}
1634
1635\AtEndDocument{\let\AfterEndPreamble\@gobble}
1636
1637% {<code>}
1638
1639\newrobustcmd*{\AfterEndDocument}{\gappto\@afterenddocumenthook}
1640\newcommand*{\@afterenddocumenthook}{}
1641
1642\patchcmd\enddocument
1643  {\deadcycles}
1644  {\let\AfterEndDocument\@firstofone
1645   \@afterenddocumenthook
1646   \deadcycles}
1647  {}
1648  {\let\etb@@end\@@end
1649   \def\@@end{%
1650     \let\AfterEndDocument\@firstofone
1651     \@afterenddocumenthook
1652     \etb@@end}}
1653
1654% {<environment>}{<code>}
1655
1656\newrobustcmd{\AtBeginEnvironment}[1]{%
1657  \csgappto{@begin@#1@hook}}
1658
1659\patchcmd\begin
1660  {\csname #1\endcsname}
1661  {\csuse{@begin@#1@hook}%
1662   \csname #1\endcsname}
1663  {}
1664  {\etb@warning{%
1665     Patching '\string\begin' failed!\MessageBreak
1666     '\string\AtBeginEnvironment' will not work\@gobble}}
1667
1668% {<environment>}{<code>}
1669
1670\newrobustcmd{\AtEndEnvironment}[1]{%
1671  \csgappto{@end@#1@hook}}
1672
1673\patchcmd\end
1674  {\csname end#1\endcsname}
1675  {\csuse{@end@#1@hook}%
1676   \csname end#1\endcsname}
1677  {}
1678  {\etb@warning{%
1679     Patching '\string\end' failed!\MessageBreak
1680     '\string\AtEndEnvironment' will not work\@gobble}}
1681
1682% {<environment>}{<code>}
1683
1684\newrobustcmd{\BeforeBeginEnvironment}[1]{%
1685  \csgappto{@beforebegin@#1@hook}}
1686
1687\pretocmd\begin
1688  {\csuse{@beforebegin@#1@hook}}
1689  {}
1690  {\etb@warning{%
1691     Patching '\string\begin' failed!\MessageBreak
1692     '\string\BeforeBeginEnvironment' will not work\@gobble}}
1693
1694% {<environment>}{<code>}
1695
1696\newrobustcmd{\AfterEndEnvironment}[1]{%
1697  \csgappto{@afterend@#1@hook}}
1698
1699\patchcmd\end
1700  {\if@ignore}
1701  {\csuse{@afterend@#1@hook}%
1702   \if@ignore}
1703  {}
1704  {\etb@warning{%
1705     Patching '\string\end' failed!\MessageBreak
1706     '\string\AfterEndEnvironment' will not work\@gobble}}
1707
1708\endinput
Note: See TracBrowser for help on using the repository browser.