summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/etextools/etextools.dtx
blob: 6dded5c5e0a0f5cc8108484fe58bdbd621190f8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
% \iffalse meta-comment
%%% etextools : more e-TeX useful tools for LaTeX package writers (v.
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any later
% version. The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
%
% This work consists of the main source file etextools.dtx
% and the derived files
%        etextools.sty, etextools.pdf, etextools.ins,
% and    etextools-examples.tex
%
% Unpacking:
%    (a) If etextools.ins is present:
%           etex etextools.ins
%    (b) Without etextools.ins:
%           etex etextools.dtx
%    (c) If you insist on using LaTeX
%           latex \let\install=y\input{etextools.dtx}
%        (quote the arguments according to the demands of your shell)
%
% Documentation:
%           (pdf)latex etextools.dtx
%           (pdf)latex etextools-examples.tex
%<*ignore>
\begingroup
  \def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
         \ifx\csname processbatchFile\endcsname\relax\else1\fi
         \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: etextools 2009/07/14 v2h e-TeX more useful tools for LaTeX package writers}
\Msg{************************************************************************}

\keepsilent
\askforoverwritefalse

\let\MetaPrefix\relax
\preamble

This is a generated file.

Copyright (C) 2009 by Florent Chervet <florent.chervet@free.fr>

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3 of this license or (at your option) any later
version. The latest version of this license is in
   http://www.latex-project.org/lppl.txt

This work consists of the main source file etextools.dtx
and the derived files
      etextools.sty, etextools.pdf, etextools.ins,
and   etextools-examples.tex

\endpreamble
\let\MetaPrefix\DoubleperCent

\generate{%
  \file{etextools.ins}{\from{etextools.dtx}{install}}%
  \file{etextools.sty}{\from{etextools.dtx}{package}}%
  \file{etextools-examples.tex}{\from{etextools.dtx}{example}}%
}

