diff options
author | Karl Berry <karl@freefriends.org> | 2008-06-24 01:04:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-06-24 01:04:06 +0000 |
commit | 71a1e8b7bc4afa972869bc22f45431c77c4cb098 (patch) | |
tree | 3adcbdfc58f4849649ab671c16e6e4adbaf2f3b9 /Master/texmf-dist/tex | |
parent | 334d61c188926ddbec6c60c3709d7470d60520c6 (diff) |
etoolbox 1.6 (23jun08)
git-svn-id: svn://tug.org/texlive/trunk@8958 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/etoolbox/etoolbox.def | 71 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/etoolbox/etoolbox.sty | 863 |
2 files changed, 643 insertions, 291 deletions
diff --git a/Master/texmf-dist/tex/latex/etoolbox/etoolbox.def b/Master/texmf-dist/tex/latex/etoolbox/etoolbox.def new file mode 100644 index 00000000000..1684eec8b38 --- /dev/null +++ b/Master/texmf-dist/tex/latex/etoolbox/etoolbox.def @@ -0,0 +1,71 @@ +% $Id: etoolbox.def,v 1.6 2008/06/22 15:26:57 lehman stable $ + +\ProvidesFile{etoolbox.def}[2008/06/22 v1.6 etoolbox debug messages] + +\begingroup +\makeatletter +\@makeother\+ +\@makeother\- +\@makeother\= +\@makeother\> + +\long\gdef\etb@dbg@trce#1{\typeout{% + [debug] tracing \string#1\on@line}}% +\long\gdef\etb@dbg@init#1{\typeout{% + [debug] analyzing \detokenize\expandafter{\string#1}}}% +\gdef\etb@dbg@info#1{\typeout{% + [debug] ++ \csuse{etb@msg@i@#1}}}% +\gdef\etb@dbg@succ#1{\typeout{% + [debug] == \csuse{etb@msg@s@#1}}}% +\gdef\etb@dbg@fail#1{\typeout{% + [debug] -- \csuse{etb@msg@f@#1}}}% + +\gdef\etb@msg@ex{^^J[debug] -> }% +\gdef\etb@msg@br{^^J[debug]\@spaces} + +\gdef\etb@msg@i@def{% + control sequence is defined} +\gdef\etb@msg@i@mac{% + control sequence is a macro} +\gdef\etb@msg@i@prm{% + control sequence is a macro with parameters} +\gdef\etb@msg@i@prl{% + control sequence is a macro without parameters} +\xdef\etb@msg@i@pro{% + control sequence is a \string\protected\space macro} +\gdef\etb@msg@i@tok{% + macro can be retokenized cleanly} +\gdef\etb@msg@i@pat{% + search pattern found in replacement text} +\gdef\etb@msg@i@pos{% + patching possible} +\gdef\etb@msg@s@red{% + redefining macro now} +\gdef\etb@msg@s@ret{% + retokenizing macro now} +\gdef\etb@msg@f@def{% + control sequence is undefined or \@backslashchar relax} +\gdef\etb@msg@f@mac{% + control sequence is not a macro} +\gdef\etb@msg@f@tok{% + macro cannot be retokenized cleanly\etb@msg@ex + the macro may have been defined under a category\etb@msg@br + code regime different from the current one\etb@msg@ex + the replacement text may contain special control\etb@msg@br + sequence tokens formed with \@backslashchar + csname...\@backslashchar endcsname;\etb@msg@ex + the replacement text may contain carriage return,\etb@msg@br + newline, or similar characters} +\xdef\etb@msg@f@hsh{% + nested patching command and parameters in patch\noexpand\etb@msg@ex + the patching command seems to be nested in the\noexpand\etb@msg@br + argument to some other command\noexpand\etb@msg@ex + the patch text seems to contain \string# characters\noexpand\etb@msg@ex + either avoid nesting or use \string# characters with\noexpand\etb@msg@br + category code 12 in the patch text\noexpand\etb@msg@ex + simply doubling the \string# characters will not work} +\gdef\etb@msg@f@pat{% + search pattern not found in replacement text} + +\endgroup +\endinput diff --git a/Master/texmf-dist/tex/latex/etoolbox/etoolbox.sty b/Master/texmf-dist/tex/latex/etoolbox/etoolbox.sty index 155446f55e3..b7e7b1e3a6c 100644 --- a/Master/texmf-dist/tex/latex/etoolbox/etoolbox.sty +++ b/Master/texmf-dist/tex/latex/etoolbox/etoolbox.sty @@ -1,4 +1,4 @@ -% $Id: etoolbox.sty,v 1.5 2008/04/26 18:23:00 lehman stable $ +% $Id: etoolbox.sty,v 1.6 2008/06/22 15:26:57 lehman stable $ % Copyright (c) 2007-2008 Philipp Lehman. % @@ -15,7 +15,7 @@ % particular purpose. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{etoolbox}[2008/04/26 v1.5 e-TeX tools for LaTeX] +\ProvidesPackage{etoolbox}[2008/06/22 v1.6 e-TeX tools for LaTeX] \begingroup \@ifundefined{eTeXversion} @@ -33,27 +33,42 @@ \edef\etb@restore{% \catcode\number`\&=\the\catcode`\&\relax - \catcode\number`\|=\the\catcode`\|\relax} + \catcode\number`\|=\the\catcode`\|\relax + \catcode\number`\:=\the\catcode`\:\relax + \catcode\number`\-=\the\catcode`\-\relax + \catcode\number`\>=\the\catcode`\>\relax +} \catcode`\&=3 \catcode`\|=3 +\@makeother\: +\@makeother\- +\@makeother\> \AtEndOfPackage{% \etb@restore \undef\etb@restore} +\protected\def\etb@error{\PackageError{etoolbox}} +\protected\def\etb@info{\PackageInfo{etoolbox}} + % {<cstoken>}[<arguments>][<optarg default>]{<definition>} \newcommand*{\newrobustcmd}{} \protected\def\newrobustcmd{% \@ifstar - {\let\l@ngrel@x\protected\etb@new@command} - {\def\l@ngrel@x{\protected\long}\etb@new@command}} + {\let\l@ngrel@x\relax\etb@new@command} + {\let\l@ngrel@x\long\etb@new@command}} \def\etb@new@command#1{\@testopt{\etb@newcommand#1}0} \def\etb@newcommand#1[#2]{% \@ifnextchar[%] {\etb@xargdef#1[#2]} - {\@argdef#1[#2]}} + {\ifx\l@ngrel@x\relax + \let\l@ngrel@x\protected + \else + \protected\def\l@ngrel@x{\protected\long}% + \fi + \@argdef#1[#2]}} \long\def\etb@xargdef#1[#2][#3]#4{% \@ifdefinable#1{% \expandafter\protected @@ -62,8 +77,7 @@ \expandafter{% \expandafter\@testopt \csname\string#1\endcsname{#3}}% - \expandafter\@yargdef - \csname\string#1\endcsname\tw@{#2}{#4}}} + \expandafter\@yargdef\csname\string#1\endcsname\tw@{#2}{#4}}} % {<cstoken>}[<arguments>][<optarg default>]{<definition>} @@ -78,7 +92,7 @@ \xdef\@gtempa{{\string#1}}% \endgroup \expandafter\@ifundefined\@gtempa - {\@latex@error{\noexpand#1undefined}\@ehc} + {\etb@error{\string#1 undefined}\@ehc} {}% \let\@ifdefinable\@rc@ifdefinable \etb@new@command#1} @@ -100,30 +114,6 @@ {\def\reserved@a{\etb@renew@command\reserved@a}}% \reserved@a}% -% {<cstoken>} - -\newrobustcmd*{\robustify}[1]{% - \ifundef#1% - {\@latex@error{\string#1 undefined}\@ehc} - {\begingroup - \edef\etb@resrvda{\meaning#1}% - \edef\etb@resrvdb{% - \noexpand\protect\expandafter\noexpand - \csname\expandafter\@gobble\string#1 \endcsname}% - \edef\etb@resrvdb{\meaning\etb@resrvdb}% - \ifx\etb@resrvda\etb@resrvdb - \letcs#1{\expandafter\@gobble\string#1 }% - \global\csundef{\expandafter\@gobble\string#1 }% - \fi - \edef\etb@resrvda{% - \def\noexpand\etb@resrvda####1\detokenize{macro:}####2->####3&{% - \protected####1\def\detokenize{#1}####2{####3}}% - \edef\noexpand\etb@resrvda{% - \noexpand\etb@resrvda\meaning#1&}}% - \etb@resrvda - \etb@scantoks\endgroup\etb@resrvda}} -\@onlypreamble\robustify - % {<cstoken>}{<true>}{<false>} \newcommand*{\ifdef}[1]{% @@ -172,34 +162,146 @@ \expandafter\@firstoftwo \fi} +% {<cstoken>}{<true}{<false>} + +\newcommand*{\ifdefmacro}{} +\edef\ifdefmacro#1{% + \noexpand\expandafter\noexpand\etb@ifdefmacro + \noexpand\meaning#1\detokenize{macro}:&} +\edef\etb@ifdefmacro{% + \def\noexpand\etb@ifdefmacro##1\detokenize{macro}:##2&} +\etb@ifdefmacro{\ifblank{#2}\@secondoftwo\@firstoftwo} + +% {<csname>}{<true>}{<false>} + +\newcommand*{\ifcsmacro}[1]{% + \ifcsdef{#1} + {\expandafter\ifdefmacro\csname#1\endcsname} + {\@secondoftwo}} + +% {<cstoken>}{<true}{<false>} + +\newcommand*{\ifdefprefix}[1]{% + \ifdefmacro{#1} + {\etb@ifdefprefix{#1}} + {\@secondoftwo}} +\edef\etb@ifdefprefix#1{% + \noexpand\expandafter\noexpand\etb@ifdefprefix@i + \noexpand\meaning#1\detokenize{macro}:&} +\edef\etb@ifdefprefix@i{% + \def\noexpand\etb@ifdefprefix@i##1\detokenize{macro}:##2&} +\etb@ifdefprefix@i{\ifblank{#1}\@secondoftwo\@firstoftwo} + +% {<csname>}{<true>}{<false>} + +\newcommand*{\ifcsprefix}[1]{% + \ifcsdef{#1} + {\expandafter\ifdefprefix\csname#1\endcsname} + {\@secondoftwo}} + +% {<cstoken>}{<true}{<false>} + +\newcommand*{\ifdefparam}{} +\edef\ifdefparam#1{% + \noexpand\expandafter\noexpand\etb@ifdefparam + \noexpand\meaning#1\detokenize{macro}:->&} +\edef\etb@ifdefparam{% + \def\noexpand\etb@ifdefparam##1\detokenize{macro}:##2->##3&} +\etb@ifdefparam{\ifblank{#2}\@secondoftwo\@firstoftwo} + +% {<csname>}{<true>}{<false>} + +\newcommand*{\ifcsparam}[1]{% + \ifcsdef{#1} + {\expandafter\ifdefparam\csname#1\endcsname} + {\@secondoftwo}} + +% {<cstoken>}{<true}{<false>} + +\newcommand*{\ifdefprotected}{} +\edef\ifdefprotected#1{% + \noexpand\expandafter\noexpand\etb@ifdefprotected + \noexpand\meaning#1\string\protected&} +\edef\etb@ifdefprotected{% + \def\noexpand\etb@ifdefprotected##1\string\protected##2&} +\etb@ifdefprotected{\ifblank{#2}\@secondoftwo\@firstoftwo} + +% {<csname>}{<true>}{<false>} + +\newcommand*{\ifcsprotected}[1]{% + \ifcsdef{#1} + {\expandafter\ifdefprotected\csname#1\endcsname} + {\@secondoftwo}} + +% {<cstoken>}{<true}{<false>} + +\newrobustcmd*{\ifdefltxprotect}[1]{% + \begingroup + \edef\etb@resrvda{% + \noexpand\protect\expandafter\noexpand + \csname\expandafter\@gobble\string#1 \endcsname}% + \expandafter\endgroup\ifx#1\etb@resrvda + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi} + +% {<csname>}{<true>}{<false>} + +\newrobustcmd*{\ifcsltxprotect}[1]{% + \ifcsdef{#1} + {\expandafter\ifdefltxprotect\csname#1\endcsname} + {\@secondoftwo}} + +% {<cstoken>}{<true>}{<false>} + +\newcommand*{\ifdefempty}[1]{% + \ifundef{#1} + {\@secondoftwo} + {\ifdefparam{#1} + {\@secondoftwo} + {\etb@ifdefempty#1}}} + +\def\etb@ifdefempty#1{% + \expandafter\expandafter + \expandafter\ifblank + \expandafter\expandafter + \expandafter{% + \expandafter\strip@prefix\meaning#1}} + +% {<csname>}{<true>}{<false>} + +\newcommand*{\ifcsempty}[1]{% + \ifcsundef{#1} + {\@secondoftwo} + {\expandafter\ifdefparam\csname#1\endcsname + {\@secondoftwo} + {\expandafter\etb@ifdefempty\csname#1\endcsname}}} + % {<cstoken>}{<true>}{<false>} \newcommand*{\ifdefvoid}[1]{% - \ifundef#1% + \ifundef{#1} {\@firstoftwo} - {\ifx#1\@empty - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi}} + {\ifdefparam{#1} + {\@secondoftwo} + {\etb@ifdefempty#1}}} % {<csname>}{<true>}{<false>} \newcommand*{\ifcsvoid}[1]{% \ifcsundef{#1}% {\@firstoftwo} - {\expandafter\ifx\csname#1\endcsname\@empty - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi}} + {\expandafter\ifdefparam\csname#1\endcsname + {\@secondoftwo} + {\expandafter\etb@ifdefempty\csname#1\endcsname}}} % {<cstoken1>}{<cstoken2>}{<true>}{<false>} \newcommand*{\ifdefequal}[2]{% - \ifundef#1% + \ifundef{#1} {\@secondoftwo} - {\ifundef#2% + {\ifundef{#2} {\@secondoftwo} {\ifx#1#2% \expandafter\@firstoftwo @@ -225,7 +327,7 @@ % {<cstoken>}{<string>}{<true>}{<false>} \newrobustcmd{\ifdefstring}[2]{% - \ifundef#1% + \ifundef{#1} {\@secondoftwo} {\begingroup \edef\etb@tempa{\expandafter\strip@prefix\meaning#1}% @@ -259,206 +361,19 @@ % {<string>}{<true>}{<false>} +\newcommand{\ifstrempty}[1]{% + \expandafter\ifx\expandafter&\detokenize{#1}&% + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi} + +% {<string>}{<true>}{<false>} + \newcommand{\ifblank}[1]{% from url.sty \etb@ifblank@i#1&&\@secondoftwo\@firstoftwo:} \long\def\etb@ifblank@i#1#2#4#5:{#4} -% {<name>} - -\newrobustcmd*{\newbool}[1]{% - \expandafter\@ifdefinable\csname if#1\endcsname{% - \expandafter\newif\csname if#1\endcsname}} - -% {<name>} - -\newrobustcmd*{\providebool}[1]{% - \ifcsundef{if#1} - {\expandafter\newif\csname if#1\endcsname} - {\begingroup - \edef\@tempa{\expandafter\meaning\csname if#1\endcsname}% - \ifx\@tempa\etb@isfalse - \else - \ifx\@tempa\etb@istrue - \else - \@latex@error{'\@backslashchar if#1' defined - but not a switch}\@eha - \fi - \fi - \endgroup}} - -% {<name>} - -\newrobustcmd*{\booltrue}[1]{% - \ifcsundef{if#1} - {\etb@noglobal\etb@err@nobool{#1}} - {\csname#1true\endcsname}} - -% {<name>} - -\newrobustcmd*{\boolfalse}[1]{% - \ifcsundef{if#1} - {\etb@noglobal\etb@err@nobool{#1}} - {\csname#1false\endcsname}} - -\edef\etb@istrue{\meaning\iftrue} -\edef\etb@isfalse{\meaning\iffalse} -\protected\def\etb@noglobal{\let\relax\relax} - -% {<name>}{<true}{<false>} - -\newcommand*{\ifbool}[1]{% - \ifcsundef{if#1} - {\etb@err@nobool{#1}\@gobbletwo} - {\csname if#1\endcsname - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi}} - -% {<name>}{<not true}{<not false>} - -\newcommand*{\notbool}[1]{% - \ifcsundef{if#1} - {\etb@err@nobool{#1}\@gobbletwo} - {\csname if#1\endcsname - \expandafter\@secondoftwo - \else - \expandafter\@firstoftwo - \fi}} - -\protected\def\etb@err@nobool#1{% - \@latex@error{Switch '\@backslashchar if#1' undefined}\@eha} - -% {<name>} - -\newrobustcmd*{\newtoggle}[1]{% - \ifcsdef{etb@tgl@#1} - {\@latex@error{Toggle '#1' already defined}\@eha} - {\cslet{etb@tgl@#1}\@secondoftwo}} - -% {<name>} - -\newrobustcmd*{\providetoggle}[1]{% - \ifcsdef{etb@tgl@#1} - {} - {\cslet{etb@tgl@#1}\@secondoftwo}} - -% {<name>} - -\newrobustcmd*{\toggletrue}[1]{% - \ifcsdef{etb@tgl@#1} - {\cslet{etb@tgl@#1}\@firstoftwo} - {\etb@noglobal\etb@err@notoggle{#1}}} - -% {<name>} - -\newrobustcmd*{\togglefalse}[1]{% - \ifcsdef{etb@tgl@#1} - {\cslet{etb@tgl@#1}\@secondoftwo} - {\etb@noglobal\etb@err@notoggle{#1}}} - -% {<name>}{<true}{<false>} - -\newcommand*{\iftoggle}[1]{% - \ifcsdef{etb@tgl@#1} - {\csname etb@tgl@#1\endcsname} - {\etb@err@notoggle{#1}\@gobbletwo}} - -% {<name>}{<not true}{<not false>} - -\newcommand*{\nottoggle}[1]{% - \ifcsdef{etb@tgl@#1} - {\csname etb@tgl@#1\endcsname\@secondoftwo\@firstoftwo} - {\etb@err@notoggle{#1}\@gobbletwo}} - -\protected\def\etb@err@notoggle#1{% - \@latex@error{Toggle '#1' undefined}\@eha} - -% {<cstoken>}{<search>}{<true}{<false>} - -\newrobustcmd{\ifpatchable}{% - \begingroup - \@makeother\#% - \etb@ifpatchable} -\@onlypreamble\ifpatchable - -\def\etb@ifpatchable#1#2{% - \endgroup - \ifundef{#1} - {\@firstoftwo} - {\begingroup - \edef\etb@resrvda{% - \def\noexpand\etb@resrvda####1->####2&{% - \noexpand\etb@resrvdb####2\detokenize{#2}&}% - \def\noexpand\etb@resrvdb####1\detokenize{#2}####2&{% - \endgroup\noexpand\noexpand\noexpand\ifblank{####2}}% - \edef\noexpand\etb@resrvda{% - \noexpand\etb@resrvda\meaning#1&}% - \noexpand\etb@resrvda}% - \etb@resrvda} - {\@secondoftwo} - {\@firstoftwo}} - -% [<prefix>]{<cstoken>}{<search>}{<replace>}{<success>}{<failure>} - -\newrobustcmd*{\patchcmd}{% - \begingroup - \@makeother\#% - \etb@patchcmd} -\@onlypreamble\patchcmd - -\newcommand{\etb@patchcmd}[4][########1]{% - \etb@ifpatchable{#2}{#3} - {\begingroup - \edef\etb@resrvda{% - \def\noexpand\etb@resrvda####1\detokenize{macro:}####2->####3&{% - #1\def\detokenize{#2}####2{\noexpand\etb@resrvdb####3&}}% - \def\noexpand\etb@resrvdb####1\detokenize{#3}####2&{% - ####1\detokenize{#4}####2}% - \edef\noexpand\etb@resrvda{% - \noexpand\etb@resrvda\meaning#2&}}% - \etb@resrvda - \etb@scantoks\endgroup\etb@resrvda - \@firstoftwo} - {\@secondoftwo}} - -\def\etb@scantoks#1#2{% - \begingroup - \edef\etb@resrvda{\endgroup - \unexpanded{#1\makeatletter\scantokens}{#2}% - \catcode\number`\@=\the\catcode`\@\relax}% - \etb@resrvda} - -% {<cstoken>}{<code>} - -\newrobustcmd*{\apptocmd}{% - \begingroup - \@makeother\#% - \etb@hooktocmd\etb@apptocmd} -\@onlypreamble\apptocmd - -\newrobustcmd*{\pretocmd}{% - \begingroup - \@makeother\#% - \etb@hooktocmd\etb@pretocmd} -\@onlypreamble\pretocmd - -\long\def\etb@hooktocmd#1#2#3{% - \endgroup - \ifundef{#2} - {\def#2{#3}} - {\begingroup - \edef\etb@resrvda{% - \def\noexpand\etb@resrvda####1\detokenize{macro:}####2->####3&{% - ####1\def\detokenize{#2}####2{#1{####3}{\detokenize{#3}}}}% - \edef\noexpand\etb@resrvda{% - \noexpand\etb@resrvda\meaning#2&}}% - \etb@resrvda - \etb@scantoks\endgroup\etb@resrvda}} - -\long\def\etb@apptocmd#1#2{#1#2} -\long\def\etb@pretocmd#1#2{#2#1} - % {<cstoken>} \newcommand*{\expandonce}[1]{% @@ -537,19 +452,19 @@ % {<cstoken>}{<code>} \newrobustcmd{\appto}[2]{% - \ifundef#1% + \ifundef{#1} {\edef#1{\unexpanded{#2}}} {\edef#1{\expandonce#1\unexpanded{#2}}}} \newrobustcmd{\eappto}[2]{% - \ifundef#1% + \ifundef{#1} {\edef#1{#2}} {\edef#1{\expandonce#1#2}}} \newrobustcmd{\gappto}[2]{% - \ifundef#1% + \ifundef{#1} {\xdef#1{\unexpanded{#2}}} {\xdef#1{\expandonce#1\unexpanded{#2}}}} \newrobustcmd{\xappto}[2]{% - \ifundef#1% + \ifundef{#1} {\xdef#1{#2}} {\xdef#1{\expandonce#1#2}}} @@ -559,19 +474,19 @@ % {<cstoken>}{<code>} \newrobustcmd{\preto}[2]{% - \ifundef#1% + \ifundef{#1} {\edef#1{\unexpanded{#2}}} {\edef#1{\unexpanded{#2}\expandonce#1}}} \newrobustcmd{\epreto}[2]{% - \ifundef#1% + \ifundef{#1} {\edef#1{#2}} {\edef#1{#2\expandonce#1}}} \newrobustcmd{\gpreto}[2]{% - \ifundef#1% + \ifundef{#1} {\xdef#1{\unexpanded{#2}}} {\xdef#1{\unexpanded{#2}\expandonce#1}}} \newrobustcmd{\xpreto}[2]{% - \ifundef#1% + \ifundef{#1} {\xdef#1{#2}} {\xdef#1{#2\expandonce#1}}} @@ -663,19 +578,386 @@ % {<counter>}{<value>} \newrobustcmd*{\defcounter}[2]{% - \ifcsundef{c@#1}% + \ifcsundef{c@#1} {\etb@noglobal\@nocounterr{#1}}% {\csname c@#1\endcsname\numexpr#2\relax\relax}} % {<length>}{<value>} \newrobustcmd*{\deflength}[2]{% - \ifundef#1% + \ifundef{#1} {\etb@noglobal\etb@err@nolen{#1}}% {#1\dimexpr#2\relax\relax}} \protected\def\etb@err@nolen#1{% - \@latex@error{No length '\string#1' defined}\@eha} + \etb@error{Length \string#1 undefined}\@eha} + +% {<name>} + +\newrobustcmd*{\newbool}[1]{% + \expandafter\@ifdefinable\csname if#1\endcsname{% + \expandafter\newif\csname if#1\endcsname}} + +% {<name>} + +\newrobustcmd*{\providebool}[1]{% + \ifcsundef{if#1} + {\expandafter\newif\csname if#1\endcsname} + {\begingroup + \edef\@tempa{\expandafter\meaning\csname if#1\endcsname}% + \ifx\@tempa\etb@isfalse + \else + \ifx\@tempa\etb@istrue + \else + \etb@error{\@backslashchar if#1 not a boolean}\@eha + \fi + \fi + \endgroup}} + +% {<name>}{<true>|<false>} + +\newrobustcmd*{\setbool}[2]{% + \ifcsundef{if#1} + {\etb@noglobal\etb@err@nobool{#1}} + {\ifcsundef{#1#2} + {\etb@noglobal\etb@err@boolval{#2}} + {\csname#1#2\endcsname}}} + +% {<name>} + +\newrobustcmd*{\booltrue}[1]{% + \ifcsundef{if#1} + {\etb@noglobal\etb@err@nobool{#1}} + {\csname#1true\endcsname}} + +% {<name>} + +\newrobustcmd*{\boolfalse}[1]{% + \ifcsundef{if#1} + {\etb@noglobal\etb@err@nobool{#1}} + {\csname#1false\endcsname}} + +\edef\etb@istrue{\meaning\iftrue} +\edef\etb@isfalse{\meaning\iffalse} +\protected\def\etb@noglobal{\let\relax\relax} + +% {<name>}{<true}{<false>} + +\newcommand*{\ifbool}[1]{% + \ifcsundef{if#1} + {\etb@err@nobool{#1}\@gobbletwo} + {\csname if#1\endcsname + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi}} + +% {<name>}{<not true}{<not false>} + +\newcommand*{\notbool}[1]{% + \ifcsundef{if#1} + {\etb@err@nobool{#1}\@gobbletwo} + {\csname if#1\endcsname + \expandafter\@secondoftwo + \else + \expandafter\@firstoftwo + \fi}} + +\protected\def\etb@err@nobool#1{% + \etb@error{\@backslashchar if#1 undefined}\@eha} + +\def\etb@err@boolval#1{% + \etb@error + {Invalid boolean value '#1'} + {Valid boolean values are 'true' and 'false'.}} + +% {<name>} + +\newrobustcmd*{\newtoggle}[1]{% + \ifcsdef{etb@tgl@#1} + {\etb@error{Toggle '#1' already defined}\@eha} + {\cslet{etb@tgl@#1}\@secondoftwo}} + +% {<name>} + +\newrobustcmd*{\providetoggle}[1]{% + \ifcsdef{etb@tgl@#1} + {} + {\cslet{etb@tgl@#1}\@secondoftwo}} + +% {<name>}{<true>|<false>} + +\newrobustcmd*{\settoggle}[2]{% + \ifcsdef{etb@tgl@#1} + {\ifcsdef{etb@toggle#2} + {\csletcs{etb@tgl@#1}{etb@toggle#2}} + {\etb@noglobal\etb@err@boolval{#2}}} + {\etb@noglobal\etb@err@notoggle{#1}}} + +% {<name>} + +\newrobustcmd*{\toggletrue}[1]{% + \ifcsdef{etb@tgl@#1} + {\cslet{etb@tgl@#1}\etb@toggletrue} + {\etb@noglobal\etb@err@notoggle{#1}}} + +% {<name>} + +\newrobustcmd*{\togglefalse}[1]{% + \ifcsdef{etb@tgl@#1} + {\cslet{etb@tgl@#1}\etb@togglefalse} + {\etb@noglobal\etb@err@notoggle{#1}}} + +\let\etb@toggletrue\@firstoftwo +\let\etb@togglefalse\@secondoftwo + +% {<name>}{<true}{<false>} + +\newcommand*{\iftoggle}[1]{% + \ifcsdef{etb@tgl@#1} + {\csname etb@tgl@#1\endcsname} + {\etb@err@notoggle{#1}\@gobbletwo}} + +% {<name>}{<not true}{<not false>} + +\newcommand*{\nottoggle}[1]{% + \ifcsdef{etb@tgl@#1} + {\csname etb@tgl@#1\endcsname\@secondoftwo\@firstoftwo} + {\etb@err@notoggle{#1}\@gobbletwo}} + +\protected\def\etb@err@notoggle#1{% + \etb@error{Toggle '#1' undefined}\@eha} + +% {<cstoken>}{<true}{<false>} + +\protected\def\etb@ifscanable#1{% + \begingroup + \edef\etb@resrvda{% + \def\noexpand\etb@resrvda####1\detokenize{macro}:####2->####3&{% + ####1\def\string\etb@resrvda####2{####3}}% + \edef\noexpand\etb@resrvda{\noexpand\etb@resrvda\meaning#1&}}% + \etb@resrvda + \makeatletter + \scantokens\expandafter{\etb@resrvda}% + \expandafter\endgroup\ifx#1\etb@resrvda + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi} + +% {<cstoken>}{<search>}{<true}{<false>} + +\protected\def\etb@ifpattern#1#2{% + \begingroup + \edef\etb@resrvda{% + \def\noexpand\etb@resrvda####1\detokenize{#2}####2&{% + \endgroup\noexpand\noexpand\noexpand\ifblank{####2}}% + \edef\noexpand\etb@resrvda{\noexpand\etb@resrvda + \expandafter\strip@prefix\meaning#1\detokenize{#2}&}% + \noexpand\etb@resrvda} + \etb@resrvda\@secondoftwo\@firstoftwo} + +% {<string>}{<true}{<false>} + +\protected\def\etb@ifhashcheck#1{% + \begingroup + \edef\etb@resrvda{\detokenize{#1}}% + \expandafter\endgroup + \expandafter\etb@ifhashcheck@i\meaning\etb@resrvda&} + +\edef\etb@ifhashcheck@i#1&{% + \noexpand\expandafter + \noexpand\etb@ifhashcheck@ii + \noexpand\strip@prefix#1\string#\string#&} + +\edef\etb@ifhashcheck@ii{% + \def\noexpand\etb@ifhashcheck@ii##1\string#\string###2&} +\etb@ifhashcheck@ii{\ifblank{#2}} + +% {<cstoken>} + +\newrobustcmd*{\robustify}[1]{% + \ifundef{#1} + {\etb@error{\string#1 undefined}\@eha} + {\ifdefmacro{#1} + {\ifdefltxprotect{#1} + {\letcs\etb@tempa{\expandafter\@gobble\string#1 }% + \@tempswatrue} + {\let\etb@tempa#1% + \@tempswafalse}% + \ifdefparam\etb@tempa + {\etb@ifscanable\etb@tempa + {\etb@robustify\etb@tempa + \let#1\etb@tempa} + {\etb@error{Failed to robustify \string#1} + {The command is special and cannot be + handled by \string\robustify.}% + \@tempswafalse}} + {\protected\edef#1{\expandonce\etb@tempa}} + \if@tempswa + \ifcsdef{\string#1 } + {} + {\csundef{\expandafter\@gobble\string#1 }}% + \fi + \undef\etb@tempa} + {\etb@error{\string#1 not a macro}\@eha}}} + +\def\etb@robustify#1{% + \begingroup + \edef\etb@resrvda{% + \def\noexpand\etb@resrvda####1\detokenize{macro}:####2->####3&{% + \protected####1\def\string#1####2{####3}}% + \edef\noexpand\etb@resrvda{% + \noexpand\etb@resrvda\meaning#1&}}% + \etb@resrvda + \etb@scantoks\endgroup\etb@resrvda} + +% {<cstoken>}{<search>}{<true}{<false>} +% *{<cstoken>}{<true}{<false>} + +\newrobustcmd{\ifpatchable}{% + \etb@dbg@trce\ifpatchable + \begingroup + \@makeother\#% + \@ifstar\etb@ifpatchable@i\etb@ifpatchable} + +\def\etb@ifpatchable#1#2{% + \endgroup + \etb@dbg@init{#1}% + \ifundef{#1} + {\etb@dbg@fail{def}\@secondoftwo} + {\etb@dbg@info{def}% + \ifdefmacro{#1} + {\etb@dbg@info{mac}% + \etb@ifscanable{#1} + {\etb@ifhashcheck{#2} + {\etb@dbg@info{tok}% + \etb@ifpattern{#1}{#2} + {\etb@dbg@info{pat}% + \etb@dbg@info{pos}\@firstoftwo} + {\etb@dbg@fail{pat}\@secondoftwo}} + {\etb@dbg@fail{hsh}\@secondoftwo}} + {\etb@dbg@fail{tok}\@secondoftwo}} + {\etb@dbg@fail{mac}\@secondoftwo}}} + +\def\etb@ifpatchable@i#1{% + \endgroup + \etb@dbg@init{#1}% + \ifundef{#1} + {\etb@dbg@fail{def}\@secondoftwo} + {\etb@dbg@info{def}% + \ifdefmacro{#1} + {\etb@dbg@info{mac}% + \ifdefparam{#1} + {\etb@dbg@info{prm}% + \etb@ifscanable{#1} + {\etb@dbg@info{tok}% + \etb@dbg@info{pos}\@firstoftwo} + {\etb@dbg@fail{tok}\@secondoftwo}} + {\etb@dbg@info{prl}% + \ifdefprotected{#1} + {\etb@dbg@info{pro}} + {}% + \etb@dbg@info{pos}\@firstoftwo}} + {\etb@dbg@fail{mac}\@secondoftwo}}} + +% [<prefix>]{<cstoken>}{<search>}{<replace>}{<success>}{<failure>} + +\newrobustcmd*{\patchcmd}{% + \etb@dbg@trce\patchcmd + \begingroup + \@makeother\#% + \etb@patchcmd} + +\newcommand{\etb@patchcmd}[4][########1]{% + \etb@ifpatchable{#2}{#3} + {\etb@dbg@succ{ret}% + \begingroup + \edef\etb@resrvda{% + \def\noexpand\etb@resrvda####1\detokenize{macro:}####2->####3&{% + #1\def\string#2####2{\noexpand\etb@resrvdb####3&}}% + \def\noexpand\etb@resrvdb####1\detokenize{#3}####2&{% + ####1\detokenize{#4}####2}% + \edef\noexpand\etb@resrvda{% + \noexpand\etb@resrvda\meaning#2&}}% + \etb@resrvda + \etb@scantoks\endgroup\etb@resrvda + \@firstoftwo} + {\@secondoftwo}} + +\def\etb@scantoks#1#2{% + \begingroup + \edef\etb@resrvda{\endgroup + \unexpanded{#1\makeatletter\scantokens}{#2}% + \catcode\number`\@=\the\catcode`\@\relax}% + \etb@resrvda} + +% {<cstoken>}{<code>} + +\newrobustcmd*{\apptocmd}{% + \etb@dbg@trce\apptocmd + \begingroup + \@makeother\#% + \etb@hooktocmd\etb@append} + +\newrobustcmd*{\pretocmd}{% + \etb@dbg@trce\pretocmd + \begingroup + \@makeother\#% + \etb@hooktocmd\etb@prepend} + +\long\def\etb@hooktocmd#1#2#3{% + \endgroup + \etb@dbg@init{#2}% + \ifundef{#2} + {\etb@dbg@fail{def}\@secondoftwo} + {\etb@dbg@info{def}% + \ifdefmacro{#2} + {\etb@dbg@info{mac}% + \ifdefparam{#2} + {\etb@dbg@info{prm}% + \etb@ifscanable{#2} + {\etb@ifhashcheck{#3} + {\etb@dbg@info{tok}% + \etb@dbg@succ{ret}% + \etb@hooktocmd@i{#1}{#2}{#3}% + \@firstoftwo} + {\etb@dbg@fail{hsh}\@secondoftwo}} + {\etb@dbg@fail{tok}\@secondoftwo}} + {\etb@dbg@info{prl}% + \ifdefprotected{#2} + {\etb@dbg@info{pro}% + \etb@dbg@succ{red}% + \protected} + {\etb@dbg@succ{red}}% + \edef#2{#1{\expandonce#2}{\unexpanded{#3}}}% + \@firstoftwo}} + {\etb@dbg@fail{mac}\@secondoftwo}}} + +\long\def\etb@hooktocmd@i#1#2#3{% + \begingroup + \edef\etb@resrvda{% + \def\noexpand\etb@resrvda####1\detokenize{macro}:####2->####3&{% + ####1\def\string#2####2{#1{####3}{\detokenize{#3}}}}% + \edef\noexpand\etb@resrvda{% + \noexpand\etb@resrvda\meaning#2&}}% + \etb@resrvda + \etb@scantoks\endgroup\etb@resrvda} + +\long\def\etb@append#1#2{#1#2} +\long\def\etb@prepend#1#2{#2#1} + +\newrobustcmd*{\tracingpatches}{% + \etb@info{Enabling tracing}% + \input{etoolbox.def}% + \global\let\tracingpatches\relax} +\@onlypreamble\tracingpatches + +\let\etb@dbg@trce\@gobble +\let\etb@dbg@init\@gobble +\let\etb@dbg@info\@gobble +\let\etb@dbg@succ\@gobble +\let\etb@dbg@fail\@gobble % {<numeral>} @@ -686,16 +968,16 @@ \expandafter\etb@rti@end \expandafter\number \expandafter\numexpr - \expandafter\etb@rti@prs\detokenize{#1}|\relax}} + \expandafter\etb@rti@prs\detokenize{#1}&\relax}} \def\etb@rti@prs#1#2{% - \ifx|#1% + \ifx% \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi {#1#2} - {\ifx|#2% + {\ifx% \expandafter\@firstoftwo \else \expandafter\@secondoftwo @@ -716,8 +998,8 @@ \expandafter\etb@rti@brk \fi} -\def\etb@rti@brk#1|{+\z@|-1} -\def\etb@rti@end#1|#2\relax{\ifblank{#2}{#1}{#2}} +\def\etb@rti@brk#1&{+\z@&-1} +\def\etb@rti@end#1\relax{\ifblank{#2}{#1}{#2}} \def\etb@rti@num#1{\csname etb@rmn@#1\endcsname} \chardef\etb@rmn@i=1 @@ -769,19 +1051,18 @@ \begingroup \edef\@tempa{\endgroup \long\csdef{#1}####1{\expandafter\noexpand - \csname etb@dolist@#1\endcsname####1\noexpand#2&}% - \long\csdef{etb@dolist@#1}####1\noexpand#2####2&{% + \csname etb@lst@#1\endcsname####1\noexpand#2&}% + \long\csdef{etb@lst@#1}####1\noexpand#2####2&{% \noexpand\ifblank{####1} {} {\noexpand\etb@doitem####1&}% \noexpand\ifblank{####2} {\noexpand\listbreak} {\expandafter\noexpand - \csname etb@dolist@#1\endcsname####2}&}}% + \csname etb@lst@#1\endcsname####2}&}}% \@tempa} \long\def\etb@doitem#1#2&{\do{#1#2}} - \newcommand*{\listbreak}{} \long\def\listbreak#1&{} @@ -850,37 +1131,42 @@ % {<code>} \newrobustcmd*{\AtEndPreamble}{\gappto\@endpreamblehook} -\@onlypreamble\AtEndPreamble \newcommand*{\@endpreamblehook}{} -\patchcmd\document - {\endgroup} - {\endgroup - \let\AtEndPreamble\@firstofone - \@endpreamblehook - \undef\@endpreamblehook} - {} - {\PackageInfo{etoolbox}{% - Patching \string\document\space not possible.\MessageBreak - Will try to fork \string\document\@gobble}% - \let\etb@document\document - \def\document{% - \endgroup - \let\AtEndPreamble\@firstofone - \@endpreamblehook - \undef\@endpreamblehook - \begingroup - \etb@document}} +\preto\document{% + \endgroup + \let\AtEndPreamble\@firstofone + \@endpreamblehook + \protected\def\AtEndPreamble{\@notprerr\@gobble}% + \undef\@endpreamblehook + \begingroup} % {<code>} -\newrobustcmd*{\AfterEndDocument}{\gappto\@afterdocumenthook} -\newcommand*{\@afterdocumenthook}{} +\newrobustcmd*{\AfterPreamble}{\AtBeginDocument} +\AtEndPreamble{\let\AfterPreamble\@firstofone} + +% {<code>} + +\newrobustcmd*{\AfterBeginDocument}{\gappto\@afterbegdochook} +\newcommand*{\@afterbegdochook}{} + +\appto\document{% + \let\AfterBeginDocument\@firstofone + \@afterbegdochook + \protected\def\AfterBeginDocument{\@notprerr\@gobble}% + \undef\@afterbegdochook + \ignorespaces} + +% {<code>} + +\newrobustcmd*{\AfterEndDocument}{\gappto\@afterenddochook} +\newcommand*{\@afterenddochook}{} \patchcmd\enddocument {\deadcycles} {\let\AfterEndDocument\@firstofone - \@afterdocumenthook + \@afterenddochook \deadcycles} {} {\PackageInfo{etoolbox}{% @@ -889,12 +1175,7 @@ \let\etb@@end\@@end \def\@@end{% \let\AfterEndDocument\@firstofone - \@afterdocumenthook + \@afterenddochook \etb@@end}} -% {<code>} - -\newrobustcmd*{\AfterPreamble}{\AtBeginDocument} -\AtEndPreamble{\let\AfterPreamble\@firstofone} - \endinput |