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

\pagestyle{myheadings}

\title{A New Implementation of \LaTeX{}'s \\ \texttt{verbatim}
       and \texttt{verbatim*} Environments}
\author{Rainer Sch\"opf\\
        \and
        Bernd Raichle\\
        \and
        Chris Rowley}

\date{2023/11/06}
\begin{document}
\markboth{Verbatim style option}{Verbatim style option}
\MaintainedByLaTeXTeam{tools}
\maketitle
  \DocInput{verbatim.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
%
%\fi
%
%
% 
% \changes{v1.5x}{2024/01/22}{Added TAB marking support to \cs{verbatiminput*}}
% \changes{v1.5u}{2020-07-07}{Typo repair and added a missing comment
%    character}
% \changes{v1.5q}{2003/08/22}{Reintroduced \cs{@noligs}, by popular
%                             request.}
% \changes{v1.5i}{1996/06/04}{Move setting of verbatim font and
%                             \cs{@noligs}.}
% \changes{v1.5g}{1995/04/26}{Removed \cs{fileversion} and
%                             \cs{filedate} from running head in
%                             driver file, as these are no longer
%                             defined.}
% \changes{v1.5f}{1994/10/25}{Removed extra \cs{typeout} commands.}
% \changes{v1.5e}{1994/06/10}{Added missing closing verbtest guard.}
% \changes{v1.5d}{1994/05/30}{\cs{NeedsTeXFormat} and
%                             \cs{ProvidesPackage} added.}
% \changes{v1.5d}{1994/05/30}{\cs{addto@hook} removed, now in kernel.}
% \changes{v1.5a}{1993/10/12}{Included \cs{newverbtext} command, as
%          written by Chris Rowley.}
% \changes{v1.5}{1993/10/11}{Included vrbinput style option by Bernd
%          Raichle.}
%
% \changes{v1.4j}{1992/06/30}{Used \cs{lowercase}\{\cs{endgroup}
%    \ldots\} trick proposed by Bernd Raichle; changed all \cs{gdef}
%    to \cs{def} since no longer necessary.}
% \changes{v1.4g}{1991/11/21}{Several improvements in the
%                           documentation.}
% \changes{v1.4f}{1991/08/05}{Corrected bug in documentation.
%                           Found by Bernd Raichle.}
% \changes{v1.4e}{1991/07/24}{Avoid reading this file twice.}
% \changes{v1.4d}{1991/04/24}{\cs{penalty}\cs{interlinepenalty} added to
%                           definition of \cs{par} in \cs{@verbatim}.
%                           Necessary to avoid page breaks in
%                           the scope of a \cs{samepage} declaration.}
% \changes{v1.4c}{1990/10/18}{Added \cs{leavevmode} to definition of
%       backquote macro.}
% \changes{v1.4b}{1990/07/14}{Converted nearly all \cs{verb}'s to
%       \texttt{\protect\string!|\ldots\protect\string!|}.}
% \changes{v1.4a}{1990/04/04}{Added a number of percent characters
%       to suppress blank space at the end of some code lines.}
% \changes{v1.4}{1990/03/07}{\cs{verb} rewritten.}
%
% \changes{v1.3a}{1990/02/04}{Removed \texttt{verbatimwrite} environment
%       from the code. Now only shown as an example.}
%
% \changes{v1.2g}{1990/02/01}{Revised documentation.}
% \changes{v1.2e}{1990/01/15}{Added \cs{every@verbatim} hook.}
% \changes{v1.2d}{1989/11/29}{Use token register \cs{@temptokena}
%                           instead of macro \cs{@tempb}.}
% \changes{v1.2d}{1989/11/29}{Use token register \cs{verbatim@line}
%                           instead of macro \cs{@tempd}.}
% \changes{v1.2b}{1989/10/25}{\cs{verbatimfile} renamed to
%           \cs{verbatiminput}. Suggested by Reinhard Wonneberger.}
%
% \changes{v1.1a}{1989/10/16}{\cs{verb} added.}
% \changes{v1.1}{1989/10/09}{Made the code more modular (as suggested by
%                          Chris Rowley):  introduced
%                          \cs{verbatim@addtoline}, etc.  Added
%                          \cs{verbatimwrite} environment.}
%
% \changes{v1.0e}{1989/07/17}{Fixed bug in \cs{verbatimfile} (*-form
%         handling, discovered by Dirk Kreimer).}
% \changes{v1.0d}{1989/05/16}{Revised documentation, fixed silly bug
%         in \cs{verbatim@@@}.}
% \changes{v1.0c}{1989/05/12}{Added redefinition of \cs{@sverb}, change
%         in end-of-line handling.}
% \changes{v1.0b}{1989/05/09}{Change in \cs{verbatim@rescan}.}
% \changes{v1.0a}{1989/05/07}{Change in \cs{verbatim@@testend}.}
%
%
% \DoNotIndex{\ ,\!,\C,\[,\\,\],\^,\`,\{,\},\~}
% \DoNotIndex{\@M,\@empty,\@flushglue,\@gobble,\@ifstar,\@ifundefined}
% \DoNotIndex{\@namedef,\@spaces,\@tempa,\@tempb,\@tempc,\@tempd}
% \DoNotIndex{\@temptokena,\@totalleftmargin,\@warning,\active}
% \DoNotIndex{\aftergroup,\arabic,\begingroup,\catcode,\char,\closein}
% \DoNotIndex{\csname,\def,\do,\docdate,\dospecials,\edef,\else}
% \DoNotIndex{\endcsname,\endgraf,\endgroup,\endinput,\endlinechar}
% \DoNotIndex{\endtrivlist,\expandafter,\fi,\filedate,\fileversion}
% \DoNotIndex{\frenchspacing,\futurelet,\if,\ifcat,\ifeof,\ifnum}
% \DoNotIndex{\ifx,\immediate,\item,\kern,\lccode,\leftskip,\let}
% \DoNotIndex{\lowercase,\m@ne,\makeatletter,\makeatother,\newread}
% \DoNotIndex{\newread,\next,\noexpand,\noindent,\openin,\parfillskip}
% \DoNotIndex{\parindent,\parskip,\penalty,\read,\relax,\rightskip}
% \DoNotIndex{\sloppy,\space,\string,\the,\toks@,\trivlist,\tt,\typeout}
% \DoNotIndex{\vskip,\write,\z@}
%
% \begin{abstract}
%   This package reimplements the \LaTeX{} \texttt{verbatim} and
%   \texttt{verbatim*} environments.
%   In addition it provides a \texttt{comment} environment
%   that skips any commands or text between
%   |\begin{comment}|
%   and the next |\end{comment}|.
%   It also defines the command |\verbatiminput| to input a whole
%   file verbatim.
% \end{abstract}
%
% \section{Usage notes}
%
% \let\docDescribeMacro\DescribeMacro
% \let\docDescribeEnv\DescribeEnv
% \def\DescribeMacro#1{}
% \def\DescribeEnv#1{}
% \LaTeX's \texttt{verbatim} and \texttt{verbatim*} environments
% have a few features that may give rise to problems. These are:
% \begin{itemize}
%   \item
%     Due to the method used to detect the closing |\end{verbatim}|
%     (i.e.\ macro parameter delimiting) you cannot leave spaces
%     between the |\end| token and |{verbatim}|.
%   \item
%     Since \TeX{} has to read all the text between the
%     |\begin{verbatim}| and the |\end{verbatim}| before it can output
%     anything, long verbatim listings may overflow \TeX's memory.
% \end{itemize}
% Whereas the first     of these points can be considered
% only a minor nuisance the other one is a real limitation.
%
%
% \DescribeEnv{verbatim}
% \DescribeEnv{verbatim*}
% This package file contains a reimplementation of the \texttt{verbatim}
% and \texttt{verbatim*} environments which overcomes these
% restrictions.
% There is, however, one incompatibility between the old and the
% new implementations of these environments: the old version
% would treat text on the same line as the |\end{verbatim}|
% command as if it were on a line by itself.
% \begin{center}
%   \bf This new version will simply ignore it.
% \end{center}
% (This is the price one has to pay for the removal of the old
% \texttt{verbatim} environment's size limitations.)
% It will, however, issue a warning message of the form
% \begin{verbatim}
%LaTeX warning: Characters dropped after \end{verbatim*}!
%\end{verbatim}
% This is not a real problem since this text can easily be put
% on the next line without affecting the output.
%
% This new implementation also solves the second problem mentioned
% above: it is possible to leave spaces (but \emph{not} begin a new
% line) between the |\end| and the |{verbatim}| or |{verbatim*}|:
% \begin{verbatim}
%\begin {verbatim*}
%   test
%   test
%\end {verbatim*}
%\end{verbatim}
%
% \DescribeEnv{comment}
% Additionally we introduce a \texttt{comment} environment, with the
% effect that the text between |\begin{comment}| and |\end{comment}|
% is simply ignored, regardless of what it looks like.
% At first sight this seems to be quite different from the purpose
% of verbatim listing, but actually the implementation of these two
% concepts turns out to be very similar.
% Both rely on the fact that the text between |\begin{...}| and
% |\end{...}| is read by \TeX{} without interpreting any commands or
% special characters.
% The remaining difference between \texttt{verbatim} and
% \texttt{comment} is only that the text is to be typeset in the
% first case and to be thrown away in the latter. Note that these
% environments cannot be nested.
%
% \DescribeMacro{\verbatiminput}
% |\verbatiminput| is a command with one argument that inputs a file
% verbatim, i.e.\ the command |\verbatiminput{xx.yy}|
% has the same effect as\\[2pt]
%   \hspace*{\MacroIndent}|\begin{verbatim}|\\
%   \hspace*{\MacroIndent}\meta{Contents of the file \texttt{xx.yy}}\\
%   \hspace*{\MacroIndent}|\end{verbatim}|\\[2pt]
% This command has also a |*|-variant that prints spaces as \verb*+ +.
%
%
% \MaybeStop{}
%
%
% \section{Interfaces for package writers}
%
% The \texttt{verbatim} environment of \LaTeXe{} does not
% offer a good interface to programmers.
% In contrast, this package provides a simple mechanism to
% implement similar features, the \texttt{comment} environment
% implemented here being an example of what can be done and how.
%
%
% \subsection{Simple examples}
%
% It is now possible to use the \texttt{verbatim} environment to define
% environments of your own.
% E.g.,
%\begin{verbatim}
% \newenvironment{myverbatim}%
%   {\endgraf\noindent MYVERBATIM:%
%    \endgraf\verbatim}%
%   {\endverbatim}
%\end{verbatim}
% can be used afterwards like the \texttt{verbatim} environment, i.e.
% \begin{verbatim}
%\begin {myverbatim}
%  test
%  test
%\end {myverbatim}
%\end{verbatim}
% Another way to use it is to write
% \begin{verbatim}
%\let\foo=\comment
%\let\endfoo=\endcomment
%\end{verbatim}
% and from that point on environment \texttt{foo} is the same as the
% comment environment, i.e.\ everything inside its body is ignored.
%
% You may also add special commands after the |\verbatim| macro is
% invoked, e.g.
%\begin{verbatim}
%\newenvironment{myverbatim}%
%  {\verbatim\myspecialverbatimsetup}%
%  {\endverbatim}
%\end{verbatim}
% though you may want to learn about the hook |\every@verbatim| at
% this point.
% \changes{v1.5h}{1995/09/21}{Clarified documentation on use of other
%               environments to define new verbatim-type ones.}
% However, there are still a number of restrictions:
% \begin{enumerate}
%   \item
%     You must not use the |\begin| or the |\end| command inside a
%     definition, e.g.~the following two examples will \emph{not} work:
%\begin{verbatim*}
%\newenvironment{myverbatim}%
%{\endgraf\noindent MYVERBATIM:%
% \endgraf\begin{verbatim}}%
%{\end{verbatim}}
%\newenvironment{fred}
%{\begin{minipage}{30mm}\verbatim}
%{\endverbatim\end{minipage}}
%\end{verbatim*}
%     If you try these examples, \TeX{} will report a
%     ``runaway argument'' error.
%     More generally, it is not possible to use
%     |\begin|\ldots\allowbreak|\end|
%     or the related environments in the definition of the new
%     environment. Instead, the correct way to define this environment
%     would be
%    \begin{verbatim*}
%\newenvironment{fred}
%{\minipage{30mm}\verbatim}
%{\endverbatim\endminipage}
%\end{verbatim*}
%   \item
%     You can\emph{not} use the \texttt{verbatim} environment inside
%     user defined \emph{commands}; e.g.,
% \changes{v1.4g}{1991/11/21}{Corrected wrong position of optional
%        argument to \cs{newcommand}. Discovered by Piet van Oostrum.}
%     \begin{verbatim*}
%\newcommand{\verbatimfile}[1]%
%           {\begin{verbatim}\input{#1}\end{verbatim}}
%\end{verbatim*}
%     does \emph{not} work; nor does
%     \begin{verbatim}
%\newcommand{\verbatimfile}[1]{\verbatim\input{#1}\endverbatim}
%\end{verbatim}
%   \item The name of the newly defined environment must not contain
%     characters with category code other than $11$ (letter) or
%     $12$ (other), or this will not work.
% \end{enumerate}
%
%
% \subsection{The interfaces}
%
% \DescribeMacro{\verbatim@font}
% Let us start with the simple things.
% Sometimes it may be necessary to use a special typeface for your
% verbatim text, or perhaps the usual computer modern typewriter shape
% in a reduced size.
%
% You may select this by redefining the macro |\verbatim@font|.
% This macro is executed at the beginning of every verbatim text to
% select the font shape.
% Do not use it for other purposes; if you find yourself abusing this
% you may want to read about the |\every@verbatim| hook below.
%
% By default, |\verbatim@font| switches to the typewriter font and
% disables the ligatures contained therein.
%
%
% \DescribeMacro{\every@verbatim}
% \DescribeMacro{\addto@hook}
% There is a hook (i.e.\ a token register) called |\every@verbatim|
% whose contents are inserted into \TeX's mouth just before every
% verbatim text.
% Please use the |\addto@hook| macro to add something to this hook.
% It is used as follows:\\[2pt]
% \hspace*{\MacroIndent}|\addto@hook|\meta{name of the hook}^^A
%  |{|\meta{commands to be added}|}|
% \vspace*{2pt}
%
%
%
% \DescribeMacro{\verbatim@start}
% After all specific setup, like switching of category codes, has been
% done, the |\verbatim@start| macro is called.
% This starts the main loop of the scanning mechanism implemented here.
% Any other environment that wants to make use of this feature should
% execute this macro as its last action.
%
%
% \DescribeMacro{\verbatim@startline}
% \DescribeMacro{\verbatim@addtoline}
% \DescribeMacro{\verbatim@processline}
% \DescribeMacro{\verbatim@finish}
% These are the things that concern the start of a verbatim
% environment.
% Once this (and other) setup has been done, the code in this package
% reads and processes characters from the input stream in the
% following way:
% \begin{enumerate}
%   \item Before the first character of an input line is read, it
%     executes the macro |\verbatim@startline|.
%   \item After some characters have been read, the macro
%     |\verbatim@addtoline| is called with these characters as its only
%     argument.
%     This may happen several times per line (when an |\end| command is
%     present on the line in question).
%   \item When the end of the line is reached, the macro
%     |\verbatim@processline| is called to process the characters that
%     |\verbatim@addtoline| has accumulated.
%   \item Finally, there is the macro |\verbatim@finish| that is called
%     just before the environment is ended by a call to the |\end|
%      macro.
% \end{enumerate}
%
%
% To make this clear let us consider the standard \texttt{verbatim}
% environment.
% In this case the three macros above are defined as follows:
% \begin{enumerate}
%   \item |\verbatim@startline| clears the character buffer
%     (a token register).
%   \item |\verbatim@addtoline| adds its argument to the character
%     buffer.
%   \item |\verbatim@processline| typesets the characters accumulated
%     in the buffer.
% \end{enumerate}
% With this it is very simple to implement the \texttt{comment}
% environment:
% in this case |\verbatim@startline| and |\verbatim@processline| are
% defined to be
% no-ops whereas |\verbatim@addtoline| discards its argument.
%
%
% Let's use this to define a variant of the |verbatim|
% environment that prints line numbers in the left margin.
% Assume that this would be done by a counter called |VerbatimLineNo|.
% Assuming that this counter was initialized properly by the
% environment, |\verbatim@processline| would be defined in this case as
% \begin{verbatim}
%\def\verbatim@processline{%
%  \addtocounter{VerbatimLineNo}{1}%
%  \leavevmode
%  \llap{\theVerbatimLineNo\ \hskip\@totalleftmargin}%
%  \the\verbatim@line\par}
%\end{verbatim}
%
% A further possibility is to define a variant of the |verbatim|
% environment that boxes and centers the whole verbatim text.
% Note that the boxed text should be less than a page, otherwise you
% have to change this example.
%
%\begin{verbatim}
%\def\verbatimboxed#1{\begingroup
%  \def\verbatim@processline{%
%    {\setbox0=\hbox{\the\verbatim@line}%
%     \hsize=\wd0
%     \the\verbatim@line\par}}%
%  \setbox0=\vbox{\parskip=0pt\topsep=0pt\partopsep=0pt
%                 \verbatiminput{#1}}%
%  \begin{center}\fbox{\box0}\end{center}%
% \endgroup}
%\end{verbatim}
%
% As a final nontrivial example we describe the definition of an
% environment called \texttt{verbatimwrite}.
% It writes all text in its body to a file whose name is
% given as an argument.
% We assume that a stream number called |\verbatim@out| has already
% been reserved by means of the |\newwrite| macro.
%
% Let's begin with the definition of the macro |\verbatimwrite|.
% \begin{verbatim}
%\def\verbatimwrite#1{%
%\end{verbatim}
% First we call |\@bsphack| so that this environment does not influence
% the spacing.
% Then we open the file and set the category codes of all special
% characters:
% \changes{v1.5t}{2020-07-05}{Added quotes around the filename in
%    order to allow a filename with spaces; also added a space and
%    comment-character to allow for thespace dlimited argument.} 
% \begin{verbatim}
%  \@bsphack
%  \immediate\openout \verbatim@out "#1" %
%  \let\do\@makeother\dospecials
%  \catcode`\^^M\active
%\end{verbatim}
% The default definitions of the macros
% \begin{verbatim}
%  \verbatim@startline
%  \verbatim@addtoline
%  \verbatim@finish
%\end{verbatim}
% are also used in this environment.
% Only the macro |\verbatim@processline| has to be changed before
% |\verbatim@start| is called:
% \begin{verbatim}
%  \def\verbatim@processline{%
%    \immediate\write\verbatim@out{\the\verbatim@line}}%
%  \verbatim@start}
%\end{verbatim}
% The definition of |\endverbatimwrite| is very simple:
% we close the stream and call |\@esphack| to get the spacing right.
% \begin{verbatim}
%\def\endverbatimwrite{\immediate\closeout\verbatim@out\@esphack}
%\end{verbatim}
%
% \section{The implementation}
%
% \let\DescribeMacro\docDescribeMacro
% \let\DescribeEnv\docDescribeEnv
%
% \changes{v1.4e}{1991/07/24}{Avoid reading this file twice.}
% The very first thing we do is to ensure that this file is not read
% in twice. To this end we check whether the macro |\verbatim@@@| is
% defined. If so, we just stop reading this file. The `package'
% guard here allows most of the code to be excluded when extracting
% the driver file for testing this package.
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{verbatim}
     [2024-01-22 v1.5x LaTeX2e package for verbatim enhancements]
\@ifundefined{verbatim@@@}{}{\endinput}
%    \end{macrocode}
%
% We use a mechanism similar to the one implemented for the
% |\comment|\ldots\allowbreak|\endcomment| macro in \AmSTeX:
% We input one line at a time and check if it contains the |\end{...}|
% tokens.
% Then we can decide whether we have reached the end of the verbatim
% text, or must continue.
%
%
% \subsection{Preliminaries}
%
% \begin{macro}{\every@verbatim}
%    The hook (i.e.\ token register) |\every@verbatim|
%    is initialized to \meta{empty}.
%    \begin{macrocode}
\newtoks\every@verbatim
\every@verbatim={}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@makeother}
% \changes{v1.1a}{1989/10/16}{\cs{@makeother} added.}
%    |\@makeother| takes as argument a character and changes
%    its category code to $12$ (other).
%    \begin{macrocode}
\def\@makeother#1{\catcode`#112\relax}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@vobeyspaces}
% \changes{v1.5}{1993/10/11}{Changed definition to not use \cs{gdef}.}
% \changes{v1.1a}{1989/10/16}{\cs{@vobeyspaces} added.}
%    The macro |\@vobeyspaces| causes spaces in the input
%    to be printed as spaces in the output.
%    \begin{macrocode}
\begingroup
\catcode`\ =\active%
%    \end{macrocode}
%    Because space is active we can't indent the following code
%    nicely---we would then get the spaces at the beginning of the
%    line as the third and fourth argument to \cs{@ifl@t@r}.
% \changes{v1.5v}{2023/11/06}{\cs{@vobeytabs} added when available (gh/1160)}
%    \begin{macrocode}
\@ifl@t@r\fmtversion{2023-11-01}%
{\def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp\@vobeytabs}}}%
{\def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}}%
\expandafter\endgroup\x
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@xobeysp}
% \changes{v1.1a}{1989/10/16}{\cs{@xobeysp} added.}
%    The macro |\@xobeysp| produces exactly one space in
%    the output, protected against breaking just before it.
%    (|\@M| is an abbreviation for the number $10000$.)
%    \begin{macrocode}
\def\@xobeysp{\leavevmode\penalty\@M\ }
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\verbatim@line}
% \changes{v1.2d}{1989/11/29}{Introduced token register
%                \cs{verbatim@line}.}
%    We use a newly defined token register called |\verbatim@line|
%    that will be used as the character buffer.
%    \begin{macrocode}
\newtoks\verbatim@line
%    \end{macrocode}
% \end{macro}
%
% The following four macros are defined globally in a way suitable for
% the \texttt{verbatim} and \texttt{verbatim*} environments.
% \begin{macro}{\verbatim@startline}
% \begin{macro}{\verbatim@addtoline}
% \begin{macro}{\verbatim@processline}
%    |\verbatim@startline| initializes processing of a line
%    by emptying the character buffer (|\verbatim@line|).
%    \begin{macrocode}
\def\verbatim@startline{\verbatim@line{}}
%    \end{macrocode}
%    |\verbatim@addtoline| adds the tokens in its argument
%    to our buffer register |\verbatim@line| without expanding
%    them.
%    \begin{macrocode}
\def\verbatim@addtoline#1{%
  \verbatim@line\expandafter{\the\verbatim@line#1}}
%    \end{macrocode}
%    Processing a line inside a \texttt{verbatim} or \texttt{verbatim*}
%    environment means printing it.
% \changes{v1.2c}{1989/10/31}{Changed \cs{@@par} to \cs{par} in
%    \cs{verbatim@processline}.  Removed \cs{leavevmode} and \cs{null}
%    (i.e.\ the empty \cs{hbox}).}
%    Ending the line means that we have to begin a new paragraph.
%    We use |\par| for this purpose.  Note that |\par|
%    is redefined in |\@verbatim| to force \TeX{} into horizontal
%    mode and to insert an empty box so that empty lines in the input
%    do appear in the output.
% \changes{v1.2f}{1990/01/31}{\cs{verbatim@startline} removed.}
%    \begin{macrocode}
\def\verbatim@processline{\the\verbatim@line\par}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\verbatim@finish}
%    As a default, |\verbatim@finish| processes the remaining
%    characters.
%    When this macro is called we are facing the following problem:
%    when the |\end{verbatim}|
%    command is encountered |\verbatim@processline| is called
%    to process the characters preceding the command on the same
%    line.  If there are none, an empty line would be output if we
%    did not check for this case.
%
%    If the line is empty |\the\verbatim@line| expands to
%    nothing.  To test this we use a trick similar to that on p.\ 376
%    of the \TeX{}book, but with |$|\ldots|$| instead of
%    the |!| tokens.  These |$| tokens can never have the same
%    category code as a |$| token that might possibly appear in the
%    token register |\verbatim@line|, as such a token will always have
%    been read with category code $12$ (other).
%    Note that |\ifcat| expands the following tokens so that
%    |\the\verbatim@line| is replaced by the accumulated
%    characters
% \changes{v1.2d}{1989/11/29}{Changed \cs{ifx} to \cs{ifcat} test.}
% \changes{v1.1b}{1989/10/18}{Corrected bug in if test (found by CRo).}
%    \begin{macrocode}
\def\verbatim@finish{\ifcat$\the\verbatim@line$\else
  \verbatim@processline\fi}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{The \texttt{verbatim} and \texttt{verbatim*} environments}
%
% \begin{macro}{\verbatim@font}
% \changes{v1.2f}{1990/01/31}{\cs{@lquote} macro removed.}
% \changes{v1.1b}{1989/10/18}{\cs{@noligs} removed.  Code inserted
%                           directly into \cs{verbatim@font}.}
% \changes{v1.1a}{1989/10/16}{\cs{verbatim@font} added.}
% \changes{v1.1a}{1989/10/16}{\cs{@noligs} added.}
% \changes{v1.1a}{1989/10/16}{\cs{@lquote} added.}
%    We start by defining the macro |\verbatim@font| that is
%    to select the font and to set font-dependent parameters.
%    Then we expand |\@noligs| (defined in the \LaTeXe{} kernel). Among
%    possibly other things, it will go through |\verbatim@nolig@list|
%    to avoid certain ligatures.
%    |\verbatim@nolig@list| is a macro defined in the \LaTeXe{} kernel
%    to expand to
%    \begin{verbatim}
%    \do\`\do\<\do\>\do\,\do\'\do\-
%\end{verbatim}
%    All the characters in this list can be part of a ligature in some
%    font or other.
% \changes{v1.2f}{1990/01/31}{\cs{@lquote} macro removed.}
% \changes{v1.4c}{1990/10/18}{Added \cs{leavevmode}.}
% \changes{v1.4k}{1992/07/13}{Replaced Blank after $96$ by \cs{relax}.
%                           (Proposed by Dan Dill.)}
% \changes{v1.5}{1993/10/11}{Definition changed according to new code
%          in latex.tex and to avoid global definition.}
% \changes{v1.5c}{1994/02/07}{Changed to use new font switching
%                           commands.}
% \changes{v1.5m}{2000/01/07}{Disable hyphenation even if the font
%    allows it.}
% \changes{v1.5q}{2003/08/22}{Use \cs{@noligs}, as it is by now properly
%    defined in the \LaTeXe{} kernel.}
%    \begin{macrocode}
\def\verbatim@font{\normalfont\ttfamily
                   \hyphenchar\font\m@ne
                   \@noligs}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@verbatim}
% \changes{v1.1a}{1989/10/16}{\cs{@verbatim} added.}
%    The macro |\@verbatim| sets up things properly.
%    First of all, the tokens of the |\every@verbatim| hook
%    are inserted.
%    Then a \texttt{trivlist} environment is started and its first
%    |\item| command inserted.
%    Each line of the \texttt{verbatim} or \texttt{verbatim*}
%    environment will be treated as a separate paragraph.
% \changes{v1.2e}{1990/01/15}{Added \cs{every@verbatim} hook.}
% \changes{v1.5b}{1994/01/24}{Removed optional argument of \cs{item}.}
%    \begin{macrocode}
\def\@verbatim{\the\every@verbatim
  \trivlist \item \relax
%    \end{macrocode}
% \changes{v1.5b}{1994/01/24}{Set \texttt{@inlabel} switch to false.}
% \changes{v1.5f}{1994/10/25}{Removed setting of \texttt{@inlabel}
%                             switch again.}
% \changes{v1.3c}{1990/02/26}{Removed extra vertical space.
%           Suggested by Frank Mittelbach.}
% \changes{v1.5h}{1995/09/21}{Added the space again, since it is
%           necessary for correct vertical spacing if \texttt{verbatim}
%           is nested inside \texttt{quote}.}
%    The following extra vertical space is for compatibility with the
%    \LaTeX{} kernel: otherwise, using the |verbatim| package changes
%    the vertical spacing of a |verbatim| environment nested within a
%    |quote| environment.
%    \begin{macrocode}
  \if@minipage\else\vskip\parskip\fi
%    \end{macrocode}
% \changes{v1.4k}{1992/07/13}{Added setting for
%        \cs{@beginparpenalty}. Suggested by Frank Mittelbach.}
%    The paragraph parameters are set appropriately:
%    the penalty at the beginning of the environment,
%    left and right margins, paragraph indentation, the glue to
%    fill the last line, and the vertical space between paragraphs.
%    The latter space has to be zero since we do not want to add
%    extra space between lines.
%    \begin{macrocode}
  \@beginparpenalty \predisplaypenalty
  \leftskip\@totalleftmargin\rightskip\z@
  \parindent\z@\parfillskip\@flushglue\parskip\z@
%    \end{macrocode}
% \changes{v1.1b}{1989/10/18}{Added resetting of \cs{parshape}
%                           if at beginning of a list.
%                           (Problem pointed out by Chris Rowley.)}
%    There's one point to make here:
%    the \texttt{list} environment uses \TeX's |\parshape|
%    primitive to get a special indentation for the first line
%    of the  list.
%    If the list begins with a \texttt{verbatim} environment
%    this |\parshape| is still in effect.
%    Therefore we have to reset this internal parameter explicitly.
%    We could do this by assigning $0$ to |\parshape|.
%    However, there is a simpler way to achieve this:
%    we simply tell \TeX{} to start a new paragraph.
%    As is explained on p.~103 of the \TeX{}book, this resets
%    |\parshape| to zero.
% \changes{v1.1c}{1989/10/19}{Replaced explicit resetting of
%                           \cs{parshape} by \cs{@@par}.}
%    \begin{macrocode}
  \@@par
%    \end{macrocode}
%    We now ensure that |\par| has the correct definition,
%    namely to force \TeX{} into horizontal mode
%    and to include an empty box.
%    This is to ensure that empty lines do appear in the output.
%    Afterwards, we insert the |\interlinepenalty| since \TeX{}
%    does not add a penalty between paragraphs (here: lines)
%    by its own initiative. Otherwise a |verbatim| environment
%    could be broken across pages even if a |\samepage|
%    declaration were present.
%
%    However, in a top-aligned minipage, this will result in an extra
%    empty line added at the top. Therefore, a slightly more
%    complicated construct is necessary.
%    One of the important things here is the inclusion of
%    |\leavevmode| as the first macro in the first line, for example,
%    a blank verbatim line is the first thing in a list item.
% \changes{v1.2c}{1989/10/31}{Definition of \cs{par} added.
%                           Ensures identical behaviour for
%                           verbatim and \cs{verbatiminput}.
%                           Problem pointed out by Chris.}
% \changes{v1.4d}{1991/04/24}{\cs{penalty}\cs{interlinepenalty} added.
%                           Necessary to avoid page breaks in
%                           the scope of a \cs{samepage} declaration.}
% \changes{v1.5b}{1994/01/24}{Improved definition of \cs{par} to work
%                           under all circumstances.}
% \changes{v1.5f}{1994/10/25}{\cs{leavevmode} added for first line.}
%    \begin{macrocode}
  \def\par{%
    \if@tempswa
      \leavevmode\null\@@par\penalty\interlinepenalty
    \else
      \@tempswatrue
      \ifhmode\@@par\penalty\interlinepenalty\fi
    \fi}%
%    \end{macrocode}
%    But to avoid an error message when the environment
%    doesn't contain any text, we redefine |\@noitemerr|
%    which will in this case be called by |\endtrivlist|.
% \changes{v1.4j}{1992/06/30}{Introduced warning instead of error
%        for empty body of verbatim text.
%        Suggested by Nelson Beebe.}
%    \begin{macrocode}
  \def\@noitemerr{\@warning{No verbatim text}}%
%    \end{macrocode}
%    Now we call |\obeylines| to make the end of line character
%    active.
%    \begin{macrocode}
  \obeylines
%    \end{macrocode}
%    The category code of all special characters is changed,
%    to $12$ (other).
%    \changes{v1.5i}{1996/06/04}{Moved \cs{verbatim@font} after
%           \cs{dospecials}.}
%    \begin{macrocode}
  \let\do\@makeother \dospecials
%    \end{macrocode}
%    We switch to the font to be used.
%    \begin{macrocode}
  \verbatim@font
%    \end{macrocode}
%    To avoid a breakpoint after the labels box, we remove the penalty
%    put there by the list macros: another use of |\unpenalty|!
% \changes{v1.5f}{1994/10/25}{Change to \cs{everypar} added.}
%    \begin{macrocode}
  \everypar \expandafter{\the\everypar \unpenalty}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\verbatim}
% \begin{macro}{\verbatim*}
%    Now we define the toplevel macros.
%    |\verbatim| is slightly changed:
%    after setting up things properly it calls
%    |\verbatim@start|.
% \changes{v1.5l}{1999/12/14}{Added \cs{begingroup} for cases where
%    \cs{verbatim} is used directly, rather than in \cs{begin}: see
%    pr/3115.}
%    This is done inside a group, so that |\verbatim| can be used
%    directly, without |\begin|.
%    \begin{macrocode}
\def\verbatim{\begingroup\@verbatim \frenchspacing\@vobeyspaces
              \verbatim@start}
%    \end{macrocode}
%    |\verbatim*| is defined accordingly.
%    \begin{macrocode}
\@namedef{verbatim*}{\begingroup\@verbatim
%    \end{macrocode}
%
% \changes{v1.5r}{2019/11/10}{Support kernel \cs{verbvisiblespace} (gh/212)}
%    \begin{macrocode}
  \@setupverbvisiblespace\@vobeyspaces
  \verbatim@start}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\endverbatim}
% \begin{macro}{\endverbatim*}
%    To end the \texttt{verbatim} and \texttt{verbatim*}
%    environments it is only necessary to finish the
%    \texttt{trivlist} environment started in |\@verbatim| and
%    close the corresponding group.
% \changes{v1.5l}{1999/12/14}{Added \cs{endgroup} for cases where
%    \cs{endverbatim} is used directly, rather than in \cs{end}: see
%    pr/3115.}
% \changes{v1.5n}{2000/08/03}{Added \cs{@endpetrue}: needed when
%    faking such a \cs{end} (pr/3234).}
% \changes{v1.5o}{2000/08/23}{Changed \cs{@endpetrue} to \cs{@doendpe}:
%    see (pr/3234).}
%    \begin{macrocode}
\def\endverbatim{\endtrivlist\endgroup\@doendpe}
\expandafter\let\csname endverbatim*\endcsname =\endverbatim
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{The \texttt{comment} environment}
%
% \begin{macro}{\comment}
% \begin{macro}{\endcomment}
% \changes{v1.1c}{1989/10/19}{Added \cs{@bsphack}/\cs{@esphack} to the
%            \texttt{comment} environment.  Suggested by Chris Rowley.}
%    The |\comment| macro is similar to |\verbatim*|.
%    However, we do not need to switch fonts or set special
%    formatting parameters such as |\parindent| or |\parskip|.
%    We need only set the category code of all special characters
%    to $12$ (other) and that of |^^M| (the end of line character)
%    to $13$ (active).
%    The latter is needed for macro parameter delimiter matching in
%    the internal macros defined below.
%    In contrast to the default definitions used by the
%    |\verbatim| and |\verbatim*| macros,
%    we define |\verbatim@addtoline| to throw away its argument
%    and |\verbatim@processline|, |\verbatim@startline|,
%    and |\verbatim@finish| to act as no-ops.
%    Then we call |\verbatim@|.
%    But the first thing we do is to call |\@bsphack| so that
%    this environment has no influence whatsoever upon the spacing.
% \changes{v1.1c}{1989/10/19}{Changed \cs{verbatim@start} to
%                           \cs{verbatim@}.  Suggested by Chris Rowley.}
% \changes{v1.1c}{1989/10/19}{\cs{verbatim@startline} and
%                           \cs{verbatim@finish} are now
%                           also redefined to do nothing.}
%    \begin{macrocode}
\def\comment{\@bsphack
             \let\do\@makeother\dospecials\catcode`\^^M\active
             \let\verbatim@startline\relax
             \let\verbatim@addtoline\@gobble
             \let\verbatim@processline\relax
             \let\verbatim@finish\relax
             \verbatim@}
