summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/etextools
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/etextools')
-rw-r--r--Master/texmf-dist/tex/latex/etextools/etextools.sty68
1 files changed, 53 insertions, 15 deletions
diff --git a/Master/texmf-dist/tex/latex/etextools/etextools.sty b/Master/texmf-dist/tex/latex/etextools/etextools.sty
index 93f0792044b..0a2382ba988 100644
--- a/Master/texmf-dist/tex/latex/etextools/etextools.sty
+++ b/Master/texmf-dist/tex/latex/etextools/etextools.sty
@@ -18,7 +18,8 @@
%%
%% This work consists of the main source file etextools.dtx
%% and the derived files
-%% etextools.sty, etextools.pdf, etextools.ins,
+%% etextools.sty, etextools.pdf, etextools.ins,
+%% and etextools-examples.tex
%%
%%% etextools : more e-TeX useful tools for LaTeX package writers
%%% Florent CHERVET
@@ -33,6 +34,8 @@
\catcode`\ =10
\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}
\newcommand*\@gobblescape{\expandafter\@gobble\string}
\newcommand\str@gobblescape[1]{\expandafter\deblank\expandafter{%
\expandafter\@gobble\detokenize{#1}}}
@@ -83,28 +86,28 @@
\begingroup\catcode`\&=3
\gdef\etextools@defcmdparser#1#2{%
\begingroup
+ \def\`##1`{\expandafter\noexpand\csname ##1\endcsname}%
\protected@edef\defineparser{\endgroup
\long\def#1####1{\noexpand\FE@ifstar{####1}
- {\noexpandcs{ettl@lst@star\string#1}}
- {\noexpandcs{ettl@lst@nost\string#1}}}%
+ {\`ettl@lst@star\string#1`}
+ {\`ettl@lst@nost\string#1`}}%
\long\csdef{ettl@lst@star\string#1}####1{\noexpand\FE@testopt{####1}
- {\noexpandcs{ettl@lst@star@pt\string#1}}{\noexpand\do}}%
+ {\`ettl@lst@star@pt\string#1`}{\noexpand\do}}%
\long\csdef{ettl@lst@nost\string#1}####1{\noexpand\FE@testopt{####1}
- {\noexpandcs{ettl@lst@nost@pt\string#1}}{\noexpand\do}}%
+ {\`ettl@lst@nost@pt\string#1`}{\noexpand\do}}%
\long\csdef{ettl@lst@star@pt\string#1}[####1]####2{%
- \noexpandcs{ettl@lst\string#1}{####2}{####1}}%
+ \`ettl@lst\string#1`{####2}{####1}}%
\long\csdef{ettl@lst@nost@pt\string#1}[####1]####2{%
- \noexpandafter\noexpandcs{ettl@lst\string#1}\noexpandafter{%
- ####2}{####1}}%
+ \noexpandafter\`ettl@lst\string#1`\noexpandafter{####2}{####1}}%
\long\csdef{ettl@lst\string#1}####1####2{%
- \noexpandcs{ettl@lst@\string#1}{####2}####1\noexpand#2&}%
- \long\csdef{ettl@lst@\string#1}####1####2\noexpand#2####3&{%
+ \`ettl@lst@\string#1`{####2}####1\unexpanded{#2}&}%
+ \long\csdef{ettl@lst@\string#1}####1####2\unexpanded{#2}####3&{%
\noexpand\ifblank{####2}
{}
{\noexpand\ettl@lst@doitem{####1}{####2}}%
\noexpand\ifblank{####3}
{\noexpand\ettl@listbreak}
- {\noexpandcs{ettl@lst@\string#1}{####1}####3}&}%
+ {\`ettl@lst@\string#1`{####1}####3}&}%
}\defineparser}%
\long\gdef\ettl@lst@doitem#1#2{#1{#2}}%
\long\gdef\ettl@listbreak#1&{}%
@@ -113,14 +116,19 @@
\begingroup\catcode`\|=3
\gdef\do{\DeclareCmdListParser\listloop{|}\undef\do}\aftergroup\do
\endgroup
-\newcommand\csvtolist[1]{\FE@ifstar{#1}\star@csvtolist\nost@csvtolist}
-\def\star@csvtolist#1{\csvloop*[{\unexpanded{\listadd#1}}]}
-\def\nost@csvtolist#1{\csvloop[{\unexpanded{\listadd#1}}]}
+\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\star@csvtolistadd#1#2{\ifblank{#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}}
\newrobustcmd\listxdel[2]{\begingroup
\protected@edef\@listxdel{\endgroup
- \unexpanded{\@listdel\def#1}{#2}%
+ \unexpanded{\@listdel\gdef#1}{#2}%
}\@listxdel}
\begingroup\catcode`\|=3\catcode`\&=3
\long\gdef\@listdel#1#2#3{%
@@ -135,6 +143,36 @@
\expandafter\@tempx\unexpanded\expandafter{#2}&}%
}\@redef}% end of \@listdel
\endgroup
+\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{}}
+ {\ettl@xgetlistindex\expandnext}}
+\gdef\ettl@xgetlistindex#1#2#3{\begingroup
+ \protected@edef\next{\endgroup\unexpanded{\ettl@getlistindex{#1}{#2}}{#3}%
+ }\next}
+\gdef\ettl@getlistindex#1#2#3{\begingroup#1\ettl@get@list@idx{#3}{#2}{\numexpr1}}
+\gdef\ettl@get@list@idx#1#2#3{% #1=expanded list, #2=item, #3=index
+ \ifblank{#1}0% the (remainder of) the list is empty
+ {\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}}}}
+\endgroup% catcode group
+\newcommand\getlistitem[1]{\FE@ifstar{#1}\ettl@getlistitem
+ {\expandnext\ettl@getlistitem}}
+\begingroup\catcode`\&=3
+\long\gdef\ettl@getlistitem#1#2{%#1=listmacro, #2=index
+ \ettl@get@list@item{#1}{\number\numexpr#2}}
+\long\gdef\ettl@get@list@item#1#2{%
+ \ifblank{#1}{}
+ {\ifnum#2=1 \ettl@afterelsefi
+ \expandonce{\ettl@list@first@item#1&}
+ \else\ifnum#2>0 \ettl@afterfifi
+ \expandnext\ettl@getlistitem{\ettl@list@other@item#1&}{#2-1}%
+ \fi\fi}}
+\endgroup
\endinput
%%