diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/etextools/etextools.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/etextools/etextools.dtx | 505 |
1 files changed, 95 insertions, 410 deletions
diff --git a/Master/texmf-dist/source/latex/etextools/etextools.dtx b/Master/texmf-dist/source/latex/etextools/etextools.dtx index c8c8520b0f2..22f33094f37 100644 --- a/Master/texmf-dist/source/latex/etextools/etextools.dtx +++ b/Master/texmf-dist/source/latex/etextools/etextools.dtx @@ -1,5 +1,5 @@ % \iffalse meta-comment -%%% etextools : e-TeX tools for LaTeX Users and package Writers (v.3.1) +%%% etextools : e-TeX tools for LaTeX Users and package Writers (v.3.1 - 2009/09/30) % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either @@ -38,7 +38,7 @@ \input docstrip.tex \Msg{************************************************************************} \Msg{* Installation} -\Msg{* Package: etextools 2009/07/14 v.3.1 e-TeX tools for LaTeX Users and package Writers} +\Msg{* Package: etextools 2009/09/30 v.3.1 e-TeX tools for LaTeX Users and package Writers} \Msg{************************************************************************} \keepsilent @@ -68,9 +68,8 @@ and etextools-examples.tex \generate{% \file{etextools.ins}{\from{etextools.dtx}{install}}% \file{etextools.sty}{\from{etextools.dtx}{package}}% - \file{etextools-examples.tex}{\from{etextools.dtx}{example}}% } -\askforoverwritetrue +\askforoverwritefalse \generate{% \file{etextools.drv}{\from{etextools.dtx}{driver}}% } @@ -99,7 +98,7 @@ and etextools-examples.tex \edef\thisfile{\jobname} \def\thisinfo{The \thispackage\ package -- an \eTeX{} package for \LaTeX{}} \def\thisrevision{3.1} -\def\thisdate{27 August 2009} +\def\thisdate{30 September 2009} \newcommand\makebookmark[1]{} %-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= \documentclass[a4paper,oneside]{ltxdockit} @@ -418,7 +417,8 @@ and etextools-examples.tex % \def\@Macro#1{\begin{macro}{#1}} % \newenvironment{Macro}[2][]{% % \expandafter\@Macro\expandafter{\@backslashchar#2} \cmdlabel{impl:#2}% -% \ifblank{#1}{\Check@FEList{#2}}{\Check@FEList{#1}}} +% \ifblank{#1}{\Check@FEList{#2}\cmdlabel{impl:#2}}% +% {\Check@FEList{#1}\cmdlabel{impl:#1}}} % {\end{macro}} % \def\Check@FEList#1{% % \ifinlist{#1}\FEIcmdlist \FEI @@ -427,8 +427,9 @@ and etextools-examples.tex % {\ifinlist{#1}\pdfFEcmdlist \pdfFE{}}}} % \everypar\expandafter{\the\everypar\seedesc{#1}\everypar{}}} % -% \newenvironment{Macro*}[1]{% -% \expandafter\@Macro\expandafter{\@backslashchar#1} \cmdlabel{impl:#1}} +% \newenvironment{Macro*}[2][]{% +% \expandafter\@Macro\expandafter{\@backslashchar#2}% +% \ifblank{#1}{\cmdlabel{impl:#2}}{\cmdlabel{impl:#1}}} % {\end{macro}} % \newlistof{command}{cmd}{\listcommandname}\let\listcommandname\@empty % \DefineVerbatimEnvironment{VerbLines}{Verbatim}{gobble=1,frame=lines,framesep=6pt,fontfamily=txtt,fontseries=b} @@ -953,7 +954,7 @@ and etextools-examples.tex % {\rmk \cs{ifdefcount} is used -- indirectly -- in the definition of \cmdref{getlistindex} and the other macros % for getting indexes: \cmdref{getcsvlistindex} etc.} % \fi -% \ClearPage* +% \ClearPage % % \cmditem[avoidvoid]+@{avoidvoid \tsptb avoidvoidcs} % \cmditem-{avoidvoid} [ replacement code ]{ cs-token / string } \FEII* @@ -998,7 +999,7 @@ and etextools-examples.tex % \cmditem-{avoidvoidcs\stform*}[ replacement code ]{ csname } \FEII* % % \csbf{avoidvoidcs}\FEII will do the same as the former (\cs{avoidvoid}) but the mandatory argument \prm{csname} -% is interpreted as a control sequence name. +% is interpreted as a control sequence name. \enlargethispage\baselineskip % Therefore, \textbfsf{you cannot test a \textvbbf{string} with \csbf{avoidvoidcs}!}§§ % \begin{VerbLines}[commandchars=$()] % ($red\avoidvoidcs){@undefined} ($nnn will expand to an empty string) @@ -1138,7 +1139,7 @@ and etextools-examples.tex % \end{VerbLines} % % {\rmk \cs{ifOneChar} is used in \cmdref{detokenizeChars} } -% +% % \cmditem-{ifOneCharWithBlanks}{ string }{ true }{ false } % % \csbf{ifOneCharWithBlanks}\FEII switches to \prm{true} if and only if \prm{string} contains a single \textsfbf{character} @@ -1434,7 +1435,7 @@ and etextools-examples.tex % % You should not test a \prm{string} which contains the following sequence:§ % \hfill\colorbox{ly}{$/__8$E$__{11}$n$__{11}$d$__{11}\S__7$S$__{11}$t$__{11}$r$__{11}$i$__{11}$n$__{11}$g$__{11}/__8$}\hfill\kern0pt\par -% +% % {\rmk nor a string which contains \CH{\chcat/8} because \chcat/8 has a special meaning for \thispackage-\cmdref*{ettl@nbk}.} % % \end{ltxsyntax} @@ -1664,7 +1665,7 @@ and etextools-examples.tex % \csbf{future\spot def}\notFE\ will read the following token with \csbf{future\blue let}. If that token is in the % \prm{list of allowed tokens}, then it will append it to \cs{macro} and continue, scanning the tokens one after another. % \end{ltxsyntax} -% +% % Until it founds a token which is not in the \prm{list of allowed tokens}. Then it stops reading % and executes the \prm{commands to expand after}. Those commands may use the \cs{macro} % just defined for analyse or whatever the user want. @@ -1732,7 +1733,7 @@ and etextools-examples.tex % \CSbf{switch} is purely expandable. See \Xpackage{boolexpr} for more information on \cs{switch}. % % \begin{ltxsyntax} -% \cmditem{futuredef\stform=}[ list of allowed tokens ]{ \cs{macro} }{ commands to expand after } +% \cmditem[starredfuturedef]{futuredef\stform=}[ list of allowed tokens ]{ \cs{macro} }{ commands to expand after } % \cmditem-{futuredef\stform*\stform=}[ list of allowed tokens ]{ \cs{macro} }{ commands to expand after } % % The \CH{\stform=} form\notFE\ of \cs{futuredef} is the same as \cs{futuredef} but the checking of single characters @@ -1741,7 +1742,7 @@ and etextools-examples.tex % only if the same character with the same ccategory code is found in the \prm{list of allowed tokens}: otherwise, \cs{futuredef} % stops reading and executes the \prm{commands to expand after}. % \end{ltxsyntax} -% +% % In general, we are not willing this behaviour and the \stform= form of \cs{futuredef} would probably never be used, unless you know % that the \prm{list of allowed tokens} is already detokenized... % Anyway, it was not difficult at all to \cmdref=[impl:futuredef=]{implement}. @@ -2054,7 +2055,7 @@ and etextools-examples.tex % very close to \LaTeX's |\@for|: see \cmdref{forcsvloop} for more explanation. % % \end{ltxsyntax} -% +% % \ClearPage % \Subsection{Loops into lists} % @@ -2209,11 +2210,11 @@ and etextools-examples.tex %(!nnn!rmk* N.B.: the items are not expanded.) % \end{VerbLines} % -% The \stform* star form is seldom used: it is there to inhibits the expansion of \prm{source: \itemitemitem*[{\stform[\blue],}]}. +% The \stform* star form is seldom used: it is there to inhibits the expansion of \prm{source: \itemitemitem*[{\stform[\blue],}]}. % But expansion occurs only if this parameter is a single control word... % \ClearPage % -% \cmditem[listtocsv]-{tokstolist} [ target: Listmacro ]{ source: tokenslistmacro \textsfsl{or} list of single tokens } +% \cmditem[tokstolist]-{tokstolist} [ target: Listmacro ]{ source: tokenslistmacro \textsfsl{or} list of single tokens } % \cmditem-{tokstolist\stform*}[ target: Listmacro ]{ source: list of single tokens } \FE* % % \csbf{tokstolist}\FE converts a list of tokens (no separator) into an internal \xpackage{etoolbox} list:§§ @@ -2457,7 +2458,7 @@ and etextools-examples.tex % \item but why {$\rred\mathbf8$} ? if someone changes the catcode of \CH{\stform[\rred]/} it is unlikely that she will choose % $\rred\mathbf8$ (the \textit{\rred math subscript} which has nothing to do with \stform[\rred]/...) whereas it is not so unlikely that % someone needs \CH{\stform[\rred]/} as a \emph{tab alignment character} (catcode $4$) or a \emph{math shift} (catcode $3$) -% or another special need (catcode $13$)... +% or another special need (catcode $13$)... Moreover, catcode $4$ may have indesirable side effects if read inside \cs{halign} or \cs{valign}. % Finally, we could have chosen {$\blue\mathbf7$} but then a sequence like: \CH{\stform[\blue]/$\mathbf{_7}$\stform[\blue]/$\mathbf{_7}$} % is read by \TeX{} like \CH{\stform[\blue]{\string^}$\mathbf{_7}$\stform[\blue]{\string^}$\mathbf{_7}$} with a very special meaning... % \end{enumerate} @@ -2475,6 +2476,7 @@ and etextools-examples.tex \TMP@EnsureCode{47}{8}% / \TMP@EnsureCode{167}{7}% § \TMP@EnsureCode{164}{7}% ¤ +\TMP@EnsureCode{95}{11}% _ \TMP@EnsureCode{42}{12}% * \TMP@EnsureCode{43}{12}% + \TMP@EnsureCode{45}{12}% - @@ -2492,7 +2494,7 @@ and etextools-examples.tex } \AtEndOfPackage{\ettl@AtEnd\undef\ettl@AtEnd} % \end{macrocode} -% +% % \Subsection{Some ``helper'' macros} % % \iffalse @@ -2531,7 +2533,7 @@ and etextools-examples.tex % \cs{ettl@char} expands to \prm{true} if its argument is a single character token. It is used in % \cmdref*{ettl@ifnextchar}. % \begin{macrocode} -\long\def\ettl@char#1{\csname ettl@\if\relax\expandafter\ettl@cdr\detokenize{#1}\@nil\relax +\long\def\ettl@char#1{\csname ettl@\if @\expandafter\ettl@cdr\detokenize{#1}\@nil @% 1\else2\fi of2\endcsname} % \end{macrocode} %\end{macro} @@ -2595,7 +2597,7 @@ and etextools-examples.tex % \cs{ettl@ney}\FEII is exactly |\ifnotempty| but with the syntax of |\ettl@nbk|: it may be used in place of |\ettl@nbk|: % \begin{macrocode} \long\def\ettl@ney#1//#2#3//{\romannumeral 0\csname @% - \if\relax\detokenize{#1}\relax first\else second\fi oftwo\endcsname + \if @\detokenize{#1}@first\else second\fi oftwo\endcsname { #2}{ #3}} % \end{macrocode} %\end{macro} @@ -2729,9 +2731,9 @@ and etextools-examples.tex {\expandafter@cmds{#2}{\expandafter\expandafter\expandafter}} {\expandafter\@swap\expandafter{#2}{#1}}} \long\def\expandafter@cmds#1#2#3{% - \ifsingletoken\expandafter@cmds{#1} + \ifsingletoken\expandaftercmds{#1} {\expandafter@cmds{#3}{\expandafter#2#2}} - {\@swap#2{#3}{#1}}} + {#2\@swap#2{#3}{#1}}} % \end{macrocode} % \end{Macro} % @@ -2933,7 +2935,7 @@ and etextools-examples.tex %<package>%% \ifdefmathchar { cs-token }{ true }{ false } \FEII % \fi % -%\begin{Macro*}[ifdefcount]{ifdefcount} +%\begin{Macro*}{ifdefcount} %\begin{Macro*}{ifdeftoks} %\begin{Macro*}{ifdefdimen} %\begin{Macro*}{ifdefskip} @@ -2942,7 +2944,7 @@ and etextools-examples.tex %\begin{Macro*}{ifdefmathchar} %\begin{Macro*}{ifdefblankspace} %\begin{Macro*}{ifdefthechar} -%\begin{Macro}{ifdeftheletter} +%\begin{Macro}[ifdefcount]{ifdeftheletter} % \cs{ettl@ifdef} will defined those five macros (and be undefined itself at the end): % \begin{macrocode} \def\ettl@ifdef[#1]{\expandafter\ettl@ifd@f\expandafter{#1}} @@ -3060,8 +3062,8 @@ and etextools-examples.tex % \cs{ifsingletoken} is a safe \cs{ifx}-test: % \begin{macrocode} \newcommand\ifsingletoken[2]{\csname @\ettl@firstspace{#2} - {\ettl@nbk#1#2//{second}{\if\relax\detokenize{#1#2}\relax first\else\ifx#1#2first\else second\fi\fi}//} - {\if\relax\detokenize\expandafter{\ettl@cdr#2\@nil}\relax + {\ettl@nbk#1#2//{second}{\if @\detokenize{#1#2}@first\else\ifx#1#2first\else second\fi\fi}//} + {\if @\detokenize\expandafter{\ettl@cdr#2\@nil}@% \expandafter\ettl@ifxsingle \else\expandafter\ettl@carcar \fi{#1}{#2}{first}{second}}% @@ -3079,8 +3081,8 @@ and etextools-examples.tex % \cs{ifOneToken} test if its argument contains only one token (possibly a space token): % \begin{macrocode} \newcommand\ifOneToken[1]{\romannumeral\csname rmn@\ettl@firstspace{#1} - {\ettl@nbk#1//{second}{\if\relax\detokenize{#1}\relax second\else first\fi}//} - {\if\relax\detokenize\expandafter{\ettl@cdr#1\@nil}\relax + {\ettl@nbk#1//{second}{\if @\detokenize{#1}@second\else first\fi}//} + {\if @\detokenize\expandafter{\ettl@cdr#1\@nil}@% first\else second\fi}oftwo\endcsname} % \end{macrocode} % \end{Macro} @@ -3089,13 +3091,13 @@ and etextools-examples.tex %<package> %<package>%% \ifsinglechar character{ string }{ true }{ false } % \fi -% +% % \begin{Macro}{ifsinglechar} % Test if \#2 is a single character equal to \#1: % \begin{macrocode} \long\def\ifsinglechar#1#2{\romannumeral\csname rmn@\ettl@firstspace{#2} - {\ettl@nbk#2//{second}{\if\relax\detokenize{#1#2}\relax first\else\ifx#1#2first\else second\fi\fi}//} - {\if\relax\detokenize\expandafter{\ettl@cdr#2\@nil}\relax + {\ettl@nbk#2//{second}{\if @\detokenize{#1#2}@first\else\ifx#1#2first\else second\fi\fi}//} + {\if @\detokenize\expandafter{\ettl@cdr#2\@nil}@% \expandafter\ettl@ifchar \else\expandafter\ettl@carcar \fi{#1}{#2}{first}{second}}% @@ -3117,8 +3119,8 @@ and etextools-examples.tex oftwo\endcsname} \else \newcommand\ifOneChar[1]{\romannumeral\csname rmn@\ettl@firstspace{#1} - {\ettl@nbk#1//{second}{\if\relax\detokenize{#1}\relax second\else first\fi}//} - {\if\relax\expandafter\ettl@cdr\detokenize{#1}\@nil\relax + {\ettl@nbk#1//{second}{\if @\detokenize{#1}@second\else first\fi}//} + {\if @\expandafter\ettl@cdr\detokenize{#1}\@nil @% first\else second\fi}oftwo\endcsname} \fi%\pdfmatch % \end{macrocode} @@ -3156,12 +3158,12 @@ and etextools-examples.tex \ettl@nbk#2//% {\ettl@nbk#1//% {\expandnexttwo\ettl@ifchar{\ettl@car#2\@nil}{\ettl@car#1\@nil}{first}{second}} - {\if\relax\detokenize{#1}\relax secondoftwo\ettl@csname\fi + {\if @\detokenize{#1}@secondoftwo\ettl@csname\fi \ettl@firstspace{#2}{first}{second}}//}% {\ettl@nbk#1//% - {\if\relax\detokenize{#2}\relax secondoftwo\ettl@csname\fi + {\if @\detokenize{#2}@secondoftwo\ettl@csname\fi \ettl@firstspace{#1}{first}{second}} - {\if\relax\detokenize{#1#2}\relax first\else second\fi}}//% + {\if @\detokenize{#1#2}@first\else second\fi}}//% oftwo\endcsname} % \end{macrocode} % \end{Macro} @@ -3175,8 +3177,8 @@ and etextools-examples.tex % \cs{ifiscs}\prm{string} expands \prm{true} only if \prm{string} is a single control-word: % \begin{macrocode} \newcommand\ifiscs[1]{\romannumeral\csname rmn@\ettl@nbk#1//% - {\if\relax\expandafter\ettl@cdr\detokenize{#1}\@nil\relax secondoftwo\ettl@csname\fi - \if\relax\detokenize\expandafter{\ettl@cdr#1\@nil}\relax + {\if @\expandafter\ettl@cdr\detokenize{#1}\@nil @secondoftwo\ettl@csname\fi + \if @\detokenize\expandafter{\ettl@cdr#1\@nil}@% \expandafter\ettl@firstspace \else secondoftwo\ettl@csname\fi{#1}{second}{first}} {second}//oftwo\endcsname} @@ -3224,11 +3226,11 @@ and etextools-examples.tex % \begin{Macro}{ifempty} % |\ifempty| is based on |\detokenize| and can manage with any argument. % \begin{macrocode} -\newcommand\ifempty[1]{\romannumeral\csname rmn@\if\relax\detokenize{#1}\relax +\newcommand\ifempty[1]{\romannumeral\csname rmn@\if @\detokenize{#1}@% first\else second\fi oftwo\endcsname} % \end{macrocode} % \end{Macro} -% +% % \iffalse %<package> %<package>%% \ifnotempty{ text }{ true }{ false } @@ -3237,11 +3239,11 @@ and etextools-examples.tex % \begin{Macro}{ifnotempty} % |\ifnotempty| is based on |\detokenize| and can manage with any argument. % \begin{macrocode} -\newcommand\ifnotempty[1]{\romannumeral\csname rmn@\if\relax\detokenize{#1}\relax +\newcommand\ifnotempty[1]{\romannumeral\csname rmn@\if @\detokenize{#1}@% second\else first\fi oftwo\endcsname} % \end{macrocode} % \end{Macro} -% +% % \iffalse %<package> %<package>%% \xifempty{ text }{ true }{ false } @@ -3258,7 +3260,7 @@ and etextools-examples.tex %<package> %<package>%% \ifnotblank{ text }{ true }{ false } % \fi -% +% % \begin{Macro}{ifnotblank} % \cs{ifnotblank} \CS{ifnotblank} |\ifnotblank| \CSbf{ifnotblank} \textvb{ifnotblank} reverses the test of \cs{ifblank}. % @@ -3446,7 +3448,7 @@ and etextools-examples.tex \fi%\pdfmatch % \end{macrocode} %\end{Macro} -% +% % \iffalse %<package> %<package>%% \DeclareStringFilter[\global]{ \StringFilterMacro }{ string } @@ -3473,15 +3475,6 @@ and etextools-examples.tex % \end{macrocode} %\end{Macro} % -%\begin{macro}{\ettl@strfilt@dot} \FE -% Used by |\ettl@strfilt@mod| to test if a character is a dot. -% \begin{macrocode} -\long\def\ettl@ifchardot#1{\csname\ettl@BasicFilter\ettl@ifchardot@filt.#1/End§String/\endcsname} -\long\def\ettl@ifchardot@filt#1.#2/End§String/{#1/#2} -% \end{macrocode} -%\end{macro} -% -% %\begin{macro}{\ettl@strfilt@mod} \FE % \cs{ettl@strfilt@mod} test the possible second modifier and choose the right macro to expand with % the right arguments: @@ -3623,7 +3616,7 @@ and etextools-examples.tex % \begin{macrocode} \long\def\ettl@BasicFilter#1#2#3/End§String/{\expandafter\ettl@B@sicFilter #1#3//#2/End§String//End§String/} \long\def\ettl@B@sicFilter#1/#2//#3/End§String/{@\ettl@nbk#3//% - {\if\relax\detokenize{#1#2}\relax first\else second\fi} + {\if @\detokenize{#1#2}@first\else second\fi} {second}//oftwo} % \end{macrocode} %\end{macro} @@ -3631,10 +3624,11 @@ and etextools-examples.tex % \begin{Macro}{FE@testopt} % Purely expandable |\@testopt|-like test: % \begin{macrocode} -\newcommand\FE@testopt[3]{\csname\ettl@BasicFilter\ettl@FE@testopt[#1/End§String/\endcsname +\newcommand\FE@testopt[3]{\ettl@FE@testopt#1/[/% {#2#1}% {#2[{#3}]{#1}}}%] -\long\def\ettl@FE@testopt#1[#2/End§String/{#1/#2} +\long\def\ettl@FE@testopt#1[#2/#3#{\csname @\if @\detokenize{#1#2}@% + first\else second\fi oftwo\endcsname} % \end{macrocode} % \end{Macro} % @@ -3645,10 +3639,11 @@ and etextools-examples.tex % \begin{Macro}{FE@ifstar} % Purely expandable |\@ifstar|-like test: % \begin{macrocode} -\newcommand\FE@ifstar[3]{\csname\ettl@BasicFilter\ettl@FE@ifstar*#1/End§String/\endcsname +\newcommand\FE@ifstar[3]{\ettl@FE@ifstar#1/*/% {#2}% {#3{#1}}} -\long\def\ettl@FE@ifstar#1*#2/End§String/{#1/#2} +\long\def\ettl@FE@ifstar#1*#2/#3#{\csname @\if @\detokenize{#1#2}@% + first\else second\fi oftwo\endcsname} % \end{macrocode} % \end{Macro} % @@ -3660,15 +3655,31 @@ and etextools-examples.tex %\begin{macro}{\FE@ifcharequal} \FE % This is the same as \cs{FE@ifstar} but for \CH{=} character (used in \cmdref*{DeclareStringFilter}): % \begin{macrocode} -\newcommand\FE@ifcharequal[3]{\csname\ettl@BasicFilter\ettl@FE@charequal=#1/End§String/\endcsname +\newcommand\FE@ifcharequal[3]{\ettl@FE@charequal#1/=/% {#2}% {#3{#1}}} -\long\def\ettl@FE@charequal#1=#2/End§String/{#1/#2} +\long\def\ettl@FE@charequal#1=#2/#3#{\csname @\if @\detokenize{#1#2}@% + first\else second\fi oftwo\endcsname} % \end{macrocode} %\end{macro} % % \iffalse %<package> +%<package>%% \ettl@strfilt@dot{ #1 } { \MacroWith= }{ \NormalMacro } % used by the string filters +% \fi +% +%\begin{macro}{\ettl@ifchardot} \FE +% Used by |\ettl@strfilt@mod| to test if a character is a dot. It is used internally and is not the same +% as |\FE@ifchar.| +% \begin{macrocode} +\newcommand\ettl@ifchardot[1]{\ettl@FE@chardot#1/./} +\long\def\ettl@FE@chardot#1.#2/#3#{\csname @\if @\detokenize{#1#2}@% + first\else second\fi oftwo\endcsname} +% \end{macrocode} +%\end{macro}% +% +% \iffalse +%<package> %<package>%% \FE@ifchar{ <Character> }{ #1 }{ \SpecialFormMacro }{ \NormalMacro } % \fi % \begin{Macro}{FE@ifchar} @@ -3697,7 +3708,7 @@ and etextools-examples.tex \expandafter[\romannumeral-`\q\ifnum#2<0 {#3}\fi]{#2}{#1+1}} % \end{macrocode} %\end{Macro} -% +% % \iffalse %<package> %<package>%% \ettl@supergobble{ p }{ q }{token_1}{token_2}...{token_p}{TOKEN_p+1}{token_p+2}...{token_p+q+1} @@ -3838,7 +3849,7 @@ and etextools-examples.tex \edef\1##1/##2/##3{##1\endgroup\unexpanded{#2}##3}% \edef\2##1/##2/##3{##1\endgroup\unexpanded{#3}##3}% \ifOneToken{#1} - {\csname ettl@\if\relax\expandafter\ettl@cdr\detokenize{#1}\@nil\relax % OneChar + {\csname ettl@\if @\expandafter\ettl@cdr\detokenize{#1}\@nil @% OneChar xifnch\else xifntk\fi\endcsname{#1}} {\2//{}}} % \end{macrocode} @@ -3922,7 +3933,7 @@ and etextools-examples.tex {\@ifchar={\ettl@futdef#1\unexpanded} {\@testopt{\ettl@futur@def#1#2}{}}}} \long\def\ettl@futur@def#1#2[#3]{% - \csname ettl@\if\relax\detokenize{#3}\relax1\else2\fi of2\endcsname + \csname ettl@\if @\detokenize{#3}@1\else2\fi of2\endcsname {\let \ettl@x \@empty \letcs \ettl@futur@def@collect{\@gobblescape#1@collectall}}% {\def \ettl@x {#3}\edef \ettl@y {#2{#3}}% \ifx\ettl@x\ettl@y \let\ettl@y\@gobble @@ -3984,7 +3995,7 @@ and etextools-examples.tex % \end{macrocode} %\end{macro} % -% \begin{macro}{futured@f (starred)} +% \begin{macro}{futured@f (starred)} \cmdlabel{impl:starredfuturedef} % \cs{ettl@futured@f} defines the \textsfsl{test-macro} (which is entitled to break the loop) and the \textsfsl{loop-macro}: % \begin{macrocode} \long\def\ettl@futured@f#1#2#3#4{% #1=detokenize #2=list, #3=macro result, #4=code-next @@ -4000,7 +4011,7 @@ and etextools-examples.tex \long\def\ettl@futured@f@space#1#2/Ne¤t/#3#4#5 {% \ettl@futur@def@collect#1#2/Ne¤t/{#3}{#4}{#5}{ }} % \end{macrocode} -% \cs{ettl@futured@f@collect} collects the next token which is appended to the argument of \cs{ettl@futured@f@test} (the \textsfsl{result}) +% \cs{ettl@futured@f@collect} collects the next token which is appended to the argument of \cs{ettl@futured@f@test} (the \textsfsl{result}) % if it is in the \prm{list of allowed tokens}, otherwise expansion is tried: % \begin{macrocode} \long\def\ettl@futured@f@collect#1#2/Ne¤t/#3#4#5#6{#2% @@ -4020,8 +4031,8 @@ and etextools-examples.tex \long\def\ettl@futured@f@space#1#2/Ne¤t/#3#4#5 {% \ettl@futur@def@collect#1#2/Ne¤t/{#3}{#4}{#5}{ }} % \end{macrocode} -% \cs{ettl@futured@f@try@expand} checks if the token shall be expanded, or if the loop shall be broken (in case the -% \prm{list of allowed tokens} is specified) or if this token shall be appended to the result +% \cs{ettl@futured@f@try@expand} checks if the token shall be expanded, or if the loop shall be broken (in case the +% \prm{list of allowed tokens} is specified) or if this token shall be appended to the result % (in case the \prm{list of allowed token} is empty): % \begin{macrocode} \long\def\ettl@futured@f@try@expand#1#2#3{% @@ -4075,12 +4086,16 @@ and etextools-examples.tex % \begin{macrocode} \newcommand\naturalloop[1]{\FE@testopt{#1}\ettl@naturalloop{\do}} \def\ettl@naturalloop[#1]#2#3{% - \ifnum\numexpr#2>0 \ExpandNext{\ettl@naturall@@p[{#1}]{#2-1}{1}{#3}}{#1[1]{#3}{#3}}% - \else\ettl@fi#3% + \ifnum\numexpr#2>0 \expandafter\@swaparg\expandafter{\romannumeral-`\q#1[0]{#3}{#3}}% + {\ettl@naturall@@p[{#1}]{#2-1}{0}{#3}} +% \ExpandNext{\ettl@naturall@@p[{#1}]{#2-1}{1}{#3}}{#1[1]{#3}{#3}}% + \else\@swap{\unexpanded{#3}}% \fi} \def\ettl@naturall@@p[#1]#2#3#4#5#6\fi{\fi% - \ifnum\numexpr#2>0 \ExpandNext{\ettl@naturall@@p[{#1}]{#2-1}{#3+1}{#4}}{#1[#3+1]{#4}{#5}}% - \else\ettl@fi#5% + \ifnum\numexpr#2>0 \expandafter\@swaparg\expandafter{\romannumeral-`\q% + \expandafter\@swap\expandafter{\expandafter[\number\numexpr#3+1]}{#1}{#4}{#5}}% + {\ettl@naturall@@p[{#1}]{#2-1}{#3+1}{#4}}% + \else\@swap{\unexpanded{#5}}% \fi} % \end{macrocode} % @@ -4168,7 +4183,7 @@ and etextools-examples.tex {}//}{}} % \end{macrocode} % \cs{ettl@getsinglelist} initiates the loop (we test if the list or the \prm{item} is empty first): -% \begin{macrocode} +% \begin{macrocode} \cmdlabel{impl:ettl@getsinglelist} \long\def\ettl@getsinglelist#1#2{\ettl@singlelist@loop{-1}{-1}{}#2//% {\ettl@expandafthree\ettl@singlelist@loop#1}% {\expandafter\ettl@singlelist@result\@thirdofthree}/End§List/} @@ -4260,10 +4275,10 @@ and etextools-examples.tex \fi{##4#3//}{\ettl@breakloop{}}% }{\ettl@breakloop{}}///End§List/}}% #1\long\def#5##1##2#3##3##4/##5##6##7/End§List/{% - \if\relax\detokenize{##2}\relax\expandafter\@gobbletwo\fi\@firstofone{##1{##2}}% + \if @\detokenize{##2}@\expandafter\@gobbletwo\fi\@firstofone{##1{##2}}% ##6{##1}##3##4//{##6}{##7}/End§List/} #1\long\def#6##1##2##3#3##4##5/##6##7##8/End§List/{% - \if\relax\detokenize{##3}\relax\expandafter\@gobbletwo\fi\@firstofone{##2[##1]{##3}}% + \if @\detokenize{##3}@\expandafter\@gobbletwo\fi\@firstofone{##2[##1]{##3}}% \expandafter##7\expandafter{\number\numexpr##1+1}{##2}##4##5//{##7}{##8}/End§List/} #1\protected\def#7{\@ifchar*% {\@ifchar+{\ettl@forloop{\expandafter#2\expandafter*\expandafter+}{[####1]####2}} @@ -4748,338 +4763,8 @@ and etextools-examples.tex %</package> % \end{macrocode} % -% \Subsection{Examples} -% -% \begin{macrocode} -%<*example> -\documentclass[11pt,french,a4paper,oneside]{scrartcl} -\usepackage[latin1]{inputenc} -\usepackage[T1]{fontenc} -\usepackage[american]{babel} -\usepackage{geometry,doc,ltxdockit,txfonts,fancyhdr,stmaryrd,graphicx,enumitem} -\usepackage{etextools} - -\usepackage{fancyvrb} - -\def\textvb#1{{\usefont{T1}{txtt}{m}{n}#1}} -\def\thispackage{\textsf{etextools}} -\hypersetup{colorlinks,pdfstartview={FitH}} -\geometry{top=1.5cm,bottom=1.2cm,left=2.5cm,right=1cm} -\fancyhf{} -\fancyhead[L]{Examples for the \thispackage package} -\pagestyle{fancy} -\DefineShortVerb{\|} -\catcode`\§ \active\def§{\par\nobreak\vskip-\parskip} -\makeatletter -\DefineVerbatimEnvironment{VerbLines}{Verbatim} - {gobble=1,commandchars=!(),frame=lines,framesep=6pt,fontfamily=txtt,fontseries=m} -\apptocmd\@list@extra{\parsep\parskip\topsep\z@\itemsep\z@}{}{} - -\def\smex{\leavevmode\hb@xt@2em{\hfil$\longrightarrow$\hfil}} -\def\FE{\setbox8\hbox{$\m@th\bindnasrepma$}% - \textcolor{fecc}{\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}} -\def\pdfFE{\setbox8\hbox{$\m@th\bindnasrepma$}% - \textcolor{fecc}{\llap{\textsf{pdf}\TeX{}\,}\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}} -\definecolor{fecc}{rgb}{.2,.6,.2} -\definecolor{dg}{rgb}{0.00,0.37,0.00} \newrobustcmd\dg{\color{dg}} \newrobustcmd\dgbf{\dg\bfseries} - -\newrobustcmd\blue{\color{blue} -\newrobustcmd\nnn{\normalfont\mdseries\upshape} - -\def\make@macro#1{\string\def\string#1\parameters@meaning#1\string{\strip@meaning#1\string}} -\newcommand\preline{\@ifstar{\@preline}{\hrulefill\par\@preline}} -\newcommand\@preline[2][1.5ex]{\noindent\hskip6pt\textvb{\make@macro#2}\par\ifblank{#1}{}{\vskip#1}} - -\ifdef\pdfstrcmp{\let\ifpdfTeX\iffalse}{\let\ifpdfTeX\iftrue} - - -\newcommand*\test{\@ifstar{\let\fe\pdfFE\testi}{\let\fe\FE\testi}} -\newcommand\testi[1]{% - \csname test#1\endcsname - \edef\usercmd{\strip@meaningcs{test#1}}\edef\result{\meaningcs{#1Test}}\noindent - \begin{tabular}{lp{15cm}} - \multicolumn{2}{l}{\textcolor{blue}{\llap{\fe\,\smex}\tt \usercmd}} \\[1.5ex] - \cmd{#1Test}= & \tt\bfseries\result - \end{tabular}\par\nobreak\hrulefill\null\goodbreak} - -\begin{document} -\title{etextools examples} -\subtitle{Examples for some macros provided by the \thispackage package} -\author{Florent Chervet} -\date{July 22, 2009} -\maketitle - -\tableofcontents\hyperdef{ettlex}{toc}{} - -\section{\cmd{expandnext} examples} - -\subsection{Test if the replacement text of macro is really empty} - -\def\xx{ } -\def\testexpandnext{% - \edef\expandnextTest{\string\xx\ is \expandnext\ifempty{\xx}{}{not} empty} -} -\preline\xx -\test{expandnext} - -\def\xx{} -\preline\xx -\test{expandnext} - -\ClearPage -\subsection{Test if the replacement text of a macro is blank (empty or spaces)} - -\def\xx{something} -\def\testexpandnext{% - \edef\expandnextTest{\string\xx\ is \expandnext\ifblank{\xx}{}{not} blank} -} -\preline\xx -\test{expandnext} - -\def\xx{ } -\preline\xx -\test{expandnext} - -\section{\cmd{ExpandNext} examples} - -Example of the main documentation file to reverse the order of the characters in a string: - -\def\swap#1#2{{#2#1}} \def\do[#1]#2{\swap #2}% \do{abcdef} -> \swap ab + cdef -> {ba}cdef - % \do{{ba}cdef} -> \swap {ba}c + def -> {cba}def - -\edef\result{\naturalloop[\do]{4}{12345}} -\ExpandNext{\def\RESULT}{\naturalloop[\do]{4}{12345}} - -\begin{VerbLines} -\def\swap#1#2{{#2#1}} \def\do[#1]#2{\swap #2} -\edef\result{\naturalloop[\do]{4}{12345}} -\meaning\result = !bfseries!meaning!result -\ExpandNext{\def\RESULT}{\naturalloop[\do]{4}{12345}} -\meaning\RESULT = !bfseries!meaning!RESULT -\end{VerbLines} - - -\subsection{Test the parameter string of a macro} - -The following commands create the filter for the string: "\textvb{[\#1]\#2"}":§ -\begin{VerbLines}[commandchars=!()] -\ExpandNext{(!blue\DeclareStringFilter\ParaFilt)} - {\ExpandAftercmds\@gobblescape{\expandafter\string\csname(!blue[#1]#2)\endcsname}} -\end{VerbLines} - -\ExpandNext{\DeclareStringFilter\ParaFilt} - {\ExpandAftercmds\@gobblescape{\expandafter\string\csname[#1]#2\endcsname}} - -\begin{enumerate}[label=\arabic*)~,noitemsep,nolistsep] -\item |\csname[#1]#2\endcsname| is expanded first -\item Immediately after: |\string| -\item At this stage: |\[#1]#2| (everything in category code other) is no more expandable -\item Then |\ExpandAftercmds| expands |\@gobblescape| -\item |[#1]#2| is no more expandable -\item Then |\ExpandNext| expands its first argument: |\DeclareStringFilter\ParaFilt{[#1]#2}| -\end{enumerate} - -Remark: |\detokenize| would have doubled the \# characters. Another possibility is to temporarily change the -category code of \# to 12 (other): -\begin{VerbLines}[commandchars=!()] -\begingroup\catcode`\#=12 - (!blue\DeclareStringFilter\ParaFilt{[#1]#2}) !nnn global declaration -\endgroup -\end{VerbLines} - -\def\macroA#1#2{Something to do with #1 and #2} -\def\macroB[#1]#2{Something to do with #1 and #2} - -\makeatother - -\preline[]\macroA -\preline*[]\macroB -\begin{Verbatim}[commandchars=!()] - !blue\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroA}{macro complies with [\#1]\#2} - !blue{macro does not comply } -\end{Verbatim} -\makeatletter -\hfill\textvb{\dgbf\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroA}{macro complies with [\#1]\#2} - {macro does not comply }} -\begin{Verbatim}[commandchars=!()] - !blue\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroB}{macro complies with [\#1]\#2} - !blue{macro does not comply } -\end{Verbatim} -\hfill\textvb{\dgbf\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroB}{macro complies with [\#1]\#2} - {macro does not comply }} -\par\hrulefill\par -\makeatother - - -\section{Testing characters} -\subsection{\cmd{ifsinglechar} versus \cmd{iffirstchar}} -\def\testifsinglechar{% - \edef\ifsinglecharTest{\ifsinglechar *{*hello*}{ single star }{ something else }} -}\hrulefill\par -\test{ifsinglechar} - -\def\testifsinglechar{% - \edef\ifsinglecharTest{\ifsinglechar *{ *}{ single star }{ something else }} -}\hrulefill\par -\test{ifsinglechar} - -\def\testifsinglechar{% - \edef\ifsinglecharTest{\ifsinglechar *{ * }{ single star }{ something else }} -}\hrulefill\par -\test{ifsinglechar} -{\small Note the space \textbf{after} the star $\uparrow$.} - -\def\testiffirstchar{% - \edef\iffirstcharTest{\iffirstchar *{*hello*}{ first char is star }{ something else }} -}\hrulefill\par -\test{iffirstchar} - -\subsection{Fully Expandable starred macros} -\def\starmacro#1{\FE@ifstar{#1}\starred\notstarred} -\def\starred#1{your "#1" will be processed by the STAR form} -\def\notstarred#1{your "#1" will be processed by the NORMAL form} -\def\testFE@ifstar{% - \edef\FE@ifstarTest{\starmacro{sample text}}} -\preline\starmacro -\preline*\starred -\preline*\notstarred -\test{FE@ifstar} - -\def\testFE@ifstar{% - \edef\FE@ifstarTest{\starmacro*{sample text}}} -\hrulefill\par -\test{FE@ifstar} - -\subsection{Fully Expandable macros with options} -\def\optmacro#1{\FE@testopt{#1}\OPTmacro{Mr.}} -\def\OPTmacro[#1]#2{#1 #2} -\def\testFE@testopt{% - \edef\FE@testoptTest{\optmacro{Woody Allen}}} -\preline\optmacro -\preline*\OPTmacro -\test{FE@testopt} - -\def\testFE@testopt{% - \edef\FE@testoptTest{\optmacro[Ms.]{Vanessa Paradis}}} -\hrulefill\par -\test{FE@testopt} - -\section{Lists management} - -\subsection{\cmd{csvloop} and \cmd{csvloop*} examples} - -\subsubsection{\cmd{makequotes}} -\def\makequotes#1{"#1"\space} -\def\testcsvloop{% - \edef\csvloopTest{\csvloop*[\makequotes]{hello,world}} -} -\preline\makequotes -\test{csvloop} - -\subsubsection{\cmd{detokenize}} -\def\testcsvloop{% - \edef\csvloopTest{\csvloop*[\detokenize]{\un,\deux}} -}\hrulefill\par -\test{csvloop} - -\subsubsection{\cmd{numexpr}} -\def\mylist{1,2,3,4,5}\def\BySeven#1{$#1\times 7 = \number\numexpr#1*7\relax$\par} -\def\testcsvloop{% - \edef\csvloopTest{\csvloop[\BySeven]\mylist}} -\preline\mylist -\preline*\BySeven -\test{csvloop} - -\subsubsection{protected \cmd{textbf}} -\def\testcsvloop{% - \protected@edef\csvloopTest{\csvloop*[\textbf]{hello ,my ,friends}} -}\hrulefill\par -\test{csvloop} - -\subsection{Index in lists and items by index} - -\subsubsection{\cmd{getlistitem}} -\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma} -\def\testgetlistitem{% - \edef\getlistitemTest{\getlistitem{4}\mylist} -}\hrulefill\par -\noindent\hskip6pt|\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex -\test{getlistitem} - -\subsubsection{\cmd{getlistindex}} -\ifpdfTeX -\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}} -\def\testgetlistindex{% - \edef\getlistindexTest{\getlistindex{alpha}\mylist} -}\hrulefill\par -\noindent\hskip6pt|\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex -\test*{getlistindex} - -\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}} -\def\testgetlistindex{% - \edef\getlistindexTest{\getcsvlistindex*{alpha}{one,two,three,four,five,alpha,beta}} -}\hrulefill\par -\test*{getlistindex} -\fi - -\hrulefill\par -\getlistindex[\myindex]{alpha}\mylist -{\color{blue}\noindent\hskip6pt\llap\smex|\getlistindex[\myindex]{alpha}\mylist|\par\vskip1.5ex} -{\tt\string\myindex=\quad\textbf{\meaning\myindex}} -\hrulefill\par\vskip.5ex - -\hrulefill\par -\newcount\myindex -\getcsvlistindex*[\myindex]{alpha}{one,two,three,four,five,alpha,beta} -\noindent\hskip6pt|\newcount\myindex|\par -{\color{blue}\noindent\hskip6pt\llap\smex|\getcsvlistindex*[\myindex]{alpha}{one,two,three,four,five,alpha,beta}|}\par\vskip.5ex -{\tt\string\the\string\myindex=\qquad\textbf{\the\myindex}} -\hrulefill\par\vskip.5ex - -\subsubsection{\cmd{xgetlistindex}} -\ifpdfTeX -\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}} -\def\x{beta} -\def\testxgetlistindex{% - \edef\xgetlistindexTest{\xgetlistindex{\x}\mylist} -}\hrulefill\par -\noindent\hskip6pt|\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex -\preline*\x -\test*{xgetlistindex} -\fi - -\subsubsection{\cmd{getlistindex} with \cmd{ifcase}} - -\leavevmode\vadjust{Always purely expandable (no need of |\pdfstrcmp|, comparison done by |\ifx|):} -\hrulefill\par\noindent -\llap{\FE\,\smex}\par\vskip-2.5\baselineskip\strut -\begin{Verbatim} - \ifcase \gettokslistindex*{D}{LRDF\relax O} - Problem - \or What do to if L - \or What do to if R - \or What do to if D - \or What do to if F - \or What do to if \relax - \or What do to if O - \fi -\end{Verbatim} - -{\tt Result=\qquad\bfseries -\ifcase\gettokslistindex*{D}{LRDF} - Problem -\or What do to if L -\or What do to if R -\or What do to if D -\or What do to if F -\fi}\par -\hrulefill\par\vskip.5ex - -\end{document} -%</example> -% \end{macrocode} -% -% \Section*{Revision history} \addcontentsline{toc}{section}{\texorpdfstring\dr{}\hskip\dimexpr\cftsecnumwidth-4pt Revision history}^^A not in .cmd file +% \Section*{Revision history} +% \addcontentsline{toc}{section}{\texorpdfstring\dr{}\hskip\dimexpr\cftsecnumwidth-4pt Revision history}^^A not in .cmd file % % \begin{changelog}\footnotesize % @@ -5088,7 +4773,7 @@ category code of \# to 12 (other): % \end{release} % % \begin{release}{3.0}{2009-09-09} -% \item Definition of \cmdref{DeclareStringFilter}, \cmdref{[FE@modifiers} and \cmdref{ettl@supergobble} +% \item Definition of \cmdref{DeclareStringFilter}, \cmdref{FE@modifiers} and \cmdref{ettl@supergobble} % % \end{release} % @@ -5120,7 +4805,7 @@ category code of \# to 12 (other): % \item % Addition of \cmdref{csvdel}, \cmd{csvedel}, \cmd{csvgdel} and \cmd{csvxdel} % \item -% Optimization of \cmdref{getlistitem} and \cmdref{getlistindex} (and csv versions either) +% Optimization of \cmdref{getlistindex} and \cmdref{getcsvlistindex} % \end{release} % % \begin{release}{2t}{2009-08-15} |