1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
|
% \iffalse meta-comment
%
% Copyright (C) 1993-2022
% The LaTeX Project and any individual authors listed elsewhere
% in this file.
%
% This file is part of the LaTeX base system.
% -------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
% https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This file has the LPPL maintenance status "maintained".
%
% The list of all files belonging to the LaTeX base distribution is
% given in the file `manifest.txt'. See also `legal.txt' for additional
% information.
%
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
%
% \fi
%
% \iffalse
%%% From File: ltfiles.dtx
%<*driver>
% \fi
\ProvidesFile{ltfiles.dtx}
[2021/10/14 v1.2p LaTeX Kernel (File Handling)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfiles.dtx}
\title{\filename}
\date{\filedate}
\author{%
Johannes Braams\and
David Carlisle\and
Alan Jeffrey\and
Leslie Lamport\and
Frank Mittelbach\and
Chris Rowley\and
Rainer Sch\"opf}
\providecommand\pkg[1]{\texttt{#1}}
\providecommand\InternalDetectionOff{}
\providecommand\InternalDetectionOn{}
\begin{document}
\MaintainedByLaTeXTeam{latex}
\maketitle
\DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \providecommand\hook[1]{\texttt{#1}}
%
%
% \changes{v1.0h}{1994/05/21}{Use new error commands}
% \changes{v1.0n}{1994/11/17}
% {\cs{@tempa} to \cs{reserved@a}}
% \changes{v1.0u}{1995/07/13}{Updates to docu}
% \changes{v1.1m}{2015/02/21}
% {Removed autoload support}
% \changes{v1.2i}{2020/08/21}{Integration of new hook management interface}
%
% \section{File Handling}
%
% The following user commands are defined in this part:
%
% \DescribeMacro{\document} (ie |\begin{document}|)\\
% Reads in the .AUX files and |\catcode|'s |@| to 12.
%
% \DescribeMacro{\nofiles}\\
% Suppresses all file output by setting |\@filesw| false.
%
% \DescribeMacro{\includeonly}\marg{NAME1, ... ,NAMEn}\\
% Causes only parts NAME1, ... ,NAMEn to be read by
% their |\include| commands. Works by setting \@partsw true
% and setting |\@partlist| to NAME1, ... ,NAMEn.
%
% \DescribeMacro{\include}\marg{NAME}\\
% Does an |\input| NAME unless |\@partsw| is true and
% NAME is not in |\@partlist|. If |\@filesw| is true, then
% it directs .AUX output to NAME.AUX, including a
% checkpoint at the end.
%
% \DescribeMacro{\input}\marg{NAME}\\
% The same as TeX's |\input|, except it allows optional
% braces around the file name. In \LaTeXe, it also avoids
% the primitive `missing file' error, if the file can not be
% found.
%
% \DescribeMacro{\IfFileExists}\marg{NAME}\marg{then}\marg{else}\\
% If the file exists on the system, execute \emph{then} otherwise
% execute \emph{else}.
%
% \DescribeMacro{\InputIfFileExists}\marg{NAME}\marg{then}\marg{else}\\
% If the file exists on the system, execute \emph{then} and input
% \emph{NAME} otherwise execute \emph{else}.
%
% \MaybeStop{}
%
% \changes{v1.0a}{1994/03/07}{Initial version, split from latex.dtx}
% \changes{v1.0a}{1994/03/07}{Long lines wrapped to 72 columns}
%
% \begin{oldcomments}
%
% \begin{macrocode}
%<*2ekernel>
\message{files,}
% \end{macrocode}
%
% VARIABLES, SWITCHES AND INTERNAL COMMANDS:
% \@mainaux : Output file number for main .AUX file.
% \@partaux : Output file number for current part's .AUX file.
% \@auxout : Either \@mainout or \@partout, depending on
% which .AUX file output goes to.
% \@input{foo} : If file foo exists, then \input's it,
% otherwise types a warning message.
% @filesw : Switch -- set false if no .AUX, .TOC, .IDX etc
% files are to be written
% @partsw : Set true by a \includeonly command.
% \@partlist : Set to the argument of the \includeonly command.
%
% \cp@FOO : The checkpoint for \include'd file FOO.TEX, written
% by \@writeckpt at the end of file FOO.AUX
%
%
% \includeonly{FILELIST} ==
% BEGIN
% \@partsw := T
% \@partlist := FILELIST
% END
%
% \include{FILE} ==
% BEGIN
% \clearpage
% if \@filesw = T
% then \immediate\write\@mainaux{\string\@input{FILE.AUX}}
% fi
% if \@partsw = T
% then \@tempswa := F
% \reserved@b == FILE
% for \reserved@a := \@partlist
% do if eval(\reserved@a) = eval(\reserved@b)
% then \@tempswa := T fi
% od
% fi
%
% if \@tempswa = T
% then \@auxout := \@partaux
% if \@filesw = T
% then \immediate\openout\@partaux{FILE.AUX}
% \immediate\write\@partaux{\relax}
% fi
% \@input{FILE.TEX}
% \clearpage
% \@writeckpt{FILE}
% if @filesw then \closeout \@partaux fi
% \@auxout := \@mainaux
% else \cp@FILE
% fi
% END
%
% \@writeckpt{FILE} ==
% BEGIN
% if \@filesw = T
% \immediate\write on file \@partaux:
% \@setckpt{FILE}{ %% }
% for \reserved@a := \cl@@ckpt
% do \immediate\write on file \@partaux:
% \global\string\setcounter
% {eval(\reserved@a)}{eval(\c@eval(\reserved@a))}
% od %% {
% \immediate\write on file \@partaux: }
% fi
% END
%
% \@setckpt{FILE}{LIST} ==
% BEGIN
% G \cp@FILE := LIST
% END
%
% INITIALIZATION
% \@tempswa := T
%
% \end{oldcomments}
%
%
% \begin{macro}{\@mainaux}
% \begin{macro}{\@partaux}
% \begin{macrocode}
\newwrite\@mainaux
\newwrite\@partaux
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@filesw}
% \begin{macro}{\if@partsw}
% \begin{macrocode}
\newif\if@filesw \@fileswtrue
\newif\if@partsw \@partswfalse
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@clubpenalty}
% This stores the current normal (non-infinite) value of
% \cs{clubpenalty}; it should therefore be reset whenever the
% normal value is changed (as in the bibliography in the standard
% styles).
% \changes{v1.1h}{1996/10/05}{Added setting its value}
% \begin{macrocode}
\newcount\@clubpenalty
\@clubpenalty \clubpenalty
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\document}
% \changes{v0.9e}{1993/12/09}{Hook added}
% \begin{macrocode}
%</2ekernel>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease> {\document}{Added hook to load l3backend code}%
%<*2ekernel|latexrelease>
\def\document{%
% \end{macrocode}
% We do cancel the grouping as part of the \cs{begin} handling
% (this is now done inside \cs{begin} instead) so that the
% \hook{env/\meta{env}/begin} hook is not hidden inside \cs{begingroup}
% \texttt{...} \cs{endgroup}.
% \begin{macrocode}
% \endgroup
% \end{macrocode}
%
% \begin{macrocode}
\UseOneTimeHook{begindocument/before}%
\@kernel@after@begindocument@before
% \end{macrocode}
%
% Added hook to load \textsf{l3backend} code:
% \changes{v1.2h}{2020/06/05}{Added hook to load \textsf{l3backend} code}
% \begin{macrocode}
\@expl@sys@load@backend@@
\ifx\@unusedoptionlist\@empty\else
\@latex@warning@no@line{Unused global option(s):^^J%
\@spaces[\@unusedoptionlist]}%
\fi
\@colht\textheight
\@colroom\textheight \vsize\textheight
\columnwidth\textwidth
\@clubpenalty\clubpenalty
\if@twocolumn
\advance\columnwidth -\columnsep
\divide\columnwidth\tw@ \hsize\columnwidth \@firstcolumntrue
\fi
\hsize\columnwidth \linewidth\hsize
\begingroup\@floatplacement\@dblfloatplacement
\makeatletter\let\@writefile\@gobbletwo
% \end{macrocode}
% \changes{v1.1a}{1995/10/24}
% {Removed multiplelabels switch}
% \begin{macrocode}
\global \let \@multiplelabels \relax
\@input{\jobname.aux}%
\endgroup
\if@filesw
\immediate\openout\@mainaux\jobname.aux
\immediate\write\@mainaux{\relax}%
\fi
% \end{macrocode}
%
% Dateline 1991/03/26: FMi added |\process@table| to support NFSS;
% This will also work with old lfonts if no other style defines
% |\process@table|. The following line forces the initialization of
% the math fonts.
% \begin{macrocode}
\process@table
\let\glb@currsize\@empty % Force math initialization.
% \end{macrocode}
% \changes{v0.9t}{1994/01/31}
% {set \cs{@normalsize} or \cs{normalsize} if necessary}
% \changes{v1.0d}{1994/03/28}
% {(DPC) remove \cs{@normalsize check}}
% \changes{v1.0d}{1994/03/28}
% {(DPC) Use \cs{normalsize} not \cs{@normalsize}}
% \changes{v1.0g}{1994/05/13}{Added execution of \cs{every@size}}
% \changes{v1.0m}{1994/11/07}{Renamed \cs{every@size} to
% \cs{every@math@size}.}
% \changes{v1.0q}{1995/04/25}
% {Removed execution of \cs{every@size} latex/1407}
% \begin{macrocode}
\normalsize
\everypar{}%
% \end{macrocode}
%
% So that punctuation in headings is not disturbed by verbatim
% or other local changes to the space factor codes, save the document
% default here. This will be locally reset by the output routine.
% For special cases a class may want to define |\normalsfcodes|
% directly, in case that definition will be used.
% (This is an old bug, problem existed in \LaTeX2.0x and plain \TeX.)
% \changes{v1.1k}{1997/04/14}
% {Set the document space factor defaults. latex/2404}
% \begin{macrocode}
\ifx\normalsfcodes\@empty
\ifnum\sfcode`\.=\@m
\let\normalsfcodes\frenchspacing
\else
\let\normalsfcodes\nonfrenchspacing
\fi
\fi
% \end{macrocode}
% For similar reasons also save the default language, this will be reset
% locally in the output routine. In particular it allows hyphenation
% in the page head even if the page break happens in verbatim.
% If this has already been set by a package, set to the value of |\language|
% at this point.
% \changes{v1.1n}{2017/03/10}{Save language default}
% \begin{macrocode}
\ifx\document@default@language\m@ne
\chardef\document@default@language\language
\fi
% \end{macrocode}
%
% Way back in 1991 (08/26) FMi \& RmS set the |\@noskipsec| switch
% to true in the preamble and to false here.
% This was done to trap lists and related text in the preamble but it
% does not catch everything; hence Change 1.1g was introduced.
% \begin{macrocode}
\@noskipsecfalse
% \end{macrocode}
% \changes{v1.1a}{1995/10/24}
% {Removed refundefined switch}
% \begin{macrocode}
\let \@refundefined \relax
% \end{macrocode}
% Just before disabling the preamble commands we execute the begin
% document hook which contains any code contributed by
% |\AtBeginDocument|. Also disable the gathering of the file list,
% if no |\listfiles| has been issued. |\AtBeginDocument| is redefined
% at this point so that and such commands that get into the hook do
% not chase their tail\ldots
% \changes{v1.1e}{1996/04/24}
% {(DPC) Reset \cs{AtBeginDocument} eg for latex/1297}
% \begin{macrocode}
\@kernel@before@begindocument
\UseOneTimeHook{begindocument}%
\@kernel@after@begindocument
% \end{macrocode}
%
% Most of the following assignments will be done globally in case
% the user adds something like |\begin{multicols}| to the document
% hook, i.e. starts are group in |\begin{document}|.
% \changes{v1.0r}{1995/04/27}
% {Added \cs{global} to support groups in hook}
% \changes{v1.0c}{1994/03/16}
% {(DPC) directly add file list settings}
% \changes{v1.0v}{1995/08/16}{set \cs{topskip} globally}
% \changes{v1.0v}{1995/08/16}{set \cs{@maxdepth}}
%
% \changes{v1.0s}{1995/05/25}
% {Added check for \cs{topskip} zero}
% \changes{v1.0t}{1995/05/25}
% {Corrected typo}
% Since a value of exactly 0pt for \cs{topskip} causes
% \cs{twocolumn[]} to misbehave, we add this check, hoping
% that it will not cause any problems elsewhere.
% \begin{macrocode}
\ifdim\topskip<1sp\global\topskip 1sp\relax\fi
\global\@maxdepth\maxdepth
\global\let\@begindocumenthook\@undefined
\ifx\@listfiles\@undefined
\global\let\@filelist\relax
\global\let\@addtofilelist\@gobble
\fi
% \end{macrocode}
% At the very end we disable all preamble commands. This has to
% happen after the begin document hooks was executed so that this
% hook can still use such commands.
% \changes{v0.9o}{1994/01/15}
% {move \cs{@preamblecmds} after document hook}
% \changes{v1.0v}{1995/08/16}{set \cs{do} globally}
% \begin{macrocode}
\gdef\do##1{\global\let ##1\@notprerr}%
\@preamblecmds
% \end{macrocode}
% The next line saves tokens and also allows |\@nodocument| to be
% used directly to trap preamble errors.
% \changes{v1.1g}{1996/09/29}{Added disabling of \cs{@nodocument}}
% \begin{macrocode}
\global\let \@nodocument \relax
% \end{macrocode}
% The next line is a pure safety measure in case a do list is ever
% expanded at the wrong place. In addition it will save a few
% tokens to get rid of the above definition.
% \begin{macrocode}
\global\let\do\noexpand
% \end{macrocode}
%
% \begin{macrocode}
\UseOneTimeHook{begindocument/end}%
% \end{macrocode}
% \changes{v1.1c}{1995/12/05}{\cs{ignorespaces} added for latex/1933}
% Use of the hook might mean that we are already in
% horizontal mode, so ignore the space after |\begin{document}|.
% \begin{macrocode}
\ignorespaces}
% \end{macrocode}
%
% The \hook{begindocument} hook already existed in the kernel since
% 1994 under the name \cs{atbegindocumenthook} the
% additional ones are originally from the \pkg{etoolbox}
% package under the names \cs{@endpreamblehook} \cs{afterpreamble}.
% \begin{macrocode}
\NewHook{begindocument}
\NewHook{begindocument/before}
\NewHook{begindocument/end}
% \end{macrocode}
% \begin{macro}{\@kernel@after@begindocument@before,
% \@kernel@before@begindocument,
% \@kernel@after@begindocument}
%
% Above we used two kernel only hooks to be run after the public
% \hook{begindocument/before} and after \hook{begindocument}
% hooks.
%
% In \cs{@kernel@after@begindocument@before} we already place one
% action: drop the fast execution code for the
% \hook{env/document/begin} hook. That hook marks the end of the
% preamble and should therefore only be run once. In a normal
% document that is anyway the case (so the code would just sit
% there taking up space afterwards, which these days is rather
% harmless), however, in more complicated scenarios where several
% full documents are combined to a single document it might get
% applied several times with harmful effects. We therefore
% explicitly drop it at this point. the coding is somewhat obscure
% due to the name of the macro which requires constructing.
% \InternalDetectionOff
% \begin{macrocode}
\edef \@kernel@after@begindocument@before {%
\let\expandafter\noexpand\csname
__hook env/document/begin\endcsname
\noexpand\@empty}
% \end{macrocode}
% \InternalDetectionOn
%
% These internal hooks are already declared earlier (in
% \texttt{ltexpl}) so that other modules could write to them.
% \changes{v1.2m}{2021/04/17}{Move \cs{@kernel@before@begindocument} and
% \cs{@kernel@after@begindocument} init earlier so that other modules can
% write to the hooks}
% \begin{macrocode}
%\let \@kernel@before@begindocument \@empty
%\let \@kernel@after@begindocument \@empty
% \end{macrocode}
%
% \end{macro}
%
%
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2017/04/15}%
%<latexrelease> {\document}{Save language for hyphenation}%
%<latexrelease>
%<latexrelease>\def\document{\endgroup
%<latexrelease> \ifx\@unusedoptionlist\@empty\else
%<latexrelease> \@latex@warning@no@line{Unused global option(s):^^J%
%<latexrelease> \@spaces[\@unusedoptionlist]}%
%<latexrelease> \fi
%<latexrelease> \@colht\textheight
%<latexrelease> \@colroom\textheight \vsize\textheight
%<latexrelease> \columnwidth\textwidth
%<latexrelease> \@clubpenalty\clubpenalty
%<latexrelease> \if@twocolumn
%<latexrelease> \advance\columnwidth -\columnsep
%<latexrelease> \divide\columnwidth\tw@ \hsize\columnwidth \@firstcolumntrue
%<latexrelease> \fi
%<latexrelease> \hsize\columnwidth \linewidth\hsize
%<latexrelease> \begingroup\@floatplacement\@dblfloatplacement
%<latexrelease> \makeatletter\let\@writefile\@gobbletwo
%<latexrelease> \global \let \@multiplelabels \relax
%<latexrelease> \@input{\jobname.aux}%
%<latexrelease> \endgroup
%<latexrelease> \if@filesw
%<latexrelease> \immediate\openout\@mainaux\jobname.aux
%<latexrelease> \immediate\write\@mainaux{\relax}%
%<latexrelease> \fi
%<latexrelease> \process@table
%<latexrelease> \let\glb@currsize\@empty % Force math initialization.
%<latexrelease> \normalsize
%<latexrelease> \everypar{}%
%<latexrelease> \ifx\normalsfcodes\@empty
%<latexrelease> \ifnum\sfcode`\.=\@m
%<latexrelease> \let\normalsfcodes\frenchspacing
%<latexrelease> \else
%<latexrelease> \let\normalsfcodes\nonfrenchspacing
%<latexrelease> \fi
%<latexrelease> \fi
%<latexrelease> \ifx\document@default@language\m@ne
%<latexrelease> \chardef\document@default@language\language
%<latexrelease> \fi
%<latexrelease> \@noskipsecfalse
%<latexrelease> \let \@refundefined \relax
%<latexrelease> \let\AtBeginDocument\@firstofone
%<latexrelease> \@begindocumenthook
%<latexrelease> \ifdim\topskip<1sp\global\topskip 1sp\relax\fi
%<latexrelease> \global\@maxdepth\maxdepth
%<latexrelease> \global\let\@begindocumenthook\@undefined
%<latexrelease> \ifx\@listfiles\@undefined
%<latexrelease> \global\let\@filelist\relax
%<latexrelease> \global\let\@addtofilelist\@gobble
%<latexrelease> \fi
%<latexrelease> \gdef\do##1{\global\let ##1\@notprerr}%
%<latexrelease> \@preamblecmds
%<latexrelease> \global\let \@nodocument \relax
%<latexrelease> \global\let\do\noexpand
%<latexrelease> \ignorespaces}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\document}{Save language for hyphenation}
%<latexrelease>\def\document{\endgroup
%<latexrelease> \ifx\@unusedoptionlist\@empty\else
%<latexrelease> \@latex@warning@no@line{Unused global option(s):^^J%
%<latexrelease> \@spaces[\@unusedoptionlist]}%
%<latexrelease> \fi
%<latexrelease> \@colht\textheight
%<latexrelease> \@colroom\textheight \vsize\textheight
%<latexrelease> \columnwidth\textwidth
%<latexrelease> \@clubpenalty\clubpenalty
%<latexrelease> \if@twocolumn
%<latexrelease> \advance\columnwidth -\columnsep
%<latexrelease> \divide\columnwidth\tw@ \hsize\columnwidth
%<latexrelease> \@firstcolumntrue
%<latexrelease> \fi
%<latexrelease> \hsize\columnwidth \linewidth\hsize
%<latexrelease> \begingroup\@floatplacement\@dblfloatplacement
%<latexrelease> \makeatletter\let\@writefile\@gobbletwo
%<latexrelease> \global \let \@multiplelabels \relax
%<latexrelease> \@input{\jobname.aux}%
%<latexrelease> \endgroup
%<latexrelease> \if@filesw
%<latexrelease> \immediate\openout\@mainaux\jobname.aux
%<latexrelease> \immediate\write\@mainaux{\relax}%
%<latexrelease> \fi
%<latexrelease> \process@table
%<latexrelease> \let\glb@currsize\@empty
%<latexrelease> \normalsize
%<latexrelease> \everypar{}%
%<latexrelease> \ifx\normalsfcodes\@empty
%<latexrelease> \ifnum\sfcode`\.=\@m
%<latexrelease> \let\normalsfcodes\frenchspacing
%<latexrelease> \else
%<latexrelease> \let\normalsfcodes\nonfrenchspacing
%<latexrelease> \fi
%<latexrelease> \fi
%<latexrelease> \@noskipsecfalse
%<latexrelease> \let \@refundefined \relax
%<latexrelease> \let\AtBeginDocument\@firstofone
%<latexrelease> \@begindocumenthook
%<latexrelease> \ifdim\topskip<1sp\global\topskip 1sp\relax\fi
%<latexrelease> \global\@maxdepth\maxdepth
%<latexrelease> \global\let\@begindocumenthook\@undefined
%<latexrelease> \ifx\@listfiles\@undefined
%<latexrelease> \global\let\@filelist\relax
%<latexrelease> \global\let\@addtofilelist\@gobble
%<latexrelease> \fi
%<latexrelease> \gdef\do##1{\global\let ##1\@notprerr}%
%<latexrelease> \@preamblecmds
%<latexrelease> \global\let \@nodocument \relax
%<latexrelease> \global\let\do\noexpand
%<latexrelease> \ignorespaces}
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
%
% \begin{macrocode}
\@onlypreamble\document
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\normalsfcodes}
% \changes{v1.1k}{1997/04/14}
% {Macro added (from patch file) latex/2404}
% The setting of |\@empty| is just a flag. This command may be defined
% in a class or package file. If it is still |\@empty| at
% |\begin{document}| it will be defined to be |\frenchspacing| or
% |\nonfrenchspacing|, depending on which of those appears to be in
% effect at that point.
% \begin{macrocode}
\let\normalsfcodes\@empty
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\nofiles}
% \changes{v1.0k}{1994/11/04}
% {Added setting of \cs{protected@write},
% \cs{makeindex} and \cs{makeglossary} to \cs{nofiles}. ASAJ.}
% \changes{v1.0o}{1994/11/30}
% {There is no \cs{@gobblethree}\ldots}
% \changes{v1.0t}{1995/05/25}
% {(CAR) added \cs{long}}
% \changes{v1.1f}{1996/05/17}
% {added \cs{write} to \cs{protected@write} for latex/2146}
% Set |\@fileswfalse| which suppresses the places where \LaTeX\ makes
% |\immediate| writes. The |\makeindex| and |\makeglossary| are
% disabled. |\protected@write| is redefined not to write to the file
% specified, but rather to write a blank line to the log file. This
% ensures that a \meta{whatsit} node is still created, and so spacing
% is not affected by the |\nofiles| command; to ensure this more
% generally, the |\if@nobreak| test is needed.
% \changes{v1.1i}{1996/11/05}
% {Standard \cs{if@nobreak} test added}
% \begin{macrocode}
\def\nofiles{%
\@fileswfalse
\typeout{No auxiliary output files.^^J}%
\long\def\protected@write##1##2##3%
{\write\m@ne{}\if@nobreak\ifvmode\nobreak\fi\fi}%
\let\makeindex\relax
\let\makeglossary\relax}
\@onlypreamble\nofiles
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\protected@write}
% This takes three arguments: an output stream, some initialization
% code, and some text to write. It then writes this, with
% appropriate handling of |\protect| and |\thepage|.
% \changes{v1.0k}{1994/11/04}{Macro added ASAJ.}
% \changes{v1.0t}{1995/05/25}
% {(CAR) added \cs{long}}
% \begin{macrocode}
\long\def \protected@write#1#2#3{%
\begingroup
\let\thepage\relax
#2%
\let\protect\@unexpandable@protect
\edef\reserved@a{\write#1{#3}}%
\reserved@a
\endgroup
\if@nobreak\ifvmode\nobreak\fi\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\let\@auxout=\@mainaux
% \end{macrocode}
%
%
% \begin{macro}{\include,\includeonly}
% \changes{v0.9p}{1994/01/18}
% {Use \cs{@input@} so include files are listed.}
% \changes{v1.0p}{1995/04/22}{Allow blanks in argument}
% \changes{v1.2a}{2019/07/01}{Support UTF-8}
% \changes{v1.2g}{2020/05/02}{Improved support for spaces in filenames
% (gh/217)}
%
% In the definition of |\include|, |\def\reserved@b| changed to
% |\edef\reserved@b| to be consistent with the |\edef| in
% |\includeonly|.
% (Suggested by Rainer Sch\"opf \& Frank Mittelbach.
% Change made 20 Jul 88.)
%
% Changed definition of |\include| to allow space at end of file name
% --- otherwise, typing |\include{foo }| would cause \LaTeX\ to
% overwrite |foo.tex|. Change made 24 May 89, suggested by Rainer
% Sch\"opf and Frank Mittelbach
%
% Made |\include| check for being used inside an |\include|'d file, as
% this will not work and cause surprising results.
% \changes{v1.2g}{2020/05/02}{Get rid of leading and trailing spaces
% from the filename (gh/217)}
% \changes{v1.2g}{2020-05-02}{Pass the filename to \cs{@include} by
% value instead of by reference (gh/217)}
%
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease> {\includeonly}{Spaces in file names}%
% \end{macrocode}
%
% \begin{macrocode}
\def\include#1{\relax
\ifnum\@auxout=\@partaux
\@latex@error{\string\include\space cannot be nested}\@eha
\else
% \end{macrocode}
% Here the normalization will add |.tex| for all files, (it uses
% the same normalization as the hooks), so we need to remove that
% manually. \cs{@strip@tex@ext} does that.
% \begin{macrocode}
\set@curr@file{#1}%
\edef\@curr@file{\@strip@tex@ext\@curr@file}%
% \end{macrocode}
% For historical reasons \cs{@include} expects an argument
% delimited by a space. This is kept (though unnecessary now) to avoid
% errors in other packages that use \cs{@include} directly.
% \begin{macrocode}
\expandafter\@include\expandafter{\@curr@file} % deliberate space
\fi}
% \end{macrocode}
%
% Here in \cs{includeonly} we also need to strip |.tex| after
% normalization:
% \begin{macrocode}
\def\includeonly#1{%
\@partswtrue
% \end{macrocode}
% Because the argument to |\includeonly| is a comma-separated list
% of filenames where there may be comma's preceding some of the
% filenames or trailing them. Therefore we need to take the list
% apart, remove the unwanted spaces while leaving the spaces
% \emph{in} the filenames intact.
% \begin{macrocode}
\let\@partlist\@empty
\@for\reserved@a:=#1 \do
{%
\expandafter\set@curr@file\expandafter{\reserved@a}%
\ifx\@partlist\@empty
\edef\@partlist{\@strip@tex@ext\@curr@file}%
\else
\edef\@partlist{\@partlist,\@strip@tex@ext\@curr@file}%
\fi
}%
}
\@onlypreamble\includeonly
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@strip@tex@ext,\@strip@tex@ext@aux}
% These macros take a (\cs{detokenize}d file name and remove any
% |.tex| extension). Extra care is taken to not remove the string
% |.tex| from the middle of a file name: it is only removed if it's
% the very last thing in the file name.
% \begin{macrocode}
\def\reserved@a#1{%
\def\@strip@tex@ext##1{%
\expandafter\@strip@tex@ext@aux
##1\@nil\@nil
#1\@nil\relax\@nnil}
\def\@strip@tex@ext@aux##1#1\@nil##2\@nnil{%
\ifx\relax##2\@empty
\expandafter\@cdr\expandafter\@empty\@cdr{}##1%
\else##1\fi}}%
\expandafter\reserved@a
\expandafter{\detokenize{.tex}}
%</2ekernel|latexrelease>
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\includeonly}{Spaces in file names}%
%<latexrelease>
%<latexrelease>\def\includeonly#1{%
%<latexrelease> \@partswtrue
%<latexrelease> \set@curr@file{\zap@space#1 \@empty}%
%<latexrelease> \let\@partlist\@curr@file
%<latexrelease> }
%<latexrelease>
%<latexrelease>\def\include#1{\relax
%<latexrelease> \ifnum\@auxout=\@partaux
%<latexrelease> \@latex@error{\string\include\space cannot be nested}\@eha
%<latexrelease> \else
%<latexrelease> \set@curr@file{#1 }%
%<latexrelease> \expandafter\@include\@curr@file
%<latexrelease> \fi}
%<latexrelease>
%<latexrelease>\let\@strip@tex@ext\@undefined
%<latexrelease>\let\@strip@tex@ext@aux\@undefined
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\includeonly}{Spaces in file names}%
%<latexrelease>\def\includeonly#1{%
%<latexrelease> \@partswtrue
%<latexrelease> \edef\@partlist{\zap@space#1 \@empty}}
%<latexrelease>
%<latexrelease>\def\include#1{\relax
%<latexrelease> \ifnum\@auxout=\@partaux
%<latexrelease> \@latex@error{\string\include\space cannot be nested}\@eha
%<latexrelease> \else \@include#1 \fi}
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
%
% \begin{macro}{\@include}
% \changes{v1.2g}{2020/05/02}{Support spaces in filenames by enclosing
% the names of \texttt{.aux}-files in quotes (gh/217)}
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease> {\@include}{Spaces in file names and hooks}%
% \end{macrocode}
%
% \changes{v1.2j}{2020/10/04}{Quotes around the aux file name removed,
% they are not needed and upset BibTeX (gh/400)}
% \changes{v1.2p}{2021/10/14}{Warn about use in preamble}
% \begin{macrocode}
\def\@include#1 {%
% \end{macrocode}
%
% \begin{macrocode}
\ifx\@nodocument\relax
% \end{macrocode}
%
% \begin{macrocode}
\clearpage
\if@filesw
\immediate\write\@mainaux{\string\@input{#1.aux}}%
\fi
\@tempswatrue
\if@partsw
\@tempswafalse
\edef\reserved@b{#1}%
\@for\reserved@a:=\@partlist\do
{\ifx\reserved@a\reserved@b\@tempswatrue\fi}%
\fi
\if@tempswa
\let\@auxout\@partaux
\if@filesw
\immediate\openout\@partaux "#1.aux"
\immediate\write\@partaux{\relax}%
\fi
% \end{macrocode}
% Now before going to the hooks we need to set \cs{CurrentFile}:
% \begin{macrocode}
%-----------------------------------------
\@filehook@set@CurrentFile
% \end{macrocode}
% Execute the \texttt{before} hooks just after we switched the
% \texttt{.aux} file \ldots
% \changes{v1.2n}{2021/07/23}{Make include/name/before a one-time hook}
% \changes{v1.2o}{2021/08/25}{Standardise generic hook names (gh/648)}
% \begin{macrocode}
\UseHook{include/before}%
\UseOneTimeHook{include/#1/before}%
%-----------------------------------------
\@input@{#1.tex}%
%-----------------------------------------
% \end{macrocode}
% \ldots{} then \texttt{end} hooks \ldots
% \changes{v1.2n}{2021/07/23}{Make include/name/end a one-time hook}
% \begin{macrocode}
\UseOneTimeHook{include/#1/end}%
\UseHook{include/end}%
%-----------------------------------------
\clearpage
%-----------------------------------------
% \end{macrocode}
% \ldots{} and after the \cs{clearpage} the \texttt{after} hooks
% followed by another \cs{clearpage} just in case new material got
% added (after all we need to be in well defined state after the
% \cs{include}).
% \changes{v1.2n}{2021/07/23}{Make include/name/after a one-time hook}
% \begin{macrocode}
\UseOneTimeHook{include/#1/after}%
\UseHook{include/after}%
\clearpage
%-----------------------------------------
\@writeckpt{#1}%
\if@filesw
\immediate\closeout\@partaux
\fi
\else
% \end{macrocode}
% If the file is not included, reset |\deadcycles|, so that a long
% list of non-included files does not generate an `Output loop'
% error.
% \changes{v1.1j}{1997/01/08}{reset \cs{deadcycles} latex/2365}
% \begin{macrocode}
\deadcycles\z@
\@nameuse{cp@#1}%
\fi
\let\@auxout\@mainaux
% \end{macrocode}
%
% \begin{macrocode}
\else
\@latex@warning{%
\noexpand\include should only be used after \string\begin{document}}%
\@input@{#1}%
\fi}
% \end{macrocode}
%
% \changes{v1.2o}{2021/08/25}{Declare non-generic include hooks}
% Now declare the non-generic \hook{include} hooks used above:
% \begin{macrocode}
\NewHook{include/before}
\NewReversedHook{include/end}
\NewReversedHook{include/after}
%<latexrelease>\EndIncludeInRelease
%</2ekernel|latexrelease>
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\@include}{Spaces in file names}%
%<latexrelease>\def\@include#1 {%
%<latexrelease> \clearpage
%<latexrelease> \if@filesw
%<latexrelease> \immediate\write\@mainaux{\string\@input{#1.aux}}%
%<latexrelease> \fi
%<latexrelease> \@tempswatrue
%<latexrelease> \if@partsw
%<latexrelease> \@tempswafalse
%<latexrelease> \edef\reserved@b{#1}%
%<latexrelease> \@for\reserved@a:=\@partlist\do
%<latexrelease> {\ifx\reserved@a\reserved@b\@tempswatrue\fi}%
%<latexrelease> \fi
%<latexrelease> \if@tempswa
%<latexrelease> \let\@auxout\@partaux
%<latexrelease> \if@filesw
%<latexrelease> \immediate\openout\@partaux #1.aux
%<latexrelease> \immediate\write\@partaux{\relax}%
%<latexrelease> \fi
%<latexrelease> \@input@{#1.tex}%
%<latexrelease> \clearpage
%<latexrelease> \@writeckpt{#1}%
%<latexrelease> \if@filesw
%<latexrelease> \immediate\closeout\@partaux
%<latexrelease> \fi
%<latexrelease> \else
%<latexrelease> \deadcycles\z@
%<latexrelease> \@nameuse{cp@#1}%
%<latexrelease> \fi
%<latexrelease> \let\@auxout\@mainaux}
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@writeckpt}
% \begin{macrocode}
\def\@writeckpt#1{%
\if@filesw
\immediate\write\@partaux{\string\@setckpt{#1}\@charlb}%
{\let\@elt\@wckptelt \cl@@ckpt}%
\immediate\write\@partaux{\@charrb}%
\fi}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@wckptelt}
% \begin{macrocode}
\def\@wckptelt#1{%
\immediate\write\@partaux{%
\string\setcounter{#1}{\the\@nameuse{c@#1}}}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setckpt}
% RmS 93/08/31: introduced |\@setckpt|
% \begin{macrocode}
\def\@setckpt#1{\global\@namedef{cp@#1}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@charlb}
% \begin{macro}{\@charrb}
% The following defines |\@charlb| and |\@charrb| to be |{| and |}|,
% respectively with |\catcode| 11.
% \begin{macrocode}
{\catcode`[=1 \catcode`]=2
\catcode`{=11 \catcode`}=11
\gdef\@charlb[{]
\gdef\@charrb[}]
]% }brace matching
% \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{Safe Input Macros}
%
%
%
% \begin{macro}{\@curr@file}
% \begin{macro}{\set@curr@file}
%
% File name handling is done by generating a csname from the
% provided file name (which means that UTF-8 octets gets turned into
% strings as this is what happens if they appear in a csname due to
% the code in \texttt{utf8.def}). By setting \cs{escapchar} to
% \texttt{-1} we ensure that we don't get a backslash in front. As a
% result we end up with all characters as catcode 12 (plus
% spaces). We then sometimes add quotes around the construct
% (removing any existing inner quotes. Sometimes we only remove the
% quotes if they have been supplied by the user. There is clearly
% some room for improvement.
%
% A side effect of the new code is that we will see quotes around
% file name displays where there haven't been any before.
%
% For compatibility with existing code using |{abc}.tex| or
% |{one.two}.png|, an initial brace group is discarded before
% expansion and |\string| is applied. The content of the brace
% group is discarded. This means that a leading space will be lost
% unless protected (by |{ }| or |" "| or |\space|) but filenames
% with a space are hopefully rare.
%
% \changes{v1.2a}{2019/07/01}{Support UTF-8}
% \changes{v1.2c}{2019/10/11}{Remove one brace group}
% \changes{v1.2d}{2019/10/26}{remove quotes}
% \changes{v1.2e}{2019/11/09}{expand and \cs{string} before removing quotes}
%
% The definition below is from 2019 and only used during kernel
% bootstrapping, later on in \texttt{ltfilehook.dtx} it will get
% overwritten.
% \begin{macrocode}
\def\set@curr@file#1{%
\begingroup
\escapechar\m@ne
\xdef\@curr@file{%
\expandafter\expandafter\expandafter\unquote@name
\expandafter\expandafter\expandafter{%
\expandafter\string
\csname\@firstofone#1\@empty\endcsname}}%
\endgroup
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\quote@name}
% \begin{macro}{\quote@@name}
% \begin{macro}{\unquote@name}
% Quoting spaces
%\begin{verbatim}
% a b c -> "a b c"
% "a b c" -> "a b c"
% a" "b" "c -> "a b c"
% -> ""
%\end{verbatim}
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\quote@name}{Quote file names}%
\def\quote@name#1{"\quote@@name#1\@gobble""}
\def\quote@@name#1"{#1\quote@@name}
% \end{macrocode}
% and removing quotes \ldots
% \begin{macrocode}
\def\unquote@name#1{\quote@@name#1\@gobble"}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \begin{macro}{\IfFileExists}
%
% \changes{v1.2a}{2019/07/01}{Support UTF-8}
% \changes{v1.2b}{2019/08/27}{Make command robust}
% \changes{v1.2d}{2019/10/26}{don't quote name}
% \begin{macrocode}
\DeclareRobustCommand\IfFileExists[1]{%
\set@curr@file{#1}%
\expandafter\IfFileExists@\expandafter{\@curr@file}}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\quote@name}{Quote file names}%
%<latexrelease>
%<latexrelease>\let\quote@name\@undefined
%<latexrelease>\let\quote@@name\@undefined
%<latexrelease>\let\unquote@name\@undefined
%<latexrelease>
%<latexrelease>\long\def \IfFileExists#1#2#3{%
%<latexrelease> \openin\@inputcheck#1 %
%<latexrelease> \ifeof\@inputcheck
%<latexrelease> \ifx\input@path\@undefined
%<latexrelease> \def\reserved@a{#3}%
%<latexrelease> \else
%<latexrelease> \def\reserved@a{\@iffileonpath{#1}{#2}{#3}}%
%<latexrelease> \fi
%<latexrelease> \else
%<latexrelease> \closein\@inputcheck
%<latexrelease> \edef\@filef@und{#1 }%
%<latexrelease> \def\reserved@a{#2}%
%<latexrelease> \fi
%<latexrelease> \reserved@a}
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
%
%
%
% \begin{macro}{\IfFileExists@}
% \changes{v0.9b}{1993/12/04}{Macro added}
% \changes{v0.9p}{1994/01/18}{New Definition}
% \changes{v1.0t}{1995/05/25}{(CAR) added \cs{long}}
% \changes{v1.2d}{2019/10/26}{quote on openin}
% \changes{v1.2k}{2021/03/12}{Allow unbalanced conditionals (gh/530)}
% Argument |#1| is |\@curr@file| so catcode 12 string with no quotes.
%
% The original definition picked up arguments |#2| and |#3| in a
% way that they couldn't contain unbalanced conditionals. A better
% implementation would have been not to pick up the arguments at
% all but instead use the usual \cs{@firstoftwo} and
% \cs{secondoftwo}. However, that changes how |#| is interpreted
% and so we can't do that nowaways without invalidating a lot of
% code. Therefore the somewhat curious construction near the end.
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2021/06/01}%
%<latexrelease> {\IfFileExists@}{manage unbalanced conditionals}
\long\def \IfFileExists@#1#2#3{%
\openin\@inputcheck"#1" %
\ifeof\@inputcheck
\ifx\input@path\@undefined
\let\reserved@a\@secondoftwo
\else
\def\reserved@a{\@iffileonpath{#1}}%
\fi
\else
\closein\@inputcheck
\edef\@filef@und{"#1" }%
\let\reserved@a\@firstoftwo
\fi
% \end{macrocode}
% This is just there so that any |#| inside |#2| or |#3| needs
% doubling (as that was the case in the past).
% \begin{macrocode}
\expandafter\def\expandafter\reserved@a
\expandafter{\reserved@a{#2}{#3}}%
\reserved@a}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\IfFileExists@}{manage unbalanced conditionals}
%<latexrelease>
%<latexrelease>\long\def \IfFileExists@#1#2#3{%
%<latexrelease> \openin\@inputcheck"#1" %
%<latexrelease> \ifeof\@inputcheck
%<latexrelease> \ifx\input@path\@undefined
%<latexrelease> \def\reserved@a{#3}%
%<latexrelease> \else
%<latexrelease> \def\reserved@a{\@iffileonpath{#1}{#2}{#3}}%
%<latexrelease> \fi
%<latexrelease> \else
%<latexrelease> \closein\@inputcheck
%<latexrelease> \edef\@filef@und{"#1" }%
%<latexrelease> \def\reserved@a{#2}%
%<latexrelease> \fi
%<latexrelease> \reserved@a}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\IfFileExists@}{manage unbalanced conditionals}
%<latexrelease>
%<latexrelease>\let\IfFileExists@\@undefined
%<latexrelease>
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
% \end{macro}
%
%
%
%
%
%
%
% \begin{macro}{\@iffileonpath}
% If the file is not found by |\openin|, and |\input@path| is defined,
% look in all the directories specified in |\input@path|.
% \changes{v0.9p}{1994/01/18}{Macro added}
% \changes{v1.0f}{1994/05/02}
% {\cs{@break@loop} renamed to \cs{@break@tfor}}
% \changes{v1.0t}{1995/05/25}
% {(CAR) added \cs{long}}
% \changes{v1.1d}{1996/01/10}
% {Change argument handling to not require doubled hash. latex/2024}
% \changes{v1.2d}{2019/10/26}{quote on openin}%
% \changes{v1.2f}{2019/11/11}{make \cs{@filef@und} match quoting used on \cs{openin}}%
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\@iffileonpath}{Quote file names}
\long\def\@iffileonpath#1{%
\let\reserved@a\@secondoftwo
\expandafter\@tfor\expandafter\reserved@b\expandafter
:\expandafter=\input@path\do{%
\openin\@inputcheck\expandafter\quote@name\expandafter{\reserved@b#1} %
\ifeof\@inputcheck\else
\edef\@filef@und{\expandafter\quote@name\expandafter{\reserved@b#1} }%
\let\reserved@a\@firstoftwo%
\closein\@inputcheck
\@break@tfor
\fi}%
\reserved@a}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\quote@name}{Quote file names}
%<latexrelease>
%<latexrelease>\long\def\@iffileonpath#1{%
%<latexrelease> \let\reserved@a\@secondoftwo
%<latexrelease> \expandafter\@tfor\expandafter\reserved@b\expandafter
%<latexrelease> :\expandafter=\input@path\do{%
%<latexrelease> \openin\@inputcheck\reserved@b#1 %
%<latexrelease> \ifeof\@inputcheck\else
%<latexrelease> \edef\@filef@und{\reserved@b#1 }%
%<latexrelease> \let\reserved@a\@firstoftwo%
%<latexrelease> \closein\@inputcheck
%<latexrelease> \@break@tfor
%<latexrelease> \fi}%
%<latexrelease> \reserved@a}
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
%
%
%
%
% \begin{macro}{\InputIfFileExists}
%
% Now define |\InputIfFileExists| to input |#1| if it seems to exist.
% Immediately prior to the input, |#2| is executed.
% If the file |#1| does not exist, execute `|#3|'.
%
% This here is a temporary definition for the kernel. The real one
% comes somewhat later in the file \texttt{ltfilehook.dtx}.
%
% \begin{macrocode}
\DeclareRobustCommand \InputIfFileExists[2]{%
\IfFileExists{#1}%
{%
\expandafter\@swaptwoargs\expandafter
{\@filef@und}{#2\@addtofilelist{#1}\@@input}}}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@swaptwoargs}
%
% \changes{v1.1o}{2019/02/07}{Helper macro added}
% Swap two arguments and return them unbraced (like
% \cs{@firstoftwo} etc).
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\@swaptwoargs}{Don't lose the file name}%
\long\def\@swaptwoargs#1#2{#2#1}
% \end{macrocode}
%
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\@swaptwoargs}{Don't lose the file name}%
%<latexrelease>\let\@swaptwoargs\@undefined
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\input}
% Input a file: if the argument is given in braces use safe input
% macros, otherwise use \TeX's primitive |\input| command (which is
% called |\@@input| in \LaTeX).
% \changes{v0.9b}{1993/12/04}{Macro reimplemented}
% \begin{macrocode}
\def\input{\@ifnextchar\bgroup\@iinput\@@input}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@iinput}
% Define |\@iinput| (i.e., |\input|) in terms of
% |\InputIfIfileExists|.
% \changes{v0.9b}{1993/12/04}{Macro reimplemented}
%
% Changes to \cs{@iinput}: adapt to the changes to
% \cs{@missingfileerror}.
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease> {\@iinput}{Change in file error handling}%
\def\@iinput#1{%
\InputIfFileExists{#1}{}%
{\filename@parse\@curr@file
\edef\reserved@a{\noexpand\@missingfileerror
{\filename@area\filename@base}%
{\ifx\filename@ext\relax tex\else\filename@ext\fi}}%
% \end{macrocode}
% This line now just sets \cs[no-index]{@missingfile@\meta{part}}:
% \begin{macrocode}
\reserved@a
% \end{macrocode}
% Now here we have to use it. The file here is guaranteed to exist,
% because \cs{@missingfileerror} ensures so, but we have to use
% \cs{InputIfFileExists} because it executes the file hooks.
% \begin{macrocode}
\edef\reserved@a{\noexpand\@iinput{%
\@missingfile@area\@missingfile@base.\@missingfile@ext}}%
\reserved@a}}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease> {\@iinput}{Quote file names}%
%<latexrelease>
%<latexrelease>\def\@iinput#1{%
%<latexrelease> \InputIfFileExists{#1}{}%
%<latexrelease> {\filename@parse\@curr@file
%<latexrelease> \edef\reserved@a{\noexpand\@missingfileerror
%<latexrelease> {\filename@area\filename@base}%
%<latexrelease> {\ifx\filename@ext\relax tex\else\filename@ext\fi}}%
%<latexrelease> \reserved@a}}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\@iinput}{Quote file names}%
%<latexrelease>\def\@iinput#1{%
%<latexrelease> \InputIfFileExists{#1}{}%
%<latexrelease> {\filename@parse{#1}%
%<latexrelease> \edef\reserved@a{\noexpand\@missingfileerror
%<latexrelease> {\filename@area\filename@base}%
%<latexrelease> {\ifx\filename@ext\relax tex\else\filename@ext\fi}}%
%<latexrelease> \reserved@a}}
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@input}
% \changes{v0.9b}{1993/12/04}{Macro reimplemented}
% \changes{v0.9p}{1994/01/18}%
% {do not use a different definition for \cs{input@path}}
% Define |\@input| in terms of |\IfIfileExists|.
% So this is a `safe input' command, but the files input are not
% listed by |\listfiles|.
%
% We don't want |.aux|, |.toc| files etc be listed by |\listfiles|.
% However, something like |.bbl| probably should be listed and thus
% should be implemented not by |\@input|.
% \begin{macrocode}
\def\@input#1{%
\IfFileExists{#1}{\@@input\@filef@und}{\typeout{No file #1.}}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@input@}
% \changes{v0.9p}{1994/01/18}{Macro added}
% \task{???}{share code with `@input ?}
% Version of |\@input| that does add the file to |\@filelist|.
% \begin{macrocode}
\def\@input@#1{\InputIfFileExists{#1}{}{\typeout{No file #1.}}}
% \end{macrocode}
% \end{macro}
%
%
%
%
%
%
% \begin{macro}{\@missingfileerror}
% This `error' command avoids \TeX's primitive missing file loop.
%
% Missing file error. Prompt for a new filename, offering a default
% extension.
% \changes{LaTeX2e}{1993/11/21}
% {Stop infinite looping on \cs{@er@ext}}
% \changes{LaTeX2e}{1993/11/28}
% {Use filename parser from dircheck}
% \changes{LaTeX2e}{1994/03/15}
% {Quit on x or X just like a real error}
% \changes{LaTeX2e}{1994/05/26}
% {Modify message format}
% \changes{v1.0j}{1994/11/03}
% {Move here from ltclass}
% \changes{v1.0w}{1995/10/06}
% {Autoload error}
%
% Changes to \cs{@missingfileerror}: rather than trying to input the
% file by force, now \cs{@missingfileerror} just returns three
% \cs[no-index]{@missingfile@\meta{part}} and the caller macro is
% responsible for doing the right thing with it.
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease> {\@missingfileerror}{Do not load missing file immediately}%
\gdef\@missingfileerror#1#2{%
\typeout{^^J! LaTeX Error: File `#1.#2' not found.^^J^^J%
Type X to quit or <RETURN> to proceed,^^J%
or enter new name. (Default extension: #2)^^J}%
\message{Enter file name: }%
{\endlinechar\m@ne
\global\read\m@ne to\@gtempa}%
\ifx\@gtempa\@empty
% \end{macrocode}
% If the user answers with \meta{return}, fallback to the |.tex| file
% (previously it did nothing).
% \begin{macrocode}
\let\@missingfile@area\@empty
\let\@missingfile@base\@empty
\def\@missingfile@ext{tex}%
\else
% \end{macrocode}
% Use \cs{batchmode}\cs{read}|-1 to |\meta{tl} to end the \TeX{} run,
% same as \pkg{expl3} does (it was \cs{batchmode}\cs{@@end} before).
% \begin{macrocode}
\def\reserved@b{\batchmode\read-1 to \reserved@a}%
\def\reserved@a{x}\ifx\reserved@a\@gtempa\reserved@b\fi
\def\reserved@a{X}\ifx\reserved@a\@gtempa\reserved@b\fi
\filename@parse\@gtempa
\edef\filename@ext{%
\ifx\filename@ext\relax#2\else\filename@ext\fi}%
\edef\reserved@a{%
% \end{macrocode}
% Only check \cs{IfFileExists} (it was \cs{InputIfFileExists}).
% \begin{macrocode}
\noexpand\IfFileExists
{\filename@area\filename@base.\filename@ext}%
% \end{macrocode}
% If the file exists, define \cs[no-index]{@missingfile@\meta{part}}.
% \begin{macrocode}
{\def\noexpand\@missingfile@area{\filename@area}%
\def\noexpand\@missingfile@base{\filename@base}%
\def\noexpand\@missingfile@ext {\filename@ext}}%
{\noexpand\@missingfileerror
{\filename@area\filename@base}{\filename@ext}}}%
\reserved@a
\fi
}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
%
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\@missingfileerror}{Do not load missing file immediately}%
%<latexrelease>
%<latexrelease>\gdef\@missingfileerror#1#2{%
%<latexrelease> \typeout{^^J! LaTeX Error: File `#1.#2' not found.^^J^^J%
%<latexrelease> Type X to quit or <RETURN> to proceed,^^J%
%<latexrelease> or enter new name. (Default extension: #2)^^J}%
%<latexrelease> \message{Enter file name: }%
%<latexrelease> {\endlinechar\m@ne
%<latexrelease> \global\read\m@ne to\@gtempa}%
%<latexrelease> \ifx\@gtempa\@empty
%<latexrelease> \else
%<latexrelease> \def\reserved@a{x}\ifx\reserved@a\@gtempa\batchmode\@@end\fi
%<latexrelease> \def\reserved@a{X}\ifx\reserved@a\@gtempa\batchmode\@@end\fi
%<latexrelease> \filename@parse\@gtempa
%<latexrelease> \edef\filename@ext{%
%<latexrelease> \ifx\filename@ext\relax#2\else\filename@ext\fi}%
%<latexrelease> \edef\reserved@a{%
%<latexrelease> \noexpand\InputIfFileExists
%<latexrelease> {\filename@area\filename@base.\filename@ext}%
%<latexrelease> {}%
%<latexrelease> {\noexpand\@missingfileerror
%<latexrelease> {\filename@area\filename@base}{\filename@ext}}}%
%<latexrelease> \reserved@a
%<latexrelease> \fi}
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@obsoletefile}
% For compatibility with \LaTeX~2.09 document styles, we distribute
% files called |article.sty|, |book.sty|, |report.sty|,
% |slides.sty| and |letter.sty|. These use the command
% |\@obsoletefile|, which produces a warning message.
% \changes{v0.9m}{1993/12/20}{Added this command, removed
% @oldfilewarning}
% \changes{v1.0f}{1994/05/02}{Make \cs{@onlypreamble}}
% \begin{macrocode}
\def\@obsoletefile#1#2{%
\@latex@warning@no@line{inputting `#1' instead of obsolete `#2'}}
\@onlypreamble\@obsoletefile
% \end{macrocode}
%
% \subsection{Listing files}
%
% \begin{macro}{\@filelist}
% A list of files input so far. The initial value of |\@gobble| eats
% the comma before the first file name.
% \begin{macrocode}
\let\@filelist\@gobble
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@addtofilelist}
% Add to the list of files input so far.
% \changes{LaTeX2e}{1994/03/13}
% {Macro added}
% \changes{LaTeX2e}{1995/10/01}
% {Macro added}
% This `real' definition is only used for `cfg' files during initex.
% An initial definition of |\@gobble| has already been set.
% \begin{macrocode}
%\def\@addtofilelist#1{\xdef\@filelist{\@filelist,#1}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\listfiles}
% A preamble command to cause |\end{document}| to list files input
% from the main file.
% \changes{LaTeX2e}{1993/11/22}
% {Removed checking for \cs{@unknownversion}}
% \changes{LaTeX2e}{1994/01/17}
% {New Version, adds `.tex' if needed, and lines up columns}
% \changes{LaTeX2e}{1994/05/13}
% {Stop \cs{listfiles} being run twice}
% \changes{v1.0i}{1994/10/18}
% {code moved here from ltclass}
% \begin{macrocode}
\def\listfiles{%
\let\listfiles\relax
\def\@listfiles##1##2##3##4##5##6##7##8##9\@@{%
\def\reserved@d{\\}%
\@tfor\reserved@c:=##1##2##3##4##5##6##7##8\do{%
\ifx\reserved@c\reserved@d
\edef\filename@area{ \filename@area}%
\fi}}%
% \end{macrocode}
%
% \changes{v1.0o}{1994/11/30}
% {Use \cs{@dofilelist}}
% \begin{macrocode}
\def\@dofilelist{%
\typeout{^^J *File List*}%
\@for\@currname:=\@filelist\do{%
\filename@parse\@currname
\edef\reserved@a{%
\filename@base.%
\ifx\filename@ext\relax tex\else\filename@ext\fi}%
\expandafter\let\expandafter\reserved@b
\csname ver@\reserved@a\endcsname
\expandafter\expandafter\expandafter\@listfiles\expandafter
\filename@area\filename@base\\\\\\\\\\\\\\\\\\\@@
\typeout{%
\filename@area\reserved@a
\ifx\reserved@b\relax\else\@spaces\reserved@b\fi}}%
\typeout{ ***********^^J}}}
% \end{macrocode}
%
% \changes{LaTeX2e}{1994/03/13}
% {Reset \cs{@addtofilelist} at begin document}
% \changes{LaTeX2e}{1994/03/16}
% {Move this code directly into \cs{document}}
% The |\@filelist| will be de-activated if |\listfiles| does not
% appear in the preamble. |\begin{document}| contains code equivalent
% to the following:
%\begin{verbatim}
% \AtBeginDocument{%
% \ifx\@listfiles\@undefined
% \let\@filelist\relax
% \let\@addtofilelist\@gobble
% \fi}
%\end{verbatim}
% \begin{macrocode}
\@onlypreamble\listfiles
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@dofilelist}
% \changes{v1.0o}{1994/11/30}
% {Macro added}
% \begin{macrocode}
\let\@dofilelist\relax
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</2ekernel>
% \end{macrocode}
% \end{macro}
%
% \Finale
%
|