%    \end{macrocode}
%    |\endcomment| is very simple: it only calls
%    |\@esphack| to take care of the spacing.
%    The |\end| macro closes the group and therefore takes care
%    of restoring everything we changed.
%    \begin{macrocode}
\let\endcomment=\@esphack
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{The main loop}
%
% Here comes the tricky part:
% During the definition of the macros we need to use the special
% characters |\|, |{|, and |}| not only with their
% normal category codes,
% but also with category code $12$ (other).
% We achieve this by the following trick:
% first we tell \TeX{} that |\|, |{|, and |}|
% are the lowercase versions of |!|, |[|, and |]|.
% Then we replace every occurrence of |\|, |{|, and |}|
% that should be read with category code $12$ by |!|, |[|,
% and |]|, respectively,
% and give the whole list of tokens to |\lowercase|,
% knowing that category codes are not altered by this primitive!
%
% But first we have ensure that
% |!|, |[|, and |]| themselves have
% the correct category code!
% \changes{v1.3b}{1990/02/07}{Introduced \cs{vrb@catcodes} instead
%                  of explicit setting of category codes.}
% To allow special settings of these codes we hide their setting in
% the macro |\vrb@catcodes|.  If it is already defined our new
% definition is skipped.
%    \begin{macrocode}
\@ifundefined{vrb@catcodes}%
  {\def\vrb@catcodes{%
     \catcode`\!12\catcode`\[12\catcode`\]12}}{}
%    \end{macrocode}
% This trick allows us to use this code for applications where other
% category codes are in effect.
%
% We start a group to keep the category code changes local.
%    \begin{macrocode}
\begingroup
 \vrb@catcodes
 \lccode`\!=`\\ \lccode`\[=`\{ \lccode`\]=`\}
%    \end{macrocode}
% \changes{v1.2f}{1990/01/31}{Code for TABs removed.}
%    We also need the end-of-line character |^^M|,
%    as an active character.
%    If we were to simply write |\catcode`\^^M=\active|
%    then we would get an unwanted active end of line character
%    at the end of every line of the following macro definitions.
%    Therefore we use the same trick as above:
%    we write a tilde |~| instead of |^^M| and
%    pretend that the
%    latter is the lowercase variant of the former.
%    Thus we have to ensure now that the tilde character has
%    category code $13$ (active).
%    \begin{macrocode}
 \catcode`\~=\active \lccode`\~=`\^^M
%    \end{macrocode}
%    The use of the |\lowercase| primitive leads to one problem:
%    the uppercase character `|C|' needs to be used in the
%    code below and its case must be preserved.
%    So we add the command:
%    \begin{macrocode}
 \lccode`\C=`\C
%    \end{macrocode}
%    Now we start the token list passed to |\lowercase|.
%    We use the following little trick (proposed by Bernd Raichle):
%    The very first token in the token list we give to |\lowercase| is
%    the |\endgroup| primitive. This means that it is processed by
%    \TeX{} immediately after |\lowercase| has finished its operation,
%    thus ending the group started by |\begingroup| above. This avoids
%    the global definition of all macros.
%    \begin{macrocode}
 \lowercase{\endgroup
%    \end{macrocode}
% \begin{macro}{\verbatim@start}
%    The purpose of |\verbatim@start| is to check whether there
%    are any characters on the same line as the |\begin{verbatim}|
%    and to pretend that they were on a line by themselves.
%    On the other hand, if there are no characters remaining
%    on the current line we shall just find an end of line character.
%    |\verbatim@start| performs its task by first grabbing the
%    following character (its argument).
%    This argument is then compared to an active |^^M|,
%    the end of line character.
%    \begin{macrocode}
    \def\verbatim@start#1{%
      \verbatim@startline
      \if\noexpand#1\noexpand~%
%    \end{macrocode}
%    If this is true we transfer control to |\verbatim@|
%    to process the next line.  We use
%    |\next| as the macro which will continue the work.
%    \begin{macrocode}
        \let\next\verbatim@
%    \end{macrocode}
%    Otherwise, we define |\next| to expand to a call
%    to |\verbatim@| followed by the character just
%    read so that it is reinserted into the text.
%    This means that those characters remaining on this line
%    are handled as if they formed a line by themselves.
%    \begin{macrocode}
      \else \def\next{\verbatim@#1}\fi
%    \end{macrocode}
%    Finally we call |\next|.
%    \begin{macrocode}
      \next}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@}
%    The three macros |\verbatim@|, |\verbatim@@|,
%    and |\verbatim@@@| form the ``main loop'' of the
%    \texttt{verbatim} environment.
%    The purpose of |\verbatim@| is to read exactly one line
%    of input.
%    |\verbatim@@| and |\verbatim@@@| work together to
%    find out whether the four characters
%    |\end| (all with category code $12$ (other)) occur in that
%    line.
%    If so, |\verbatim@@@| will call
%    |\verbatim@test| to check whether this |\end| is
%    part of |\end{verbatim}| and will terminate the environment
%    if this is the case.
%    Otherwise we continue as if nothing had happened.
%    So let's have a look at the definition of |\verbatim@|:
% \changes{v1.1a}{1989/10/16}{Replaced \cs{verbatim@@@} by \cs{@nil}.}
%    \begin{macrocode}
    \def\verbatim@#1~{\verbatim@@#1!end\@nil}%
%    \end{macrocode}
%    Note that the |!| character will have been replaced by a
%    |\| with category code $12$ (other) by the |\lowercase|
%    primitive governing this code before the definition of this
%    macro actually takes place.
%    That means that
%    it takes the line, puts |\end| (four character tokens)
%    and |\@nil| (one control sequence token) as a
%    delimiter behind it, and
%    then calls |\verbatim@@|.
% \end{macro}
%
% \begin{macro}{\verbatim@@}
%    |\verbatim@@| takes everything up to the next occurrence of
%    the four characters |\end| as its argument.
%    \begin{macrocode}
    \def\verbatim@@#1!end{%
%    \end{macrocode}
%    That means: if they do not occur in the original line, then
%    argument |#1| is the
%    whole input line, and |\@nil| is the next token
%    to be processed.
%    However, if the four characters |\end| are part of the
%    original line, then
%    |#1| consists of the characters in front of |\end|,
%    and the next token is the following character (always remember
%    that the line was lengthened by five tokens).
%    Whatever |#1| may be, it is verbatim text,
%    so |#1| is added to the line currently built.
%    \begin{macrocode}
       \verbatim@addtoline{#1}%
%    \end{macrocode}
%    The next token in the input stream
%    is of special interest to us.
%    Therefore |\futurelet| defines |\next| to be equal
%    to it before calling |\verbatim@@@|.
%    \begin{macrocode}
       \futurelet\next\verbatim@@@}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@@@}
% \changes{v1.1a}{1989/10/16}{Replaced \cs{verbatim@@@} by
%                           \cs{@nil} where used as delimiter.}
%    |\verbatim@@@| will now read the rest of the tokens on
%    the current line,
%    up to the final |\@nil| token.
%    \begin{macrocode}
    \def\verbatim@@@#1\@nil{%
%    \end{macrocode}
%    If the first of the above two cases occurred, i.e.\ no
%    |\end| characters were on that line, |#1| is empty
%    and |\next| is equal to |\@nil|.
%    This is easily checked.
%    \begin{macrocode}
       \ifx\next\@nil
%    \end{macrocode}
%    If so, this was a simple line.
%    We finish it by processing the line we accumulated so far.
%    Then we prepare to read the next line.
% \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.}
%    \begin{macrocode}
         \verbatim@processline
         \verbatim@startline
         \let\next\verbatim@
%    \end{macrocode}
%    Otherwise we have to check what follows these |\end|
%    tokens.
%    \begin{macrocode}
       \else
%    \end{macrocode}
%    Before we continue, it's a good idea to stop for a moment
%    and remember where we are:
%    We have just read the four character tokens |\end|
%    and must now check whether the name of the environment (surrounded
%    by braces) follows.
%    To this end we define a macro called |\@tempa|
%    that reads exactly one character and decides what to do next.
%    This macro should do the following: skip spaces until
%    it encounters either a left brace or the end of the line.
%    But it is important to remember which characters are skipped.
%    The |\end|\meta{optional spaces}|{| characters
%    may be part of the verbatim text, i.e.\ these characters
%    must be printed.
%
%    Assume for example that the current line contains
%    \begin{verbatim*}
%      \end {AVeryLongEnvironmentName}
%\end{verbatim*}
%    As we shall soon see, the scanning mechanism implemented here
%    will not find out that this is text to be printed until
%    it has read the right brace.
%    Therefore we need a way to accumulate the characters read
%    so that we can reinsert them if necessary.
%    The token register |\@temptokena| is used for this purpose.
%
%    Before we do this we have to get rid of the superfluous
%    |\end| tokens at the end of the line.
% \changes{v1.4j}{1992/06/30}{Removed use of \cs{toks@}. Suggested by
%           Bernd Raichle.}
%    To this end we define a temporary macro whose argument
%    is delimited by |\end\@nil| (four character tokens
%    and one control sequence token) to be used below
%    on the rest of the line, after appending a |\@nil| token to it.
%    (Note that this token can never appear in |#1|.)
%    We use the following definition of
%    |\@tempa| to get the rest of the line (after the first
%    |\end|).
%    \begin{macrocode}
         \def\@tempa##1!end\@nil{##1}%
%    \end{macrocode}
%    We mentioned already that we use token register
%    |\@temptokena|
%    to remember the characters we skip, in case we need them again.
%    We initialize this with the |\end| we have thrown away
%    in the call to |\@tempa|.
%    \begin{macrocode}
         \@temptokena{!end}%
%    \end{macrocode}
%    We shall now call |\verbatim@test|
%    to process the characters
%    remaining on the current line.
%    But wait a moment: we cannot simply call this macro
%    since we have already read the whole line.
%    Therefore we have to first expand the macro |\@tempa| to insert
%    them again after the |\verbatim@test| token.
%    A |^^M| character is appended to denote the end of the line.
%    (Remember that this character comes disguised as a tilde.)
% \changes{v1.2}{1989/10/20}{Taken local definition of \cs{@tempa} out
%                          of \cs{verbatim@@@} and introduced
%                          \cs{verbatim@test} instead.}
%    \begin{macrocode}
         \def\next{\expandafter\verbatim@test\@tempa#1\@nil~}%
%    \end{macrocode}
%    That's almost all, but we still have to
%    now call |\next| to do the work.
%    \begin{macrocode}
       \fi \next}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\verbatim@test}
% \changes{v1.2}{1989/10/20}{Introduced \cs{verbatim@test}.}
%    We define |\verbatim@test| to investigate every token
%    in turn.
%    \begin{macrocode}
    \def\verbatim@test#1{%
%    \end{macrocode}
%    First of all we set |\next| equal to |\verbatim@test|
%    in case this macro must call itself recursively in order to
%    skip spaces.
%    \begin{macrocode}
           \let\next\verbatim@test
%    \end{macrocode}
%    We have to distinguish four cases:
%    \begin{enumerate}
%      \item The next token is a |^^M|, i.e.\ we reached
%            the end of the line.  That means that nothing
%            special was found.
%            Note that we use |\if| for the following
%            comparisons so that the category code of the
%            characters is irrelevant.
%    \begin{macrocode}
           \if\noexpand#1\noexpand~%
%    \end{macrocode}
%            We add the characters accumulated in token register
%            |\@temptokena| to the current line.  Since
%            |\verbatim@addtoline| does not expand its argument,
%            we have to do the expansion at this point.  Then we
%            |\let| |\next| equal to |\verbatim@|
%            to prepare to read the next line.
% \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.}
%    \begin{macrocode}
             \expandafter\verbatim@addtoline
               \expandafter{\the\@temptokena}%
             \verbatim@processline
             \verbatim@startline
             \let\next\verbatim@
%    \end{macrocode}
%      \item A space character follows.
%            This is allowed, so we add it to |\@temptokena|
%            and continue.
%    \begin{macrocode}
           \else \if\noexpand#1
             \@temptokena\expandafter{\the\@temptokena#1}%
%    \end{macrocode}
% \changes{v1.2f}{1990/01/31}{Code for TABs removed.}
%      \item An open brace follows.
%            This is the most interesting case.
%            We must now collect characters until we read the closing
%            brace and check whether they form the environment name.
%            This will be done by |\verbatim@testend|, so here
%            we let |\next| equal this macro.
%            Again we will process the rest of the line, character
%            by character.
% \changes{v1.2}{1989/10/20}{Moved the initialization of
%                          \cs{@tempc} from \cs{verbatim@testend} into
%                          \cs{verbatim@test}.}
%            The characters forming the name of the environment will
%            be accumulated in |\@tempc|.
%            We initialize this macro to expand to nothing.
% \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.}
%    \begin{macrocode}
           \else \if\noexpand#1\noexpand[%
             \let\@tempc\@empty
             \let\next\verbatim@testend
%    \end{macrocode}
%            Note that the |[| character will be a |{| when
%            this macro is defined.
%      \item Any other character means that the |\end| was part
%            of the verbatim text.
%            Add the characters to the current line and prepare to call
%            |\verbatim@| to process the rest of the line.
%  \changes{v1.0f}{1989/10/09}{Fixed \cs{end} \cs{end} bug
%                            found by Chris Rowley}
%    \begin{macrocode}
           \else
             \expandafter\verbatim@addtoline
               \expandafter{\the\@temptokena}%
             \def\next{\verbatim@#1}%
           \fi\fi\fi
%    \end{macrocode}
%    \end{enumerate}
%    The last thing this macro does is to call |\next|
%    to continue processing.
%    \begin{macrocode}
           \next}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@testend}
%    |\verbatim@testend| is called when
%    |\end|\meta{optional spaces}|{| was seen.
%    Its task is to scan everything up to the next |}|
%    and to call |\verbatim@@testend|.
%    If no |}| is found it must reinsert the characters it read
%    and return to |\verbatim@|.
%    The following definition is similar to that of
%    |\verbatim@test|:
%    it takes the next character and decides what to do.
% \changes{v1.2}{1989/10/20}{Removed local definition of \cs{@tempa}
%                          from \cs{verbatim@testend} which now
%                          does the work itself.}
%    \begin{macrocode}
    \def\verbatim@testend#1{%
%    \end{macrocode}
%    Again, we have four cases:
%    \begin{enumerate}
%      \item |^^M|: As no |}| is found in the current line,
%            add the characters to the buffer.  To avoid a
%            complicated construction for expanding
%            |\@temptokena|
%            and |\@tempc| we do it in two steps.  Then we
%            continue with |\verbatim@| to process the
%            next line.
% \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.}
%    \begin{macrocode}
         \if\noexpand#1\noexpand~%
           \expandafter\verbatim@addtoline
             \expandafter{\the\@temptokena[}%
           \expandafter\verbatim@addtoline
             \expandafter{\@tempc}%
           \verbatim@processline
           \verbatim@startline
           \let\next\verbatim@
%    \end{macrocode}
%      \item |}|: Call |\verbatim@@testend| to check
%            if this is the right environment name.
% \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.}
%    \begin{macrocode}
         \else\if\noexpand#1\noexpand]%
           \let\next\verbatim@@testend
