summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/nicetext/fifinddo.sty
blob: 456ddd1a67f56eda7de2ad3b7da9fff1b2509753 (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
%% Macro package `fifinddo.sty' for LaTeX2e,    %% FIDO, FIND!

%% copyright (C) 2009 Uwe L\"uck, 

%%   http://www.contact-ednotes.sty.de.vu 

%% -- author-maintained in the sense of LPPL below -- 

%% for processing tex(t) files 

%% (checking, filtering, converting, substituting, expanding, ...)

 

\def\fileversion{0.4} \def\filedate{2010/03/29}



%% This file can be redistributed and/or modified under 

%% the terms of the LaTeX Project Public License; either 

%% version 1.3a of the License, or any later version.

%% The latest version of this license is in

%%

%%     http://www.latex-project.org/lppl.txt

%%

%% We did our best to help you, but there is NO WARRANTY. 

%% Please report bugs, problems, and suggestions via 

%% 

%%   http://www.contact-ednotes.sty.de.vu 

%% 

%% For the full documentation, look for `fifinddo.pdf'. 

%% Its source starts in `fifinddo.tex'.

%%

%% === Format and package version ===

\NeedsTeXFormat{LaTeX2e}[1994/12/01] 

% 1994/12/01: \newcommand* etc. 

\ProvidesPackage{fifinddo}[\filedate\space v\fileversion\space

                           filtering TeX(t) files by TeX (UL)] 

%% 

%% === Category codes ===

%%

%% We use the ``underscore" as ``compound identifier." 

\catcode`\_=11 %% underscore used in control words

%%

%% |\MakeOther| is a synonym for `\@makeother', needed for matching 

%% special characters from the input file. It is exemplified by 

%% |\fdPatternCodes| which is the default of |\PatternCodes|. 

%% The latter is used in setup macros for reading patterns. 

%% We offer |\SetPatternCodes{<commands>}| 

%% (redefining `\PatternCodes')

%% and |\ResetPatternCodes| 

%% (for returning to `\fdPatternCodes') 

%% so setup scripts such as 'mdoccorr.cfg' have shorter lines.

\@ifundefined{MakeOther}{\let\MakeOther\@makeother}{}

\newcommand*{\fdPatternCodes}{\MakeOther\&\MakeOther\$} 

\newcommand*{\SetPatternCodes}{\def\PatternCodes}

\newcommand*{\ResetPatternCodes}{\let\PatternCodes\fdPatternCodes}

\newcommand*{\PatternCodes}{} \ResetPatternCodes

  %% TODO adding/removing; `*' may be wrong 2010/03/29

%%

%% It would be bad to have `\MakeOther\%' and `\MakeOther\ ' here in 

%% that this may have unexpected, weird effects with arguments of 

%% setup macros. (With `\MakeOther\ ' you must not indent within a

%% setup command, and if you add `\MakeOther\%' the setup command 

%% must stay in one line.)

%% Therefore neither `\dospecials' nor `\@sanitize' are 

%% used. Curly braces remain untouched as default delimiters in setup 

%% macros. For matching them, you must use `\MakeOther\{' and 

%% `\MakeOther' in your `\PatternCodes', or |\Delimiters| to introduce 

%% new ones at the same time, e.g., `\Delimiters\[\]': 

\newcommand*{\Delimiters}[2]{%

  \MakeOther\{\MakeOther\}\catcode`#1=1\catcode`#2=2\relax}

%%

%% For replacing strings or for defining other strings of ``other" 

%% characters by `\edef', you can use some \LaTeX\ constructs---here 

%% are copies |\PercentChar| and |\BackslashChar| of them

%% (do you need more?): 

\newcommand*{\PercentChar}{}   \let\PercentChar\@percentchar

\newcommand*{\BackslashChar}{} \let\BackslashChar\@backslashcar

%%

%%  == File handling ==

\newwrite\result_file %% or write to \@mainaux!?

%% |\ResultFile{<output>}| opens (and empties) a file 

%% <output> to be written into. 

\newcommand*{\ResultFile}[1]{%

  \def\result_file_name{#1}%

  \immediate\openout\result_file=#1}

%% |\WriteResult{<balanced>}| writes a <balanced> line into 

%% <output> (or more lines with `^^J').

\newcommand*{\WriteResult}[1]{% 

  \immediate\write\result_file{#1}}

%% |\WriteProvides| writes a `\ProvidesFile' command to the 

%% opened <output> file. This should be used when <output> 

%% is made as \LaTeXe\ input. 

\newcommand*{\WriteProvides}{%

  \WriteResult{%

    \string\ProvidesFile{\result_file_name}% 

      [\the\year/\two@digits\month/\two@digits\day\space 

       automatically generated with fifinddo.sty]}}%

%% |\ProcessFileWith{<input>}{<loop-body>}| opens a file <input> 

%% and runs a loop on its lines the main body of which is <loop-body>. 

%% When the <loop> starts, a new line of <input> is stored as macro 

%% %% <- the <loop> 2010/03/10

%% |\fdInputLine|. 

\newcommand*{\ProcessFileWith}[2]{%

  \openin\@inputcheck=#1%

%   \ifeof\@inputcheck  %% bad `exists?' test

%     \PackageError{fifinddo}{File `#1' not here}%

%                            {Mistyped?}%

%   \else

    \global\c@fdInputLine=\z@ %% line counter reset

    \begingroup 

      \MakeOther\{\MakeOther\}\@sanitize

      %% from docstrip.tex: 

      % \MakeOther\^^A\MakeOther\^^K%% irrelevant, not LaTeX

      \endlinechar\m@ne

      %% <- cf. TeXbook "extended keyboards" up-/downarrow

      %%    -> "math specials", cf. "space specials"

      \MakeOther\^^I% ASCII horizontal tab -- guessed!? ^^L!?

%% With v3.1, we support non-ASCII:

      \count@=128

      \loop

      \ifnum\count@<\@cclvi

        \catcode\count@=12

        \advance\count@\@ne

      \repeat

      \loop \ifeof\@inputcheck \else 

        \read\@inputcheck to \fdInputLine

        \ignorespaces #2%

      \repeat

    \endgroup

%   \fi

  \closein\@inputcheck} 

%% |\CloseResultFile| closes <output>. 

\newcommand*{\CloseResultFile}{\immediate\closeout\result_file}

%%

%% TODO: write EOF for debugging!?---%% 2010/03/18

%% Peter Wilson's \ctanpkgref{newfile}

%% provides more powerful file handling. 

%% % <- TODO relevant? 2009/04/12

%%

%% %% \pagebreak %% removed 2010/03/24

%% TODO move theory to fifinddo.tex 2009/04/12

%%  == Basic handling of substring conditionals ==

%% \label{sec:theory}

%% === ``Substring Theory" === 

%% \begin{flushright}\it

%% I wished I could study string theory,\\

%% but I only could study substring theory.

%% \end{flushright}

%% A \TeX\ macro, say, `\find' whose parameter text 

%% (cf. \TeX book p.~203)

%% starts with `#1<pattern>#2&' stops \TeX\ with an error if it does 

%% not find <pattern> and then `&'. Otherwise we have a situation 

%% `\find<split1><pattern><split2>&', and `\find' reads <split1> as 

%% #1 and <split2> as #2. An important point to note is that <split1> 

%% will not contain <pattern>, but possibly <pattern> has more 

%% occurrences in <split2>. In this sense, `\find' uses the 

%% \emph{first} occurrence of <pattern> it finds in order to delimit #1. 

%% Finding the \emph{last} occurrence of <pattern> therefore needs a 

%% special idea. 

%%

%% In order to use `\find' for a test whether <pattern> is in 

%% <target>, we build a ``sandbox" |\find<sand>&|, where <sand> 

%% contains <target> \emph{and additionally} <pattern>---as a 

%% ``dummy;" so `&' delimits the search and `\find' finds 

%% <pattern> either in <target> or somewhere else before `&'. 

%%

%% Consider the simple sandbox |\find<target><pattern>&|. 

%% We can test #1 and #2 on being empty by `\ifx$#1$' and `\ifx$#2$'. 

%% If #2 is empty, <pattern> is \emph{not} in <target>. 

%% If #1 is empty at the same time, <target> is empty. 

%% If #1 is empty and #2 is not, <pattern> \emph{starts} <target>! 

%% This can be used to implement 

%% Wikipedia-like lists                 %% TODO 2009/04/11

%% and to distinguish package code from comments in 'makedoc'. 

%%

%% If #2 is \emph{not} empty, <pattern> occurs in <target>---or this once 

%% was \emph{thought}, some time in developping the present package, 

%% as well as in the version of 'substr.sty' marked 

%% `2005-11-29',\footnote{\url{http://ctan.org/pkg/substr}. 

%%                        'substr' does not change category codes 

%%                        as 'fifinddo' does 

%%                        and uses \cs{@nil} as delimiter instead of 

%%                        our &&.} try 

%% (if that version still is installed)\footnote{The ``feature" has 

%%                        been fixed with v1.2 as of 2009/10/20 of 

%%                        'substr.sty'.}

%% \[`\IfSubStringInString{<str1><str2><str1>}{<str1><str2>}{YES}{NO}'\] 

%% which works \emph{verbatim} as well as considering <str1> and 

%% <str2> \emph{placeholders}, e.g., for

%% \begin{center}

%%   `\IfSubStringInString{day after day}{day after }{YES}{NO}'\footnote{%

%%     Likewise \texttt{t\string\^ete-\string\`a-t\string\^ete} ...}\\ 

%%     %% <- `e' was missing 2010/03/17

%%   `\IfSubStringInString{AMSTERDAM}{AMSTERD}{YES}{NO}'\\

%%   `\IfSubStringInString{TORONTO}{TORON}{YES}{NO}'\\

%%   `\IfSubStringInString{bonbon}{bon}{YES}{NO}'\footnote{%

%%     Polynesian: `aku aku', `rongorongo', `wiki wiki' ...}\\

%%   `\IfSubStringInString{bonobo}{bono}{YES}{NO}'

%%   (an ape)

%% \end{center}

%% or `\IfSubStringInString{ionization}{ionizat}{YES}{NO}'.\footnote{%

%%   Read 'substr.sty' or try ``normal" things to convince yourself 

%%   that the syntax indeed is 

%%   &\IfSubStringInString{<pattern>}{<target>}{<yes>}{<no>}.} 

%% Same with \LaTeX's internal `\in@':\footnote{\cs{in@} has been 

%%              fixed after my warning on Heiko Oberdiek's proposal---at 

%%              least in the repository.---On 2009/04/21 

%%              I learn from Manuel P\'egouri\'e-Gonnard 

%%              that the first versions of his 'ted' 

%%              had a similar bug, fixed on v1.05 essentially like here; 

%%              Steven Segletes confirms that his 'stringstrings' doesn't 

%%              suffer the problem (returning positions of substrings and 

%%              numbers of occurrences).}

%% \[`\makeatletter \in@{bonbon}{bon}\ifin@ YES\else NO\fi \makeatother'\]

%% %% \makeatletter \in@{bonbon}{bon}\ifin@ YES\else NO\fi \makeatother

%% %% \IfSubStringInString{ionization}{ionizat}{YES}{NO}

%%

%% In general, the previous approach \emph{fails if and exactly if} 

%% <pattern> has a \emph{period} $p$---less than its length---in the sense of that 

%% the $p$th token to the right or left of each token in <pattern> 

%% is the \emph{same} token. 

%% `AMSTERDAM' has a period 8, `day after day' 10, `bonbon' 3, `bonobo' 4.

%% There is a counterexample <target> of length $p$ iff 

%% <pattern> has period $p$, namely the first substring of <pattern> 

%% having length $p$. If the length of <pattern> exceeds a multiple 

%% $mp$ of its period, the first $mp$ tokens of <pattern> form 

%% a counterexample <target>. 

%%

%% Therefore, a sandbox must have something between <target> and 

%% <pattern>.\footnote{Must? Actually, I preferred this solution to 

%%   other ideas like measuring the length of <split2>.}

%% We choose |\find<target>~<pattern>$&| as standard. 

%% The `$' will be used as an argument delimiter to get rid of the dummy 

%% <pattern> in <split2>, as well as to decide whether the match was 

%% in <target> or in the dummy part of the sandbox. 

%% The `$' can be replaced by another tilde `~' in order to 

%% test whether <target> \emph{ends} on a <pattern>, defining a macro 

%% like `\findatend' whose parameter text starts with `#1<pattern>~#2&'.

%% 

%% === Plan for proceeding ===

%% When we check a file for several patterns, we seem to need 

%% \emph{two} macros for each pattern: one that has the pattern 

%% in its parameter text and one that stores the pattern for building 

%% the sandbox.\footnote{If it were for the pattern only, the parsing 

%%   macro might suffice and the macro calling it might extract the 

%%   pattern from a ``dummy expansion." Somewhat too much for me now; 

%%   on the other hand the calling macro also hands some ``current" 

%%   informations to the parsing macro---oh, even this could be 

%%   handled by a general ``calling" macro \dots}

%%   %% TODO 2009/04/15

%% We use a separate \emph{``name space"} for each of 

%% both kinds. The parsing macro and the macro building the sandbox 

%% will have a common \emph{``identifier"} by which the user or 

%% programmer calls them. Actually, she will usually (first) call 

%% the sandbox box builder. The sandbox builder calls the parsing 

%% macro. When \emph{all} occurrences of a pattern in the target are 

%% looked for, the parser may call itself. 

%%

%% Actually, the parsing macro will execute certain actions 

%% depending on what it finds in the sandbox, so we call it a 

%% \emph{``substring conditional"}. It may read additional arguments 

%% after the sandbox that store information gathered before. 

%% This is especially useful for designing \emph{``expandable"} 

%% chains (sequences) of conditionals where macros cannot store information in 

%% macros. The macro setting up the sandbox will initialize such 

%% extra arguments at the same time. 

%%

%% It may be more efficient \emph{not} to use the following setup 

%% macros but to type the macros yourself, just using the following 

%% as templates. The setup macros are especially useful with patterns 

%% that contain ``special characters," as when you are looking for 

%% %% TODO repetition of single right quote not working 2010/03/19

%% lines that might be package comments. 

%%

%% === Meta-Setup ===

%%

%% A setup command <setup-cmd> will have the following syntax: 

%% \[|<setup-cmd>{<job-id>}[<changes>]{<pattern>}<more-args>|\]

%% <changes> will, in the first instance, be category code changes 

%% for reading <pattern> overriding the settings in `\PatternCodes'. 

%% They are executed after the latter in a local group. 

%% It may be safer to redefine `\PatternCodes' instead 

%% of using the optional <changes> argument.

%%

%% A macro 

%% \[|\StartFDsetup{<do-setup>}{<job-id>}[<changes>]|\]

%% shared by setup commands 

%% may read <job-id> and <changes> for <setup-cmd>. 

%% |<do-setup>| will be the macro that reads <pattern> (and more) 

%% and processes it. It must contain `\endgroup' to match 

%% `\begingroup' from `\FD_prepare_pattern'.

%% <job-id> is stored in a macro |\fdParserId|.

%% The default for <changes> is \emph{nothing}.

\newcommand*{\StartFDsetup}[1]{%

    \let\FD_do_setup#1%

    \afterassignment\FD_prepare_pattern

    \def\fdParserId}

\newcommand*{\FD_prepare_pattern}[1][]{%

    \begingroup \PatternCodes #1\FD_do_setup}

%% So <setup-cmd> should be set up about as follows:

%% \begin{quote}

%%   `\newcommand*{<setup-cmd>}{\StartFDsetup<do-setup>}'\\

%%   `\newcommand*{<do-setup>}[<args>]{<action>}'

%% \end{quote}

%% <do-setup>'s first argument will be the <pattern> argument

%% of <setup-cmd>.

%%

%% === Setup for conditionals ===

%% `substr_cond' is the ``name space" for substring conditionals. 

%% A colon separates it from \emph{``job identifiers"} in the actual 

%% macro names. 

\def\substr_cond{substr_cond:}

%%

%% |\MakeSubstringConditional{<id>}[<changes>]{<pattern>}| 

%% starts the definition of a conditional with identifier <id> 

%% and pattern <pattern>. <changes> optionally add commands to 

%% be executed after `\PatternCodes' in a local group. 

%%

\newcommand*{\MakeSubstringConditional}

            {\StartFDsetup\mk_substr_cond}

%%

%% `\begingroup' |\mk_substr_cond{<pattern>}| %% TODO!? 2010/03/22

%% can be directly called by other programmer setup commands when 

%% `\fdParserId' and <pattern> have been read.

\def\mk_substr_cond #1{%% #1 pattern string

  \endgroup \@namedef{\substr_cond \fdParserId}##1#1##2&}

%%

%% This really is not \LaTeX. We are starting defining a macro 

%% `\substr_cond:<id>' in primitive \TeX\ with `\def' in the form

%% \[`\def\substr_cond:<id>#1<pattern>#2&'\]

%% where `\csname' etc. render \lq`:<id>'\rq\ part of the macro name. 

%% The user or programmer macro produces the part of the definition 

%% until the delimiter `&' to match the sandbox. You have to add 

%% (maybe) #3 etc. and the `{<definition text>}' 

%% just as with primitive \TeX.

%%

%% === Setup for sandboxes === 

%% There was a \emph{question:} will we rather see 

%% \emph{string macros} or \emph{strings from macro arguments}? 

%% The input file content always comes 

%% as `\fdInputLine' first, so we at least \emph{must account} for 

%% the possibility of string macros as input.

%%

%% One easy way to apply several checks and substitutions to 

%% `\fdInputLine' before the result is written to <output> is 

%% `\let\OutputString\fdInputLine' and then let `\OutputString' 

%% be to what each job refers as \emph{its} 

%% input and output, finally `\WriteResult{\OutputString}'. 

%% (`\fdInputLine' might better not be touched, it could be used 

%% for a final test whether any change applied for some message on 

%% screen, even with an entirely expandable chain of actions.)

%% This way each job, indeed each recursive substitution of a single 

%% string must start with expanding `\OutputString'. 

%%

%% On the other hand, there is the idea of \emph{``expandable" 

%% chains of substitutions}. We may, e.g., define a macro, say, 

%% `\manysubstitutions{<macro-name>}', such that 

%% `\WriteResult{\manysubstitutions{\fdInputLine}}'

%% writes to <output> the result of applying many expandable 

%% substitutions to `\fdInputLine'. 

%% Such a macro `\manysubstitutions' may read `\fdInputLine', 

%% but it must not redefine any macros. 

%% Instead, the substitution macros it calls must read results 

%% of previous substitutions as \emph{arguments}.

%% 

%% Another aspect: 

%% the order of substitutions should be easy to 

%% change. Therefore expanding of string macros should rather be 

%% controlled by the way a job is \emph{called}, not right here 

%% at the \emph{definition} of the job. For this reason, 

%% a variant of the sandbox builder expanding some macro was given up. 

%% %% <- TODO!? 2010/03/25 



%% `setup_substr_cond' is the name space for macros that build

%% sandboxes and initialize arguments for conditional macros. 

\def\setup_substr_cond{setup_substr_cond:}

%% \[|\MakeSetupSubstringCondition{<id>}[<changes>]{<pattern>}{<more-args>}|\]

%% % <- TODO allow `%' and ` ' for breaking code lines. 

%% ---same <id>, <changes>, <pattern> as for 

%% `\MakeSubstringConditional' (this is bad, there may be 

%% |\MakeSubstringConditional*{<more-args>}|)---creates the 

%% % <- TODO: store args in \Make...Conditional

%% corresponding sandbox, by default without tilde wrap. 

%% <more-args> may contain `{#1}' to store the string that was tested,

%% also `{<id>}' for calling repetitions and `{<pattern>}' for screen 

%% or log informations. 

\newcommand*{\MakeSetupSubstringCondition}

            {\StartFDsetup\mk_setup_substr_cond}

%% |\mk_setup_substr_cond{<pattern>}{<more-args>}| 

%% %% without \begingroup 2010/03/29

%% can be directly called by other programmer setup commands after 

%% `\fdParserId' and <pattern> have been read:

\def\mk_setup_substr_cond #1#2{%% #1 pattern string, 

  %% #2 additional arguments, e.g., `{#1}' to keep tested string

  \endgroup 

  \expandafter \edef 

   \csname \setup_substr_cond \fdParserId \endcsname ##1{%

      \make_not_expanding_cs{\substr_cond \fdParserId}%

%% By `\edef', the name of the substring conditional is stored here 

%% as a single token. The rest of the sandbox follows. 

          ##1\noexpand~#1\dollar_tilde&#2}%

  \let\dollar_tilde\sandbox_dollar}

%% If a tilde `~' has been used instead of `$', the default 

%% is restored. 

\def\sandbox_dollar{$}

\let\dollar_tilde\sandbox_dollar

%% The following general tool |\make_not_expanding_cs| has been used 

%% (many definitions in 'latex.ltx' could have used it): %% 2009/04/10

\def\make_not_expanding_cs#1{%

    \expandafter \noexpand \csname #1\endcsname}

%%

%% === Getting rid of the tildes ===

%% |\let~\TildeGobbles| can be used to suppress dummy patterns 

%% (contained in <split2>) 

%% in `\write'ing or with `\edef'. ... will probably become obsolete 

%% ... however, it is helpful in that you needn't care 

%% whether there is a dummy wrap left at all. (2009/04/13)

\newcommand{\TildeGobbles}{}       \def\TildeGobbles#1${} 

%% |\RemoveDummyPattern| is used to remove the dummy pattern 

%% \emph{immediately}, not waiting for `\write'ing

%% or other ``total" expansion:   %% 2009/04/13

\newcommand{\RemoveDummyPattern}{} \def\RemoveDummyPattern#1~#2${#1}

%% |\RemoveDummyPatternArg<macro>{<arg>}| executes 

%% `\RemoveDummyPattern' in the next argument: 

\newcommand*{\RemoveDummyPatternArg}[2]{% 

  \expandafter #1\expandafter {\RemoveDummyPattern #2}} 

%% |\RemoveTilde| is used to remove the tilde that separated 

%% the dummy pattern from <split1>. 

% %% An alternative policy is to pass 

% %% <target> (as an argument) to the parsing macro.

\newcommand{\RemoveTilde}{} \def\RemoveTilde#1~{#1}

%% |\RemoveTildeArg<macro>{<arg>}| executes `\RemoveTilde' 

%% in the next argument: 

\newcommand*{\RemoveTildeArg}[2]{% 

  \expandafter #1\expandafter {\RemoveTilde #2}} 

%%

%% === Calling conditionals ===

%% |\ProcessStringWith{<target-string>}{<id>}| builds the sandbox 

%% to search <target-string> for the <pattern> associated with the 

%% parser-conditional that is identified by <id>, the sandbox then 

%% calls the parser. 

%% % Finally, the command \emph{``returns"} the 

%% % result of applying job <id> to <target-string>---in the sense of 

%% % \emph{expanding} to it. %% more precisely 2010/03/25

%% %% <- removed again, wrong 2010/03/26

\newcommand*{\ProcessStringWith}[2]{%

  \csname \setup_substr_cond #2\endcsname{#1}}

%% |\ProcessExpandedWith{<string-macro>}{<id>}| does the same but with 

%% a \emph{macro} (like `\fdInputLine' or `\OutputString') in which 

%% the string to be tested is stored.

%% %% TODO or \the<tok-reg> 2010/03/25

\newcommand*{\ProcessExpandedWith}[2]{%

  \csname \setup_substr_cond #2\expandafter \endcsname

    \expandafter{#1}}

%% I would have preferred the reversed order of arguments which seems 

%% to be more natural, but the present is more efficient. 

%% Macros with reversed order are currently stored after `\endinput' 

%% in section~\ref{sec:pondered}, may be they once return. 

%%

%% Anyway, most desired will be |\ProcessInputWith{<id>}| just 

%% applying to `\fdInputLine':

\newcommand*{\ProcessInputWith}[1]{%

  \csname \setup_substr_cond #1\expandafter \endcsname

    \expandafter{\fdInputLine}}

%% (Definition almost copied for efficiency.)

  %% TODO: error when undefined 2009/04/07

%%

%% === Copy jobs ===

%% A job identifier <id> may also be considered a mere \emph{hook}, 

%% a \emph{placeholder} for a parsing job. What function actually is 

%% called may depend on conditions that change while reading the 

%% <input> file. %%% On a certain condition, 

%% |\CopyFDconditionFromTo{<id1>}{<id2>}| 

%% \emph{creates or redefines a sandbox builder} with identifier <id2> 

%% that afterwards behaves like the sandbox builder <id1>. 

%% So you can store a certain behaviour as <id1> in advance in order 

%% once to change the behaviour of <id2> into that of <id1>. 

\newcommand*{\CopyFDconditionFromTo}[2]{%

  \expandafter \let 

    \csname \setup_substr_cond #2\expandafter \endcsname 

      \csname \setup_substr_cond #1\endcsname}

%% (Only the \emph{sandbox} is copied here---what about 

%% changing conditionals?) %% TODO 

%%

%% An ``almost" example is typesetting documentation from a package 

%% file where the ``Legalese" header might be typeset verbatim 

%% although it is marked as ``comment." (The present %% 2009/04/07

%% example changes ``hand-made" macros instead.)

%%

%% This feature could have been placed more below as a ``programming 

%% tool."

%%

%%  == Programming tools ==

%% === Tails of conditionals ===

%% \label{sec:tails}

%% When creating complex \emph{expandable} conditionals, 

%% this may amount to have primitive `\if' ... `\fi' conditionals 

%% nested quite deeply, once perhaps too deep for \TeX's memory. 

%% To avoid this, you can apply the common `\expandafter' trick 

%% which finishes the current `\if' ... `\fi' before an inside 

%% macro is executed (cf. \TeX book p.~219 on ``tail recursion").

%%

%% Internally tests whether certain strings are present at certain 

%% places will be carried out by tests on emptiness or 

%% %% onwards) %% !? 2009/12/28

%% on starting with `~'. E.g., 

%% ``#1~=~<split1> empty" indicates that either the <pattern> 

%% starts a line or the line is empty altogether (this must be 

%% decided by another test). 

%%

%% |\IfFDempty{<arg>}{<when-empty>}{<when-not-empty>}|

%% is used to test <arg> on emptyness (without expanding it): 

\newcommand*{\IfFDempty}[1]{%

  \ifx$#1$\expandafter \@firstoftwo  \else

          \expandafter \@secondoftwo \fi}

%% |\IfFDinputEmpty{<when-empty>}{<when-not-empty>}| is a variant of 

%% the previous to execute <when-empty> if the loop processing <input> 

%% finds an empty line---otherwise <when-not-empty>.

\newcommand*{\IfFDinputEmpty}{%

  \ifx\fdInputLine\@empty \expandafter \@firstoftwo  \else

                          \expandafter \@secondoftwo \fi}

%% |\IfFDdollar{<arg>}{<when-empty>}{<when-not-empty>}| 

%% is another variant, testing <split2> for being `$', 

%% main indicator of there is a match anywhere in <target> 

%% (as opposed to starting or ending match):

\newcommand*{\IfFDdollar}[1]{%

  \ifx$#1\expandafter \@firstoftwo  \else

         \expandafter \@secondoftwo \fi}

%% It is exemplified and explained in section~\ref{sec:replchain}.

%% (The whole policy requires that `~' remains active in any 

%%  testing macros here!)

%%

%% However, you might always just type the replacement text 

%% (in one line) instead of 

%% such an `\If'\,... (for efficiency \dots)

%%

%% If expandability is not desired, you can just chain macros that 

%% rework (so re-define) `\OutputString' or so. 

%%

%% 2009/04/11: tending towards combining ...

%% Keeping empty input and empty arguments apart is useful in that 

%% \emph{one} test of emptiness per input line should suffice---it

%% may be left open whether this should be the first of all tests 

%% \dots

%%

%% === Line counter ===

%% A \LaTeX\ counter |fdInputLine| may be useful for screen or log 

%% messages, moreover you can use it to control processing of the 

%% <input> file ``from outside," not dependent on what the parsing 

%% macros find. The header of the file might be typeset verbatim, 

%% but we may be too lazy to define the ``header" in terms of 

%% what is in the file. We just decide that the first ... lines 

%% are the ``header," even without counting just trying whether 

%% the output is fine. It may be necessary to change that number 

%% manually when the header changes. 

%% 

%% You also can insert lines in <output> 

%% which have no counterpart in <input>---if you know what you are 

%% doing. With 'makedoc', there is a hook `\EveryComment' that can 

%% be used to issue commands ``from outside" at a place where 

%% executing the command is safe or appropriate. 

\newcounter{fdInputLine}

%% You then must insert |\CountInputLines| in the second argument 

%% of `\ProcessFileWith' (or in a macro called from there) 

%% so that the counter is stepped. %% TODO!? 2009/04/07

\newcommand*{\CountInputLines}{\global\advance\c@fdInputLine\@ne}

%% At present %% 2009/04/07 TODO 

%% the counter is reset by `\ProcessFileWith', this may change. 

%%

%% |\IfInputLine{<relation><number>}{<true>}{<false>}|, when called 

%% from the processing loop (second argument of `\ProcessFileWith')

%% issues <true> commands if `\value{fdInputLine}<relation><number>' 

%% is true, otherwise <false>. <relation> is one out of 

%% \HardNVerb+<+, `=', `>'. %% 2010/03/24 2010/03/29

\newcommand*{\IfInputLine}[1]{%

  \ifnum\c@fdInputLine#1\relax \expandafter \@firstoftwo

  \else                        \expandafter \@secondoftwo \fi}

%%

%% === The ``identity job" `LEAVE' ===

%% \label{sec:LEAVE}

%% The job with identifier |LEAVE| 

%% \emph{leaves} an (expandable) chain of jobs 

%% (as expandable replacement in section~\ref{sec:replchain}) 

%% and \emph{leaves} the processed string without changing it 

%% and without the braces enclosing it:

\expandafter \let 

  \csname \setup_substr_cond LEAVE\endcsname \@firstofone

%% I.e., `\ProcessStringWith{<string>}{LEAVE}' expands to <string> 

%% ... \ProcessStringWith{(Indeed!)}{LEAVE}



%%  == Setup for expandable chains of replacements ==

%% \label{sec:replchain}%% TODO makedoc: provide less visible label/ref 2009/04/11 

%% By the following means, you can create macros 

%% (`\Transform' among them) such that, e.g., 

%% \[`\edef\OutputString{\Transform{<string>}}'\] renders `\OutputString' 

%% the result of applying a chain (sequence) of stringwise replacements 

%% to <string>. 

%% You can even write a transformed input <string> to a file 

%% without defining anything anything after `\read to'\,.\,.\,.

%% In this case however, you don't get any statistical message 

%% about what happened or not. With `\edef\OutputString' you can at 

%% least issue some `changed!' or `left!' (maybe `\message{!}' vs.\ 

%% `\message{.}'). 

%% There is an application in 'makedoc' for ``typographical upgrading" 

%% from plain text to \TeX\ input. 

%%

%% |\repl_all_chain_expandable| will be the backbone of the 

%% replacements. It is called by some parsing macro <parser>

%% and receives from the latter <split1>~=~#1 and <split2>~=~#2. 

%% #3 is the result of what happened so far. 

\def\repl_all_chain_expandable#1#2#3#4#5#6{%

  %% #1, #2 splits, #3 past,   #4 substitute, 

  %% #5 repeat parser,         #6 pass to 

%   \ifx~#2\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi 

%% The previous line would be somewhat faster, but let us exemplify 

%% `\IfFDdollar' from section~\ref{sec:tails} instead: 

  \IfFDdollar{#2}%

%% If #2 starts with `$'---with category code 3, ``math shift"!, 

%% it \emph{is} `$', due to not reading `$' 

%% from input with its standard category code 3

%% and the sandbox construction (where `$' appears with its standard 

%% category code). %% TODO might be explained earlier 2009/04/11

%%                 %%      or refer to here. 

%% And this is the case \emph{exactly} when the <pattern> from 

%% <parser> didn't match, again due to the input category codes. 

%% Now on \emph{no} match, the sandbox builder #6 is called 

%% with target string #3#1 where the last tested string is attached

%% to previous results. The ending `~' is removed, #6 inserts a new 

%% wrap for the new dummy pattern. 

             {\RemoveTildeArg #6{#3#1}}%

%% Otherwise ... the \emph{sandbox builder} <sandbox>

%% (that will be shown below) that called <parser> 

%% initialized #5 to be that <parser> itself. (<parser> otherwise 

%% wouldn't know who it is.) So <parser> calls itself with another sandbox 

%% `#2&'. Note that #2 contains \lq`~<pattern>$'\rq\ due to the initial 

%% <sandbox> building. 

             {#5#2&{#3#1#4}{#4}#5#6}}

%% #4 is the replacement string that <sandbox> passed to <parse>. 

%% The first argument after the `&' is previous stuff plus 

%% the recently skipped <split1> 

%% plus #4 replacing the string <pattern> that was matched. 

%% 

%% Finally, #5 and #6 again ``recall" <parser> and the sandbox 

%% builder to which to change in case of no other match. 

%%

%% \pagebreak[3] %% 2010/03/22

%% % TODO move following up!? 2009/04/11

%% \[|\MakeExpandableAllReplacer{<id>}[<chng>]{<find>}{<replace>}{<id-next>}|\]

%% creates sandbox and parser with common identifier <id> and search 

%% pattern <find>. Each occurrence of <find> will be replaced by 

%% <replace>. When <find> is not found, the sandbox builder for 

%% <id-next> is called. This may be another replacing macro of the 

%% same kind. To return the result without further transformations, 

%% call job `LEAVE' (section~\ref{sec:LEAVE}).

%% Optional argument <chng> changes category codes locally 

%% for reading <find> and <replace>.

%% %% <- added <cat>, <pattern> -> <find> 2010/03/19

\newcommand*{\MakeExpandableAllReplacer}

            {\StartFDsetup\mk_setup_xpdbl_all_repl}

\newcommand*{\mk_setup_xpdbl_all_repl}[3]{%

  %% #1 pattern, #2 substitute, #3 pass to

  \endgroup

%% We take pains to call next jobs by single 

%% command strings and store them this way, not by `\csname', 

%% as `\ProcessStringWith' would do it. `\edef\@tempa' 

%% is used for this purpose, but \dots

    \edef\@tempa{%

      \noexpand\mk_setup_substr_cond{#1}{%

        {}{#2}%

        \noexpand\noexpand

%% That `\edef\@tempa' must \emph{not expand} the controll 

%% words after they have been computed from `\csname' etc. 

%% Moreover, expansion of the parser commands 

%% must be avoided another time, when `\@tempa' is executed. 

          \make_not_expanding_cs{\substr_cond\fdParserId}%

        \noexpand\noexpand

          \make_not_expanding_cs{\setup_substr_cond #3}}}%

%% Those internal setup commands start with `\endgroup' to switch back 

%% to standard category codes. We must match them here by 

%% `\begingroup'.

    \begingroup \@tempa

    \begingroup \mk_substr_cond{#1}{%

      \repl_all_chain_expandable{##1}{##2}}}

%% The final command is the one that we explained first. %% TODO 2009/04/11 

%%

%% \[|\PrependExpandableAllReplacer{<id>}[<cat>]{<find>}{<replace>}|\]

%% is hoped to be a slight relief in composing replacement chains.

%% It does something like invoking `\MakeExpandableAllReplacer' 

%% with <prev-setup-id> for the last <next-id> argument

%% where <prev-setup-id> is the <id> of the job that was set up most 

%% recently. If you have adjacent lines 

%% \begin{quote}

%%  \leavevmode\hbox to 0pt\bgroup

%%   `\MakeExpandableAllReplacer{<id-0>}{<find-0>}{<subst-0>}{LEAVE}'% 

%%  \hss\egroup \\

%%   `\PrependExpandableAllReplacer{<id-1>}{<find-1>}{<subst-1>}'\\

%%   `\PrependExpandableAllReplacer{<id-2>}{<find-2>}{<subst-2>}'

%% \end{quote}

%% and call <id-2>, it will call <id-1>, and the latter will call 

%% <id-0>. So you can reorder the chain my moving `\Prepend'... lines. 

\newcommand*{\PrependExpandableAllReplacer}{%

    \let\fdParserId_before\fdParserId

    \StartFDsetup\prep_xpdbl_all_repl}

\newcommand*{\prep_xpdbl_all_repl}[2]{%

    \mk_setup_xpdbl_all_repl{#1}{#2}{\fdParserId_before}}%

%%

%% %% 2010/03/29:

%% |\MakeDocCorrectHook{<string>}| belongs to 'makedoc', 

%% but in the meantime ('nicetext' release 0.3) 

%% I have proposed to use it with 'fifinddo' only as well

%% (running files `fdtxttex.tpl', `fdtxttex.tex'). 

%% Therefore I offer some simplification |\SetCorrectHookJob{<job-id>}|

%% for defining `\MakeDocCorrectHook' \emph{here.} 

\newcommand*{\SetCorrectHookJob}[1]{%

    \def\MakeDocCorrectHook##1{\ProcessStringWith{##1}{#1}}}

%% |\SetCorrectHookJobLast| just uses the job that was set up 

%% most recently.

\newcommand*{\SetCorrectHookJobLast}

            {\SetCorrectHookJob\fdParserId}

%%

%%  == Leave package mode ==

%% We restore the underscore `_' for math subscripts. 

%% (This might better depend on something \dots) %% TODO 2009/04/07

\catcode`\_=8   %% restores underscore use for subscripts

%%

\endinput 

%% \TeX\ ignores the rest of the file when it is \emph{input} 

%% ``in the sense of `\input'", as opposed to just reading 

%% the file line by line to a macro like `\fdInputLine'. 

%%

%% == Pondered ==

%% \label{sec:pondered}

  %% TODO abbreviated commands (aliases) \MkSubstrCond...

  %% TODO \@onlypreamble!?

\newcommand*{\ApplySubstringConditional}[1]{%

  %% #1 identifier; text to be searched expected next

  \csname setup_substr_cond:#1\endcsname}

\newcommand*{\ApplySubstringConditionalToExpanded}[1]{% 2009/03/31+

  \csname setup_substr_cond:#1\expandafter \endcsname \expandafter}

\newcommand*{\ApplySubstringConditionalToInputString}[1]{% 2009/03/31+

  \csname setup_substr_cond:#1\expandafter \endcsname 

    \expandafter {\fdInputLine}}

  %% TODO or `\OutputString', even `\read' to `\OutputString'!?

% \newcommand*{\ApplySubstringConditionalToExpanded}[2]{%

%   %% note: without assignments, robust!

%   %% BUT the `\csname ... \expandafter \endcsname' method is faster

%   \expandafter \reversed_apply_substr_cond

%     \expandafter {#2}{#1}}

% \newcommand*{\reversed_apply_substr_cond}[2]{%

%   \ApplySubstringConditional{#2}{#1}}

  %% ODER: 

% \newcommand*{\expand_attach_arg}[2]{%% 2009/03/31

%   %% #1 command with previous args, TODO cf. LaTeX3

%   \expandafter \attach_arg \expandafter {#1}{#2}}

%   %% actually #1 may contain more than one token, 

%   %% only first expanded

% \newcommand*{\attach_arg}[2]{#2{#1}}

% \newcommand*{\ApplySubstringConditionalToExpanded}[2]{%

%   \expandafter \attach_arg \expandafter 

%     {#2}{\ApplySubstringConditional{#1}}}

%%

%%

%%

%% == VERSION HISTORY ==

%%

v0.1   2009/04/03   very first version, tested on morgan.sty

v0.2   2009/04/05   counter fdInputLine, \ProvidesFile moved from 

                    \ProcessFile to \ResultFile, \CopyFD...,

                    category section first, more sectioning, 

                    suppressing empty code lines before section 

                    titles; discussion, \Delimiters

       2009/04/06   more discussion

       2009/04/07   more discussion, factored \WriteProvides out from 

                    \ResultFile, \ProcessExpandedWith corrected

       2009/04/08   \InputString -> \fdInputline; 

                    removed \ignorespaces 

       2009/04/09   \WhenInputLine[2] -> \IfInputline[3], 

                    \ProcessInputWith, typos, 

                    \WriteProvides message `with'

       2009/04/10   \make_not_expanding_cs

                    DISCOVERED ``IF SUBSTRING" ALGORITHM WRONG

                    (<str1><str2><str1> in <str1><str2>)

v0.3   2009/04/11   SOME THINGS GIVEN UP EARLIER WILL BE REMOVED, 

                    TO BE STORED IN THE COPY AS OF 2009/04/10

                    mainly: sandbox setup (tilde/dollar) 

                    REAL ADDITION: setup for expandable replacing 

       2009/04/12   played with `chain' vs. `sequence';

                    plain `...', `cf.', `etc.' for `mdcorr.cfg'

       2009/04/13   \RemoveTilde...

       2009/04/15   reworked text, same mistake \in@

v0.31  2009/04/21f. comments on ted, stringstrings 

       2009/12/28   "onwards)" !? "safer", not "more safe"

       2010/03/10   the loop starts

       2010/03/17   corr. t^ete; set up -> setup for

       2010/03/18   TODO EOF, ctan.org/pkg/newfile; non-ASCII

       2010/03/19   extended description of \MakeExpandableAll...; 

                    '' -> "

       2010/03/20   \ctanpkgref

       2010/03/22   \StartFDsetup, \Prepend...

       2010/03/23   URL for `substr.sty'

SENT TO CTAN



v0.4   2010/03/24   removed \pagebreak before "substrings"; 

                    <relation> with \IfInputLine precisely

       2010/03/25   todo \ProcessExp... more precisely, etc.

       2010/03/26   ... was wrong, removed

       2010/03/29   \SetPatternCodes, \ResetPatternCodes, 

                    \SetCorrectHookJob, \SetCorrectHookJobLast; 

                    <relation> with \HardNVerb; 

                    don't mention \begingroup with 

                    \mk_setup_substr_cond; renamed v0.4



TODO: cleveref 2010/03/18