summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/etextools
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-08-14 23:52:07 +0000
committerKarl Berry <karl@freefriends.org>2009-08-14 23:52:07 +0000
commite5bc967eb0517b8377d70914cc45484e5f4f2c7c (patch)
treec84dda99e2c37af655bc79627867111ec6bb2ba9 /Master/texmf-dist/tex/latex/etextools
parent3cda51c4ea4ac2affd9b693c6f071d884ab6b951 (diff)
etextools (11aug09)
git-svn-id: svn://tug.org/texlive/trunk@14676 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/etextools')
-rw-r--r--Master/texmf-dist/tex/latex/etextools/etextools.sty112
1 files changed, 82 insertions, 30 deletions
diff --git a/Master/texmf-dist/tex/latex/etextools/etextools.sty b/Master/texmf-dist/tex/latex/etextools/etextools.sty
index 0a2382ba988..e11696396a5 100644
--- a/Master/texmf-dist/tex/latex/etextools/etextools.sty
+++ b/Master/texmf-dist/tex/latex/etextools/etextools.sty
@@ -22,7 +22,6 @@
%% and etextools-examples.tex
%%
%%% etextools : more e-TeX useful tools for LaTeX package writers
-%%% Florent CHERVET
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesPackage{etextools}
[2009/07/14 v2e e-TeX more useful tools for LaTeX package writers]
@@ -32,34 +31,49 @@
\AtEndOfPackage{\ettl@restore@space@catcode
\let\ettl@restore@space@catcode\ettl@undefined}
\catcode`\ =10
+
+% A few helper macros
\long\def\ettl@afterelse#1\else#2\fi{\fi#1}
\long\def\ettl@afterfi#1\fi{\fi#1}
\long\def\ettl@afterfifi#1\fi\fi{\fi\fi#1}
\long\def\ettl@afterelsefi#1\else#2\fi\fi{\fi#1}
+\begingroup\catcode`\|=4
+\long\gdef\ettl@cdr#1#2|{#2}
+\endgroup
+
\newcommand*\@gobblescape{\expandafter\@gobble\string}
\newcommand\str@gobblescape[1]{\expandafter\deblank\expandafter{%
\expandafter\@gobble\detokenize{#1}}}
-
\newcommand*\noexpandcs[1]{\expandafter\noexpand\csname #1\endcsname}
\newcommand\noexpandafter{\noexpand\expandafter}
+
+% \expandnext : expansion control
+% level 1 : \expandnext#1{...} <=> \expandafter#1\expandafter{...}
+% level 2 : \expandnext\expandnext#1{...} etc.
\newcommand\expandnext[2]{%
\ifx#1\expandnext
\ettl@afterelse\expandafter\expandafter\expandafter
- \expandafter\@expandnext{#2}{\expandafter\expandafter\expandafter}
- \else\ettl@afterfi\expandafter#1\expandafter{#2}
+ \expandafter\@expandnext{#2}{\expandafter\expandafter\expandafter}%
+ \else\ettl@afterfi\expandafter#1\expandafter{#2}%
\fi}
\long\def\@expandnext#1#2#3{%
\ifx#1\expandnext
\expandafter\ettl@afterelse\expandafter\expandafter\expandafter
- \expandafter\@expandnext{#3}{\expandafter#2#2}
+ \expandafter\@expandnext{#3}{\expandafter#2#2}%
\else
- \expandafter\ettl@afterfi#2#1#2{#3}
+ \expandafter\ettl@afterfi#2#1#2{#3}%
\fi}
+
\newcommand\deblank{}
-\begingroup\catcode`\&=3% a & as a math shift
-\long\gdef\deblank#1{\@deblank#1 &}
-\long\gdef\@deblank#1 #2&{\ifblank{#2}{#1}{#1\@deblank#2 &}}
-\endgroup
+\newcommand\ifempty{}
+\begingroup\catcode`\|=4% a | as a tab array
+\long\gdef\deblank#1{\@deblank#1 |}
+\long\gdef\@deblank#1 #2|{\ifblank{#2}{#1}{#1\@deblank#2 |}}
+
+% \ifempty{ text }{ true }{ false }
+\long\gdef\ifempty#1{\csname @\ifx|#1|first\else second\fi oftwo\endcsname}
+\endgroup% catcode group
+
\newrobustcmd\xifblank[1]{\begingroup
\protected@edef\@xifblank{\endgroup
\noexpand\ifblank{#1}%
@@ -74,16 +88,31 @@
\ettl@afterelse\ifblank{#2}\@secondoftwo\@firstoftwo
\else \expandafter\@secondoftwo
\fi}
-\newcommand\ifsinglechar[2]{%
- \expandnext\expandnext\ifblank{\expandafter\@cdr\string#2 \@nil}
+\newcommand\ifsinglechar{}
+\begingroup\catcode`\|=4
+\long\gdef\ifsinglechar#1#2{%
+ \csname @\expandafter\expandafter\expandafter\ifx
+ \expandafter\expandafter\expandafter|%
+ \expandafter\ettl@cdr\string#2||first\else second\fi
+ oftwo\endcsname
{\iffirstchar{#1}{#2}}
\@secondoftwo}
+\endgroup% catcode group
+
+%\FE@testopt{#1}{commands}{default option}
\newcommand\FE@testopt[3]{\ifsinglechar [{#1}{#2#1}{#2[{#3}]{#1}}}
+
+%\FE@ifstar{#1}{\StarredMacro}{\NotStarredMacro}
\newcommand\FE@ifstar[3]{\ifsinglechar *{#1}{#2}{#3{#1}}}
+
+%% \iffalse
+
+% \DeclareCmdListParser : general constructor for command-list parsers
+% \DeclareCmdListParser\ParserName{separator}
\newrobustcmd*\DeclareCmdListParser[2]{%
\@ifdefinable#1
{\expandafter\etextools@defcmdparser\expandafter{#1}{#2}}}
-\begingroup\catcode`\&=3
+\begingroup\catcode`\&=3\catcode`\`=3
\gdef\etextools@defcmdparser#1#2{%
\begingroup
\def\`##1`{\expandafter\noexpand\csname ##1\endcsname}%
@@ -112,27 +141,46 @@
\long\gdef\ettl@lst@doitem#1#2{#1{#2}}%
\long\gdef\ettl@listbreak#1&{}%
\endgroup
+
+
+% \csvloop[\command]\csvListMacro
+% \csvloop*[\command]{item,item,item}
\DeclareCmdListParser\csvloop{,}
\begingroup\catcode`\|=3
- \gdef\do{\DeclareCmdListParser\listloop{|}\undef\do}\aftergroup\do
-\endgroup
-\newcommand\csvtolist{\@ifstar\star@csvtolist\nost@csvtolist}
-\def\star@csvtolist#1{\let#1\@empty\csvloop*[{\unexpanded{\listadd#1}}]}
-\def\nost@csvtolist#1{\let#1\@empty\csvloop[{\unexpanded{\listadd#1}}]}
-\newcommand\csvtolistadd{\@ifstar\star@csvtolistadd\nost@csvtolistadd}
+ \def\do{\DeclareCmdListParser\listloop{|}}%
+\expandafter\endgroup\do
+
+%\csvtolist\csvListMacro
+%\csvtolist*{item,item,item}
+\newcommand\csvtolist{\@ifstar\star@csvtolist\nost@csvtolist}%
+\def\star@csvtolist#1{\let#1\@empty\csvloop*[{\unexpanded{\listadd#1}}]}%
+\def\nost@csvtolist#1{\let#1\@empty\csvloop[{\unexpanded{\listadd#1}}]}%
+
+%\csvtolistadd\csvListMacro
+%\csvtolistadd*{item,item,item}
+\newcommand\csvtolistadd{\@ifstar\star@csvtolistadd\nost@csvtolistadd}%
\def\star@csvtolistadd#1#2{\ifblank{#2}
- {\let#1\@empty}{\csvloop*[{\unexpanded{\listadd#1}}]{#2}}}
+ {\let#1\@empty}{\csvloop*[{\unexpanded{\listadd#1}}]{#2}}}%
\def\nost@csvtolistadd#1#2{\ifblank{#2}
- {\let#1\@empty}{\csvloop[{\unexpanded{\listadd#1}}]{#2}}}
-\newrobustcmd\listdel[2]{\@listdel\def{#1}{#2}}
-\newrobustcmd\listgdel[2]{\@listdel\gdef{#2}{#2}}
+ {\let#1\@empty}{\csvloop[{\unexpanded{\listadd#1}}]{#2}}}%
+
+%\listdel\listMacro{item}
+%\listgdel\listMacro{item}
+%\listedel\listMacro{item}
+%\listxdel\listMacro{item}
+\newrobustcmd\listdel[2]{\@listdel\def{#1}{#2}}%
+\newrobustcmd\listgdel[2]{\@listdel\gdef{#1}{#2}}%
\newrobustcmd\listxdel[2]{\begingroup
\protected@edef\@listxdel{\endgroup
- \unexpanded{\@listdel\gdef#1}{#2}%
- }\@listxdel}
- \begingroup\catcode`\|=3\catcode`\&=3
- \long\gdef\@listdel#1#2#3{%
- \begingroup
+ \unexpanded{\@listdel\gdef{#1}}{#2}%
+ }\@listxdel}%
+\newrobustcmd\listedel[2]{\begingroup
+ \protected@edef\@listedel{\endgroup
+ \unexpanded{\@listdel\def{#1}}{#2}%
+ }\@listedel}
+\begingroup\catcode`\|=3\catcode`\&=3
+\long\gdef\@listdel#1#2#3{%
+\begingroup
\def\@tempa##1|#3|##2&{##1|##2\@tempb}%
\def\@tempb|##1|\@tempb##2|\@tempb{%
\ifblank{##2}{\unexpanded{##1}}
@@ -143,9 +191,10 @@
\expandafter\@tempx\unexpanded\expandafter{#2}&}%
}\@redef}% end of \@listdel
\endgroup
+
+
+% \getlistindex (result in \indexinlist)
\begingroup\catcode`\|=3\catcode`\&=3
-\gdef\ettl@list@first@item#1|#2&{#1}
-\gdef\ettl@list@other@item#1|#2&{#2}
\gdef\getlistindex#1{\FE@ifstar{#1}{\ettl@getlistindex{}}
{\ettl@getlistindex\expandnext}}
\gdef\xgetlistindex#1{\FE@ifstar{#1}{\ettl@xgetlistindex{}}
@@ -159,6 +208,8 @@
{\expandnext\ifstrequal{\ettl@list@first@item#1&}{#2}
{\endgroup\edef\indexinlist{\number#3\relax}}
{\expandnext\ettl@get@list@idx{\ettl@list@other@item#1&}{#2}{#3+1}}}}
+\gdef\ettl@list@first@item#1|#2&{#1}
+\gdef\ettl@list@other@item#1|#2&{#2}
\endgroup% catcode group
\newcommand\getlistitem[1]{\FE@ifstar{#1}\ettl@getlistitem
{\expandnext\ettl@getlistitem}}
@@ -174,6 +225,7 @@
\fi\fi}}
\endgroup
+
\endinput
%%
%% End of file `etextools.sty'.