%    \end{macrocode}
%  \changes{v1.0f}{1989/10/09}{Introduced check for
%              {\tt\string\verb!\string|!\string\!\string|} to fix
%              single brace bug found by Chris Rowley}
%      \item |\|: This character must not occur in the name of
%            an environment.  Thus we stop collecting characters.
%            In principle, the same argument would apply to other
%            characters as well, e.g., |{|.
%            However, |\| is a special case, since it may be
%            the first character of |\end|.  This means that
%            we have to look again for
%            |\end{|\meta{environment name}|}|.
%            Note that we prefixed the |!| by a |\noexpand|
%            primitive, to protect ourselves against it being an
%            active character.
% \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.}
%    \begin{macrocode}
         \else\if\noexpand#1\noexpand!%
           \expandafter\verbatim@addtoline
             \expandafter{\the\@temptokena[}%
           \expandafter\verbatim@addtoline
             \expandafter{\@tempc}%
           \def\next{\verbatim@!}%
%    \end{macrocode}
%      \item Any other character: collect it and continue.
%            We cannot use |\edef| to define |\@tempc|
%            since its replacement text might contain active
%            character tokens.
%    \begin{macrocode}
         \else \expandafter\def\expandafter\@tempc\expandafter
           {\@tempc#1}\fi\fi\fi
%    \end{macrocode}
%    \end{enumerate}
%    As before, the macro ends by calling itself, to
%    process the next character if appropriate.
%    \begin{macrocode}
         \next}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@@testend}
