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
|
%% \CheckSum{724}
% \iffalse (Comment)
% This is the code for the relenc package, with doc style comments.
% \fi
%
% \iffalse (Driver code)
% (The driver is enclosed in a macrocode environment, even though the
% iffalse will make \TeX\ skip past it, just in case.)
% \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\usepackage{2sidedoc}
\newcommand\B{\penalty300\relax}
\newcommand\package[1]{\textsf{#1}}
\title{\texttt{relenc.dtx}}
\author{Lars Hellstr\"om%
\thanks{E-mail: \texttt{Lars.Hellstrom@math.umu.se}}%
}
\date{1999/01/23}
\begin{document}
\maketitle
\DocInput{relenc.dtx}
\begin{thebibliography}{99}
%
\bibitem{ltoutenc}
Johannes Braams, David Carlisle, Alan Jeffrey, Frank Mittelbach,
Chris Rowley, Rainer Sch\"opf: \texttt{ltoutenc.dtx} (part of the
\LaTeXe\ base distribution).
%
\bibitem{fontinst}
Alan Jeffrey, Rowland McDonnell (manual), Sebastian Rahtz,
Ulrik Vieth: \emph{The fontinst utility} (v\,1.8),
\texttt{fontinst.dtx}, in CTAN at \texttt{ftp:/\slash
ftp.tex.ac.uk\slash tex-archive\slash fonts\slash utilities\slash
fontinst\slash}\textellipsis
%
\bibitem{fntguide}
\LaTeX3 Project Team: \emph{\LaTeXe\ font selection},
\texttt{fntguide.tex} (part of the \LaTeXe\ base distribution).
%
\bibitem{encguide}
Frank Mittelbach [et al. ?]: \texttt{encguide.tex}. To appear as
part of the \LaTeXe\ base distribution. Sometime. Or at least, that
is the intention.
%
\end{thebibliography}
\end{document}
%</driver>
% \end{macrocode}
% \fi
%
% \StopEventually{}
%
% \section{Implementation}
% \label{Implementation}
%
% \iffalse (Comment)
% The following code really belong in the preamble, but since there
% are two documents which contain the text in this file, I prefer to
% put the code in one place instead.
% \fi
% \makeatletter
% \def\gobble@zeroX#10X{}
% \newcommand\St@rtShowGeneric[1]{^^A
% \begin{list}{}{^^A
% \@beginparpenalty=\predisplaypenalty
% \@endparpenalty=\postdisplaypenalty
% \@itempenalty=100\relax
% \setlength\leftmargin\z@
% \setlength\rightmargin\z@
% \setlength\listparindent\z@
% \setlength\parsep\z@skip
% \setlength\itemsep\z@skip
% \MacroFont
% \frenchspacing
% }^^A
% \ifnum#1<\@ne\else
% \item[]\leavevmode
% \rlap{
% \count@=\z@
% \loop
% \ \advance\count@\@ne
% \if \expandafter\gobble@zeroX \the\count@ X0XXX^^A
% ^^A \the\count@ does not end with 0.
% \else
% \hb@xt@\z@{{\hss\normalfont\tiny\the\count@\hss}}^^A
% \fi
% \ifnum\count@<#1\relax\repeat
% \llap{\strut\vrule}^^A
% }^^A
% \fi
% \def\mynewline{\unskip\hfil\penalty-\@M\vadjust{}}
% \set@display@protect
% }
% \newcommand\ShowGenericError[5][0]{^^A
% \St@rtShowGeneric{#1}^^A
% \item[]^^A
% \def\MessageBreak{\mynewline#2}^^A
% ! #3.\mynewline\mynewline
% #4\mynewline
% Type H <return> for immediate help\mynewline
% \ ...\mynewline\mynewline
% I.100\mynewline\mynewline
% \item[]^^A
% \def\MessageBreak{\mynewline}^^A
% ? h\mynewline
% #5\mynewline
% \end{list}^^A
% }
% \newcommand{\ShowGenericWarningOrInfo}[3][0]{^^A
% \St@rtShowGeneric{#1}^^A
% \item[]^^A
% \def\MessageBreak{\mynewline#2}^^A
% #3.\par
% \end{list}
% }
% \newcommand{\ShowPackageError}[4][0]{^^A
% \ShowGenericError[#1]{^^A
% (#2)\@spaces\@spaces\@spaces\@spaces
% }{^^A
% Package #2 Error: #3^^A
% }{^^A
% See the #2 package documentation for explanation.^^A
% }{#4}^^A
% }
% \newcommand\ShowPackageWarning[3][0]{^^A
% \ShowGenericWarningOrInfo[#1]{^^A
% (#2)\@spaces\@spaces\@spaces\@spaces
% }{^^A
% Package #2 Warning: #3^^A
% }^^A
% }
% \newcommand\ShowPackageInfo[3][0]{^^A
% \ShowGenericWarningOrInfo[#1]{^^A
% (#2) \@spaces\@spaces\@spaces
% }{^^A
% Package #2 Info: #3^^A
% }^^A
% }
% \makeatother
%
%
% \subsection{Initial stuff}
% The obligatory header code for a \LaTeXe\ package.
% \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{relenc}[1999/01/23]
% \end{macrocode}
% \bigskip
%
% At the moment, there are no options for the \package{relenc} package.
%
%
% \subsection{Variables and similar things}
%
% \begin{macro}{\RE@temptoks}
% |\RE@temptoks| is used by the basic search mechaism to store
% the part of the search path that has not yet been used.
% \begin{macrocode}
\newtoks\RE@temptoks
% \end{macrocode}
% \end{macro}
% \begin{macro}{\RE@garbage}
% The |\RE@garbage| macro is used as a target for some assignments that
% really shouldn't be made, but where a mechanism for detecting this
% would not be worth the cost. It is also used as a temporary storage
% by some definition commands.
% \end{macro}
% \begin{macro}{\RE@first@search@item}
% During a search, the |\RE@first@search@item| macro will expand the
% first item in the search path. This is needed for the define first
% mechanism to work.
% \end{macro}
% \begin{macro}{\RE@define@first}
% The |\RE@define@first| macro works like a switch. If it is
% |\RE@active@define|\B|@first| then the define first mechanism is
% active: If the search does not find anything on the first try but
% finds something later then the first command in the search path gets
% |\let| to whatever the search finds. If |\RE@define@first| is
% |\@gobbletwo| then the define first mechanism is inactive and nothing
% happens. This construction allows for other possibilities as well.
%
% The initial setting is |\@gobbletwo|, i.e., off.
% \begin{macrocode}
\let\RE@define@first\@gobbletwo
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Search mechanisms for variable commands}
%
% Variable commands are intended to be used as definitions of
% encoding-specific commands or compositions of such. Thus variable
% commands are actually instances of some user level command, which is
% not the same \TeX\ control sequence as the variable command itself.
%
% A variable command is defined to be a parameterless macro whose
% expansion consists of two tokens. The first is |\RE@text@variable| if
% the command is not a composition and it is |\RE@text@comp@variable| if
% the command is a composition. The second token is the user level
% command itself; this command will not be expanded, its name is merely
% used as a word-stem from which names of possible variants are formed.
% Thus if the definition of the user level command |\foo| in the
% \texttt{T1R} encoding (which would be stored in the control sequence
% |\T1R\foo|) would be a variable command, that definition would be
% \begin{quote}
% |\RE@text@variable|\,|\foo|
% \end{quote}
%
%
% \subsubsection{Identifying the search path and initiating the search}
% \begin{macro}{\RE@text@variable}
% \begin{macro}{\RE@text@comp@variable}
% \begin{macro}{\RE@spath@unavailable}
% \begin{macro}{\RE@spath@available}
% The first thing |\RE@text@variable| must do is to find the
% search path to use. It might be either a family-specific search
% path, in which case it is stored in the macro
% |\|\meta{encoding}|/|\meta{family}\texttt{-path},
% or the general search path for the entire encoding, in which case
% it is stored in the macro |\|\meta{encoding}\texttt{-path}.
% If the family-specific search path exists, it is chosen. If neither
% exists, this is an error which is reported.
%
% The second thing |\RE@text@variable| does is setting up the
% search along the search path. This is by expanding to
% \begin{quote}
% |\RE@first@read@spath|\,\meta{search path}\,^^A
% |\RE@read@spath|
% \end{quote}
% which starts the next phase of the search.
%
% \begin{macrocode}
\def\RE@text@variable{%
\expandafter\ifx \csname\cf@encoding/\f@family-path\endcsname \relax
\expandafter\ifx \csname\cf@encoding-path\endcsname \relax
\RE@spath@unavailable
\else
\RE@spath@available\RE@first@read@spath\RE@read@spath
\fi
\else
\expandafter\expandafter \expandafter\RE@first@read@spath
\csname\cf@encoding/\f@family-path\expandafter\endcsname
\expandafter\RE@read@spath
\fi
}
% \end{macrocode}
% Hackers may find a few things in the definition a little strange.
% To begin with, I use |\cf@encoding|\label{Why cf@encoding}
% for the name of the current
% encoding, although \cite{fntguide} says that |\f@encoding|
% is defined as precisely that. I too find this a little odd, but the
% corresponding routines in the \LaTeXe\ kernel use |\cf@encoding|
% (see~\cite{ltoutenc}) so I suppose that is safer, for some
% reason. I believe the only time at which |\cf@encoding| and
% |\f@encoding| are different is during a font change, but I might
% be mistaken about that.
%
% The usage of |\RE@spath@unavailable| and |\RE@spath@available|
% might also be confusing, but the alternative to this is heavily
% nested |\expandafter| sequences, and those things are not easy to
% read. Besides, |\RE@spath@unavailable| must do something with the
% initial command token anyway, because |\RE@text|\B|@variable| does
% not move it.
%
% |\RE@spath@available| have two real arguments: The initial search
% command header (which can be |\RE@first@read@spath| or
% |\RE@first@comp@read|\B|@spath|) and the initial search command tail
% (which can be |\RE@read@spath| or |\RE@comp@read@spath|). The other
% arguments are ``dummys'' used to remove unvanted tokens.
%
% All arguments of |\RE@spath@unavailable| are such dummys.
%
% \begin{macrocode}
\def\RE@spath@available#1#2#3\fi#4\fi{\fi\fi
\expandafter\expandafter \expandafter#1%
\csname\cf@encoding-path\endcsname#2%
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@spath@unavailable#1\fi#2\fi#3{%
\fi\fi
\PackageError{relenc}{%
There is no search path for relaxed encoding \cf@encoding%
}\@eha
}
% \end{macrocode}
%
% Example error message:
% \ShowPackageError{relenc}{There is no search path for relaxed
% encoding XX}{\csname @eha\endcsname}
%
% The reason that |\RE@text@comp@variable| and |\RE@text@variable|
% exist as separate macros is that there are separate commands
% |\RE@first@comp|\B|@read|\B|@spath| and |\RE@first@read@spath| at
% the next stage of the search process.
%
% \begin{macrocode}
\def\RE@text@comp@variable{%
\expandafter\ifx \csname\cf@encoding/\f@family-path\endcsname \relax
\expandafter\ifx \csname\cf@encoding-path\endcsname \relax
\RE@spath@unavailable
\else
\RE@spath@available\RE@first@comp@read@spath\RE@comp@read@spath
\fi
\else
\expandafter\expandafter \expandafter\RE@first@comp@read@spath
\csname\cf@encoding/\f@family-path\expandafter\endcsname
\expandafter\RE@comp@read@spath
\fi
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{Performing the search}
%
% Between the steps of the second stage of the search, the initial
% font-dependent command (|\foo| say) will have expanded to
% \begin{quote}
% \meta{search header}\,\meta{remaining search path}\,^^A
% \meta{search tail}\,|\foo|
% \end{quote}
% The \meta{search header} can be one of |\RE@read@spath|,
% |\RE@first@read@spath|, |\RE@comp@read@spath|, and
% |\RE@first@comp@read@spath|. The \meta{search tail} can be either
% |\RE@read@spath| or |\RE@comp@read@spath|.
%
% The \meta{search path} consists mainly of a sequence of blocks that
% looks as follows
% \begin{quote}
% |{| \meta{character tokens, macros} |}|
% \end{quote}
% The macros should also expand to character tokens. At each step, the
% first of these blocks is extracted as the |#1| argument of the search
% header. The remaining blocks are put in the |#2| argument and if no
% definition is found then these will be the \meta{remaining search path}
% to use when setting up for the next step. For the moment, it is put
% away in the token list register |\RE@temptoks|.
%
% Argument |#1| is first checked for whether the
% control sequence formed by expanding
% \begin{quote}
% |\csname|\,|#1|\,|\string|\,|#3|\,|\endcsname|
% \end{quote}
% (|#3| is the control sequence named |\foo| above) exists. If it does,
% it is assumed to be the definition of |\foo| for the current font,
% otherwise everything is set up for the next step using the
% \meta{remaining search path} as search path.
%
% There is no check to see if |#2| is empty, so if the entire search path
% consisted of blocks like the one above, using a font-dependent command
% for which no definition has been given would cause an infinite loop.
% There is however a hack which prevents this: When a search path is set
% using the proper command, the control sequence |\RE@var@not@found| is
% appended to the search path. Primarily, this macro is a hack that
% prevents the search loop from going haywire, but it also has the
% advantage of stopping the expansion of the search header from stripping
% off the braces around the last group prematurely (when
% \begin{quote}
% |\RE@read@spath|\,|{a}|\,|{b}|\,|{cd}|\,|\RE@read@spath|\,|\foo|
% \end{quote}
% is expanded |#1| will be |a| and |#2| will be |{b}|\,|{cd}|, but when
% \begin{quote}
% |\RE@read@spath|\,|{b}|\,|{cd}|\,|\RE@read@spath|\,|\foo|
% \end{quote}
% is expanded |#1| will be |b| and |#2| will be |cd|, so the next time
% round, |#1| will be |c| and |#2| will be |d|---the last group has been
% split---but if the last item in the search path is not a group, but a
% single token, there is no group to split).
%
% \begin{macro}{\RE@read@spath}
% \begin{macro}{\RE@first@read@spath}
% \begin{macro}{\RE@comp@read@spath}
% \begin{macro}{\RE@first@comp@read@spath}
% Considering their usage only, the difference between |\RE@read@spath|
% and |\RE@comp|\B|@read|\B|@spath| is that |\RE@read@spath| is used
% for actual font-dependent commands while |\RE@comp@read@spath| is
% used for compositions of a font-dependent command and its argument.
% In that case, the third argument will not be |\foo| but rather
% something like |\\foo-a| (a single control sequence, the first
% backslash is the escape character and the second is part of the
% actual name); this particular case occurs when the user has written
% |\foo|\,|{a}|).
%
% If, on the other hand, their definitions are looked at, the
% difference is that while |\RE@read@spath| checks if the expansion of
% \begin{quote}
% |\csname|\,|#1|\,|\string|\,|#3|\,|\endcsname|
% \end{quote}
% is defined, |\RE@comp@read@spath| checks if the expansion of
% \begin{quote}
% |\csname|\,|#1|\,|\@empty\|\,|string|\,|#3|\,|\endcsname|
% \end{quote}
% is defined. In most cases, these expand to the same thing (since
% |\@empty| is a parameterless macro which expands to nothing), but
% sometimes one needs to write a |#1| which gives somewhat different
% results depending on whether |#3| is a command or a composition.
% These blocks in the search path can now simply test whether the token
% after the parameter is |\@empty| or |\string|. The two macros that
% currently do this are |\RE@var@not@found| and |\RE@convert@nfss|.
%
% The difference between |\RE@read@spath| and |\RE@first@read@spath|
% is that the latter is used in the first step, while the former is
% used in all the other steps. This difference exists because of the
% define first mechanism: If |\RE@first|\B|@read|\B|@spath| finds a
% definition in the first step, there is no need to call the mechanism
% no matter what the value of |\RE@define@first| is, but if
% |\RE@first@read@spath| does not find a definition then it must store
% the first block of the search path for a possible future use by
% |\RE@active@define@first|. |\RE@read@spath|, on the other hand,
% should never store a search path block, but if it finds a
% definition then it should call |\RE@define@first| since the define
% first mechanism might be active.
%
% Quite naturally, |\RE@comp@read@spath| relates to
% |\RE@first@comp@read@spath| as |\RE@read@spath| to
% |\RE@first@read@spath| and |\RE@first@comp@read@spath| relates to
% |\RE@first@read@spath| as |\RE@comp@read@spath| to |\RE@read@spath|
% [phew!].
%
% \begin{macrocode}
\def\RE@read@spath#1#2\RE@read@spath#3{%
\RE@temptoks={#2}%
\expandafter\ifx \csname#1\string#3\endcsname \relax
\expandafter\RE@read@spath \the\expandafter\RE@temptoks
\expandafter\RE@read@spath \expandafter#3%
\else
\RE@define@first{#1}{#3}%
\csname#1\string#3\expandafter\endcsname
\fi
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@first@read@spath#1#2\RE@read@spath#3{%
\RE@temptoks={#2}%
\expandafter\ifx \csname#1\string#3\endcsname \relax
\def\RE@first@search@item{#1}%
\expandafter\RE@read@spath \the\expandafter\RE@temptoks
\expandafter\RE@read@spath \expandafter#3%
\else
\csname#1\string#3\expandafter\endcsname
\fi
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@comp@read@spath#1#2\RE@comp@read@spath#3{%
\RE@temptoks={#2}%
\expandafter\ifx \csname#1\@empty\string#3\endcsname \relax
\expandafter\RE@comp@read@spath \the\expandafter\RE@temptoks
\expandafter\RE@comp@read@spath \expandafter#3%
\else
\RE@define@first{#1\@empty}{#3}%
\csname#1\@empty\string#3\expandafter\endcsname
\fi
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@first@comp@read@spath#1#2\RE@comp@read@spath#3{%
\RE@temptoks={#2}%
\expandafter\ifx \csname#1\@empty\string#3\endcsname \relax
\def\RE@first@search@item{#1\@empty}%
\expandafter\RE@comp@read@spath \the\expandafter\RE@temptoks
\expandafter\RE@comp@read@spath \expandafter#3%
\else
\csname#1\@empty\string#3\expandafter\endcsname
\fi
}
% \end{macrocode}
%
% The definition of |\RE@read@spath| is not quite trivial. It must
% not leave any |\fi| up ahead, since everything should eventually
% expand to the actual definition of the searched-for command, and
% this is very likely to have parameters. There must be no surplus
% tokens between this command and its arguments; this is why
%\begin{verbatim}
% \def\RE@read@spath#1#2\RE@read@spath#3{%
% \RE@temptoks={#2}%
% \expandafter\ifx \csname#1\string#3\endcsname \relax
% \expandafter\RE@read@spath\the\RE@temptoks\RE@read@spath#3%
% \else
% \RE@define@first{#1}{#3}%
% \csname#1\string#3\endcsname
% \fi
% }
%\end{verbatim}
% would not do as a definition of |\RE@read@spath|.
%
% A definition that would work is
%\begin{verbatim}
% \def\RE@read@spath#1#2\RE@read@spath#3{%
% \expandafter\ifx \csname#1\string#3\endcsname \relax
% \expandafter\@firstoftwo
% \else
% \expandafter\@secondoftwo
% \fi{%
% \RE@read@spath#2\RE@read@spath#3%
% }{%
% \RE@define@first{#1}{#3}%
% \csname#1\string#3\endcsname
% }%
% }
%\end{verbatim}
% but I prefer the ``save away'' definition since it makes a few
% additional features possible; the most important perhaps being that
% it gives a chance to peek in afterwards and see where the search
% ended (using |\ShowVariantSearchResult|).
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{Miscellaneous search-related macros}
%
% \begin{macro}{\RE@active@define@first}
% \begin{macro}{\RE@again@read@spath}
% |\RE@active@define@first| is the macro which performs the actual
% assignments done by the define first mechanism, if it is active.
% The macro simply expands to the suitable global assignment; |#1| is
% the block from the search path that found a definition (with
% |\@empty| added if the search was for a composition) and |#2| is the
% command or composition whose definition was searched.
%
% \begin{macrocode}
\def\RE@active@define@first#1#2{%
\global\expandafter\let
\csname\RE@first@search@item\string#2\expandafter\endcsname
\csname#1\string#2\endcsname
}
% \end{macrocode}
% In some cases, the scan of the search path is resumed after a
% variant has been found. This is made possible by the fact that the
% remaining serach path is stored in |\RE@temptoks|, but the define
% first mechanism adds a complication. It cannot be allowed to copy a
% variant other than the first in the search path as that could
% actually change the effect of a command.
%
% The typical case here (the only one possible to define using user
% level commands of \package{relenc}) is that a command has two
% variants, one of which is composed and one which is not. The
% composed occurs before the noncomposed and the default definition of
% the composed is to resume the scan of the search path. If the
% command is executed for an argument for which there is no
% composition, an active define first mechanism will hide all
% composite definitions!
%
% Thus the define first mechanism must be temporarily disabled.
% One way to do this is to put a dummy value in
% |\RE@first@search@item|, and this solution is implemented in
% |\RE@again@read@spath|.\label{RE@again@read@spath}
% \begin{macrocode}
\def\RE@again@read@spath{%
\def\RE@first@search@item##1\expandafter\endcsname{%
RE@garbage\expandafter\endcsname
}%
\expandafter\RE@read@spath \the\RE@temptoks \RE@read@spath
}
% \end{macrocode}
% \end{macro}\end{macro}
%
%
% \begin{macro}{\RE@var@not@found}
% \begin{macro}{\RE@gobble@readspath}
% \begin{macro}{\RE@text@comp@unavail}
% These macros put a graceful end to a search that has found
% nothing. When |\RE@var@not@found|, which should be the very last token
% in every search path (it is automatically added by
% |\SetEncodingSearchPath| and |\SetFamilySearchPath|), is expanded
% it should appear in the following context
% \begin{quote}
% |\expandafter|\,|\ifx|\,|\csname|\,|\RE@var@not@found|\,^^A
% \meta{optional \cs{@empty}}\\
% |\string|\,\meta{command or composition}\,|\endcsname|
% \end{quote}
% As |\RE@var@not@found| inserts an additional |\endcsname| and |\fi|
% when expanded by the |\csname|, the entire |\ifx| is finished
% before \TeX{} gets to |\RE@gobble|\B|@readspath|. There are however
% a lot of mismatched tokens left over by |\RE@var@not@found|, some of
% which will be used in composing the error message.
%
% \begin{macrocode}
\def\RE@var@not@found{relax\endcsname\relax\fi
\RE@gobble@readspath
}
% \end{macrocode}
%
% When |\RE@gobble@readspath| is expanded, it is in the context
% \begin{quote}
% |\RE@gobble@readspath|\,\meta{optional \cs{@empty}}\,^^A
% |\string|\\ \meta{command or composition}\,^^A
% |\endcsname|\,\meta{some text}\,|\fi|
% \end{quote}
% The |\fi| is the |\fi| that originally matched the |\ifx| mensioned
% above.
%
% The |\@empty| is there iff \meta{command or composition} is a
% composition. If it is, this composition is |\string|ed and the
% first backslash is thrown away. Then the remaining `other' tokens
% are given to |\RE@text@comp@unavail| which will figure out what is
% the original command and what is its argument. If it is not a
% composition, the command is given to |\TextSymbolUnavailable|. In
% any case, everything up to and including the |\fi| disappears.
%
% \begin{macrocode}
\def\RE@gobble@readspath#1\string#2\endcsname#3\fi{%
\ifx\@empty#1%
% \end{macrocode}
% If |#2| is a composition then
% \begin{macrocode}
\expandafter\expandafter \expandafter\RE@text@comp@unavail
\expandafter\@gobble \string#2\RE@text@comp@unavail
\else
\TextSymbolUnavailable{#2}%
\fi
}
% \end{macrocode}
%
% As there is a hyphen between the original command and its argument,
% |\RE@text@comp@unavail| splits the name of the composition at the
% first hyphen. This is the right thing to do as long as |-| is not
% used as part of the name of the original command (unlikely, as
% \LaTeX\ does not define |\-| as an encoding-specific command).
%
% \begin{macrocode}
\def\RE@text@comp@unavail#1-#2\RE@text@comp@unavail{%
\PackageError{relenc}{%
The composition of command #1 with #2\MessageBreak is declared %
in encoding \cf@encoding,\MessageBreak but no definition could %
be found%
}\@eha
}
% \end{macrocode}
%
% Example error text:
% \iffalse Some editing is necessary to compensate for the \catcode
% differences.\fi
%
% \ShowPackageError{relenc}{The composition of command
% \protect\foo\space with A\MessageBreak is declared in encoding
% XXX,\MessageBreak but no definition could be found}
% {\csname@eha\endcsname}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Making variable text commands}
%
% \subsubsection{Miscellaneous support macros}
%
% \begin{macro}{\RE@empty@is@qmark}
% Expands to its argument if that is nonempty, otherwise it expands
% to |?|. This macro is primarily meant to be used inside a |\csname|
% \textellipsis\ |\endcsname| block. As always, an ingenious fool might
% break it, but a category 3 |^^M| is extremely unlikely (and hard to
% type), so it should work for any reasonable argument.
% \begin{macrocode}
\begingroup
\lccode`\$=13\relax
\lowercase{%
\gdef\RE@empty@is@qmark#1{\ifx$#1$?\else#1\fi}%
}
\endgroup
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\RE@font@spec}
% This macro concatenates the four parameters \meta{encoding},
% \meta{family}, \meta{series}, and \meta{shape} into
% \package{relenc}'s name for this font, i.e., puts slashes between
% the arguments and replaces every empty argument with a question mark.
% \begin{macrocode}
\def\RE@font@spec#1#2#3#4{%
\RE@empty@is@qmark{#1}/\RE@empty@is@qmark{#2}/%
\RE@empty@is@qmark{#3}/\RE@empty@is@qmark{#4}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\RE@bsl@string}
% One thing which complicates the definition of the definition commands
% (which must work even if they appear in a font definition file) is
% that \LaTeX\ has the naughty habit of changing the \TeX\ parameter
% |\escapechar| when it is defing a new font (loading the
% corresponding font definition file). The |\escapechar| parameter
% decides which character, if any, should be put in front of a control
% sequence name which is |\string|ed or written to the log file as
% part of some |\tracing|\textellipsis\ operation. (To see this effect
% yourself, set |\tracingmacros| positive just before a font change
% that loads a new font definition file (better reset it to zero
% after the font change though) and have a look at the log
% file---throughout a large chunk of logged macro expansions there
% are no backslashes on the command names!) The reason I don't
% like this is that (i) it doesn't achieve anything that couldn't just
% as well be achieved by a combination of |\expandafter| and gobbling
% of unwanted tokens and (ii) some font definition files are read by
% \LaTeX\ having |\escapechar| set to its normal value, so you can't
% trust it either way!
%
% Still, that is how \LaTeX\ does it and this must somehow be coped
% with. The |\RE@bsl@string| macro acts like |\string| but inserts a
% backslash in front of control sequence names even when |\string|
% wouldn't insert anything there. It is used instead of |\string| in
% all defining commands.
%
% \begin{macrocode}
\def\RE@bsl@string{%
\ifnum \escapechar<\z@ \@backslashchar \fi
\string
}
% \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Declaration commands}
%
% \begin{macro}{\DeclareTextVariableCommand}
% \begin{macro}{\DeclareTextVariableCommandNoDefault}
% \begin{macro}{\DeclareTextVariableSymbol}
% Two of these are the obvious counterparts of |\DeclareTextCommand|
% and |\Declare|\B|TextSymbol|. The parameters are the same, and the
% actual declaring (from the \LaTeXe\ kernel's point of view) is done
% by |\DeclareTextCommand|.
%
% |\DeclareTextVariableCommandNoDefault| is a new possibility that
% exists since a relaxed encoding definition file need not actually
% specify the definition of any font-dependent command. It can, for
% example, specify that ``Unless otherwise stated, use the definition
% from encoding \textellipsis{} ''.
%
% As the ordinary counterparts of these commands are preamble
% commands, I have made these preamble commands as well.
% \begin{macrocode}
\newcommand\DeclareTextVariableCommand{\RE@dec@text@varcmd\newcommand}
\@onlypreamble\DeclareTextVariableCommand
% \end{macrocode}
% \begin{macrocode}
\newcommand\DeclareTextVariableCommandNoDefault{%
\RE@dec@text@varcmd\@gobble
}
\@onlypreamble\DeclareTextVariableCommandNoDefault
% \end{macrocode}
% \begin{macrocode}
\newcommand\DeclareTextVariableSymbol[3]{%
\RE@dec@text@varcmd\chardef#1{#2}#3\relax
}
\@onlypreamble\DeclareTextVariableSymbol
% \end{macrocode}
% \begin{macrocode}
\def\RE@dec@text@varcmd#1#2#3{%
\DeclareTextCommand{#2}{#3}{\RE@text@variable#2}%
\expandafter#1\csname#3/?/?/?\string#2\endcsname
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ProvideTextVariableCommand}
% This is the variable counterpart of |\ProvideTextCommand|, and it
% has the same set of parameters. Its definition is a bit more
% complicated than that of the earlier commands for declaring variable
% font-dependent commands, partly because |\ProvideTextCommand| does
% not tell whether the definition it provided was used, but also
% becuase this command need not be meaningless even if the
% font-dependent command it should declare already was declared.
%
% If the font-dependent command is not declared (the
% |\|\meta{encoding}|\|\meta{command} control sequence is |\relax|),
% |\ProvideTextCommand| is used to declare it and |\providecommand|
% is used to give an encoding level definition. If the font-dependent
% command was declared and variable, then |\providecommand| is still
% called, to give an encoding-level definition of the command in
% case there wasn't already one. Otherwise
% it must have been declared as a non-variable font-dependent command
% and the following info message is given:
% \ShowPackageInfo{relenc}{You have provided a declaration of
% \protect\foo\space in\MessageBreak encoding T1R as a
% variable command, but it was\MessageBreak already declared
% as a non-variable command.\MessageBreak Your declaration
% has been ignored}
% In this case, the slight problem of the left-over definition
% remains. This is taken care of by giving it to |\providecommand| as
% a definition of |\RE@garbage| (which was introduced for this kind
% of tasks).
%
% |\ProvideTextCommand| is not a preamble-only command, so I have
% left |\ProvideTextVariableCommand| free to use anywhere too, although
% I cannot see why it should be needed after |\begin|\,|{document}|.
% \begin{macrocode}
\newcommand\ProvideTextVariableCommand[2]{%
\expandafter\ifx \csname#2\string#1\endcsname \relax
\ProvideTextCommand#1#2{\RE@text@variable#1}%
\expandafter\providecommand
\csname#2/?/?/?\string#1\expandafter\endcsname
\else
\long\def\RE@garbage{\RE@text@variable#1}%
\expandafter\ifx \csname#2\string#1\endcsname \RE@garbage
\expandafter\providecommand
\csname#2/?/?/?\string#1\expandafter\expandafter
\expandafter\endcsname
\else
\PackageInfo{relenc}{You have provided a declaration of
\protect#1 in\MessageBreak encoding #2 as a variable
command, but it was\MessageBreak already declared as a
non-variable command.\MessageBreak Your declaration has
been ignored}%
\expandafter\providecommand
\csname RE@garbage\expandafter\expandafter
\expandafter\endcsname
\fi
\fi
}
% \end{macrocode}
% \end{macro}
%
% \iffalse
% A command that was later scrapped, as it turned out it wasn't needed:
% % \newcommand{\DeclareTextComposableVariable}[3]{%
% % \DeclareTextCommand{#1}{#2}[1]{\RE@text@variable#1{##1}}%
% % \expandafter\newcommand \csname#2/?/?/?\string#1\endcsname [1]{#3}%
% % }
% % \@onlypreamble\DeclareTextComposableVariable
% \fi
%
% \begin{macro}{\DeclareTextVariableAccent}
% This is the variable counterpart of |\DeclareTextAccent|, and again
% this counterpart has the same parameters as its non-variable model.
% Also, it is a preamble-only command, just as its model.
% \begin{macrocode}
\newcommand{\DeclareTextVariableAccent}[3]{%
\DeclareTextCommand{#1}{#2}{\RE@text@variable#1}%
\expandafter\newcommand \csname#2/?/?/?\string#1\endcsname
{\add@accent{#3}}%
}
\@onlypreamble\DeclareTextVariableAccent
% \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Definition commands}
%
% There is an important difference between the declaration commands and
% the definition commands, and this has to do with when they are
% executed. A definition command usually appears in a \texttt{.fd}
% file, which is read in inside a group (usually several, but that is
% irrelevant), but the definitions it makes should be in force after the
% group has ended. Therefore the definitions must be global, but the
% |\newcommand| family of \LaTeX\ definition commands only make local
% definitions. Because of this, I have chosen to primarily use the
% \TeX\ primitive |\gdef| and its relatives in the definition commands,
% although in several cases \LaTeX-style alternatives are available as
% well.
%
% \begin{macro}{\DefineTextCommandVariant}
% The basic defintion command, |\gdef| style. As simple as it can
% be, but note that the \meta{parameter text} does not become one of
% the arguments of the macro. This has some consequences for when
% spaces are ignored.
% \begin{macrocode}
\newcommand{\DefineTextCommandVariant}[5]{%
\expandafter\gdef
\csname\RE@font@spec{#2}{#3}{#4}{#5}\RE@bsl@string#1\endcsname
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DefineTextSymbolVariant}
% The basic command for defining a text symbol command.
% \begin{macrocode}
\newcommand{\DefineTextSymbolVariant}[6]{%
\global\expandafter\chardef
\csname\RE@font@spec{#2}{#3}{#4}{#5}\RE@bsl@string#1\endcsname
=#6\relax
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DefineTextAccentVariant}
% The basic command for defining an accent command. Very much a
% special case of |\DefineTextCommandVariant|.
% \begin{macrocode}
\newcommand{\DefineTextAccentVariant}[6]{%
\expandafter\gdef
\csname\RE@font@spec{#2}{#3}{#4}{#5}\RE@bsl@string#1\endcsname
{\add@accent{#6}}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NewTextCommandVariant}
% \begin{macro}{\RenewTextCommandVariant}
% \begin{macro}{\ProvideTextCommandVariant}
% \begin{macro}{\RE@make@text@cmd@variant}
% \begin{macro}{\RE@make@text@cmd@var@x}
% These commands are the \LaTeX-style commands to define variable
% font-dependent commands. As the \LaTeX\ commands they are built on is
% not really meant to be used for global definitions, this involves
% some hacking (using the \LaTeX\ core's private control sequences to
% do things they are not meant to do, for example). Everything would
% have been much simpler if the autoload format hook |\aut@global| had
% been available in all \LaTeX\ formats, but it is not. The purpose of
% |\RE@make@text@cmd@variant| is to save some |\csname| \ldots\
% |\endcsname| pairs, the real defining is done by
% |\RE@make@text@cmd@var@x|.
% \begin{macrocode}
\CheckCommand*{\newcommand}{\@star@or@long\new@command}
\newcommand{\NewTextCommandVariant}
{\RE@make@text@cmd@variant\new@command}
% \end{macrocode}
% \begin{macrocode}
\CheckCommand*{\renewcommand}{\@star@or@long\renew@command}
\newcommand{\RenewTextCommandVariant}
{\RE@make@text@cmd@variant\renew@command}
% \end{macrocode}
% \begin{macrocode}
\CheckCommand*{\providecommand}{\@star@or@long\provide@command}
\newcommand{\ProvideTextCommandVariant}
{\RE@make@text@cmd@variant\provide@command}
% \end{macrocode}
% \begin{macrocode}
\def\RE@make@text@cmd@variant#1#2#3#4#5#6{%
\expandafter\RE@make@text@cmd@var@x
\csname\RE@font@spec{#3}{#4}{#5}{#6}\RE@bsl@string#2\endcsname
{#1}%
}
% \end{macrocode}
% Instead of |\aut@global|, |\l@ngrel@x| is used as a hook. |\l@ngrel@x|
% is defined to be a macro whose last action is to execute |\global|. As
% |\l@ngrel@x| appears just before the central |\def|, this makes that
% definition global in exactly those cases where the definition is made.
% This requires that the topmost layer of |\newcommand| (and its cousins),
% the one in which the |*|-processing takes place, is stepped over.
% Otherwise the definition of |\l@ngrel@x| would be reset.
%
% If the command has an optional argument, however, a simple
%\begin{verbatim}
% \def\l@ngrel@x{\global}
%\end{verbatim}
% is not sufficient. In that case the command the user issues is only a
% preparation that inserts the default optional argument if none is
% present and issues the real command (the name of the real command is
% the name of the user command with an extra backslash prepended to it).
%
% The real command will be globally defined, thanks to the |\global|
% at the end of |\l@ngrel@x|, but the preparation command is at the time
% of |\l@ngrel@x| only locally defined. This is why |\l@ngrel@x| |\let|s
% the preparation command to itself globally, this preserves the
% definition but makes it global. If the command does not have an optional
% argument, this does no harm as the incorrect definition is overwritten
% with the correct just after |\l@ngrel@x|.
%
% Finally, |\l@ngrel@x| resets itself to |\relax|, in case something
% expects it to be |\long| or |\relax|. As |\l@ngrel@x| is not reset
% if no command definition takes place, there is a slight chance of
% error in that case, but at least all \LaTeX\ core user commands reset
% it before using so the hack should not have any side-effects.
% \begin{macrocode}
\def\RE@make@text@cmd@var@x#1#2{%
\def\l@ngrel@x{%
\global\let#1#1%
\let\l@ngrel@x\relax
\global
}%
#2#1%
}
% \end{macrocode}
% To examine sometime: Can |\globaldefs=1| be used instead here? As
% that makes all assignments global, there is a definite chance it
% might break something else.
% \end{macro}\end{macro}\end{macro}\end{macro}\end{macro}
%
% \iffalse
% An auxillary command that has been scrapped.
% % \begin{macro}{\RE@globalize@if@defined}
% % This command globally |\let|s its argument to itself, if it is
% % defined. This makes the definition of the argument global,
% % regardless of whether the definition was local or global earlier.
% % \begin{macrocode}
% \def\RE@globalize@if@defined#1{%
% \ifx#1\relax\else
% \global\let#1#1%
% \fi
% }
% % \end{macrocode}
% % \end{macro}
% \fi
%
%
% \subsection{Making compositions of font-dependent commands}
% \begin{macro}{\RE@if@composed}
% This is a general test to see if a macro is a command that is set
% up for having compositions, i.e., if the expansion of the macro
% begins with |\@text@composite|. This is the same test as is used in
% |\DeclareTextCompositeCommand|.
%
% The syntax is as follows:
% \begin{quote}
% |\RE@if@composed|\,\meta{command}\,\marg{then-text}\,^^A
% \marg{else-text}
% \end{quote}
% expands to \meta{then-text} if \meta{command} can have
% compositions and to \meta{else-text} otherwise.
% \begin{macrocode}
\def\RE@if@composed#1{%
\expandafter\expandafter \expandafter\ifx
\expandafter\@car #1\relax\relax\@nil \@text@composite
% \end{macrocode}
% If it is composite then \textellipsis
% \begin{macrocode}
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Commands for compositions that are variable}
%
% The \LaTeXe\ kernel's method of forming the names of compositions is
% to |\string| the name of the base command and append |-|\meta{argument}
% to that, all of which is then |\csname|d. This generates names like
% \begin{quote}
% |\\T1\foo-a|
% \end{quote}
% for the command |\foo|'s composition with the argument |a| in the |T1|
% encoding. As the \LaTeXe\ kernel's mechanism for checking for
% compositions is used for compositions that have variable definitions
% as well, the names of these commands are formed using the same
% procedure.
%
% Should then the names of the variants of the composition be generated
% from names as the above, then these names would be things like
% \begin{quote}
% |\T1R/zcm/m/n\\T1R\foo-a|
% \end{quote}
% which is a bit longish, even for my taste. Therefore the names of the
% variants are formed from a base consisting only of the name of the
% font-dependent command and its argument, which is |\\foo-a| in the above
% example. This reduces the above to
% \begin{quote}
% |\T1R/zcm/m/n\\foo-a|
% \end{quote}
% saving two to four characters. This difference in naming does however
% have some consequences for the usage of definitions from a non-relaxed
% encoding.
%
%
% If, for example, |{T1}| is included in the current search path and a
% definition of the composition |\foo|\,|{a}| is looked for, a possible
% definition of this in the |T1| encoding will not be found! This is
% because the name tried is |\T1\\foo-a|, but the command is called
% |\\T1\foo-a|. This is the reason for the macro |\RE@convert@nfss|,
% which looks ahead to see if a composition or a plain command is
% currently looked for. Had instead |{\RE@convert@nfss|\,|{T1}}| been
% included, |\T1\\foo-a| would have been changed to |\\T1\foo-a|.
%
% \begin{macro}{\DeclareVariableTextComposition}
% \begin{macro}{\RE@dec@var@text@comp}
% This is the variable analog of \LaTeX's |\DeclareTextCompositeCommand|,
% although it is somewhat less as it does not make a default
% definition for the composition. Thus it is also an analog of
% |\DeclareTextVariableCommandNoDefault| for compositions.
% \begin{macrocode}
\newcommand{\DeclareVariableTextComposition}[3]{%
\expandafter\RE@dec@var@text@comp
\csname\string#1-#3\expandafter\endcsname
\csname\@backslashchar#2\string#1-#3\endcsname
{#1}{#2}{#3}%
}
% \end{macrocode}
% As |\DeclareVariableTextComposition| merely make a few combinations of
% its arguments and then call |\RE@dec@var@text@comp|, the arguments of
% the latter are worth an explanation. Continuing the above example of
% |\foo|\,|{a}| in the |T1R| encoding, the arguments will be
% \begin{quote}
% \begin{tabular}{r@{ is }l r@{ is }l r@{ is }l}
% |#1|&|\\foo-a|& |#2|&|\\T1R\foo-a| &\omit\span\omit\\
% |#3|&|\foo|& |#4|&|T1R|& |#5|&|a|
% \end{tabular}
% \end{quote}
%
% Should the composition already have been declared, but the
% definition is not variable, that definition is made the encoding
% level definition and the composition is made variable. If the
% definition is variable, an info message is given and the
% definition is not changed.
% \begin{macrocode}
\def\RE@dec@var@text@comp#1#2#3#4#5{%
\ifx#2\relax
% \end{macrocode}
% If this composition has not been declared then \textellipsis
% \begin{macrocode}
\DeclareTextCompositeCommand{#3}{#4}{#5}%
{\RE@text@comp@variable#1}%
\else
\expandafter\expandafter \expandafter\ifx
\expandafter\@car#2\@nil
\RE@text@variable
% \end{macrocode}
% If this composition is variable then \textellipsis
% \begin{macrocode}
\PackageInfo{relenc}{Redundant \protect
\DeclareVariableTextComposition.\MessageBreak
The composition of \protect#3 with #5 is\MessageBreak
already declared as a variable command\MessageBreak
in encoding #4%
}%
\else
\expandafter\let \csname#4/?/?/?\string#1\endcsname #2
\def#2{\RE@text@comp@variable#1}%
\fi
\fi
}
% \end{macrocode}
% Example message:
% \ShowPackageInfo{relenc}{Redundant \protect
% \DeclareVariableTextComposition.\MessageBreak
% The composition of \protect\foo\space with a is\MessageBreak
% already declared as a variable command\MessageBreak
% in encoding T1R}
% \end{macro}\end{macro}
%
%
% \begin{macro}{\DefineTextCompositionVariant}
% \begin{macro}{\DefineTextCompositionVariantCommand}
% \begin{macro}{\RE@def@text@comp@var}
% These are the commands that actually define variants of compositions.
% The first makes the variant a chardef token, the second
% makes it a parameterless macro.
%
% The arguments for |\RE@def@text@comp@var| should be the following
% things: The command that does the defining (|\chardef| or |\gdef|),
% the base user command, the relevant encoding, family, series, and
% shape, and finally the argument for the composition. Note that the
% actual definition (slot number or replacement text, respectively)
% is not among the arguments of |\RE@def@text@comp@var|.
% \begin{macrocode}
\newcommand\DefineTextCompositionVariant[7]{%
\global \RE@def@text@comp@var\chardef{#1}{#2}{#3}{#4}{#5}{#6}%
#7\relax
}
% \end{macrocode}
% \begin{macrocode}
\newcommand\DefineTextCompositionVariantCommand{%
\RE@def@text@comp@var\gdef
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@def@text@comp@var#1#2#3#4#5#6#7{%
\expandafter#1%
\csname
\RE@font@spec{#3}{#4}{#5}{#6}\@backslashchar
\RE@bsl@string#1-#6%
\endcsname
}
% \end{macrocode}
% \end{macro}\end{macro}\end{macro}
%
% \begin{macro}{\DefineTextUncomposedVariant}
% \begin{macro}{\RE@def@text@uncmp}
% \begin{macro}{\RE@def@text@uncmp@x}
% |\DefineTextUncomposedVariant| extracts the definition used for
% arguments that does not have definitions, inserts the given
% argument, and makes the resulting token sequence the definition of
% the variant at hand. Doing this requires that the definition of
% the command that the \LaTeXe\ kernel sees is taken apart, so it
% might be worth describing how it is contructed.
%
% If |\foo| is composite in the |T1| encoding, |\T1\foo| is a macro
% which expands to
% \begin{quote}
% |\@text@composite|\,|\T1\foo|\,|#1|\,|\@empty|\,^^A
% |\@text@composite|\\
% |{|\,\meta{noncomposite definition}\,|}|
% \end{quote}
% where \meta{noncomposite definition} is what is needed here. The
% stuff before checks if the composition is defined, but in this case
% things are best if that part is never expanded further that this.
%
% The actual ``work'' is done by |\RE@def@text@uncmp@x|, as this macro
% contains the |\gdef| which is the only command in this that \TeX's
% stomach sees; everything else just expands in one way or another
% (unless the warning is issued, that of course contains some stomach
% stuff too). |\DefineTextUncomposedVariant| makes two |\csname|s: The
% name of the macro from which the definition is to be extracted and
% the name of the macro to define.
%
% |\RE@def@text@uncmp| checks if the macro to extract from really is
% composed, and if it is then it expands it \emph{one level}, feeding
% it the \meta{argument} as argument. Then |\RE@def@text@uncmp@x| is
% given this one level expansion, and the |\@text@composite|s and
% everything between them is thrown away. The
% \meta{noncomposite definition} is made the replacement text of a
% |\gdef| defining the macro to be defined. If the macro to extract a
% definition from is not composed however, a warning is given.
%
% As this command refers to a specific encoding's definition of a
% command, the \meta{encoding} argument mustn't be empty.
% \begin{macrocode}
\newcommand\DefineTextUncomposedVariant[6]{%
\expandafter\RE@def@text@uncmp
\csname#2\RE@bsl@string#1\expandafter\endcsname
\csname#2/\RE@empty@is@qmark{#3}/\RE@empty@is@qmark{#4}/%
\RE@empty@is@qmark{#5}\@backslashchar\RE@bsl@string#1-#6%
\endcsname
{#6}{#1}{#2}%
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@def@text@uncmp#1#2#3#4#5{%
\RE@if@composed#1{%
\expandafter\RE@def@text@uncmp@x #1{#3}{#2}%
}{%
\PackageWarning{relenc}{There are no compositions for %
\protect#4 in\MessageBreak the #5 encoding. %
\protect\DefineTextUncomposedVariant\MessageBreak
makes no sense here%
}%
}%
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@def@text@uncmp@x\@text@composite#1\@text@composite#2#3{%
\gdef#3{#2}%
}
% \end{macrocode}
% Example warning:
% \ShowPackageWarning{relenc}{There are no compositions for ^^A
% \string\foo\space in\MessageBreak the T1 encoding. ^^A
% \string\DefineTextUncomposedVariant\MessageBreak
% makes no sense here}
% \end{macro}\end{macro}\end{macro}
%
%
% \subsubsection{Commands for variants with compositions}
%
% The \package{relenc} package offers another way in which a command can
% be defined relative to both argument and font, and that is to allow
% variants of font-dependent commands to have compositions. It is pretty
% similar to the usual making of composite commands in \LaTeX.
%
% \begin{macro}{\DefineTextVariantComposition}
% \begin{macro}{\DefineTextVariantCompositionCommand}
% These commands define the composition and make the variant a
% command with compositions, if it is not already. The mechanism used
% for compositions uses |\@text@composite|, exactly like the
% compositions made by commands in the \LaTeXe\ kernel.
%
% |\DefineTextVariantComposition| makes the final definition a
% chardef token. |\DefineTextVariantCompositionCommand| makes the
% final definition a macro without parameters.
%
% An interesting point about these commands is that a variant need not
% be defined before a composition of it is made! If this happens then
% of course technicaly the variant gets defined, but its definition
% for the case when that composition is not found is simply to set things
% up for a continued scan of the search path. What makes this possible
% is that the remaining search path is stored in |\RE@temptoks|.
%
% \begin{macrocode}
\newcommand\DefineTextVariantComposition[7]{%
\RE@def@text@var@comp\chardef{#1}{#2}{#3}{#4}{#5}{#6}#7\relax
}
% \end{macrocode}
% \begin{macrocode}
\newcommand\DefineTextVariantCompositionCommand{%
\RE@def@text@var@comp\gdef
}
% \end{macrocode}
%
% \begin{macro}{\RE@def@text@var@comp}
% \begin{macro}{\RE@make@text@comp}
% These are the macros that do the actual work. The parameters of
% |\RE@def@text|\B|@var@comp| are the user level command, the
% encoding, family, series, and shape in question, the argument for
% the composition, the assignment command
% that should define the composition, and finally
% the text that should be put after the control sequnce of the
% composition to complete the assignment. When the assignment command
% is |\chardef|, as is the case when |\DefineTextVariantComposition|
% makes the call, this is simply a \meta{number}---the slot. The extra
% |\relax| is to stop \TeX\ from reading ahead too
% far when looking for the end of the \meta{number}.
%
% The first thing |\RE@def@text@var@comp| does is to check if the
% variant the user wants do define a composition of is defined.
% \begin{macrocode}
\def\RE@def@text@var@comp#1#2#3#4#5#6#7{%
\expandafter\let \expandafter\RE@garbage
\csname\RE@font@spec{#3}{#4}{#5}{#6}\RE@bsl@string#2\endcsname
\ifx \RE@garbage\relax
% \end{macrocode}
% This means the variant has not been defined. The default definition
% given sets up a continued scan along the search path. The key macro
% here is |\RE@again@read@spath| (the definition of which is found on
% page \pageref{RE@again@read@spath}). It temporarily disables the
% define first mechanism and then it expands to
% \begin{quote}
% |\expandafter|\,|\RE@read@spath|\,|\the|\,|\RE@temptoks|\,^^A
% |\RE@read@spath|
% \end{quote}
% As the |##1| below has become |#1| when |\RE@make@text@comp| is
% expanded, this will act as a normal |#1| in the definition
% |\RE@make@text@comp| expands to.
% \begin{macrocode}
\expandafter\RE@make@text@comp\csname
\RE@font@spec{#3}{#4}{#5}{#6}\RE@bsl@string#2%
\endcsname {\RE@again@read@spath#2{##1}}%
% \end{macrocode}
% Otherwise it must be checked if the variant is composed. If it is,
% then everything is fine, if it isn't, then the current definition
% is made the default definition.
% \begin{macrocode}
\else
\RE@if@composed\RE@garbage{}{%
\expandafter\RE@make@text@comp
\csname
\RE@font@spec{#3}{#4}{#5}{#6}\RE@bsl@string#2%
\expandafter\endcsname
\expandafter{\RE@garbage{##1}}%
}%
\fi
% \end{macrocode}
% Then it is finally time to define the composition. This is pretty
% straight off.
% \begin{macrocode}
\global\expandafter#1\csname
\@backslashchar\RE@font@spec{#3}{#4}{#5}{#6}\RE@bsl@string#2-#7%
\endcsname
}
% \end{macrocode}
% |\RE@make@text@comp| makes |#1| a composed command, with |#2| as
% the default definition. This is exactly what the corresponding
% command in standard \LaTeX\ does, but for some reason \LaTeX\ ^^A
% defines this command of the fly each time it is needed.
% \begin{macrocode}
\def\RE@make@text@comp#1#2{%
\gdef#1##1{\@text@composite#1##1\@empty\@text@composite{#2}}%
}
% \end{macrocode}
% \end{macro}\end{macro}\end{macro}\end{macro}
%
%
% \subsection{Miscellanenous commands}
%
% \subsubsection{Search paths}
%
% A very important thing about search paths is that they are
% responsible for ending a search that has found nothing, as the macros
% which actually perform the search contain no mechanism for this. The
% easiest way to ensure this is to append the token |\RE@var@not@found|
% to every search path set, and this is exactly what the standard
% commands for setting search paths do. Anyone who does not use these
% commands for setting a search path must be aware that if a search
% path does not contain any block that ends the search then some tiny errors
% are likely to start infinite loops.
%
% \begin{macro}{\SetEncodingSearchPath}
% \begin{macro}{\SetFamilySearchPath}
% \begin{macro}{\RE@set@spath}
% \begin{macro}{\RE@spath@catcodes}
% These are all fairly standard. |\RE@set@spath| does the actual
% setting of a search path while |\SetEncodingSearchPath| and
% |\SetFamilySearchPath| merely form the name of the macro that will
% store the search path and temporarily change some |\catcode|s to make
% typing the search path somewhat easier. The |\catcode|s are changed
% by |\RE@spath@catcodes|.
%
% \begin{macrocode}
\newcommand{\SetEncodingSearchPath}[1]{%
\begingroup
\RE@spath@catcodes
\expandafter\RE@set@spath \csname#1-path\endcsname
}
% \end{macrocode}
% \begin{macrocode}
\newcommand{\SetFamilySearchPath}[2]{%
\begingroup
\RE@spath@catcodes
\expandafter\RE@set@spath \csname#1/#2-path\endcsname
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@set@spath#1#2{%
\gdef#1{#2\RE@var@not@found}%
\endgroup
}
% \end{macrocode}
% \begin{macrocode}
\def\RE@spath@catcodes{%
\catcode`\ =9\relax
\catcode`\^^I=9\relax
\catcode`\^^M=9\relax
\catcode`\@=11\relax
\catcode`\/=12\relax
\catcode`\?=12\relax
}
% \end{macrocode}
% \end{macro}\end{macro}\end{macro}\end{macro}
%
% \begin{macro}{\RE@convert@nfss}
% For some relaxed encodings, one wants the definition of a
% font-dependent command to be identical to the definition of the command
% in a non-relaxed encoding (this is the case with \texttt{T1R}, which
% is designed to be a relaxed version of \texttt{T1}). As there are
% slight differences in how the names of compositions are generated
% between the \LaTeXe\ kernel and \package{relenc}, it would not be
% sufficient to simply include |{T1}| in the search path of the
% \texttt{T1R} encoding to make it use \texttt{T1}'s definitions of
% compositions as variants of that composition. The purpose of
% |\RE@convert@nfss| is to overcome this by changing the names of the
% variants of compositions where required. Including
% |\RE@convert@nfss|\,|{T1}| in the search path of \texttt{T1R} gives
% the intended effect.
% \begin{macrocode}
\def\RE@convert@nfss#1#2{%
\ifx\@empty#2%
\@backslashchar#1\expandafter\expandafter \expandafter\@gobble
\else
#1\expandafter#2%
\fi
}
% \end{macrocode}
% \end{macro}
%
%
% \subsubsection{The define first mechanism}
%
% \begin{macro}{\ActivateDefineFirst}
% \begin{macro}{\DeactivateDefineFirst}
% These commands can be used to turn the define first mechanism on and
% off. I am not sure at the moment whether implementing it was a good
% idea, but as it exists it might as well stay so it can be evaluated.
%
% It could be worth pointing out that these commands act locally. The
% define first mechanism, on the other hand, acts globally.
% \begin{macrocode}
\newcommand\ActivateDefineFirst{%
\let\RE@define@first\RE@active@define@first
}
\newcommand\DeactivateDefineFirst{%
\let\RE@define@first\@gobbletwo
}
% \end{macrocode}
% \end{macro}\end{macro}
%
% \subsection{Debugging}
%
% \begin{macro}{\ShowVariantSearchResult}
% This command offers a way to peek into the search mechanism, and in
% particular to see where it stopped. This command has a potential to
% come in real handy, but note that it is the \emph{remaining search
% path} that is shown. You do not see the block that was actually
% used, you see all blocks that come after it.
% \begin{macrocode}
\newcommand{\ShowVariantSearchResult}{%
\immediate\write\sixt@@n{Encoding: \cf@encoding}%
\immediate\write\sixt@@n{Family: \f@family}%
\immediate\write\sixt@@n{Series: \f@series}%
\immediate\write\sixt@@n{Shape: \f@shape}%
\immediate\write\sixt@@n
{Remaining search path:\MessageBreak\the\RE@temptoks}%
\show\RE@first@search@item
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Fix for a bug in \LaTeX}
%
% The definition of the control sequence |\@text@composite@x| in
% \LaTeX{}es released 1998 and earlier has a bug (number 2930 in the
% \LaTeX\ bugs database). The definition in question is
%\begin{verbatim}
% \def\@text@composite@x#1#2{%
% \ifx#1\relax
% \expandafter#2%
% \else
% #1%
% \fi}
%\end{verbatim}
% The problem with this definition is the |\expandafter|. According to
% \cite{ltoutenc}, it was ``added so that less chaos ensues from the
% misuse of this code with commands that take several arguments'', but
% unfortunately, it was placed in a position where it can do no good.
% |#2| is in all reasonable cases a sequence of more than one token,
% hence the |\expandafter| will not expand the following |\else|, but
% some token in |#2| instead! I suspect that the |\expandafter| was
% really meant to be placed in front of the |#1|, which actually is just
% a single token.
%
% As it happens, the above bug can cause some serious problems when the
% non-composite definition of a composite command happens to be
% variable, since the above |\expandafter| will then expand a control
% sequence which should \emph{not} be expanded.
%
% \begin{macro}{\@text@composite@x}
% The following code fixes the above bug if the \LaTeX\ used is
% one with that bug. This is done as a curtesy to all those \LaTeX\
% users which (like myself) are not always updating \LaTeX\ as soon
% as a new release appears. The definition of |\@text@composite@x| is
% checked and, if it matches the above, replaced with the fixed
% definition.
% \begin{macrocode}
\def\RE@garbage#1#2{%
\ifx#1\relax
\expandafter#2%
\else
#1%
\fi}
\ifx \@text@composite@x\RE@garbage
\def\@text@composite@x#1{%
\ifx #1\relax
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi
#1%
}
\fi
\let\RE@garbage\relax
%</package>
% \end{macrocode}
% \end{macro}
%
\endinput
|