\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{*     etextools.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `etextools.dtx'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\edef\thisfile{\jobname}
\def\thisinfo{The \thispackage\ package -- an \eTeX{} package for \LaTeX{}}
\documentclass[a4paper,oneside]{ltxdockit}
\usepackage[latin9]{inputenc}
\usepackage[american]{babel}
\usepackage{doc,tocloft,stmaryrd,amsmath,graphics,geometry,fancyhdr,framed,bbding,trace,embedfile,etoolbox,marvosym,fancyvrb}
\CodelineNumbered\CodelineIndex
\embedfile{\thisfile.dtx}
\geometry{left=4.5cm,marginparwidth=14pt,right=2cm,totalheight=26.5cm}
\titlepage{%
  title={The \sty{etextools} package},
  subtitle={An \etex package providing useful tools for LaTeX Users \\ and package Writers},
  url={http://www.ctan.org/tex-archive/macros/latex/contrib/etextools/},
  author={Florent CHERVET},
  email={florent.chervet@free.fr},
  revision={2\:$\boldsymbol{\eta}$},
  date={12 août 2009}}
\hypersetup{%
  hyperindex=true,
  pdftitle={The etextools package},
  pdfsubject={An e-TeX package for more useful tools for LaTeX package writers},
  pdfauthor={Florent CHERVET},
  colorlinks,linkcolor=reflink,
  pdfkeywords={tex, e-tex, latex, package, programming},
  bookmarksopen=true,bookmarksopenlevel=2}
\begin{document}
   \DocInput{\thisfile.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \DoNotIndex{\begin,\CodelineIndex,\CodelineNumbered,\def,\DisableCrossrefs,\if}
% \DoNotIndex{\DocInput,\documentclass,\EnableCrossrefs,\end,\GetFileInfo}
% \DoNotIndex{\NeedsTeXFormat,\OnlyDescription,\RecordChanges,\usepackage}
% \DoNotIndex{\ProvidesClass,\ProvidesPackage,\ProvidesFile,\RequirePackage}
% \DoNotIndex{\filename,\fileversion,\filedate,\let}
% \DoNotIndex{\@listctr,\@nameuse,\csname,\else,\endcsname,\expandafter}
% \DoNotIndex{\gdef,\global,\if,\item,\newcommand,\nobibliography}
% \DoNotIndex{\par,\providecommand,\relax,\renewcommand,\renewenvironment}
% \DoNotIndex{\stepcounter,\usecounter,\nocite,\fi}
% \DoNotIndex{\@fileswfalse,\@gobble,\@ifstar,\@unexpandable@protect}
% \DoNotIndex{\AtBeginDocument,\AtEndDocument,\begingroup,\endgroup}
% \DoNotIndex{\frenchspacing,\MessageBreak,\newif,\PackageWarningNoLine}
% \DoNotIndex{\protect,\string,\xdef,\ifx,\texttt,\@biblabel,\bibitem}
% \DoNotIndex{\z@,\wd,\wheremsg,\vrule,\voidb@x,\verb,\bibitem}
% \DoNotIndex{\FrameCommand,\MakeFramed,\FrameRestore,\hskip,\hfil,\hfill,\hsize,\hspace,\hss,\hbox,\hb@xt@,\endMakeFramed,\escapechar}
% \DoNotIndex{\do,\date,\if@tempswa,\@tempdima,\@tempboxa,\@tempswatrue,\@tempswafalse,\ifdefined,\ifhmode,\ifmmode,\cr}
% \DoNotIndex{\box,\author,\advance,\multiply,\Command,\outer,\next,\leavevmode,\kern,\title,\toks@,\trcg@where,\tt}
% \DoNotIndex{\the,\width,\star,\space,\section,\subsection,\textasteriskcentered,\textwidth}
% \DoNotIndex{\",\:,\@empty,\@for,\@gtempa,\@latex@error,\@namedef,\@nameuse,\@tempa,\@testopt,\@width,\\,\m@ne,\makeatletter,\makeatother}
% \DoNotIndex{\maketitle,\parindent,\setbox,\x,\kernel@ifnextchar}
% \DoNotIndex{\un,\deux,\xx,\tt,\title,\times,\texttt,\tableofcontents,\&,\@preline,\@redef,\\,\`,\|,\ ,\author}
% \DoNotIndex{\bfseries,\clearpage,\cmd,\csvloopTest,\defineparser,\endinput,\expandnextTest}
% \DoNotIndex{\fancyhf,\fancyhead,\FE@testoptTest,\FE@ifstarTest,\get@params,\goodbreak,\hypersetup,\iffirstcharTest,\ifsinglecharTest}
% \DoNotIndex{\llap,\rlap,\longrightarrow,\make@macro,\makequotes,\MakeShortVerb,\mdseries,\multicolumn,\mylist}
% \DoNotIndex{\nobreak,\noindent,\null,\OPTmacro,\notstarred,\pagestyle,\preline,\quad,\result,\smex,\starmacro,\starred,\strip@macro}
% \DoNotIndex{\strip@macroprefix,\strip@meaning,\strip@prefix,\sty,\subsubsection,\subtitle,\test}
% \DoNotIndex{\testcsvloop,\testexpandnext,\testFE@testopt,\testFE@ifstar,\testgetlistitem,\testiffirstchar,\testifsinglechar,\getlistitemTest}
% \DoNotIndex{\textbf,\textcolor,\vskip,\long,\hrulefill,\&,\@get@params,\geometry,\edef,\BySeven,\optmacro,\@xifblank,\ettl@onlyonce,\ettl@undefined,\usercmd,\noexpand}
% \DoNotIndex{\@listedel,\@listgdel,\@listxdel}
%
% \makeatletter
% \def\thispackage{\sty{\thisfile}}
% \font\ding=dingbat scaled 800
% \hypersetup{hyperindex=true}
% \fancyhf{}\fancyhead[L]{The \sty{etextools} package -- an \eTeX\, package for \LaTeX}
% \fancyfoot[L]{\color[gray]{.35}\scriptsize\thispackage\quad\copyright\,\lower.3ex\hbox{\NibRight}\,Florent Chervet}
% \fancyfoot[R]{\oldstylenums{\thepage} / \oldstylenums{\pageref{LastPage}}}
% \pagestyle{fancy}
% \fancypagestyle{plain}{%
%  \fancyhf{}\let\headrulewidth\z@
%  \fancyfoot[R]{\oldstylenums{\thepage} / \oldstylenums{\pageref{LastPage}}}}
% \def\CTAN#1{\href{http://www.ctan.org/tex-archive/#1}{\nolinkurl{CTAN:#1}}}
% \definecolor{spot}{rgb}{.7,0.1,0.2}
% \newcommand\fecccolor{\color{fecc}}\definecolor{fecc}{rgb}{.2,.6,.2}
% \newcommand\macrocodecolor{\color{macrocode}}\definecolor{macrocode}{rgb}{0.18,0.00,0.45}
% \newcommand\reflinkcolor{\color{reflink}}\definecolor{reflink}{rgb}{.3,0,0}
% \newcommand\rmklinkcolor{\color{rmklink}}\definecolor{rmklink}{rgb}{.2,.2,.2}
% \newcommand\rmkcolor{\color{rmk}\let\reflinkcolor\rmklinkcolor}\definecolor{rmk}{gray}{.35}
% \newcommand\rmk{\par\nobreak\footnotesize\rmkcolor}
% \definecolor{shadecolor}{rgb}{0.93,0.94,0.81}
% \renewcommand\ltxsyntaxlabelfont{\spotcolor \displayverbfont\bfseries}
% \newcommand\eol{\textcolor[gray]{.5}{$\hookleftarrow$}}
% \newenvironment{codecomment}{\par\vskip\parskip\begin{small}\color[gray]{.2}\parskip=0pt}{\end{small}}
% \g@addto@macro\macro@font{\macrocodecolor\let\AltMacroFont\macro@font}
% \MakeShortVerb{\|}
% \catcode`\§\active\def§{\par\nobreak\vskip-\parskip}
% \renewcommand\partformat{}\let\thepart\partformat\renewcommand\raggedpart{\centering}
% \newcommand\cmdref[1]{\hyperref[#1]{\underline{\sty{\reflinkcolor\textbackslash #1}}}}
% \newcommand\cmdlabel[1]{\label{#1}\hyperdef{cmdlabel}{#1}{}}
% \newcommand\seeimpl[1]{%
%  \ifblank{#1}{\colorbox{yellow}{\textcolor{red}{\LARGE\Laserbeam}}}
%              {\hfill \hyperref{}{cmdlabel}{impl:#1}{\colorbox{yellow}{\textcolor{red}{\LARGE\Laserbeam}}}}}
% \newsavebox\seedescbox
% \setbox\seedescbox\hbox{\rlap{\kern.4em\colorbox{green}{\textcolor{red}{\SunshineOpenCircled}}}}
% \newcommand\seedesc[1]{%
%  \ifblank{#1}{\copy\seedescbox}
%              {\vadjust{\vskip-1.5\ht\seedescbox\hfill
%                   \hbox{\rlap{\kern.4em\hyperref{}{cmdlabel}{#1}{\colorbox{green}{\textcolor{red}{\SunshineOpenCircled}}}}}}}}
%  \def\FE{\setbox8\hbox{$\m@th\bindnasrepma$}%
%            \marginpar{\raisebox{-2pt}{{\fecccolor\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}}}\space}
%  \def\pdfFE{\setbox8\hbox{$\m@th\bindnasrepma$}%
%            \marginpar{\raisebox{-2pt}{{\fecccolor\llap{\textsf{pdf}\TeX{}\,}\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}}}}
% \def\clap#1{\hb@xt@\z@{\hss#1\hss}}
% \def\smex{\leavevmode\hb@xt@2em{\hfil\spotcolor$\longrightarrow$\hfil}}
% \font\manual=manfnt\def\dbend{\marginpar{\manual\char127}\space}
% \def\CS#1{\texttt{\expandafter\@gobble\string\\#1}}
% \def\CSbf#1{\textbf{\CS{#1}}}
% \def\Xpackage{\@dblarg\X@package}
%  \def\X@package[#1]#2{%
%     \sty{#2\footnote{\noindent\sty{#2}: \href{http://www.ctan.org/tex-archive/macros/latex/contrib/#1}{\nolinkurl{CTAN:macros/latex/contrib/#1}}}}}
% \parindent\z@\topsep\z@\partopsep\z@\parskip.3\baselineskip
% \cftbeforesecskip=4pt
% \cftbeforepartskip=11pt
% \let\footnoterule\relax
% \footskip=0pt
% \lastlinefit999
% \makeatother
%
% \thispagestyle{plain}\printtitlepage\medskip
% \fontfamily{ua1}\selectfont
% \tableofcontents\medskip\thispagestyle{plain}\enlargethispage{2.5\baselineskip}
%
% \begin{shaded}\parindent0pt\noindent\normalsize\topsep=-\parskip\itemsep=-\parskip
%
% {\bfseries\catcode`\ \active\let =\,\hfil\NibSolidRight A b s t r a c t \NibSolidLeft\hfil}\par
%
% The \sty{etextools} package is based on the \sty{etex} and \sty{etoolbox}
% packages and defines more tools for \LaTeX\ Users or package Writers.
% Before using this package, it is highly recommended to read the
% documentation (of this package and...) of the \sty{etoolbox} package.
%
% This package requires the \sty{etex} package from David Carlisle
% and the \sty{etoolbox} package from Philipp Lehman. Both of them
% are available on CTAN under the \sty{/latex/contrib/} directory \footnotemark.
%
% \underline{The main contributions of this package are :}
% \begin{itemize}
%   \item the \cmdref{expandnext} macro and the \cmdref{ifempty} and \cmdref{xifempty} macros
%   \item the ability to define fully expandable macros with parameter and/or star version (with a small restriction)
%           -- see \cmdref{FE@testopt}, \cmdref{FE@ifstar}
%   \item a Command-List Parser constructor that uses this new feature : command-list parsers are fully expandable:
%           \cmdref{csvloop}, \cmdref{listloop}, \cmdref{toksloop} and more...
%   \item four macros that are lacking from the \sty{etoolbox} package for removing elements from lists :
%              \cmdref{listdel} and \cmdref{listgdel}, \cmdref{listedel}, \cmdref{listxdel}
%   \item get the index of an item in a list: \cmdref{getlistindex} and \cmdref{xgetlistindex} and conversely
%         the item at a given position in a list: \cmdref{getlistitem}
%   \item a vectorized form of \cmd{futurelet}: \cmdref{collecttoks} is a standard token scanner.
% \end{itemize}
%
% \end{shaded}
%
% \footnotetext{This documentation is produced with the \sty{ltxdockit}
% classe and package by Philipp Lehman using the |DocStrip| utility.
% \begin{tabbing}
% \qquad\=\smex\=To get the documentation, \= run (twice):\quad\= \sty{pdflatex etextools.dtx} \\
% \>\smex\>To get the package, \> run:\>        \sty{etex etextools.dtx}
% \end{tabbing}
% The .dtx file is embeded in this pdf thank to \sty{embedfile} by H. Oberdiek.}
%
% \vfil\eject
%
% \section{Introduction}
%
% \subsection{Motivation}
%
% The first motivation for this package was to define a list-parser macro:
% \begin{itemize}
% \item just like the \cs{docsvlist} and \cs{dolistloop} macros from \sty{etoolbox}
% \item fully expandable (\ie in an |\edef|)
% \item that take the auxiliary command(s) (\cs{do} in \sty{etextools}) as an optional argument.
% \end{itemize}
%
% As a result, a method for defining fully expandable macros with optional parameter is built here.
%
% \subsection{Purely Expandable macros}
%
% The \FE fully expandable (or purely expandable) commands defined in this package
% can be easily spotted with the special marker displayed here in the margin for information.
% \medskip
%
% Go directly to the implementation of a\marginpar{\llap{\seeimpl{}\hskip-1.5em}} command by clicking
% on the symbol displayed here in the margin for information.
% \medskip
%
% Now from the implementation, \marginpar{\llap{\seedesc{}\kern4pt}} you can return to the description
% section just by clicking on the symbol displayed here in the margin for information.
%
% \subsection{The example file}
%
% The example file provided with \thispackage\ illustrates the macros defined here.
%
% \subsection{Requirements}
%
% This package requires the packages \sty{etex} package by David Carlisle and
% \sty{etoolbox} by Philipp Lehman.
%
% \subsection{Acknowledgements -- Thank You !}
%
% Thanks to Philipp Lehman for the \sty{etoolbox} package (and also for this nice class of documentation).
% Much of my work on lists are based on his work and package.
%
% \clearpage
% \part*{All User Commands}
% \addtocontents{toc}{\protect\contentsline{part}{All User Commands}{}{}}
%
% \section{Expansion control}
%
% \begin{ltxsyntax}
%
% \cmditem{expandnext}{cstoken}{first parameter of cstoken} \cmdlabel{expandnext} \seeimpl{expandnext}
%
% We\FE often want a control sequence to be expanded after its first argument. For example, if you
% want to test if a command |\foo| has a blank replacement text you will say:
%
% \qquad |\expandafter\ifblank\expandafter{\foo}{|\prm{true part}|}{|\prm{false part}|}|
%
% With |\expandnext| you'll just have to say:
%
% \qquad |\expandnext\ifblank{\foo}{|\prm{true part}|}{|\prm{false part}|}|
%
% Now observe the following game :
% \begin{tabbing}
% \qquad\= |\def\foo{foo}| \qquad \= \smex \qquad \=  |\def\Foo{\foo}| \quad \= \eol \\
% \>       |\def\\FOo{\Foo}| \>   \smex \>    |\def\FOO{\FOo}| \> \eol \\
% \>       |\def\fool{\FOO}|
% \end{tabbing}
%  Guess how many \cmd{expandafter} are needed to test ``|\ifblank{foo}|'' directly from |\fool| ???
%
% |\expandnext| solves this problem : |\fool| has 5 degrees of expansion until it expands to ``foo'', therefore exactly 5
% |\expandnext| are required. The solution is:
%
% \qquad |\expandnext\expandnext\expandnext\expandnext\expandnext\ifblank{\fool}|
%
% Other example: suppose you want to define a macro |\detokenizecs{|\prm{csname}|}| that expands to the detokenized content
% of |\csname |\prm{csname}|\endcsname|. Without |\expandnext| you will have to say:
% \begin{tabbing}
% \qquad\= |\expandafter\expandafter\expandafter\detokenize| \\
% \>       |\expandafter\expandafter\expandafter{\csname |\prm{csname}|\endcsname}|
% \end{tabbing}
% \textbf{six} \cmd{expandafter}(s). With |\expandnext| you just have to say:§
% \qquad|\expandnext\expandnext\detokenize{\csname #1\endcsname}|
%
% \cmditem{noexpandcs}{csname}   \cmdlabel{noexpandcs}\seeimpl{noexpandcs}
%
% In an \FE expansion context (|\edef|) we often want a control sequence whose name results
% from the expansion of some macros and/or other tokens to be created, but not expanded at that point.
% Roughly:§
% \qquad |\edef{\noexpandcs{<balanced text to be expanded as a cs-name>}}|§
% will expand to: |\"cs-name"| but this (new) control sequence itself will not be expanded.
% A typical use is shown in the following code:§
% \smex |\edef\abc{\noexpandcs{abc@\@gobblescape\controlword}}|§
% \smex if equivalent to:\quad|\def\abc{\abc@controlword}|.
%
% {\rmk|\noexpandcs| may be abbreviated f.ex. in |\`#1`| in |\edef| that take place in a group. }
%
% \cmditem{noexpandafter}\cmdlabel{noexpandafter}\seeimpl{noexpandafter}
%
% |\noexpandafter|\FE only means |\noexpand\expandafter| and is shorter to type.
%
% {\rmk This command is used in the definition of \cmdref{DeclareCmdListParser}.}
%
% \end{ltxsyntax}
%
% \clearpage
% \section{Characters and Strings}
%
% \begin{ltxsyntax}
%
% \cmditem{ifempty}{string}{true}{false} \cmdlabel{ifempty} \seeimpl{ifempty}
%
% |\ifempty|\FE is similar to |\ifblank| but it test if a string is really empty
% (it shall not contain any character nor spaces). To test if the replacement
% text of a macro is empty, one may use |\ifempty| in conjunction with \cmdref{expandnext}:
% \begin{tabbing}
% \quad\=|\expandnext\ifempty{\macro}| \prm{true}\prm{false}
% \end{tabbing}
%
% |\ifempty| is based on |\detokenize| and accept anything in its argument.
%
%
% \cmditem{xifempty}{string or cs-token}{true}{false} \cmdlabel{xifempty} \seeimpl{xifempty}
%
% |\xifempty|\pdfFE is similar to |\ifempty| but the argument is expanded during comparison.
%
% \begin{tabbing}
% \quad\=|\def\x{\@empty}\def\y{}| \\
% \>|\xifempty{\x\y}| \prm{true}\prm{false}
% \end{tabbing}
%
% {\rmk The macro is based on the \cs{pdfstrcmp} primitive.}
%
% \cmditem{ifnotempty}{string}{true}{false} \cmdlabel{ifnotempty}\seeimpl{ifnotempty}
%
% |\ifnotempty|\FE reverses the test of |\ifempty|
%
%
% \cmditem{xifblank}{string}{true}{false} \seeimpl{xifblank}
%
% |\xifblank| is similar to |\ifblank| except that the \prm{string} is first expanded
% with |\protected@edef|.
% \medbreak
%
% \cmditem{iffirstchar}{string1}{string2}{true}{false} \cmdlabel{iffirstchar}\seeimpl{iffirstchar}
% \cmditem*{iffirstchar}{}{string}{true}{false}
%
% |\iffirstchar| \FE compares the character codes of the \textbf{first} characters of each \prm{string}. The
% comparison is \emph{catcode agnostic} and the macro is fully expandable. Neither \prm{string1} nor \prm{string2}
% is expanded before comparison. Example:§
% \qquad|\iffirstchar *{*hello*}{begins with a star}{begins with something else}|
%
% Alternatively, you may use the \cmdref{ifstrmatch} test.
%
% There is a ``special'' use of this command when one want to test if a \prm{string} begins
% with an \emph{escape} character (\,\textbackslash\,) one may say:
% \begin{tabbing}
%\qquad\= |\iffirstchar \@backslashchar{|\prm{string}|}|\qquad\= or even easier:\\
% \>|\iffirstchar {}{|\prm{string}|}|
% \end{tabbing}
%
% Please note that the tests:
% \begin{tabbing}
% \qquad\qquad\=|\iffirstchar |\=|{|\prm{whatever string1 is}|}{}|\\
% and:\>|\iffirstchar |\>|{}{}|
% \end{tabbing}
%  are \textbf{always expanded into \underline{\prm{false}}}
% (for consistency with the shortcut-test for |\@backslashchar|).\medbreak
%
% \cmditem{ifsinglechar}{string1}{string2}{true}{false} \cmdlabel{ifsinglechar}\seeimpl{ifsinglechar}
%
% |\ifsinglechar|\FE performs the test |\iffirstchar| but only if \prm{string2} has one single character.
%
% Note that there is a small difference if you run on pdf\TeX{} or on another system:§
% \DeleteShortVerb{\|}
% \hfil
% \begin{tabular}{|c|c|}\hline
% pdf\TeX{} (use \cs{pdfstrcmp}) & Other \\ \hline
% \cs{ifsinglechar} *\{\textvisiblespace*\} is \textbf{false} & \cs{ifsinglechar} *\{\textvisiblespace*\} is \textbf{true} \\ \hline
% \end{tabular}\hfil
%
% \MakeShortVerb{\|}
% But: \cs{ifsinglechar} *\{*\textvisiblespace\}\quad is \textbf{always false}.
%
%
% \cmditem{iflastchar}{string1}{string2}{true}{false} \cmdlabel{iflastchar}\seeimpl{impl:iflastchar}
%
% |\iflastchar| compares the end of \prm{string2} with the totality of \prm{string1} (\prm{string1} is not
% necessarily a single character but the macro has been designed for this purpose first, hence the name).
%
% |\iflastchar| is NOT purely expandable (use \cmdref{ifstrmatch} for purely expandable test).
%
%
% \cmditem{ifstrcmp}{string1}{string2}{true}{false} \cmdlabel{ifstrcmp}\seeimpl{ifstrcmp}
%
% |\ifstrcmp|\pdfFE is the \LaTeX{} form of |\pdfstrcmp| primitive.
%
% Neither \prm{string1} not \prm{string2} is expanded during comparison. The comparison is
% \textit{catcode agnostic} (use of |\detokenize |).
%
% \cmditem{ifstrmatch}{pattern}{string}{true}{false} \cmdlabel{ifstrmatch}\seeimpl{ifstrmatch}
%
% |\ifstrmatch|\pdfFE is based on the |\pdfmatch| primitive that implements POSIX-regex.
%
% You can test the last character of a string in a purely expandable way by:
% \begin{tabbing}
% \quad\=\cs{ifstrmatch}\{[\textasteriskcentered]\$\}\{\prm{string}\}
% \end{tabbing}
% for example to test \raise2pt\hbox{\textasteriskcentered}.
% \end{ltxsyntax}
%
% \section{Fully expandable macros with options}
% \vskip-\baselineskip
% Now with the macro |\ifsinglechar| it becomes possible to write fully expandable macros with an option, \textbf{provided
% that this macro has at least one non-optional argument}, as far as we don't use |\futurelet| nor any assignation.
% The ``trick'' is the following:
% \begin{tabbing}
% \qquad\= |\def\MacroWithOption#1{\ifsing|\=|lechar|\=|[{#1}| \\
% \>\>|{\MacroHasOption[}| \\
% \>\>|{\MacroNoOption{#1}}}}|\\
% \> |\def\MacroHasOption[#1]#2|... \>\textit{definition} \\
% \> |\def\MacroNoOption#1|...\>\textit{definition}
% \end{tabbing}
%
% Moreover (in the style of |\@testopt|):
% \begin{tabbing}
%  \qquad\= |\def\MacroWithOption#1{\ifsing|\=|lechar|\=|[{#1}|\\
%  \>\>|{\MacroHasOption#1}|\\
%  \>\>|{\MacroHasOption[default]{#1}}}|
% \end{tabbing}
%
% \begin{ltxsyntax}
%
% \cmditem{FE@testopt}{argument to be tested}{commands}{default option} \cmdlabel{FE@testopt}\seeimpl{FE@testopt}
%
%  |\FE@testopt|\FE mimics the behaviour of |\@testopt| but is Fully Expandable (\sty{FE}) and can be used as follow:§
% \qquad |\def\MacroWithOption#1{\FE@testopt{#1}\MacroHasOption{default}}|\par
%
% Note that |\MacroWithOption| \textbf{must have at least one mandatory argument.}\medbreak
%
% {\rmk |\FE@testopt| is used in the definition of \cmdref{DeclareCmdListParser}.}
%
% \cmditem{FE@ifstar}{argument to be tested}{star-commands}{non-star commands} \cmdlabel{FE@ifstar}\seeimpl{FE@ifstar}
%
% Similarly,\FE it becomes possible to mimic the behaviour of |\@ifstar| but in a fully expandable(\sty{FE}) way.
% |\FE@ifstar| can be used as follow :§
% \begin{tabbing}
% \qquad\= |\def\StarOrNotCommand#1{\FE@|\=|ifstar|\=|{#1}|\\
% \>\>|{\StarredCommand}|\\
% \>\>|{\NotStarredCommand}}|
% \end{tabbing}
%
% Remember that |\StarredCommand| and |\NotStarredCommand| \textbf{must have at least one mandatory argument.}
%
% {\rmk |\FE@ifstar| is used in the definitions of \cmdref{DeclareCmdListParser}, \cmdref{csvloop}, \cmdref{listloop}
% and \cmdref{toksloop}.}
%
% \cmditem{FE@ifchar}{Variant Mark Character}{argument to be tested}{special-commands}{normal-commands}\cmdlabel{FE@ifchar}\seeimpl{FE@ifchar}
%
% As a\FE generalisation of \cs{FE@ifstar} \sty{etextools} provides \cmd{FE@ifchar} for use with other variants than the star-form.
%
% For example, to define a `\,$\boldsymbol{+}$\,`  variant:
% \begin{tabbing}
%   \qquad\=|\def\SpecialMacro#1{\FE@|\=|ifchar|{+}\=|{#1}|\\
%   \>\>|{\SpecialFormMacro}|\\
%   \>\>|{\NormalFormMacro}}|
% \end{tabbing}
%
% |\SpecialMacro| must have at least one mandatory argument.
%
% \end{ltxsyntax}
%
% \section{Lists management}
%
% \subsection{The Command-List Parser}
%
% The \sty{etoolbox} package provides a way to define list parsers a fully expandable macros:
% the list parser is able to expand the auxiliary command |\do| on each item of a list.
% \iffalse
% Declaration of a list parser is done via the |\DeclareListParser| macro\footnotemark.
% \footnotetext{besides, \sty{etoolbox} defines the \sty{\textbackslash docsvlist} and the
% \sty{\textbackslash dolistloop} macros: the choice of this name is not very friendly
% and we expected to have a \sty{\textbackslash docsvloop} macro instead...}.
% \fi
%
% Here we provide a |\DeclareCmdListParser| macro that is compatible and slightly different, because the auxiliary
% command is not necessarily |\do|. Such a command-list-parser is fully expandable.
%
% The idea is that if |\csvloop| has been defined as a command-parser then, thank to the fully expandable macro |\FE@testopt|
% we can call for expansion:
% \begin{tabbing}
% \qquad\= |\csvloop*{item,item,...}|\,\= as a shortcut for\,\= |\csvloop*[\do]{item,...}|\\
% or:\>       |\csvloop*[\listadd\mylist]{item,item,...}|\quad
% \end{tabbing}
% for example to convert the csv-list into internal \sty{etoolbox} list.
%
% {\rmk The star-form of \cmdref{csvloop} will be explained below.}
%
% \begin{ltxsyntax}
%
% \cmditem{DeclareCmdListParser}{command}{separator}\cmdlabel{DeclareCmdListParser}\seeimpl{DeclareCmdListParser}
%
% |\DeclareCmdListParser| acts in the same way as \sty{etoolbox}-|\DeclareListParser| and the command-list-parser
% are sensitive to the category code of the \prm{separator}
% {\catcode`\ =13\let =-\it(which is not necessarily a single character and shall not be a {\tt\string&} with a catcode of 3)}.
%
% A Command-List-Parser is then defined as a purely expandable macro. It has a \textit{star form} for the case
% of the list given is already expanded, and a \textit{normal form} if the list is given as a macro name.
%
% You may then use the following syntaxes:
% \begin{tabbing}
% \qquad\=|\CmdListParser\mylist| \\
% \>|\CmdListParser*{item|\prm{sep}|item|\prm{sep}|item}| \\
% \>|\CmdListParser[\Commands]\mylist| \\
% or:\>|\CmdListParser*[\Commands]{item|\prm{sep}|item|\prm{sep}|item}|
% \end{tabbing}
%
% \subsection{Loops into lists}
%
% Now we have to declare two command-list-parsers : |\listloop| for \sty{etoolbox} lists
% and |\csvloop| for comma-separated lists.
%
% \cmditem{csvloop}[auxiliary commands]{csvlistmacro} \cmdlabel{csvloop}\seeimpl{csvloop}
% \cmditem*{csvloop*}[auxiliary commands]{item,item,item,...}
% \cmditem*{listloop}[auxiliary commands]{listmacro}    \cmdlabel{listloop}
% \cmditem*{listloop*}[auxiliary commands]{expanded list}
% \cmditem{toksloop}[auxiliary commands]{tokenslistmacro} \cmdlabel{toksloop}
% \cmditem*{toksloop*}[auxiliary commands]{list of tokens}
%
% |\listloop|\FE acts exactly as \sty{etoolbox}-|\dolistloop| with an optional argument to change
% the default auxiliary command |\do| to apply to each item of the list :
% \begin{tabbing}
% \qquad\=|\listloop\mylist|\;\=\textit{is}\;\= |\listloop[\do]\mylist|\;\=\textit{and is also}\;\= |\dolistloop\mylist|\\
% \>      |\csvloop\csvlist|\> \textit{is}\> |\csvloop[\do]\csvlist|\> \textit{and is also}: \eol \\
% \>\>\> |\expandafter\docsvlist\expandafter{\csvlist}|
% \end{tabbing}
%
%  The token list is a list without delimiter.
%
%
%
% \subsection{Converting csv lists to \sty{etoolbox}-lists}
%
% \cmditem{csvtolist}{listmacro}{csvlistmacro} \cmdlabel{csvtolist}\seeimpl{csvtolist}
% \cmditem*{csvtolist*}{listmacro}{item,item,item...}
%
% |\csvtolist| converts a comma separated list into an internal \sty{etoolbox} list. It is useful to insert more than one item
% at a time in a list. Those macros are not fully expandable because of the redefinition of \prm{listmacro} done by |\listadd|...
%
% It's also the first application of the \cmdref{csvloop} macro just defined.
%
%
% \cmditem{csvtolistadd}{listmacro}{csvlistmacro} \cmdlabel{csvtolistadd}\seeimpl{csvtolistadd}
% \cmditem*{csvtolistadd*}{listmacro}{item,item,item...}
%
% |\csvtolistadd| acts similarly but does not reset the \prm{listmacro} to |\@empty|.
%
%
% \subsection{Converting lists of tokens to \sty{etoolbox}-lists}
%
% \cmditem{tokstolist}{listmacro}{tokenslistmacro} \cmdlabel{tokstolist}\seeimpl{tokstolist}
% \cmditem*{tokstolist*}{listmacro}{list of tokens}
%
% |\tokstolist| converts a list of tokens (no separator) into an internal \sty{etoolbox} list.
%
% It's also the first application of the \cmdref{toksloop} macro just defined.
%
% \cmditem{tokstolistadd}{listmacro}{tokslistmacro} \cmdlabel{tokstolistadd}\seeimpl{tokstolistadd}
% \cmditem*{tokstolistadd*}{listmacro}{list of tokens}
%
% |\tokstolistadd| acts similarly but does not reset the \prm{listmacro} to |\@empty|.

%
% \subsection{Removing elements from \sty{etoolbox}-lists}
%
% The \sty{etoolbox} package provides |\listadd|, |\listgadd| and |\listxadd| commands
% to add items to a list. However, no command is designed to remove an element from a
% list.
%
%
% \cmditem{listdel}{listmacro}{item}      \cmdlabel{listdel}\seeimpl{listdel}
% \cmditem*{listgdel}{listmacro}{item}    \cmdlabel{listgdel}
% \cmditem*{listedel}{listmacro}{item}    \cmdlabel{listedel}
% \cmditem*{listxdel}{listmacro}{item}    \cmdlabel{listxdel}
%
% The |\listdel| command removes the element \prm{item} from the list \prm{listmacro}. Note that the
% \prm{listmacro} is redefined after deletion:
%
% Commands |\listgdel| and |\listxdel| are similar, except that the assignment (\ie the redefinition
% of the list) is global; for the latter, the \prm{item} is first expanded using |\protected@edef|:
%
% \end{ltxsyntax}
%
% \subsection{Index of an element in a list}
%
% \subsubsection{\sty{etoolbox}-lists}
%
% \begin{ltxsyntax}
%
% \cmditem{getlistindex}[myindex]{item}{listmacro} \cmdlabel{getlistindex}\seeimpl{getlistindex}
% \cmditem*{xgetlistindex}[myindex]{item}{listmacro} \cmdlabel{xgetlistindex}
% \cmditem*{getlistindex*}[myindex]{item}{list}
% \cmditem*{xgetlistindex*}[myindex]{item}{list}
%
% \end{ltxsyntax}
%
% Sometimes it is interesting to know at which offset in a list lies a given item. |\getlistindex| answers to this question.
% |\xgetlistindex| does the same thing but expands the \prm{item} while looking for it in the list.
%
% The comparison is \textit{catcode agnostic}.
%
% As for the command-list-parser, the star versions are designed in case the list (in the second argument) is already expanded.
%
% When used\pdfFE on pdf\TeX{}, |\pdfstrcmp| does the comparison and the macros are purely expandable:
%
% \begin{itemize}
% \item \ If \prm{item} is not found in the list, \cs{getlistindex} expands to 0
% \item \ If \prm{item} is found in first position then \cs{getlistindex} expands to 1 and so on.
% \end{itemize}
%
%
% Those macros are purely expandable only if |\pdfstrcmp| exists.
% Otherwise, the comparison is done with \sty{etoolbox}-|\ifstrequal| and you shall use the optional argument
% to let the result in:
% \begin{tabbing}
%  \qquad\=|\getlistindex[\myindex]{|\prm{item}|}{|\prm{listmacro}|}| \\
% \end{tabbing}
%
% \textbf{N.B. If \cs{myindex} is not a counter it is (possibly \textit{re-})defined as macro.}
%
% \subsubsection{Comma-separated lists}
%
% \begin{ltxsyntax}
% \cmditem{getcsvlistindex}[myindex]{item}{csvlistmacro} \cmdlabel{getcsvlistindex}\seeimpl{getcsvlistindex}
% \cmditem*{xgetcsvlistindex}[myindex]{item}{csvlistmacro} \cmdlabel{xgetcsvlistindex}
% \cmditem*{getcsvlistindex*}[myindex]{item}{item,item,item,...}
% \cmditem*{xgetcsvlistindex*}[myindex]{item}{item,item,item,...}
% \end{ltxsyntax}
%
% This is the same as \cmdref{getlistindex} but for comma-separated lists.
%
% As for the command-list-parser, the star versions are designed in case the list (in the second argument) is already expanded.
%
% Those macros\pdfFE are purely expandable only if |\pdfstrcmp| exists.
%
% Otherwise, use the optional argument to let the result in:
% \begin{tabbing}
%  \qquad\=|\getcsvlistindex*[\myindex]{|\prm{item}|}{|\prm{item,item,item...}|}| \\
% \end{tabbing}
%
% If \cs{myindex} is not a counter it is (possibly \textit{re-})defined as macro.
%
% \subsubsection{Lists of tokens}
%
% \begin{ltxsyntax}
% \cmditem{gettokslistindex}[myindex]{item}{tokenslistmacro} \cmdlabel{gettokslistindex}\seeimpl{gettokslistindex}
% \cmditem*{gettokslistindex*}[myindex]{item}{list of tokens}
% \end{ltxsyntax}
%
% There\FE is no x- version for those macros. They work in a different way: the comparison if done by \cs{ifx} and
% not \cmd{pdfstrcmp}.
%
% Therefore, \cs{gettokslistindex} is \textbf{always purely expandable}, but for symmetry reasons, the optional form:§
% \begin{tabbing}
% \qquad\=|\gettokslistindex[\myindex]{|\prm{item}|}{|\prm{tokenslistmacro}|}| \\
% and:\> |\gettokslistindex*[\myindex]{|\prm{item}|}{|\prm{list of tokens}|}|
% \end{tabbing}
% are defined.
%
% An interesting application is the following:
%
% \begin{Verbatim}[gobble=1,commandchars=!\[\]]
%        !textbf[\ifcase  \gettokslistindex*{R}{LORG}]
%              Not in the list: Error ?%
%        \or   Here it's L%
%        \or   Here it's O%
%        \or   Here it's R%
%        \or   Here it's G%
%        !textbf[\fi]
% \end{Verbatim}
%
% Please, refer to the examples...
%
% \subsection{Extract by index from a list}
%
% \begin{ltxsyntax}
%
% \subsubsection{\sty{etoolbox}-lists}
%
% \cmditem{getlistitem}{index [numexpr expression]}{listmacro} \cmdlabel{getlistitem}\seeimpl{getlistitem}
% \cmditem*{getlistitem*}{index [numexpr expression]}{list}
%
% Now\FE the reverse operation of ``getting the index'' is ``getting the element'' whose index is known. Note that this macro
% is fully expandable for we don't have to compare the items (just count the loop using |\numexpr| -- no counter). Therefore we use the
% fully expandable version of |\ifstar| : \cmdref{FE@ifstar} to keep the ``fully-expand-ability'' of the star-form as well:
% \begin{itemize}
% \item \ If the \prm{index} is in the range $[1\dots n]$ then the macro expands to \prm{item}$_n$
% \item \ If the \prm{index} is non positive or $>n$ then the macro expands to nothing (|{}|).
%  \end{itemize}
%
% \subsubsection{Comma-separated lists}
%
% \cmditem{getcsvlistitem}{index [numexpr expression]}{csvlistmacro} \cmdlabel{getcsvlistitem}\seeimpl{getcsvlistitem}
% \cmditem*{getcsvlistitem*}{index [numexpr expression]}{item,item,item,...}
%
% This is\FE the same as \cmdref{getlistitem} but for comma-separated lists.
%
% \subsubsection{Lists of tokens}
%
% \cmditem{gettokslistitem}{index [numexpr expression]}{tokenslistmacro} \cmdlabel{gettokslistitem}\seeimpl{gettokslistitem}
% \cmditem*{gettokslistitem*}{index [numexpr expression]}{list of tokens}
%
% The same\FE as \cmdref{getlistitem} for list of tokens.
% \end{ltxsyntax}
%
% \section{Vectorized \cmd{futurelet}}
%
%
% \sty{etextools} defines a vectorized version of \cs{futurelet}. The idea is to say:
%
% \quad|\collecttoks\macro{|\prm{list of allowed tokens}|}{|\prm{commands to execute next}|}|
%
% Then \cs{collecttoks} is a kind of simple scanner for tokens. It can be used to define an \textbf{\textit{undelimited macro}}
% \ie a macro that has no delimiter but whose content of arguments is restricted.
%
% \begin{ltxsyntax}
% \cmditem{collecttoks}{cs-token}{list of tokens}{commands to expand after}   \cmdlabel{collecttoks}\seeimpl{collecttoks}
% \end{ltxsyntax}
%
% The macro \cs{collecttoks} will read the following tokens with \cs{futurelet}. If that token is in the allowed
% list, then it will append it to \cs{macro} (\prm{cs-token}) and continue, scanning the tokens one after another.
%
% Until it founds a token which is not in the list. Then it stops reading and execute the \prm{commands to expand}.
% Those commands may use the \cs{macro} defined for analyse or whatever the user want.
%
% \medskip
% As an application, it can be used to define an easy interface for |\hdashline| (the dashed lines in tabulars and arrays
% provided by the \sty{arydshln} package): modifying \cmd{hline} in order to give sense to the following:
% \begin{tabbing}
%  \qquad\=|\hline..|\qquad\=|\hline--|\qquad\=|\hline==|\qquad\= |\hline.-|\qquad\=|\hline.-.|\ \= etc.
% \end{tabbing}
%
% After having collected the allowed tokens with:§
% |\collecttoks\nexttokens{.-=}{|\prm{commands next}|}| \quad it is possible to
% test the pattern given using \cs{pdfstrcmp} and, for example, the \CSbf{switch} construction of the \sty{boolexpr} package:
%
% \begin{Verbatim}[gobble=1,commandchars=!()]
%     !textbf(\switch[\pdfstrcmp{\nexttokens}])
%     \case{{..}}\hdashline[parameters]%
%     \case{{--}}\hdashline[parameters]%
%     \case{{==}}\hdashline[parameters]%
%     \case{[.-.}}\hdashline[parameters]%
%     \otherwise \original@hline%
%     !textbf(\endswitch)
% \end{Verbatim}
%
% \CSbf{switch} is purely expandable.
%
% If you replace \cs{pdfstrcmp} by |\ifstrequal|, \cs{switch} works but is not purely expandable.
%
% See \sty{boolexpr} (\CTAN{macros/latex/contrib/boolexpr/}) for more information on \cs{switch}.
%
%
%
%
% \StopEventually{
% }
%
% \part*{\LaTeX{} code}
% \addtocontents{toc}{\protect\contentsline{part}{\large\LaTeX{} code}{}{}}
%
% \section{Implementation}
%
% \subsection{Package identification}
%
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesPackage{etextools}
   [2009/08/14 v2h e-TeX more useful tools for LaTeX package writers]
\csname ettl@onlyonce\endcsname\let\ettl@onlyonce\endinput
%    \end{macrocode}
%
% \subsection{Requirements}
%
% This package requires the packages \sty{etex} package by David Carlisle and
% \sty{etoolbox} by Philipp Lehman.
%
%    \begin{macrocode}
\RequirePackage{etex,etoolbox}
%    \end{macrocode}
%
% Furthermore, the space token must have its natural catcode (10) all along this package.
%
%    \begin{macrocode}
\let\ettl@AtEnd\@empty
\def\TMP@EnsureCode#1#2{%
  \edef\ettl@AtEnd{%
    \ettl@AtEnd
    \catcode#1 \the\catcode#1\relax
  }%
  \catcode#1 #2\relax
}
\TMP@EnsureCode{32}{10}% space
\ifundef\pdfstrcmp{%
  \TMP@EnsureCode{33}{9}% ! ignore
  \TMP@EnsureCode{34}{14}% " comment
}{\TMP@EnsureCode{33}{14}% ! comment
  \TMP@EnsureCode{34}{9}% " ignore
}
\AtEndOfPackage{\ettl@AtEnd\undef\ettl@AtEnd}
%    \end{macrocode}
%
% \subsection{A few (7) ``helper'' macros}
%
% \iffalse
%<package>
%<package>% A few helper macros
% \fi
%    \begin{macrocode}
\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}
\long\def\ettl@afterorfi#1\or#2\fi{\fi#1}
%    \end{macrocode}
%
% \iffalse
%<package>
% \fi
%
% \begin{macro}{\ettl@ifstrcmp}
% Use of the pdf\TeX{} primitive \cs{pdfstrcmp} and design a \LaTeX{} form.
%    \begin{macrocode}
\def\ettl@ifstrcmp#1#2{\csname @%
   \ifnum\pdfstrcmp{#1}{#2}=0 first\else second\fi oftwo\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@gobblescape}
%
% This sequence of command is very often used, even in \sty{latex.ltx}. So
% it appears to be better to put it in a macro. It's aim is to reverse the
% mechanism of |\csname|...|\endcsname|:
%    \begin{macrocode}
\newcommand*\@gobblescape{\expandafter\@gobble\string}
%    \end{macrocode}
% {\rmk May be we could do better, testing first if the next token is a control sequence...}
% \end{macro}
%
%
%    \begin{macrocode}
\def\ettl@onlypdfTeX#1#2{\ifundef{#1}
   {\def#2{\PackageError{etextools}{\string#1\space primitive not found\MessageBreak
   pdfTeX seems not to be running}
   {\string#2\space works only if used with pdfTeX (requires \string#1)}}}
   {}}
%    \end{macrocode}
%
% \subsection{Expansion control}
%
%
% \begin{macro}{\noexpandcs}\cmdlabel{impl:noexpandcs}
% {\rmk|\noexpandcs| may be abbreviated f.ex. in |\`#1`| or |\"#1"| in |\edef| that take place in a group.}\seedesc{noexpandcs}
%    \begin{macrocode}
\newcommand*\noexpandcs[1]{\expandafter\noexpand\csname #1\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\noexpandafter}\cmdlabel{impl:noexpandafter}
% {\rmk \cmd{noexpandafter} only means \cmd{noexpand}\cmd{expandafter} and is shorter to type.}\seedesc{noexpandafter}
%    \begin{macrocode}
\newcommand\noexpandafter{\noexpand\expandafter}
%    \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\expandnext}\cmdlabel{impl:expandnext}
%
% This code is not properly \seedesc{expandnext} tricky but if you're eager to understand the job of each expandafter,
% it's best to go straight at the log.
%
% Note that the first argument of |\expandnext| must be a single \prm{cstoken} (for \cmd{expandafter} acts
% only on the first following token).
%
% \iffalse
%<package>
%<package>% \expandnext : expansion control
%<package>% level 1 : \expandnext#1{...}  <=> \expandafter#1\expandafter{...}
%<package>% level 2 : \expandnext\expandnext#1{...} etc.
% \fi
%    \begin{macrocode}
\newcommand\expandnext[2]{%
   \ifx#1\expandnext
      \ettl@afterelse\expandafter\expandafter\expandafter
            \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}%
   \else
      \expandafter\ettl@afterfi#2#1#2{#3}%
   \fi}
%    \end{macrocode}
% \end{macro}
% \iffalse
%<package>
% \fi
%
%
% \subsection{Character and Strings}
%
% \iffalse
%<package>
%<package>% \ifempty{ text }{ true }{ false }
% \fi
%
% \begin{macro}{\ifempty} \cmdlabel{impl:ifempty}
% |\ifempty| is based on |\detokenize| and can manage with any argument.\seedesc{ifempty}
%    \begin{macrocode}
\newcommand\ifempty[1]{\csname @\expandafter\ifx
   \expandafter\relax\detokenize{#1}\relax
   first\else second\fi oftwo\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \ifnotempty{ text }{ true }{ false }
% \fi
%
% \begin{macro}{\ifnotempty} \cmdlabel{impl:ifnotempty}
% |\ifnotempty| is based on |\detokenize| and can manage with any argument.\seedesc{ifnotempty}
%    \begin{macrocode}
\newcommand\ifnotempty[1]{\csname @\expandafter\ifx
   \expandafter\relax\detokenize{#1}\relax
   second\else first\fi oftwo\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \xifempty{ text }{ true }{ false }
% \fi
% \begin{macro}{\xifempty} \cmdlabel{impl:xifempty}
% |\xifempty| is based on pdf-TeX{} |\pdfstrcmp| and work with any argument.\seedesc{xifempty}
%    \begin{macrocode}
\newcommand\xifempty[1]{\xifstrcmp{#1}{}}
\ettl@onlypdfTeX\pdfstrcmp\xifempty
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \ifnotblank{ text }{ true }{ false }
% \fi
%
% \begin{macro}{\ifnotblank} \cmdlabel{impl:ifnotblank}
% |\ifnotblank| reverses the test of |\ifblank|.\seedesc{ifnotblank}
%    \begin{macrocode}
\begingroup\catcode`\&=3\catcode`\:=12
\ifcsundef{ifnotblank}{%
\long\gdef\ifnotblank#1{\etb@ifblank@i#1&&\@firstoftwo\@secondoftwo:}}
\relax\endgroup
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \xifblank{ string }{ true }{ false }
% \fi
%
% \begin{macro}{\xifblank}\cmdlabel{impl:xifblank}
% Just expands the parameter using |\protected@edef| before testing for |\ifblank|: \seedesc{xifblank}
%    \begin{macrocode}
\newrobustcmd\xifblank[1]{\begingroup
   \protected@edef\@xifblank{\endgroup
         \noexpand\ifblank{#1}%
   }\@xifblank}
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%<package>
%<package>% \iffirstchar{ string1 }{ string2 }{ true }{ false }
% \fi
%
% \begin{macro}{\iffirstchar}\cmdlabel{impl:iffirstchar}
% |\iffirstchar| test if |#1| and |#2| begins with the same character. \seedesc{iffirstchar}
%    \begin{macrocode}
\newcommand\iffirstchar[2]{\csname @%
   \if \expandafter\@car\detokenize{#2}\relax\@nil\expandafter\@car\detokenize{#1}\string\\\@nil
      \ifblank{#2}{second}{first}%
   \else second%
   \fi oftwo\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \ifsinglechar character{ string }{ true }{ false }
% \fi
%
% \begin{macro}{\ifsinglechar}\cmdlabel{impl:ifsinglechar}
% Test if |#2| is a single character equal to |#1|: \seedesc{ifsinglechar}
%    \begin{macrocode}
\newcommand\ifsinglechar[2]{%
%    \end{macrocode}
%
% \begin{codecomment}
% Remember that neither \prm{string1} nor \prm{string2} is expanded.§
% First: test if |#2| is a single character:
%    \begin{macrocode}
   \csname @\ifblank{#2}{second}{%
"      \ifnum\pdfstrcmp{\detokenize{#1}}{\detokenize{#2}}=0
"         \ifnum\pdfstrcmp{\detokenize{#2}}{\expandafter\@car\detokenize{#2}\relax\@nil}=0
"            first%
"         \else second%
"         \fi
"      \else second%
"      \fi oftwo\endcsname}}
!     \expandafter\expandafter\expandafter\ifx
!         \expandafter\expandafter\expandafter\relax\expandafter\@cdr\detokenize{#2}\@nil\relax
!         \iffirstchar{#1}{#2}{first}{second}\else second\fi oftwo\endcsname}}
%    \end{macrocode}
% \end{codecomment}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \iflastchar{ string1 }{ string2 }{ true }{ false }
% \fi
%
% \begin{macro}{\iflastchar} \cmdlabel{impl:iflastchar}
% This macro is not purely expandable. \seedesc{iflastchar}
%    \begin{macrocode}
\begingroup\catcode`\&=3
\long\gdef\iflastchar#1#2{%
   \long\def\ettl@iflastchar##1#1##2&{%
      \ifstrcmp{##2}{#1}\@firstoftwo{%
         \ifempty{##2}\@secondoftwo{\ettl@iflastchar##2&}}
   }\ettl@iflastchar#2#1&}
\endgroup
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%<package>
%<package>% \ifstrcmp{ string1 }{ string2 }{ true }{ false }
% \fi
%
% \begin{macro}{\ifstrcmp}\cmdlabel{impl:ifstrcmp}
% The macro is base on the |\pdfstrcmp| primitive.\seedesc{ifstrcmp}
%    \begin{macrocode}
\newcommand\ifstrcmp[2]{\csname @%
  \ifnum\pdfstrcmp{\detokenize{#1}}{\detokenize{#2}}=0 first\else second\fi
  oftwo\endcsname}
\ettl@onlypdfTeX\pdfstrcmp\ifstrcmp
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>% \xifstrcmp{ string1 }{ string2 }{ true }{ false }
% \fi
%
% \begin{macro}{\xifstrcmp}\cmdlabel{impl:xifstrcmp}
% The macro is based on the |\pdfstrcmp| primitive.\seedesc{ifxstrcmp}
%    \begin{macrocode}
\newcommand\xifstrcmp[2]{\csname @%
  \ifnum\pdfstrcmp{#1}{#2}=0 first\else second\fi
  oftwo\endcsname}
\ettl@onlypdfTeX\pdfstrcmp\ifxstrcmp
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\xifstrequal}\cmdlabel{impl:xifstrequal}
% The macro is based on \sty{etoolbox}-|\ifstrequal|.\seedesc{ifxstrequal}
%    \begin{macrocode}
\newrobustcmd*\xifstrequal[2]{\begingroup
   \protected@edef\@xifstrequal{\endgroup\noexpand\ifstrequal{#1}{#2}%
   }\@xifstrequal}
%    \end{macrocode}
% \end{macro}
%
%
%
% \iffalse
%<package>
%<package>% \ifstrmatch{ pattern }{ true }{ false }
% \fi
%
% \begin{macro}{\ifstrmatch}\cmdlabel{impl:ifstrmatch}
% The macro is base on the |\pdfmatch| primitive.\seedesc{ifstrmatch}
%    \begin{macrocode}
\newcommand\ifstrmatch[2]{\csname @%
 \ifnum\pdfmatch{\detokenize{#1}}{\detokenize{#2}}=1 first\else second\fi
  oftwo\endcsname}
\ettl@onlypdfTeX\pdfmatch\ifstrmatch
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Purely expandable macros with options}
%
% \iffalse
%<package>%----------------------------------------------------------------------------
%<package>% Purely Expandable Macros With Options / Star Forms / Variants
%<package>% \FE@testopt{ #1 }{ commands }{ default option }
% \fi
% \begin{macro}{\FE@testopt}\cmdlabel{impl:FE@testopt}
% Fully expandable |\@testopt|-like test:\seedesc{FE@testopt}
%    \begin{macrocode}
\newcommand\FE@testopt[3]{\ifsinglechar [{#1}{#2#1}{#2[{#3}]{#1}}}
%    \end{macrocode}
%
% \end{macro}
%
% \iffalse
%<package>
%<package>% \FE@ifstar{ #1 } { \StarredMacro }{ \NotStarredMacro }
% \fi
% \begin{macro}{\FE@ifstar}\cmdlabel{impl:FE@ifstar}
% Fully expandable |\@ifstar|-like test:\seedesc{FE@ifstar}
%    \begin{macrocode}
\newcommand\FE@ifstar[3]{\ifsinglechar *{#1}{#2}{#3{#1}}}
%    \end{macrocode}
%
% \end{macro}
%
% \iffalse
%<package>
%<package>% \FE@ifchar{#1}{#2}{ \SpecialFormMacro }{ \NormalMacro }
% \fi
% \begin{macro}{\FE@ifchar}\cmdlabel{impl:FE@ifchar}
% Plus généralement, on peut tester si une macro est suivie d'un caractère donné:\seedesc{FE@ifchar}
%    \begin{macrocode}
\newcommand\FE@ifchar[4]{\ifsinglechar{#1}{#2}{#3}{#4{#2}}}
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%<package>
% \fi
%
% \goodbreak
%
% \begin{macro}{\DeclareCmdListParser}\cmdlabel{impl:DeclareCmdListParser}
%
% |\DeclareCmdListParser|\seedesc{DeclareCmdListParser} acts in the same way as
% \sty{etoolbox}-|\DeclareListParser| and the command-list-parser
% are sensitive to the category code of the \prm{separator}
%
%% \iffalse
%<package>
%<package>% \DeclareCmdListParser : general constructor for command-list parsers
%<package>%                         \DeclareCmdListParser\ParserName{separator}
% \fi
% \begin{codecomment}
% The command-list-parser will be defined only if it is definable:
%
%    \begin{macrocode}
\newrobustcmd*\DeclareCmdListParser[2]{%
  \@ifdefinable#1
    {\expandafter\etextools@defcmdparser\expandafter{#1}{#2}}}
%    \end{macrocode}
%
% Then the job is done by |\etextools@defcmdparser|: we need the `\,\&\,' to have a catcode of 3
% and globally define the macro inside a purposeful group:
%
%    \begin{macrocode}
\begingroup\catcode`\&=3\catcode`\`=3
\gdef\etextools@defcmdparser#1#2{%
   \begingroup
   \def\`##1`{\expandafter\noexpand\csname ##1\endcsname}%
%    \end{macrocode}
% Now the parser definition is made inside an protected-|\edef| in order to expand control sequences names:
%    \begin{macrocode}
   \protected@edef\defineparser{\endgroup
%    \end{macrocode}
% Here we define the entry-point: we first test if the command was starred.
% This is possible because the list-parser has always a mandatory argument (the \prm{list} itself or the \prm{listmacro}) :
%    \begin{macrocode}
   \long\def#1####1{\noexpand\FE@ifstar{####1}
      {\`ettl@lst@opt\string#1`{}}
      {\`ettl@lst@opt\string#1`\noexpandafter}}%
%    \end{macrocode}
% Both starred and not-starred versions have an optional argument which is the auxiliary command, whose name is |\do| if not specified.
% It is possible to test the option for the same reason:
%    \begin{macrocode}
   \long\csdef{ettl@lst@opt\string#1}####1####2{\noexpand\FE@testopt{####2}
      {\`ettl@lst@@pt\string#1`{####1}}{\noexpand\do}}%
%    \end{macrocode}
% Definition of the parser with its arguments :\quad |[optional command]{list or listmacro}|. If the starred version
% was used, then we do not have to expand the (mandatory) \prm{list}:
%    \begin{macrocode}
   \long\csdef{ettl@lst@@pt\string#1}####1[####2]####3{%
      ####1\`ettl@lst\string#1`####1{####3}{####2}}%
%    \end{macrocode}
% On the other hand, if the parser was not starred, the (mandatory) \prm{listmacro} is expanded once:
%    \begin{macrocode}
%    \end{macrocode}
% ListParser is defined and leads to |\`ettl@lst\string\ListParser`| in all cases; here the \prm{list} is in first position,
% the auxiliary commands come after, so we reverse the order and add a \prm{separator} in case the \prm{list} is empty:
%    \begin{macrocode}
   \long\csdef{ettl@lst\string#1}####1####2{%
         \`ettl@lst@\string#1`{####2}####1\unexpanded{#2}&}%
%    \end{macrocode}
% In the following macro, we extract the first item from the list (before the \prm{separator} |#2|), for treatment:
%    \begin{macrocode}
   \long\csdef{ettl@lst@\string#1}####1####2\unexpanded{#2}####3&{%
%    \end{macrocode}
% Proceed with the first item, if not empty:
%    \begin{macrocode}
      \noexpand\ifblank{####2}
            {}
            {\noexpand\ettl@lst@doitem{####1}{####2}}%
%    \end{macrocode}
% If the remainder of the list is empty then break loop, otherwise restart extracting the next, first item for treatment:
%    \begin{macrocode}
      \noexpand\ifblank{####3}
            {\noexpand\ettl@listbreak}
            {\`ettl@lst@\string#1`{####1}####3}&}%
%    \end{macrocode}
% Now the definitions are ready, execute them:
%    \begin{macrocode}
   }\defineparser}%
%    \end{macrocode}
% |\ettl@lst@doitem| apply the auxiliary command(s) (in |#1|) to the item (|#2|):
% |\ettl@listbreak| breaks the loop, removing the extra \sty{\&}:
%    \begin{macrocode}
   \long\gdef\ettl@lst@doitem#1#2{#1{#2}}%
   \long\gdef\ettl@listbreak#1&{}%
%    \end{macrocode}
% Leave ``catcode-group'':
%    \begin{macrocode}
\endgroup
%    \end{macrocode}
% \end{codecomment}
% \end{macro}
% \iffalse
%<package>
%<package>
%<package>% \csvloop[\command]\csvListMacro
%<package>% \csvloop*[\command]{item,item,item}
% \fi
%
% \begin{macro}{\csvloop}\cmdlabel{impl:csvloop}
% Definition of |\csvloop|:\seedesc{csvloop}
%    \begin{macrocode}
\DeclareCmdListParser\csvloop{,}
%    \end{macrocode}
% \end{macro}
%
% \begin{codecomment}
% Definition of |\listloop| (with a `\,\textbar\,'  of catcode 3 -- cf.\sty{etoolbox}):
%    \begin{macrocode}
\begingroup\catcode`\|=3
   \def\do{\DeclareCmdListParser\listloop{|}}%
\expandafter\endgroup\do
%    \end{macrocode}
% \end{codecomment}
%
% \begin{codecomment}
% Definition of |\toksloop| (with no delimiter):
%    \begin{macrocode}
\DeclareCmdListParser\toksloop{}%
%    \end{macrocode}
% \end{codecomment}
%
% \iffalse
%<package>
%<package>% \csvtolist \ListMacro \csvListMacro
%<package>% \csvtolist* \ListMacro {item,item,item}
% \fi
% \begin{macro}{\csvtolist}\cmdlabel{impl:csvtolist}
% This is the first application of |\csvloop|:\seedesc{csvtolist}
%    \begin{macrocode}
\newrobustcmd*\csvtolist{\@ifstar
      {\ettl@tolist\z@{}\csvloop}
      {\ettl@tolist\z@\expandnext\csvloop}}%
\long\def\ettl@tolist#1#2#3#4#5{\ifx#1\z@\let#4\@empty\fi
   \def\ettl@to@list{#3*[{\unexpanded{\listadd#4}}]%
   }#2\ettl@to@list{#5}}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
% \fi
%
% \begin{macro}{\tokstolist}\cmdlabel{impl:tokstolist}
% This is the first application of |\toksloop|:\seedesc{tokstolist}
%    \begin{macrocode}
\newrobustcmd*\tokstolist{\@ifstar{\ettl@tokstolist\z@{}}{\ettl@tokstolist\z@\expandnext}}
\def\ettl@tokstolist#1#2#3#4{\ifx#1\z@\let#3\@empty\fi
      \def\ettl@toks@tolist{\toksloop*[{\unexpanded{\listadd#3}}]}%
         #2\ettl@toks@tolist{#4{}}}
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%<package>
%<package>% \csvtolistadd \ListMacro \csvListMacro
%<package>% \csvtolistadd* \ListMacro {item,item,item}
% \fi
% \begin{macro}{\csvtolistadd}\cmdlabel{impl:csvtolistadd}
% It's quite the same\seedesc{csvtolistadd} as the latter except it does not
% reset the list to empty at the very beginning:
%    \begin{macrocode}
\newrobustcmd*\csvtolistadd{\@ifstar
      {\ettl@tolist\@ne{}\csvloop}
      {\ettl@tolist\@ne\expandnext\csvloop}}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
% \fi
%
% \begin{macro}{\tokstolistadd}\cmdlabel{impl:tokstolistadd}
% It's quite the same\seedesc{tokstolistadd} as the latter except it does not
% reset the list to empty at the very beginning:
%    \begin{macrocode}
\newrobustcmd*\tokstolistadd{\@ifstar{\ettl@tokstolist\@ne{}}{\ettl@tokstolist\@ne\expandnext}}%
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>%\listdel\listMacro{item}
%<package>%\listgdel\listMacro{item}
%<package>%\listedel\listMacro{item}
%<package>%\listxdel\listMacro{item}
% \fi
% \begin{macro}{\listdel}\cmdlabel{impl:listdel}
% |\listdel| removes an item from a list:\seedesc{listdel}
%    \begin{macrocode}
\newrobustcmd\listdel[2]{\@listdel\def{#1}{#2}}%
%    \end{macrocode}
% \end{macro}
%
%
%    \begin{macrocode}
\newrobustcmd\listgdel[2]{\@listdel\gdef{#1}{#2}}%
\newrobustcmd\listxdel[2]{\begingroup
   \protected@edef\@listxdel{\endgroup
      \unexpanded{\@listdel\gdef{#1}}{#2}%
   }\@listxdel}%
\newrobustcmd\listedel[2]{\begingroup
   \protected@edef\@listedel{\endgroup
      \unexpanded{\@listdel\def{#1}}{#2}%
   }\@listedel}
%    \end{macrocode}
%
% \begin{codecomment}
% Now you noticed the job is delayed to a general macro |\@listdel| which is relatively tricky !
% We need first to be placed in an environment where the `\,\textbar\,' delimiter has a category code of 3
% (cf \sty{etoolbox}-lists definitions):
%    \begin{macrocode}
\begingroup\catcode`\|=3\catcode`\&=3
%    \end{macrocode}
% Inside this ``catcode-group'' the definition of |\@listdel| ought to be global:
%    \begin{macrocode}
\long\gdef\@listdel#1#2#3{%
%    \end{macrocode}
% \qquad |#1|=|\def| or |\gdef|, |#2|=\prm{listmacro}, |#3|=\prm{item} to remove.\par
% In order to preserve the hash-table from temporary definitions, a group is opened:
%    \begin{macrocode}
\begingroup
      \long\def\@tempa##1|#3|##2&{##1|##2\@tempb}%
%    \end{macrocode}
%
% |\@tempa| is a delimited macro whose aim is to remove the first \prm{item} found in the list
% and it adds |\@tempb| after the result. If the \prm{item} was not in the list, then |##2|
% will be empty. Note that |\@tempa| is the only macro whose definition depends on the \prm{item}
% (and then leads |\@listdel| not to be fully-expandable).
%
% The result of |\@tempa| expansion is then given to |\@tempb| whose purpose is to cancel out
% whatever is found between the two delimiters: \textbar|\@tempb|...\textbar|\@tempb|:
%    \begin{macrocode}
   \long\def\@tempb|##1|\@tempb##2|\@tempb{%
      \ifblank{##2}{\unexpanded{##1}}
%    \end{macrocode}
% If the \prm{item} \textbf{was not} is the list, then |##2| will be empty, and§
% \qquad |\@tempb|\textbar...\textbar|\@tempb|...\textbar|\@tempb|§
% is replaced by the \emph{original-}list (\ie |##1| -- that we shall not expand), then the loop is broken;
% otherwise the \prm{item} was in the list and |##1| is the \emph{shortened-}list without the \prm{item}. We have to loop
% to remove all the \prm{item{\tt s}} of the list, except in the case where the \emph{shortened-}list
% is empty after having removing \prm{item} (|##1| empty):
%    \begin{macrocode}
      {\ifblank{##1}{}{\@tempx##1&}}}%
%    \end{macrocode}
% Now we just have to (define and) expand |\@tempx| in an |\edef| which is going to redefine
% the \prm{listmacro}. |\@tempx| expands first |\@tempa| and then |\@tempb| on the result of
% the expansion of |\@tempa|. The macro |\@tempx| itself has an argument: it is (at first stage) the
% replacement text of \prm{listmacro}:
%    \begin{macrocode}
   \long\def\@tempx##1&{\expandafter\@tempb\@tempa|##1|\@tempb|#3|&}%
   \edef\@redef{\endgroup
      \unexpanded{#1#2}{% ie: \def or \gdef   \listmacro
%    \end{macrocode}
% |\@redef| redefines the list using (|\def| or |\gdef|), the replacement text is the result
% of the expansion of |\@tempx| on the \prm{listmacro} which is expanded once (to see  its items...):
%    \begin{macrocode}
      \expandafter\@tempx\unexpanded\expandafter{#2}&}%
%    \end{macrocode}
% Then just expand |\@redef| to proceed the redefinition of \prm{listmacro}:
%    \begin{macrocode}
   }\@redef}% end of \@listdel
%    \end{macrocode}
% And ends the ``catcode-group'':
%    \begin{macrocode}
\endgroup
%    \end{macrocode}
% \end{codecomment}
%
%\iffalse
%<package>
%<package>
%<package>% \getlistindex[\indexmacro]{ \listmacro }
%<package>% \getlistindex*[\indexmacro]{ expanded list }
% \fi
%
%
% \begin{macro}{\getlistindex}\cmdlabel{impl:getlistindex}
% \cmd{getlistindex} may be defined, with its star form (no expansion of the list)\seedesc{getlistindex}
% and normal form (\prm{listmacro} expanded once);
% The search-index is initialised at 1:
%
% We first need to get into a group where delimiter `\,\textbar\,' and `\,\&\,' have catcode 3:
%    \begin{macrocode}
\newcommand\getlistindex[1]{\FE@ifstar{#1}
            {\ettl@getlistindex{}\unexpanded}
            {\ettl@getlistindex\expandnext\unexpanded}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\xgetlistindex}\cmdlabel{impl:xgetlistindex}
% |\xgetlistindex| is similar but the \prm{item} is expanded during string comparison (inside |\pdfstrcmp| is pdf\TeX{},
% or before the test if this primitive is not found).
%    \begin{macrocode}
\newcommand\xgetlistindex[1]{\FE@ifstar{#1}
           {\ettl@getlistindex{}\@firstofone}
           {\ettl@getlistindex\expandnext\@firstofone}}
%    \end{macrocode}
% \end{macro}
%
%
% Then the following macro does the job in a loop, which is fully expandable when we can use |\pdfstrcmp|:
%
%    \begin{macrocode}
\begingroup\catcode`\|=3\catcode`\&=3
\long\gdef\ettl@getlistindex#1#2#3{\FE@testopt{#3}{\ettl@get@listindex{#1}{#2}}{}}
\long\gdef\ettl@get@listindex#1#2[#3]#4#5{#1\ettl@get@list@idx{#5}{#4}{\numexpr1}{#2}[{#3}]}
\long\gdef\ettl@get@list@idx#1#2#3#4[#5]{% #1=expanded list, #2=item, #3=index, #4=\unexpanded (event., #5=indexmacro)
   \ifblank{#1}0% the (remainder of) the list is empty
"      {\xifstrcmp{\expandonce{\ettl@list@first@item#1&}}{#4{#2}}}
!      {\ettl@listitem@cmp{\ettl@list@first@item#1&}{#2}{#4}}
         {\ifblank{#5}{\number#3\relax}{\ettl@ifiscount{#5}{#5=\number#3\relax}{\edef#5{\number#3}}}}
         {\expandnext\ettl@get@list@idx{\ettl@list@other@item#1&}{#2}{#3+1}{#4}[{#5}]}}
%    \end{macrocode}
%
% \begin{codecomment}
%
% The next two macros expand to the first item in a list or the remainder of the list respectively:
%
%    \begin{macrocode}
\long\gdef\ettl@list@first@item#1|#2&{#1}
\long\gdef\ettl@list@other@item#1|#2&{#2}
!\long\gdef\ettl@listitem@cmp#1#2#3{%
!   \ifx#3\unexpanded\def\ettl@listitem@cmp@{#2}%
!   \else\protected@edef\ettl@listitem@cmp@{#2}%
!   \fi
!   \expandafter\ifstrequal\expandafter{#1}{#2}}
\edef\ettl@ifiscount{%
   \gdef\noexpand\ettl@ifiscount##1{%
      \noexpand\expandafter\noexpand\ettl@ifiscount@i
         \noexpand\meaning##1\string\count\noexpand\@nil}%
}\ettl@ifiscount
\edef\ettl@ifiscount@i{%
   \gdef\noexpand\ettl@ifiscount@i##1\string\count##2\noexpand\@nil{%
      \noexpand\ifempty{##1}}%
}\ettl@ifiscount@i
%    \end{macrocode}
%
% \end{codecomment}
%
% \iffalse
%<package>
%<package>%\getcsvlistindex{ item }{ csvlistmacro }
%<package>%\getcsvlistindex*{ item }{ item,item,item }
% \fi
% \begin{macro}{\getcsvlistindex} \cmdlabel{impl:getcsvlistindex}
% \strut\seedesc{getcsvlistindex}
%    \begin{macrocode}
\long\gdef\getcsvlistindex#1{\FE@ifstar{#1}
                  {\ettl@getcsvlistindex{}\unexpanded}
                  {\ettl@getcsvlistindex\expandnext\unexpanded}}
%    \end{macrocode}
% \end{macro}
%
% |\xgetcsvlistindex| is similar but the \prm{item} is expanded during string comparison (inside |\pdfstrcmp| is pdf\TeX{},
% or before the test if this primitive is not found).
%
%    \begin{macrocode}
\long\gdef\xgetcsvlistindex#1{\FE@ifstar{#1}
                  {\ettl@getcsvlistindex{}\@firstofone}
                  {\ettl@getcsvlistindex\expandnext\@firstofone}}
%    \end{macrocode}
%
% Then the following macro does the job in a loop, which is fully expandable when we can use |\pdfstrcmp|:
%
%    \begin{macrocode}
\long\gdef\ettl@getcsvlistindex#1#2#3{\FE@testopt{#3}{\ettl@get@csvlistindex{#1}{#2}}{}}
\long\gdef\ettl@get@csvlistindex#1#2[#3]#4#5{#1\ettl@get@csvlist@idx{#5}{#4}{\numexpr1}{#2}[{#3}]}
\long\gdef\ettl@get@csvlist@idx#1#2#3#4[#5]{% #1=expanded list, #2=item, #3=index, #4=\unexpanded (event., #5=indexmacro)
   \ifblank{#1}0% the (remainder of) the list is empty
"      {\xifstrcmp{\expandonce{\ettl@csvlist@first@item#1&}}{#4{#2}}}
!      {\ettl@listitem@cmp{\ettl@csvlist@first@item#1&}{#2}{#4}}
         {\ifblank{#5}{\number#3\relax}{\ettl@ifiscount{#5}{#5=\number#3\relax}{\edef#5{\number#3}}}}
         {\expandnext\ettl@get@csvlist@idx{\ettl@csvlist@other@item#1&}{#2}{#3+1}{#4}[{#5}]}}
%    \end{macrocode}
%
% \begin{codecomment}
% The next two macros expand to the first item in a list or the remainder of the list respectively:
%    \begin{macrocode}
\long\gdef\ettl@csvlist@first@item#1,#2&{#1}
\long\gdef\ettl@csvlist@other@item#1,#2&{#2}
%    \end{macrocode}
% \end{codecomment}
%
%
% \iffalse
%<package>
%<package>%\gettokslistindex{ item }{ tokenslistmacro }
%<package>%\gettokslistindex*{ item }{ list of tokens }
% \fi
% \begin{macro}{\gettokslistindex}\cmdlabel{impl:gettokslistindex}
% \strut\seedesc{gettokslistindex}
%    \begin{macrocode}
\long\gdef\gettokslistindex#1{\FE@ifstar{#1}
                  {\ettl@gettokslistindex{}}
                  {\ettl@gettokslistindex\expandnext}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\long\gdef\ettl@gettokslistindex#1#2{\FE@testopt{#2}{\ettl@get@tokslistindex{#1}}{}}
\long\gdef\ettl@get@tokslistindex#1[#2]#3#4{#1\ettl@get@tokslist@idx{#4}{#3}{\numexpr1}[{#2}]}
\long\gdef\ettl@get@tokslist@idx#1#2#3[#4]{% #1=expanded list, #2=item, #3=index
   \ifblank{#1}0% the (remainder of) the list is empty
      {\expandafter\ifx\expandafter#2\ettl@tokslist@first@item#1&%
         \ettl@afterelse\ifblank{#4}{\number#3\relax}
                  {\ettl@ifiscount{#4}{#4=\number#3\relax}{\edef#4{\number#3}}}%
       \else \ettl@afterfi
         \expandnext\ettl@get@tokslist@idx{\ettl@tokslist@other@item#1&}{#2}{#3+1}[{#4}]%
       \fi}}
%    \end{macrocode}
%
% \begin{codecomment}
% The next two macros expand to the first item in a list or the remainder of the list respectively:
%    \begin{macrocode}
\long\gdef\ettl@tokslist@first@item#1#2&{#1}
\long\gdef\ettl@tokslist@other@item#1#2&{#2}
\endgroup% catcode group
%    \end{macrocode}
% \end{codecomment}
%
%
%
% \iffalse
%<package>
%<package>
%<package>%\getlistitem{ number }{ listmacro }
%<package>%\getlistitem*{ number }{ listmacro }
% \fi
% \begin{macro}{\getlistitem}\cmdlabel{impl:getlistitem}
% \strut\seedesc{getlistitem}
%    \begin{macrocode}
\newcommand\getlistitem[1]{\FE@ifstar{#1}{\ettl@getlistitem{}}
                                         {\ettl@getlistitem\expandnext}}
\begingroup\catcode`\&=3
\long\gdef\ettl@getlistitem#1#2#3{%#2=index, #3=list or list-macro
   #1\ettl@get@list@item{#3}{\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@get@list@item{\ettl@list@other@item#1&}{#2-1}%
      \fi\fi}}
\endgroup
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>
%<package>% \getcsvlistitem{ number }{ csvlistmacro }
%<package>% \getcsvlistitem*{ number }{ item,item,item,... }
% \fi
% \begin{macro}{\getcsvlistitem}\cmdlabel{impl:getcsvlistitem}
% \strut\seedesc{getcsvlistitem}
%    \begin{macrocode}
\newcommand\getcsvlistitem[1]{\FE@ifstar{#1}{\ettl@getcsvlistitem{}}
                                            {\ettl@getcsvlistitem\expandnext}}
\begingroup\catcode`\&=3
\long\gdef\ettl@getcsvlistitem#1#2#3{%#2=index, #3=list or list-macro
   #1\ettl@get@csvlist@item{#3,}{\numexpr#2}}
\long\gdef\ettl@get@csvlist@item#1#2{%
   \ifblank{#1}{}
      {\ifnum#2=1 \ettl@afterelsefi
            \expandonce{\ettl@csvlist@first@item#1&}%
      \else\ifnum#2>0 \ettl@afterfifi
            \expandnext\ettl@get@csvlist@item{\ettl@csvlist@other@item#1&}{#2-1}%
      \fi\fi}}
\endgroup
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
%<package>
%<package>% \gettokslistitem{ number }{ tokslistmacro }
%<package>% \gettokslistitem*{ number }{ list of tokens }
% \fi
% \begin{macro}{\gettokslistitem}\cmdlabel{impl:gettokslistitem}
% \strut\seedesc{gettokslistitem}
%    \begin{macrocode}
\newcommand\gettokslistitem[1]{\FE@ifstar{#1}{\ettl@gettokslistitem{}}
                                            {\ettl@gettokslistitem\expandnext}}
\begingroup\catcode`\&=3
\long\gdef\ettl@gettokslistitem#1#2#3{%#2=index, #3=list or list-macro
   #1\ettl@get@tokslist@item{#3{}}{\numexpr#2}}
\long\gdef\ettl@get@tokslist@item#1#2{%
   \ifblank{#1}{}
      {\ifnum#2=1 \ettl@afterelsefi
            \expandonce{\ettl@tokslist@first@item#1&}%
      \else\ifnum#2>0 \ettl@afterfifi
            \expandnext\ettl@get@tokslist@item{\@gobble#1}{#2-1}%
      \fi\fi}}
\endgroup
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \iffalse
%<package>%----------------------------------------------------------------------------
%<package>
%<package>% \collectoks{ cs-token }{ list of allowed tokens }{ commands to expand after }
%<package>
% \fi
% \begin{macro}{\collecttoks}\cmdlabel{impl:collecttoks}
% A simple token scanner, vectorized version of \cs{futurelet}.\seedesc{collecttoks}
%    \begin{macrocode}
\newrobustcmd*\collecttoks{\@ifstar\ettl@scantoks\ettl@collecttoks}
\def\ettl@scantoks{\@latex@error{The starred version of \noexpand\collecttoks
   \MessageBreak (i.e. scantoks) is NOT implemented YET.}\@ehd}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<package>
% \fi
%
% \begin{macro}{\ettl@collecttoks}
%    \begin{macrocode}
\def\ettl@collecttoks#1#2#3{\begingroup
   \def\ettl@collecttoks@list{#2}%
   \let#1=\@empty
   \def\Next{\ettl@collect@toks{#1}}%
   \def\finale{#3}%
   \futurelet\ettl@x\Next}
\def\ettl@collect@toks#1{%
   \edef\ettl@i{\gettokslistindex\ettl@x\ettl@collecttoks@list}%
   \ifcase\ettl@i \edef\next{\endgroup
      \def\noexpand#1{\expandonce{#1}}\expandonce{\finale}}%
   \else \def\next{\ettl@collect@toks@next{#1}}%
   \fi\next}
\def\ettl@collect@toks@next#1#2{%
   \edef#1{\expandonce{#1}\unexpanded{#2}}%
   \futurelet\ettl@x\Next}
%    \end{macrocode}
% \end{macro}
%
%
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \subsection{Example}
%
%    \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,fancyvrb}
\usepackage{etextools}
\hypersetup{colorlinks,pdfstartview={FitH}}
\geometry{top=1.5cm,bottom=1.2cm,left=2.5cm,right=1cm}
\fancyhf{}
\fancyhead[L]{Examples for the \sty{etextools} package}
\pagestyle{fancy}
\MakeShortVerb{\|}

\makeatletter
\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$}}}
\definecolor{fecc}{rgb}{.2,.6,.2}
\def\strip@meaning{\expandafter\strip@prefix\meaning}
\def\strip@macro{\expandafter\strip@macroprefix\meaning}
\def\get@params#1{\expandafter\@get@params\meaning#1\@nil}
\edef\@get@params{%
   \def\noexpand\@get@params\detokenize{macro:}##1\detokenize{->}##2\noexpand\@nil{##1}%
}\@get@params
\def\make@macro#1{\string\def\string#1\get@params#1\string{\strip@meaning#1\string}}
\newcommand\preline{\@ifstar{\@preline}{\hrulefill\par\@preline}}
\def\@preline#1{\noindent\hskip6pt\texttt{\make@macro#1}\par\vskip1.5ex}

\def\meaningcs#1{\expandafter\meaning\csname#1\endcsname}
\def\Meaningcs#1{\expandafter\strip@meaning\csname #1\endcsname}
\@ifundefined{pdfstrcmp}{\let\ifpdfTeX\iffalse}{\let\ifpdfTeX\iftrue}

\newcommand*\test{\@ifstar{\let\fe\relax\testi}{\let\fe\FE\testi}}
\newcommand\testi[1]{%
   \csname test#1\endcsname
   \edef\usercmd{\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 \sty{etextools} package}
\author{Florent Chervet}
\date{July 22, 2009}
\maketitle

\tableofcontents


\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}



\subsection{Detokenize the replacement text of a named-sequence}
\def\detokenizecs#1{\expandnext\expandnext\detokenize{\csname #1\endcsname}}
\def\testexpandnext{%
   \edef\expandnextTest{\detokenizecs{document}}}
\preline\detokenizecs
\test{expandnext}


\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}
%
% \begin{changelog}\footnotesize
%
% \begin{release}{2t}{2009-08-15}
% \item
% Addition of \cmdref{ifnotempty}, \cmdref{iflastchar}, \cmdref{ifstrcmp}, \cmdref{ifstrmatch}
%
%
% \end{release}
%
% \begin{release}{2h}{2009-08-14}
% \item
%  \cmdref{getlistindex} is now fully expandable
%
% \item Addition of\\
%  \cmdref{toksloop} and \cmd{toksloop*} \\
%  \cmdref{tokstolist} and \cmd{tokstolist*} \\
%  \cmdref{getcsvlistindex} and \cmdref{getcsvlistitem} \\
%  \cmdref{gettokslistindex} and \cmdref{gettokslistitem} \\
%
% \item Addition of\\
% \cmdref{collecttoks} -- a vectorized version of \cs{futurelet}.\\
% \cmdref{FE@ifchar} as a generalization of \cmdref{FE@ifstar}.
%
% \end{release}
%
% \begin{release}{2z}{2009-08-12}
% \item Addition of \\
% \cmdref{ifempty}, \cmdref{toksloop}, \cmdref{tokstolist} and \cmdref{tokstolistadd}
% \item
%  Modification of \cmdref{ifsinglechar}\\
% |\ifsinglechar| now works with |\ifempty| so that:\\
% \begin{tabbing}
% \quad\=|\macro{  *  }|\quad\= is no more considered as a starred form \\
% \>\>because of the spaces following the |*| \\
% \>\> however, the spaces \textbf{before} are skipped, \\
% \>\>as does |\@ifnextchar| from the \LaTeX{} kernel.
% \end{tabbing}
%
% \item
% Index added to this documentation paper.
% \end{release}

% \begin{release}{2e}{2009-07-14}
% \item
% First version (include an example file)
% \end{release}
%
% \end{changelog}
%
% \begin{thebibliography}{9}
%
% \bibitem{etex}
%   David Carlisle and Peter Breitenlohner
%   \textit{The \sty{etex} package};
%   1998/03/26 v2.0;
%   \CTAN{macros/latex/contrib/etex-pkg/}.
%
% \bibitem{etoolbox}
%   Philipp Lehman
%   \textit{The \sty{etoolbox} package};
%   2008/06/28 v1.7;
%   \CTAN{macros/latex/contrib/etoolbox/}.
%
% \end{thebibliography}
%
% \setcounter{IndexColumns}{2}\clearpage
% \PrintIndex
%
% \label{LastPage}
% \Finale