%    Unlike the previous macros |\verbatim@@testend| is simple:
%    it has only to check if the |\end{|\ldots|}|
%    matches the corresponding |\begin{|\ldots|}|.
%    \begin{macrocode}
    \def\verbatim@@testend{%
%    \end{macrocode}
%    We use |\next| again to define the things that are
%    to be done.
%    Remember that the name of the current environment is
%    held in |\@currenvir|, the characters accumulated
%    by |\verbatim@testend| are in |\@tempc|.
%    So we simply compare these and prepare to execute
%    |\end{|\meta{current environment}|}|
%    macro if they match.
%    Before we do this we call |\verbatim@finish| to process
%    the last line.
%    We define |\next| via |\edef| so that
%    |\@currenvir| is replaced by its expansion.
%    Therefore we need |\noexpand| to inhibit the expansion
%    of |\end| at this point.
%    \begin{macrocode}
       \ifx\@tempc\@currenvir
         \verbatim@finish
         \edef\next{\noexpand\end{\@currenvir}%
%    \end{macrocode}
%    Without this trick the |\end| command would not be able
%    to correctly check whether its argument matches the name of
%    the current environment and you'd get an
%    interesting \LaTeX{} error message such as:
%    \begin{verbatim}
%! \begin{verbatim*} ended by \end{verbatim*}.
%\end{verbatim}
%    But what do we do with the rest of the characters, those
%    that remain on that line?
%    We call |\verbatim@rescan| to take care of that.
%    Its first argument is the name of the environment just
%    ended, in case we need it again.
%    |\verbatim@rescan| takes the list of characters to be
%    reprocessed as its second argument.
%    (This token list was inserted after the current macro
%    by |\verbatim@@@|.)
%    Since we are still in an |\edef| we protect it
%    by means of |\noexpand|.
%    \begin{macrocode}
                    \noexpand\verbatim@rescan{\@currenvir}}%
%    \end{macrocode}
%    If the names do not match, we reinsert everything read up
%    to now and prepare to call |\verbatim@| to process
%    the rest of the line.
%    \begin{macrocode}
       \else
         \expandafter\verbatim@addtoline
           \expandafter{\the\@temptokena[}%
           \expandafter\verbatim@addtoline
             \expandafter{\@tempc]}%
         \let\next\verbatim@
       \fi
%    \end{macrocode}
%    Finally we call |\next|.
%    \begin{macrocode}
       \next}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@rescan}
%    In principle |\verbatim@rescan| could be used to
%    analyse the characters remaining after the |\end{...}|
%    command and pretend that these were read
%    ``properly'', assuming ``standard'' category codes are in
%    force.\footnote{Remember that they were all read with
%          category codes $11$ (letter) and $12$ (other) so
%          that control sequences are not recognized as such.}
%    But this is not always possible (when there are unmatched
%    curly braces in the rest of the line).
%    Besides, we think that this is not worth the effort:
%    After a \texttt{verbatim} or \texttt{verbatim*} environment
%    a new line in the output is begun anyway,
%    and an |\end{comment}| can easily be put on a line by itself.
%    So there is no reason why there should be any text here.
%    For the benefit of the user who did put something there
%    (a comment, perhaps)
%    we simply issue a warning and drop them.
%    The method of testing is explained in Appendix~D, p.\ 376 of
%    the \TeX{}book. We use |^^M| instead of the |!|
%    character used there
%    since this is a character that cannot appear in |#1|.
%    The two |\noexpand| primitives are necessary to avoid
%    expansion of active characters and macros.
%
%    One extra subtlety should be noted here: remember that
%    the token list we are currently building will first be
%    processed by the |\lowercase| primitive before \TeX{}
%    carries out the definitions.
%    This means that the `|C|' character in the
%    argument to the |\@warning| macro must be protected against
%    being changed to `|c|'.  That's the reason why we added the
%    |\lccode`\C=`\C| assignment above.
%    We can now finish the argument to |\lowercase| as well as the
%    group in which the category codes were changed.
%    \begin{macrocode}
    \def\verbatim@rescan#1#2~{\if\noexpand~\noexpand#2~\else
        \@warning{Characters dropped after `\string\end{#1}'}\fi}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \cs{verbatiminput} command}
%
% \begin{macro}{\verbatim@in@stream}
%    We begin by allocating an input stream (out of the 16 available
%    input streams).
%\iffalse
%  Vorstellbar ist auch der Aufruf von |`verbatiminput| innerhalb eines
%  |`verbatiminput| (z.B: wenn man |`input|-Anweisungen im zu lesenden
%  File hat und auch diese Files automatisch lesen will).  Dies kann
%  man jedoch nur ermoeglichen, wenn man einen besseren Mechanismus
%  verwendet als es das simple, statische |`newread| darstellt.
%  Vorstellbar fuer eine neuere \LaTeX-Version ist eine (lokale)
%  Allokation des Streams durch ein |`open| und eine Freigabe des
%  Streams durch |`close| oder Verlassen der Gruppe.
%\fi
%    \begin{macrocode}
\newread\verbatim@in@stream
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@readfile}
%    The macro |\verbatim@readfile| encloses the main loop by calls to
%    the macros |\verbatim@startline| and |\verbatim@finish|,
%    respectively.  This makes sure
%    that the user can initialize and finish the command when the file
%    is empty or doesn't exist.  The \texttt{verbatim} environment has a
%    similar behaviour when called with an empty text.
%    \begin{macrocode}
\def\verbatim@readfile#1{%
  \verbatim@startline
%    \end{macrocode}
%    When the file is not found we issue a warning.
%    \begin{macrocode}
  \openin\verbatim@in@stream #1\relax
  \ifeof\verbatim@in@stream
    \typeout{No file #1.}%
  \else
%    \end{macrocode}
%    At this point we pass the name of the file to |\@addtofilelist|
%    so that it appears in the output of a |\listfiles|
%    command.
% \changes{v1.5j}{1996/09/25}{Add \cs{@addtofilelist} and
%    \cs{ProvidesFile} so that the name of the file
%    read in appears in the \cs{listfiles} output (Omission pointed
%    out by Patrick W.~Daly).}
%    In addition, we use |\ProvidesFile| to make a log entry in the
%    transcript file and to distinguish files read in via
%    |\verbatiminput| from others.
%    \begin{macrocode}
    \@addtofilelist{#1}%
    \ProvidesFile{#1}[(verbatim)]%
%    \end{macrocode}
%    While reading from the file it is useful to switch off the
%    recognition of the end-of-line character.  This saves us stripping
%    off spaces from the contents of the line.
%    \begin{macrocode}
    \expandafter\endlinechar\expandafter\m@ne
    \expandafter\verbatim@read@file
    \expandafter\endlinechar\the\endlinechar\relax
    \closein\verbatim@in@stream
  \fi
  \verbatim@finish
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@read@file}
%    All the work is done in |\verbatim@read@file|.  It reads the input
%    file line by line and recursively calls itself until the end of
%    the file.
%    \begin{macrocode}
\def\verbatim@read@file{%
  \read\verbatim@in@stream to\next
  \ifeof\verbatim@in@stream
  \else
%    \end{macrocode}
%    For each line we call |\verbatim@addtoline| with the contents of
%    the line. \hskip0pt plus 3cm\penalty0\hskip0pt plus -3cm
%    |\verbatim@processline| is called next.
%    \begin{macrocode}
    \expandafter\verbatim@addtoline\expandafter{\next}%
    \verbatim@processline
%    \end{macrocode}
%    After processing the line we call |\verbatim@startline| to
%    initialize all before we read the next line.
%    \begin{macrocode}
    \verbatim@startline
%    \end{macrocode}
%    Without |\expandafter| each call of |\verbatim@read@file| uses
%    space in \TeX's input stack.\footnote{A standard \TeX\ would
%    report an overflow error if you try to read a file with more than
%    ca.\ 200~lines.  The same error occurs if the first line of code
%    in \S 390 of \textsl{``TeX: The Program''\/} is missing.}
%    \begin{macrocode}
    \expandafter\verbatim@read@file
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\verbatiminput}
%    |\verbatiminput| first starts a group to keep font and category
%    changes local.
%    Then it calls the macro |\verbatim@input| with additional
%    arguments, depending on whether an asterisk follows.
%    \begin{macrocode}
\def\verbatiminput{\begingroup
%    \end{macrocode}
% 
%   \changes{v1.5x}{2024/01/22}{Added TAB marking support into the
%   starred version (gh/1245)}
%   If starred, we mark spaces and TABs, the two
%   added pieces are the same as for verbatim*.
%    \begin{macrocode}
  \@ifstar{\verbatim@input{\@setupverbvisiblespace\@vobeyspaces}}%
          {\verbatim@input{\frenchspacing\@vobeyspaces}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\verbatim@input}
% \changes{1.5k}{1997/04/30}{Have \cs{verbatim@input} check for
%    existence of file.}
%    |\verbatim@input| first checks whether the file exists, using
%    the standard macro |\IfFileExists| which leaves the name of the
%    file found in |\@filef@und|. 
%    Then everything is set up as in the |\verbatim| macro. But, as
%    |\@verbatim| contains a call to |\every@verbatim| which
%    \emph{might} contain an |\input| statement, which would overwrite
%    the contents of |\@filef@und|, we need to save it by expanding it
%    first. The use of |\@swaptwoargs| makes it so that the
%    \emph{expansion} of |\@filef@und| gets to be the second argument
%    of |\verbatim@readfile|.
% \changes{v1.5t}{2020-07-06}{Expand \cs{@filef@und} before the call
%    of \cs{@verbatim} (gh/222)}
%    \begin{macrocode}
\def\verbatim@input#1#2{%
  \IfFileExists {#2}{%
    \expandafter\@swaptwoargs\expandafter
      {\expandafter{\@filef@und}}%
      {\@verbatim #1\relax
%    \end{macrocode}
%    Then it reads in the file, finishes off the \texttt{trivlist}
%    environment started by |\@verbatim| and closes the group.
%    This restores everything to its normal settings.
%    \begin{macrocode}
        \verbatim@readfile}%
      \endtrivlist\endgroup\@doendpe}%
%    \end{macrocode}
%    If the file is not found a more or less helpful message is
%    printed. The final |\endgroup| is  needed to close the group
%    started in |\verbatiminput| above.
%    \begin{macrocode}
   {\typeout {No file #2.}\endgroup}}
%</package>
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Getting verbatim text into arguments}
%
% One way of achieving this is to define a macro (command) whose
% expansion is the required verbatim text.  This command can then be
% used anywhere that the verbatim text is required.  It can be used in
% arguments, even moving ones, but it is fragile (at least, the
% version here is).
%
% Here is some code which claims to provide this.  It is a much revised
% version of something I (Chris) did about 2 years ago.  Maybe it needs
% further revision.
%
% It is only intended as an extension to |\verb|, not to the
% \texttt{verbatim} environment.  It should therefore, perhaps, treat
% line-ends similarly to whatever is best for |\verb|.
%
% \begin{macro}{\newverbtext}
% This is the command to produce a new macro whose expansion is
% verbatim text.  This command itself cannot be used in arguments,
% of course! It is used as follows:
%
% \begin{verbatim}
%    \newverbtext{\myverb}"^%{ &~_\}}@ #"
% \end{verbatim}
%
% The rules for delimiting the verbatim text are the same as those for
% |\verb|.
%
%    \begin{macrocode}
%<*verbtext>
\def \newverbtext {%
  \@ifstar {\@tempswatrue \@verbtext }{\@tempswafalse \@verbtext *}%
}
%    \end{macrocode}
% \end{macro}
%    I think that a temporary switch is safe here: if not, then
%    suitable |\let|s can be used.
%    \changes{v1.5i}{1996/06/04}{Moved processing of
%              \cs{verbatim@nolig@list} after \cs{dospecials}.}
%    \changes{v1.5p}{2001/03/12}{Added missing right brace in
%               definition of \cs{@verbtext} (PR 3314).}
%    \begin{macrocode}
\def \@verbtext *#1#2{%
   \begingroup
     \let\do\@makeother \dospecials
     \let\do\do@noligs \verbatim@nolig@list
     \@vobeyspaces
     \catcode`#2\active
     \catcode`~\active
     \lccode`\~`#2%
     \lowercase
%    \end{macrocode}
%    We use a temporary macro here and a trick so that the definition of
%    the command itself can be done inside the group and be a local
%    definition (there may be better ways to achieve this).
%    \begin{macrocode}
     {\def \@tempa ##1~%
           {\whitespaces
%    \end{macrocode}
%    If these |\noexpand|s were |\noexpand\protect\noexpand|, would
%    this make these things robust?
%    \begin{macrocode}
            \edef #1{\noexpand \@verbtextmcheck
                     \bgroup
                     \if@tempswa
                       \noexpand \visiblespaces
                     \fi
                     \noexpand \@verbtextsetup
                     ##1%
                     \egroup}%
            }%
      \expandafter\endgroup\@tempa
     }
}
%    \end{macrocode}
%    This sets up the correct type of group for the mode: it must not
%    be expanded at define time!
%    \begin{macrocode}
\def \@verbtextmcheck {%
   \relax\ifmmode
           \hbox
         \else
           \leavevmode
           \null
         \fi
}
%    \end{macrocode}
%    This contains other things which should not be expanded during the
%    definition.
%    \begin{macrocode}
\def \@verbtextsetup {%
   \frenchspacing
   \verbatim@font
   \verbtextstyle
}
%    \end{macrocode}
%    The command |\verbtextstyle| is a document-level hook which can be
%    used to override the predefined typographic treatment of commands
%    defined with |\newverbtext| commands.
%
%    |\visiblespaces| and |\whitespaces| are examples of possible values
%    of this hook.
%    \begin{macrocode}
\let \verbtextstyle \relax
\def \visiblespaces {\chardef \  32\relax}
\def \whitespaces {\let \ \@@space}
\let \@@space \ %
%</verbtext>
%    \end{macrocode}
%
%
% \section{Testing the implementation}
%
% For testing the implementation and for demonstration we provide
% an extra file. It can be extracted by using the conditional
% `\textsf{testdriver}'. It uses a small input file called
% `\texttt{verbtest.tst}' that is distributed separately.
% Again, we use individual `+' guards.
%    \begin{macrocode}
%<*testdriver>
\documentclass{article}

\usepackage{verbatim}

\newenvironment{myverbatim}%
   {\endgraf\noindent MYVERBATIM:\endgraf\verbatim}%
   {\endverbatim}

\makeatletter

\newenvironment{verbatimlisting}[1]%
 {\def\verbatim@startline{\input{#1}%
    \def\verbatim@startline{\verbatim@line{}}%
    \verbatim@startline}%
  \verbatim}{\endverbatim}

\newwrite\verbatim@out

\newenvironment{verbatimwrite}[1]%
 {\@bsphack
  \immediate\openout \verbatim@out #1
  \let\do\@makeother\dospecials\catcode`\^^M\active
  \def\verbatim@processline{%
    \immediate\write\verbatim@out{\the\verbatim@line}}%
  \verbatim@start}%
 {\immediate\closeout\verbatim@out\@esphack}

\makeatother

\addtolength{\textwidth}{30pt}

\begin{document}

\typeout{}
\typeout{===> Expect ``characters dropped''
         warning messages in this test! <====}
\typeout{}

Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
  \begin{verbatim}
    test
    \end{verbatim*}
    test
    \end{verbatim
    test of ligatures: <`!`?`>
    \endverbatim
    test
    \end  verbatim
    test
    test of end of line:
    \end
    {verbatim}
  \end{verbatim} Further text to be typeset: $\alpha$.
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
  \begin{verbatim*}
    test
    test
  \end {verbatim*}
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
  \begin{verbatim*}  bla bla
    test
    test
  \end {verbatim*}
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text

First of Chris Rowley's fiendish tests:
\begin{verbatim}
the double end test<text>
\end\end{verbatim}  or even \end \end{verbatim}
%
%not \end\ended??
%\end{verbatim}

Another of Chris' devils:
\begin{verbatim}
the single brace test<text>
\end{not the end\end{verbatim}
%
%not \end}ed??
%\end{verbatim}
Back to my own tests:
  \begin{myverbatim}
    test
    test
  \end {myverbatim} rest of line
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text

Test of empty verbatim:
\begin{verbatim}
\end{verbatim}
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
  \begin {verbatimlisting}{verbtest.tex}
    Additional verbatim text
      ...
  \end{verbatimlisting}
And here for listing a file:
  \verbatiminput{verbtest.tex}
And again, with explicit spaces:
  \verbatiminput*{verbtest.tex}
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
  \begin{comment}
    test
    \end{verbatim*}
    test
    \end {comment
    test
    \endverbatim
    test
    \end  verbatim
    test
  \end {comment} Further text to be typeset: $\alpha$.
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
  \begin{comment}  bla bla
    test
    test
  \end {comment}
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text

\begin{verbatimwrite}{verbtest.txt}
asfa<fa<df
sdfsdfasd
asdfa<fsa
\end{verbatimwrite}

\end{document}
%</testdriver>
%    \end{macrocode}
%
%
% \Finale
%
\endinput
%%