start at 2017?05?01
[latex2e.git] / trunk / base / ltclass.dtx
blobfcecac6531ec25530acf5f5a950a0c87382a9c23
1 % \iffalse meta-comment
3 % Copyright 1993-2016
4 % The LaTeX3 Project and any individual authors listed elsewhere
5 % in this file.
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 %    http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2005/12/01 or later.
18 % This file has the LPPL maintenance status "maintained".
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
22 % information.
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
28 % \fi
30 % \iffalse
31 %%% From File: ltclass.dtx
33 %<*driver>
34 % \fi
35 \ProvidesFile{ltclass.dtx}
36              [2017/03/08 v1.2c LaTeX Kernel (Class & Package Interface)]
37 % \iffalse
38 \documentclass{ltxdoc}
39 \GetFileInfo{ltclass.dtx}
40 \begin{document}
41 \title{The main structure of documents}
42 \author{Frank Mittelbach\and Chris Rowley\and Alan Jeffrey\and
43         David Carlisle}
44 \date{\filedate}
45  \MaintainedByLaTeXTeam{latex}
46  \maketitle
47  \DocInput{\filename}
48 \end{document}
49 %</driver>
50 % \fi
52 % \iffalse
53 % (C) Copyright Frank Mittelbach, Chris Rowley,
54 %               Alan Jeffrey and David Carlisle 1993-1998.
55 % All rights reserved.
56 % \fi
59 % \changes{v1.0f}{1994/05/22}{Use new warning and error commands}
60 % \changes{v1.0l}{1994/11/17}{\cs{@tempa} to \cs{reserved@a}}
61 % \changes{v1.0z}{1998/03/21}{Added to documentation of filecontents}
62 % \changes{v1.1c}{1998/08/17}{(RmS) Minor documentation fixes.}
64 % \section{Introduction}
66 % This file implements the following declarations, which replace
67 % |\documentstyle| in  \LaTeXe\ documents.
69 % Note that old documents containing |\documentstyle| will be run using
70 % a compatibility option---thus keeping everyone happy, we hope!
72 % The overall idea is that there are two types of `style files':
73 % `class files' which define elements and provide a default formatting
74 % for them;  and `packages' which provide extra functionality.  One
75 % difference between \LaTeXe\ and \LaTeX2.09 is that \LaTeXe\ packages
76 % may have options. Note that options to classes packages may be
77 % implemented such that they input files, but these file names are not
78 % necessarily directly related to the option name.
80 % \section{User interface}
82 % |\documentclass[|\meta{main-option-list}|]{|^^A
83 %   \meta{class}|}[|\meta{version}|]|
85 % There must be exactly one such declaration, and it must come first.
86 % The \meta{main-option-list} is a list of options which can modify the
87 % formatting of elements which are defined in the \meta{class} file
88 % as well as in all following |\usepackage| declarations (see below).
89 % The \meta{version} is a version number, beginning with a date in the
90 % format |YYYY/MM/DD|.  If an older version of the class is found, a
91 % warning is issued.
93 % \bigskip
95 % |\documentstyle[|\meta{main-option-list}|]{|^^A
96 %   \meta{class}|}[|\meta{version}|]|
98 % The |\documentstyle| declaration is kept in order to maintain upward
99 % compatibility with \LaTeX2.09 documents.  It is similar to
100 % |\documentclass|, but it causes all options in
101 % \meta{main-option-list} that the \meta{class} does not use to be
102 % passed to |\RequirePackage| after the options have been processed.
103 % This maintains compatibility with the 2.09 behaviour. Also a flag is
104 % set to indicate that the document is to be processed in \LaTeX2.09
105 % compatibility mode.  As far as most packages are concerned, this
106 % only affects the warnings and errors \LaTeX\ generates. This flag
107 % does affect the definition of font commands, and |\sloppy|.
109 % \bigskip
111 % |\usepackage[|\meta{package-option-list}|]{|^^A
112 %    \meta{package-list}|}[|\meta{version}|]|
114 % There can be any number of these declarations. All packages in
115 % \meta{package-list} are called with the same options.
117 % Each \meta{package} file defines new elements (or modifies those
118 % defined in the \meta{class}), and thus extends the range of documents
119 % which can be processed.
120 % The \meta{package-option-list} is a list of options which can modify
121 % the formatting of elements defined in the \meta{package} file.
122 % The \meta{version} is a version number, beginning with a date in the
123 % format |YYYY/MM/DD|.  If an older version of the package is found, a
124 % warning is issued.
126 % Each package is loaded only once.  If the same package is requested
127 % more than once, nothing happens, unless the package has been requested
128 % with options that were not given the first time it was loaded, in
129 % which case an error is produced.
131 % As well as processing the options given in the
132 % \meta{package-option-list}, each package processes the
133 % \meta{main-option-list}.  This means that options that affect all
134 % of the packages can be given globally, rather than repeated for every
135 % package.
137 % Note that class files have the extension |.cls|, packages have the
138 % extension |.sty|.
140 % \DescribeEnv{filecontents}
141 % The environment |filecontents| is intended for passing the contents
142 % of packages, options, or other files along with a document in a
143 % single file.
144 % It has one argument, which is the name of the file to create. If that
145 % file already exists (maybe only in the current directory if the OS
146 % supports a notion of a `current directory' or `default directory')
147 % then nothing happens
148 % (except for an information message) and the body of the environment
149 % is bypassed. Otherwise, the body of the environment is written
150 % verbatim to the file name given as the first argument, together with
151 % some comments about how it was produced.
153 % The environment is allowed only before |\documentclass| to ensure
154 % that all packages or options necessary for this particular run are
155 % present when needed.  The begin and end tags should each be on a
156 % line by itself.  There is also a star-form; this does not write
157 % extra comments into the file.
159 % \subsection{Option processing}
161 % When the options are processed, they are divided into two types: {\em
162 % local\/} and {\em global}:
163 % \begin{itemize}
165 % \item For a class, the options in the |\documentclass| command are
166 %    local.
168 % \item For a package, the options in the |\usepackage| command are
169 %    local, and the options in the |\documentclass| command are global.
171 % \end{itemize}
172 % The options for |\documentclass| and |\usepackage|
173 % are processed in the following way:
174 % \begin{enumerate}
176 % \item The local and global options that have been declared
177 %   (using |\DeclareOption| as  described below) are processed
178 %   first.
180 %  In the case of |\ProcessOptions|, they are processed in the order
181 %  that they were declared in the class or package.
183 %  In the case of |\ProcessOptions*|, they are processed in the order
184 %  that they appear in the option-lists. First the global options, and
185 %  then the local ones.
187 % \item Any remaining local options are dealt with using the default
188 %   option (declared using the |\DeclareOption*| declaration described
189 %   below).  For document classes, this usually does nothing, but
190 %   records the option on a list of unused options.
191 %   For packages, this usually produces an error.
193 % \end{enumerate}
194 % Finally, when |\begin{document}| is reached, if there are any global
195 % options which have not been used by either the class or any package,
196 % the system will produce a warning.
199 % \section{Class and Package interface}
201 % \subsection{Class name and version}
203 % \DescribeMacro\ProvidesClass
204 % A class can identify itself with the
205 % |\ProvidesClass{|\meta{name}|}[|\meta{version}|]| command.  The
206 % \meta{version} should begin with a date in the format |YYYY/MM/DD|.
208 % \subsection{Package name and version}
210 % \DescribeMacro\ProvidesPackage
211 % A package can identify itself with the
212 % |\ProvidesPackage|\marg{name}\oarg{version} command.  The
213 % \meta{version} should begin with a date in the format |YYYY/MM/DD|.
215 % \subsection{Requiring other packages}
217 % \DescribeMacro\RequirePackage
218 % Packages or classes can load other packages using\\
219 % |\RequirePackage|\oarg{options}\marg{name}\oarg{version}.\\
220 % If the package has already been loaded, then nothing happens unless
221 % the requested options are not a subset of the options with which it
222 % was loaded, in which case an error is called.
224 % \DescribeMacro\LoadClass
225 %  Similar to |\RequirePackage|, but for classes, may not be used in
226 %  package files.
228 % \DescribeMacro\PassOptionsToPackage
229 % Packages can pass options to other packages using:\\
230 % |\PassOptionsToPackage{|\meta{options}|}{|\meta{package}|}|.\\
231 % \DescribeMacro\PassOptionsToClass
232 % This adds the \meta{options} to the options list of any future
233 % |\RequirePackage| or |\usepackage| command.  For example:
234 % \begin{verbatim}
235 %    \PassOptionsToPackage{foo,bar}{fred}
236 %    \RequirePackage[baz]{fred}\end{verbatim}
237 % is the same as:
238 % \begin{verbatim}
239 %    \RequirePackage[foo,bar,baz]{fred}\end{verbatim}
241 % \DescribeMacro\LoadClassWithOptions
242 % |\LoadClassWithOptions|\marg{name}\oarg{version}:\\
243 % This is similar to
244 % |\LoadClass|, but it always calls class \meta{name} with
245 % exactly the same option list that is being used by the current class,
246 % rather than an option explicitly  supplied or passed on by
247 % |\PassOptionsToClass|.
248 % \DescribeMacro\RequirePackageWithOptions
249 % |\RequirePackageWithOptions| is the analogous command for packages.
251 % This is mainly intended to allow one class to simply build on another,
252 % for example:
253 %\begin{verbatim}
254 %   \LoadClassWithOptions{article}
255 %\end{verbatim}
257 % This should be contrasted with the slightly different construction
258 %\begin{verbatim}
259 %   \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
260 %   \ProcessOptions
261 %   \LoadClass{article}
262 %\end{verbatim}
264 % As used here, the effects are more or less the same, but the
265 % version using |\LoadClassWithOptions| is slightly quicker
266 % (and less to type).
267 % If, however, the class declares options of its own then
268 % the two constructions are different; compare, for example:
269 %\begin{verbatim}
270 %   \DeclareOption{landscape}{...}
271 %   \ProcessOptions
272 %   \LoadClassWithOptions{article}
273 %\end{verbatim}
274 % with:
275 %\begin{verbatim}
276 %   \DeclareOption{landscape}{...}
277 %   \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
278 %   \ProcessOptions
279 %   \LoadClass{article}
280 %\end{verbatim}
281 % In the first case, the \textsf{article} class will be called with
282 % option |landscape| precisely when the current class is called with
283 % this option; but in the second example it will
284 % not as in that case \textsf{article} is only passed options by the
285 % default option handler, which is not used for |landscape| as that
286 % option is explicitly declared.
288 % \DescribeMacro\@ifpackageloaded
289 % To find out if a package has already been loaded, use\\
290 % \DescribeMacro\@ifclassloaded
291 % |\@ifpackageloaded{|\meta{package}|}{|\meta{true}|}{|\meta{false}|}|.
293 % \DescribeMacro\@ifpackagelater
294 % \changes{v1.1i}{2013/07/07}{Correctly describe how the date in
295 %       \cs{@ifpackagelater} is used}
296 % To find out if a package has already been loaded with a version
297 % equal to or more
298 % recent than \meta{version}, use\\
299 % \DescribeMacro\@ifclasslater
300 % |\@ifpackagelater{|\meta{package}|}{|\meta{version}|}{|^^A
301 % \meta{true}|}{|\meta{false}|}|.
303 % \DescribeMacro\@ifpackagewith
304 % To find out if a package has already been loaded with at least the
305 % options \meta{options}, use
306 % \DescribeMacro\@ifclasswith
307 % |\@ifpackagewith{|\meta{package}|}{|\meta{options}|}{|^^A
308 % \meta{true}|}{|\meta{false}|}|.
310 % There exists one package that can't be tested with the above
311 % commands: the \texttt{fontenc} package pretends that it was never
312 % loaded to allow for repeated reloading with different options (see
313 % \texttt{ltoutenc.dtx} for details).
316 % \subsection{Declaring new options}
318 % Options for classes and packages are built using the same macros.
320 % \DescribeMacro\DeclareOption To define a builtin option, use
321 % |\DeclareOption{|\meta{name}|}{|\meta{code}|}|.
323 % \DescribeMacro{\DeclareOption*} To define the default action to
324 % perform for local options which have not been declared, use
325 % |\DeclareOption*{|\meta{code}|}|.
327 % {\em Note\/}: there should be no use of\\
328 %  |\RequirePackage|, |\DeclareOption|, |\DeclareOption*| or
329 %   |\ProcessOptions|\\
330 % inside |\DeclareOption| or |\DeclareOption*|.
332 % Possible uses for |\DeclareOption*| include:
334 % |\DeclareOption*{}|\\
335 %    Do nothing. Silently accept unknown options. (This suppresses the
336 %    usual warnings.)
338 % |\DeclareOption*{\@unkownoptionerror}|\\
339 %     Complain about unknown local options. (The initial setting for
340 %       package files.)
342 % |\DeclareOption*{\PassOptionsToPackage{\CurrentOption}|^^A
343 %                                     |{|\meta{pkg-name}|}|\\
344 % Handle the the current option by passing it on to the package
345 % \meta{pkg-name}, which will presumably be loaded via
346 % |\RequirePackage| later in the file. This is useful for building
347 % `extension' packages, that perhaps handle a couple of new options,
348 % but then pass everything else on to an existing package.
350 % |\DeclareOption*{\InputIfFileExists{xx-\CurrentOption.yyy}%|\\
351 % |               {}%|\\
352 % |               {\OptionNotUsed}}|\\
353 %  Handle the option foo by loading the file |xx-foo.yyy| if it
354 %  exists, otherwise do nothing, but declare that the option was not
355 %  used.
356 %  Actually the |\OptionNotUsed| declaration is only needed if this is
357 %  being used in class files, but does no harm in package files.
360 % \subsection{Safe Input Macros}
361 % \DescribeMacro{\InputIfFileExists}
362 %  |\InputIfFileExists{|\meta{file}|}{|\meta{then}|}{|\meta{else}|}|\\
363 % Inputs \meta{file} if it exists. Immediately before the input,
364 % \meta{then} is executed. Otherwise \meta{else} is executed.
366 % \DescribeMacro{\IfFileExists}
367 % As above, but does not input the file.
369 % One thing you might like to put in the \meta{else} clause is
371 % \DescribeMacro{\@missingfileerror}
372 % This starts an interactive request for a filename, supplying default
373 % extensions. Just hitting return causes the whole input to be skipped
374 % and entering |x| quits the current run,
376 % \DescribeMacro{\input}
377 % This has been redefined from the \LaTeX2.09 definition, in terms of
378 % the new commands |\InputIfFileExists| and |\@missingfileerror|.
381 % \DescribeMacro{\listfiles} Giving this declaration in the preamble
382 % causes a list of all files input via the `safe input' commands to be
383 % listed at the end. Any strings specified in the optional argument to
384 % |\ProvidesPackage| are listed alongside the file name. So files in
385 % standard (and other non-standard) distributions can put informative
386 % strings in this argument.
388 % \StopEventually{}
390 % \section{Implementation}
392 %    \begin{macrocode}
393 %<*2ekernel>
394 %    \end{macrocode}
397 % \changes{v0.2g}{1993/11/23}
398 %         {Various macros now moved to latex.tex.}
399 % \changes{v0.2g}{1993/11/23}
400 %         {Warnings and errors now directly coded.}
401 % \changes{v0.2h}{1993/11/28}
402 %         {Primitive filenames now terminated by space not \cs{relax}.}
403 % \changes{v0.2h}{1993/11/28}
404 %         {Directory syntax checing moved to dircheck.dtx}
405 % \changes{v0.2h}{1993/11/28}
406 %         {Assorted commands now in the kernel removed.}
407 % \changes{v0.2i}{1993/12/03}
408 %         {\cs{@onlypreamble}: Many commands declared.}
409 % \changes{v0.2i}{1993/12/03}
410 %         {Removed obsolete \cs{@documentclass}}
411 % \changes{v0.2o}{1993/12/13}
412 %         {Removed setting \cs{errorcontextlines}\ (now in latex.tex)}
413 % \changes{v0.2p}{1993/12/15}
414 %         {Removed extra `.'s from \cs{@@warning}s}
415 % \changes{v0.2s}{1994/01/17}
416 %         {Added many more \cs{@onlypreamble} commands}
417 % \changes{v0.2s}{1994/01/17}
418 %         {Wrapped long lines to column 72}
419 % \changes{v0.3a}{1994/03/02}
420 %         {Remove need for driver file}
421 % \changes{v0.3b}{1994/03/08}
422 %         {Modify driver code into `new style'}
423 % \changes{v0.3c}{1994/03/12}
424 %         {Change name from docclass to ltclass}
425 % \changes{v0.3h}{1994/04/25}
426 %         {Removed spurious extra `.'s at the end of error messages}
427 % \changes{v1.0a}{1994/04/29}
428 %         {Change version number to 1 (no other change)}
429 % \changes{v1.0k}{1994/11/03}
430 %         {Move \cs{@missingfileerror} to ltfiles}
432 % \begin{macro}{\if@compatibility}
433 %    The flag for compatibility mode.
434 %    \begin{macrocode}
435 \newif\if@compatibility
436 %    \end{macrocode}
437 % \end{macro}
439 % \begin{macro}{\@documentclasshook}
440 %    The hook called after the first |\documentclass| command.  By
441 %    default this checks to see if |\@normalsize| is undefined, and if
442 %    so, sets it to |\normalsize|.
443 % \changes{v0.2q}{1993/12/17}
444 %         {Macro added}
445 % \changes{v0.2z}{1994/02/10}
446 %         {Changed the name from \cs{@compatibility} to
447 %          \cs{@documentclasshook}, and added the check for whether
448 %          \cs{@normalsize} has been defined.  ASAJ.}
449 %    \begin{macrocode}
450 \def\@documentclasshook{%
451    \ifx\@normalsize\@undefined
452       \let\@normalsize\normalsize
453    \fi
455 %    \end{macrocode}
456 % \end{macro}
458 %  \begin{macro}{\@declaredoptions}
459 %    This list is automatically built by |\DeclareOption|.
460 %    It is the list of options (separated by commas) declared in
461 %    the class or package file and it defines the order in which the
462 %    the corresponding |\ds@|\meta{option} commands are executed.
463 %    All local \meta{option}s which are not declared will be processed
464 %    in the order defined by the optional argument of |\documentclass|
465 %    or |\usepackage|.
466 %    \begin{macrocode}
467 \let\@declaredoptions\@empty
468 %    \end{macrocode}
469 %  \end{macro}
471 %  \begin{macro}{\@classoptionslist}
472 %    List of options of the main class.
473 % \changes{v1.0u}{1996/07/26}{made only preamble}
474 %    \begin{macrocode}
475 \let\@classoptionslist\relax
476 \@onlypreamble\@classoptionslist
477 %    \end{macrocode}
478 %  \end{macro}
480 %  \begin{macro}{\@unusedoptionlist}
481 % \changes{v1.0u}{1996/07/26}{made only preamble}
482 %    List of options of the main class that haven't been declared or
483 %    loaded as class option files.
484 %    \begin{macrocode}
485 \let\@unusedoptionlist\@empty
486 \@onlypreamble\@unusedoptionlist
487 %    \end{macrocode}
488 %  \end{macro}
490 %  \begin{macro}{\CurrentOption}
491 %    Name of current package or option.
492 % \changes{v0.2c}{1993/11/17}
493 %         {Name changed from \cs{@curroption}}
494 %    \begin{macrocode}
495 \let\CurrentOption\@empty
496 %    \end{macrocode}
497 %  \end{macro}
499 %  \begin{macro}{\@currname}
500 %    Name of current package or option.
501 %    \begin{macrocode}
502 \let\@currname\@empty
503 %    \end{macrocode}
504 %  \end{macro}
506 % \begin{macro}{\@currext}
507 %    The current file extension.
508 % \changes{v0.2a}{1993/11/14}{Name changed from \cs{@currextension}}
509 %    \begin{macrocode}
510 \global\let\@currext=\@empty
511 %    \end{macrocode}
512 % \end{macro}
514 % \begin{macro}{\@clsextension}
515 % \begin{macro}{\@pkgextension}
516 %    The two possible values of |\@currext|.
517 %    \begin{macrocode}
518 \def\@clsextension{cls}
519 \def\@pkgextension{sty}
520 \@onlypreamble\@clsextension
521 \@onlypreamble\@pkgextension
522 %    \end{macrocode}
523 % \end{macro}
524 % \end{macro}
526 % \begin{macro}{\@pushfilename}
527 % \begin{macro}{\@popfilename}
528 % \begin{macro}{\@currnamestack}
529 % Commands to push and pop the file name and extension. \\
530 % |#1| current name.      \\
531 % |#2| current extension. \\
532 % |#3| current catcode of |@|. \\
533 % |#4| Rest of the stack.
534 %    \begin{macrocode}
535 \def\@pushfilename{%
536   \xdef\@currnamestack{%
537     {\@currname}%
538     {\@currext}%
539     {\the\catcode`\@}%
540     \@currnamestack}}
541 \@onlypreamble\@pushfilename
542 %    \end{macrocode}
544 %    \begin{macrocode}
545 \def\@popfilename{\expandafter\@p@pfilename\@currnamestack\@nil}
546 \@onlypreamble\@popfilename
547 %    \end{macrocode}
549 %    \begin{macrocode}
550 \def\@p@pfilename#1#2#3#4\@nil{%
551   \gdef\@currname{#1}%
552   \gdef\@currext{#2}%
553   \catcode`\@#3\relax
554   \gdef\@currnamestack{#4}}
555 \@onlypreamble\@p@pfilename
556 %    \end{macrocode}
558 %    \begin{macrocode}
559 \gdef\@currnamestack{}
560 \@onlypreamble\@currnamestack
561 %    \end{macrocode}
562 % \end{macro}
563 % \end{macro}
564 % \end{macro}
566 % \begin{macro}{\@ptionlist}
567 %    Returns the option list of the file.
568 %    \begin{macrocode}
569 \def\@ptionlist#1{%
570   \@ifundefined{opt@#1}\@empty{\csname opt@#1\endcsname}}
571 \@onlypreamble\@ptionlist
572 %    \end{macrocode}
573 % \end{macro}
575 % \begin{macro}{\@ifpackageloaded}
576 % \begin{macro}{\@ifclassloaded}
577 %   |\@ifpackageloaded{|\meta{name}|}|
578 %  Checks to see whether a file has been loaded.
579 % \changes{v0.2t}{1994/01/18}
580 %         {Fix typo \cs{@pkgetension}}
581 %    \begin{macrocode}
582 \def\@ifpackageloaded{\@ifl@aded\@pkgextension}
583 \def\@ifclassloaded{\@ifl@aded\@clsextension}
584 \@onlypreamble\@ifpackageloaded
585 \@onlypreamble\@ifclassloaded
586 %    \end{macrocode}
588 %    \begin{macrocode}
589 \def\@ifl@aded#1#2{%
590   \expandafter\ifx\csname ver@#2.#1\endcsname\relax
591     \expandafter\@secondoftwo
592   \else
593     \expandafter\@firstoftwo
594   \fi}
595 \@onlypreamble\@ifl@aded
596 %    \end{macrocode}
597 % \end{macro}
598 % \end{macro}
600 % \begin{macro}{\@ifpackagelater}
601 % \begin{macro}{\@ifclasslater}
602 % |\@ifpackagelater{|\meta{name}|}{YYYY/MM/DD}|
603 % Checks that the package loaded is more recent than the given date.
604 %    \begin{macrocode}
605 \def\@ifpackagelater{\@ifl@ter\@pkgextension}
606 \def\@ifclasslater{\@ifl@ter\@clsextension}
607 \@onlypreamble\@ifpackagelater
608 \@onlypreamble\@ifclasslater
609 %    \end{macrocode}
611 %    \begin{macrocode}
612 \def\@ifl@ter#1#2{%
613   \expandafter\@ifl@t@r
614     \csname ver@#2.#1\endcsname}
615 \@onlypreamble\@ifl@ter
616 %    \end{macrocode}
618 % This internal macro is also used in |\NeedsTeXFormat|.
619 % \changes{v0.2f}{1993/11/22}
620 %         {Added //00 so parsing never produces a runaway argument.}
621 %    \begin{macrocode}
622 \def\@ifl@t@r#1#2{%
623   \ifnum\expandafter\@parse@version#1//00\@nil<%
624         \expandafter\@parse@version#2//00\@nil
625     \expandafter\@secondoftwo
626   \else
627     \expandafter\@firstoftwo
628   \fi}
629 \@onlypreamble\@ifl@t@r
630 %    \end{macrocode}
632 % \changes{v1.1j}{2016/06/20}
633 %         {don't declare as \cs{@onlypreamble}}
634 % \changes{v1.2c}{2017/03/08}
635 %         {add \cs{@parse@version@dash} to support yyyy-mm-dd as well as yyyy/mm/dd }
636 %    \begin{macrocode}
637 %</2ekernel>
638 %<*2ekernel|isodate>
639 \def\@parse@version#1/#2/#3#4#5\@nil{%
640 \@parse@version@dash#1-#2-#3#4\@nil
642 %    \end{macrocode}
644 % The |\if| test here ensures that an argument with no |/|  or |-| produces 0 (actually 00).
645 %    \begin{macrocode}
646 \def\@parse@version@dash#1-#2-#3#4#5\@nil{%
647   \if\relax#2\relax\else#1\fi#2#3#4 }
648 %</2ekernel|isodate>
649 %<*2ekernel>
650 %    \end{macrocode}
651 % \end{macro}
652 % \end{macro}
654 % \begin{macro}{\@ifpackagewith}
655 % \begin{macro}{\@ifclasswith}
656 % |\@ifpackagewith{|\meta{name}|}{|\meta{option-list}|}|
657 % Checks that \meta{option-list} is a subset of the options
658 % \textbf{with} which \meta{name} was loaded.
659 %    \begin{macrocode}
660 \def\@ifpackagewith{\@if@ptions\@pkgextension}
661 \def\@ifclasswith{\@if@ptions\@clsextension}
662 \@onlypreamble\@ifpackagewith
663 \@onlypreamble\@ifclasswith
664 %    \end{macrocode}
666 %    \begin{macrocode}
667 \def\@if@ptions#1#2{%
668   \@expandtwoargs\@if@pti@ns{\@ptionlist{#2.#1}}}
669 \@onlypreamble\@if@ptions
670 %    \end{macrocode}
672 % Probably shouldn't use |\CurrentOption| here\ldots (changed to
673 % |\reserved@b|.)
674 % \changes{v0.2y}{1994/02/07}
675 %         {Add extra ,s so `two' is not matched with `twocolumn'}
676 % \changes{v1.1i}{2011/08/19}
677 %         {Re-jig definition after more stringent \cs{in@} test.}
678 %    \begin{macrocode}
679 %</2ekernel>
680 %<latexrelease>\IncludeInRelease{2017/01/01}%
681 %<latexrelease>                 {\@if@pti@ns}{Spaces in option clash check}%
682 %<*2ekernel|latexrelease>
683 \def\@if@pti@ns#1#2{%
684  \let\reserved@a\@firstoftwo
685 %    \end{macrocode}
686 % \changes{v1.2a}{2016/10/02}
687 %         {Ignore spaces while checking for option clash}
688 %    \begin{macrocode}
689  \edef\reserved@b{\zap@space#2 \@empty}%
690  \@for\reserved@b:=\reserved@b\do{%
691    \ifx\reserved@b\@empty
692    \else
693      \expandafter\in@\expandafter{\expandafter,\reserved@b,}{,#1,}%
694      \ifin@
695      \else
696        \let\reserved@a\@secondoftwo
697      \fi
698    \fi
699  }%
700  \reserved@a}
701 %</2ekernel|latexrelease>
702 %<latexrelease>\EndIncludeInRelease
703 %<latexrelease>\IncludeInRelease{0000/00/00}%
704 %<latexrelease>                 {\@if@pti@ns}{Spaces in option clash check}%
705 %<latexrelease>\def\@if@pti@ns#1#2{%
706 %<latexrelease> \let\reserved@a\@firstoftwo
707 %<latexrelease> \@for\reserved@b:=#2\do{%
708 %<latexrelease>  \ifx\reserved@b\@empty
709 %<latexrelease>   \else
710 %<latexrelease>   \expandafter\in@\expandafter
711 %<latexrelease>                   {\expandafter,\reserved@b,}{,#1,}%
712 %<latexrelease>    \ifin@
713 %<latexrelease>    \else
714 %<latexrelease>     \let\reserved@a\@secondoftwo
715 %<latexrelease>    \fi
716 %<latexrelease>  \fi
717 %<latexrelease> }%
718 %<latexrelease> \reserved@a}
719 %<*2ekernel>
720 %    \end{macrocode}
722 %    \begin{macrocode}
723 \@onlypreamble\@if@pti@ns
724 %    \end{macrocode}
725 % \end{macro}
726 % \end{macro}
728 % \begin{macro}{\ProvidesPackage}
729 %    Checks that the current filename is correct, and defines
730 %    |\ver@filename|.
731 % \changes{v0.3c}{1994/03/12}
732 %         {Add \cs{wlog}}
733 % \changes{v0.3c}{1994/03/12}
734 %         {use \cs{@gtempa}}
735 %    \begin{macrocode}
736 \def\ProvidesPackage#1{%
737   \xdef\@gtempa{#1}%
738   \ifx\@gtempa\@currname\else
739     \@latex@warning@no@line{You have requested
740       \@cls@pkg\space`\@currname',\MessageBreak
741        but the \@cls@pkg\space provides `#1'}%
742   \fi
743   \@ifnextchar[\@pr@videpackage{\@pr@videpackage[]}}%]
744 \@onlypreamble\ProvidesPackage
745 %    \end{macrocode}
747 %    \begin{macrocode}
748 \def\@pr@videpackage[#1]{%
749   \expandafter\xdef\csname ver@\@currname.\@currext\endcsname{#1}%
750   \ifx\@currext\@clsextension
751     \typeout{Document Class: \@gtempa\space#1}%
752   \else
753     \wlog{Package: \@gtempa\space#1}%
754   \fi}
755 \@onlypreamble\@pr@videpackage
756 %    \end{macrocode}
757 % \end{macro}
759 % \begin{macro}{\ProvidesClass}
760 %    Like |\ProvidesPackage|, but for classes.
761 %    \begin{macrocode}
762 \let\ProvidesClass\ProvidesPackage
763 \@onlypreamble\ProvidesClass
764 %    \end{macrocode}
765 % \end{macro}
767 % \begin{macro}{\ProvidesFile}
768 %    Like |\ProvidesPackage|, but for arbitrary files. Do not apply
769 %    |\@onlypreamble| to these, as we may want to label files input
770 %    during the document.
771 % \changes{v0.2l}{1993/12/07}
772 %         {Macro added}
773 % \changes{v0.3c}{1994/03/12}
774 %         {Add \cs{wlog}}
775 % \changes{v0.3g}{1994/04/11}
776 %         {Protect against weird catcodes.}
777 % \begin{macro}{\@providesfile}
778 % \changes{v1.0r}{1995/10/17}
779 %         {Delay definition of \cs{ProvidesFile} till ltfinal}
780 % \changes{v1.1a}{1998/03/21}
781 %         {Allow \&. Internal/2702}
782 % \changes{v1.1d}{2001/05/25}{Explicitly set catcode of
783 %                              \cs{endlinechar} to 10 (pr/3334)}
784 % \changes{v1.1e}{2001/06/04}{But only if it is a char (pr/3334)}
785 % \changes{v1.1f}{2001/08/26}{Readded setting of space char (pr/3353)}
786 %    \begin{macrocode}
787 \def\ProvidesFile#1{%
788   \begingroup
789     \catcode`\ 10 %
790     \ifnum \endlinechar<256 %
791       \ifnum \endlinechar>\m@ne
792         \catcode\endlinechar 10 %
793       \fi
794     \fi
795     \@makeother\/%
796     \@makeother\&%
797 %    \end{macrocode}
798 % \changes{v1.1g}{2004/01/28}{Use kernel version of
799 %                             \cs{@ifnextchar} (pr/3501)}
800 %    \begin{macrocode}
801     \kernel@ifnextchar[{\@providesfile{#1}}{\@providesfile{#1}[]}}
802 %    \end{macrocode}
804 % During initex a special version of |\@providesfile| is used.
805 % The real definition is installed right at the end, in |ltfinal.dtx|.
806 %\begin{verbatim}
807 %\def\@providesfile#1[#2]{%
808 %    \wlog{File: #1 #2}%
809 %    \expandafter\xdef\csname ver@#1\endcsname{#2}%
810 %  \endgroup}
811 %    \end{macrocode}
812 %\end{verbatim}
813 % \end{macro}
814 % \end{macro}
816 % \begin{macro}{\PassOptionsToPackage}
817 % \begin{macro}{\PassOptionsToClass}
818 % If the package has been loaded, we check that it was first loaded with
819 % the options.  Otherwise we add the option list to that of the package.
820 %    \begin{macrocode}
821 \def\@pass@ptions#1#2#3{%
822   \expandafter\xdef\csname opt@#3.#1\endcsname{%
823     \@ifundefined{opt@#3.#1}\@empty
824       {\csname opt@#3.#1\endcsname,}%
825     \zap@space#2 \@empty}}
826 \@onlypreamble\@pass@ptions
827 %    \end{macrocode}
829 %    \begin{macrocode}
830 \def\PassOptionsToPackage{\@pass@ptions\@pkgextension}
831 \def\PassOptionsToClass{\@pass@ptions\@clsextension}
832 \@onlypreamble\PassOptionsToPackage
833 \@onlypreamble\PassOptionsToClass
834 %    \end{macrocode}
835 % \end{macro}
836 % \end{macro}
838 % \begin{macro}{\DeclareOption}
839 % \begin{macro}{\DeclareOption*}
840 %    Adds an option as a |\ds@| command, or the default |\default@ds|
841 %    command.
842 % \changes{v0.2c}{1993/11/17}
843 %         {Error checking added}
844 % \changes{v1.0m}{1995/04/21}
845 %         {Made long /1498}
846 % \changes{v1.0n}{1995/05/12}
847 %         {Use \cs{toks@} to remove need to double hash /1557}
848 %    \begin{macrocode}
849 \def\DeclareOption{%
850   \let\@fileswith@pti@ns\@badrequireerror
851   \@ifstar\@defdefault@ds\@declareoption}
852 \long\def\@declareoption#1#2{%
853    \xdef\@declaredoptions{\@declaredoptions,#1}%
854    \toks@{#2}%
855    \expandafter\edef\csname ds@#1\endcsname{\the\toks@}}
856 \long\def\@defdefault@ds#1{%
857   \toks@{#1}%
858   \edef\default@ds{\the\toks@}}
859 \@onlypreamble\DeclareOption
860 \@onlypreamble\@declareoption
861 \@onlypreamble\@defdefault@ds
862 %    \end{macrocode}
863 % \end{macro}
864 % \end{macro}
866 % \begin{macro}{\OptionNotUsed}
867 % If we are in a class file, add |\CurrentOption| to the list of
868 % unused options. Otherwise, in a package file do nothing.
869 %    \begin{macrocode}
870 \def\OptionNotUsed{%
871   \ifx\@currext\@clsextension
872     \xdef\@unusedoptionlist{%
873       \ifx\@unusedoptionlist\@empty\else\@unusedoptionlist,\fi
874       \CurrentOption}%
875   \fi}
876 \@onlypreamble\OptionNotUsed
877 %    \end{macrocode}
878 % \end{macro}
880 % \begin{macro}{\default@ds}
881 % The default default option code.
882 % Set by |\@onefilewithoptions| to either |\OptionNotUsed| for
883 % classes, or |\@unknownoptionerror| for packages. This may be reset
884 % in either case with |\DeclareOption*|.
885 %    \begin{macrocode}
886 % \let\default@ds\OptionNotUsed
887 %    \end{macrocode}
888 % \end{macro}
890 % \begin{macro}{\ProcessOptions}
891 % \begin{macro}{\ProcessOptions*}
892 % |\ProcessOptions| calls |\ds@option| for each known package option,
893 % then calls |\default@ds| for each option on the local options list.
894 % Finally resets all the declared options to |\relax|. The empty option
895 % does nothing, this has to be reset on the off chance it's set to
896 % |\relax| if an empty element gets into the |\@declaredoptions| list.
898 % The star form is similar but executes options given in the order
899 % specified in the document, not the order they are declared in the
900 % file. In the case of packages, global options are executed before
901 % local ones.
902 % \changes{v0.2a}{1993/11/14}
903 %         {Stop adding the global option list inside class files.}
904 % \changes{v0.2a}{1993/11/14}
905 %         {Optimise `empty option' code.}
906 % \changes{v0.2b}{1993/11/15}
907 %         {Star form added.}
908 % \changes{v0.2c}{1993/11/17}
909 %         {restoring \cs{@fileswith@pti@ns} added.}
910 %    \begin{macrocode}
911 \def\ProcessOptions{%
912   \let\ds@\@empty
913   \edef\@curroptions{\@ptionlist{\@currname.\@currext}}%
914   \@ifstar\@xprocess@ptions\@process@ptions}
915 \@onlypreamble\ProcessOptions
916 %    \end{macrocode}
918 % \changes{v0.2y}{1994/02/07}
919 %         {Add extra ,s so `two' is not matched with `twocolumn'}
920 %    \begin{macrocode}
921 \def\@process@ptions{%
922   \@for\CurrentOption:=\@declaredoptions\do{%
923     \ifx\CurrentOption\@empty\else
924       \@expandtwoargs\in@{,\CurrentOption,}{%
925          ,\ifx\@currext\@clsextension\else\@classoptionslist,\fi
926          \@curroptions,}%
927       \ifin@
928         \@use@ption
929         \expandafter\let\csname ds@\CurrentOption\endcsname\@empty
930       \fi
931     \fi}%
932   \@process@pti@ns}
933 \@onlypreamble\@process@ptions
934 %    \end{macrocode}
936 % \changes{v0.2y}{1994/02/07}
937 %         {Add extra ,s so `two' is not matched with `twocolumn'}
938 %    \begin{macrocode}
939 \def\@xprocess@ptions{%
940   \ifx\@currext\@clsextension\else
941     \@for\CurrentOption:=\@classoptionslist\do{%
942       \ifx\CurrentOption\@empty\else
943         \@expandtwoargs\in@{,\CurrentOption,}{,\@declaredoptions,}%
944         \ifin@
945           \@use@ption
946           \expandafter\let\csname ds@\CurrentOption\endcsname\@empty
947         \fi
948       \fi}%
949   \fi
950   \@process@pti@ns}
951 \@onlypreamble\@xprocess@ptions
952 %    \end{macrocode}
954 % The common part of |\ProcessOptions| and |\ProcessOptions*|.
955 %    \begin{macrocode}
956 \def\@process@pti@ns{%
957   \@for\CurrentOption:=\@curroptions\do{%
958     \@ifundefined{ds@\CurrentOption}%
959       {\@use@ption
960        \default@ds}%
961 %    \end{macrocode}
962 % There should not be any non-empty definition of |\CurrentOption| at
963 % this point, as all the declared options were executed earlier. This is
964 % for compatibility with 2.09 styles which use |\def\ds@|\ldots\
965 % directly, and so have options which do not appear in
966 % |\@declaredoptions|.
967 %    \begin{macrocode}
968       \@use@ption}%
969 %    \end{macrocode}
970 % Clear all the definitions for option code. First set all the declared
971 % options to |\relax|, then reset the `default' and `empty' options. and
972 % the lst of declared options.
973 %    \begin{macrocode}
974   \@for\CurrentOption:=\@declaredoptions\do{%
975     \expandafter\let\csname ds@\CurrentOption\endcsname\relax}%
976 %    \end{macrocode}
977 % \changes{v1.0r}{1995/10/17}
978 %         {Reset \cs{CurrentOption} for graphics/1873}
979 %    \begin{macrocode}
980   \let\CurrentOption\@empty
981   \let\@fileswith@pti@ns\@@fileswith@pti@ns
982   \AtEndOfPackage{\let\@unprocessedoptions\relax}}
983 \@onlypreamble\@process@pti@ns
984 %    \end{macrocode}
985 % \end{macro}
986 % \end{macro}
988 % \begin{macro}{\@options}
989 % |\@options| is a synonym for |\ProcessOptions*| for upward
990 % compatibility with \LaTeX2.09 style files.
991 %    \begin{macrocode}
992 \def\@options{\ProcessOptions*}
993 \@onlypreamble\@options
994 %    \end{macrocode}
995 % \end{macro}
997 % \begin{macro}{\@use@ption}
998 % Execute the code for the current option.
999 % \changes{v0.2g}{1993/11/23}
1000 %         {Name changed from \cs{@executeoption}}
1001 % \changes{v1.0e}{1994/05/17}
1002 %         {Execute option after removing from list, not before}
1003 %    \begin{macrocode}
1004 \def\@use@ption{%
1005   \@expandtwoargs\@removeelement\CurrentOption
1006   \@unusedoptionlist\@unusedoptionlist
1007   \csname ds@\CurrentOption\endcsname}
1008 \@onlypreamble\@use@ption
1009 %    \end{macrocode}
1010 % \end{macro}
1012 % \begin{macro}{\ExecuteOptions}
1013 % |\ExecuteOptions{|\meta{option-list}|}| executes the code declared
1014 % for each option.
1015 % \changes{v0.2d}{1993/11/18}
1016 %         {Use \cs{CurrentOption} not \cs{reserved@a}}
1017 % \changes{v0.2k}{1993/12/06}
1018 %         {Preserve \cs{CurrentOption}.}
1019 %    \begin{macrocode}
1020 %</2ekernel>
1021 %<latexrelease>\IncludeInRelease{2017/01/01}%
1022 %<latexrelease>                 {\@if@pti@ns}{Spaces in \ExecuteOptions}%
1023 %<*2ekernel|latexrelease>
1024 \def\ExecuteOptions#1{%
1025 %    \end{macrocode}
1026 % \changes{v1.2a}{2016/10/02}
1027 %         {Ignore spaces in argument}
1028 % Use |\@fortmp| here as it is anyway cleared during |\@for| loop
1029 % so does not change any existing names.
1030 %    \begin{macrocode}
1031   \edef\@fortmp{\zap@space#1 \@empty}%
1032   \def\reserved@a##1\@nil{%
1033     \@for\CurrentOption:=\@fortmp\do
1034              {\csname ds@\CurrentOption\endcsname}%
1035     \edef\CurrentOption{##1}}%
1036   \expandafter\reserved@a\CurrentOption\@nil}
1037 %</2ekernel|latexrelease>
1038 %<latexrelease>\EndIncludeInRelease
1039 %<latexrelease>\IncludeInRelease{0000/00/00}%
1040 %<latexrelease>                 {\@if@pti@ns}{Spaces in \ExecuteOptions}%
1041 %<latexrelease>\def\ExecuteOptions#1{%
1042 %<latexrelease>  \def\reserved@a##1\@nil{%
1043 %<latexrelease>    \@for\CurrentOption:=#1\do
1044 %<latexrelease>             {\csname ds@\CurrentOption\endcsname}%
1045 %<latexrelease>    \edef\CurrentOption{##1}}%
1046 %<latexrelease>  \expandafter\reserved@a\CurrentOption\@nil}
1047 %<*2ekernel>
1048 %    \end{macrocode}
1050 %    \begin{macrocode}
1051 \@onlypreamble\ExecuteOptions
1052 %    \end{macrocode}
1053 % \end{macro}
1055 % The top-level commands, which just set some parameters then call
1056 % the internal command, |\@fileswithoptions|.
1057 % \begin{macro}{\documentclass}
1058 % \changes{v1.0q}{1995/06/19}
1059 %         {Dont redefine \cs{usepackage} in compat mode for /1634}
1060 % The main new-style class declaration.
1061 %    \begin{macrocode}
1062 \def\documentclass{%
1063   \let\documentclass\@twoclasseserror
1064   \if@compatibility\else\let\usepackage\RequirePackage\fi
1065   \@fileswithoptions\@clsextension}
1066 \@onlypreamble\documentclass
1067 %    \end{macrocode}
1068 % \end{macro}
1070 % \begin{macro}{\documentstyle}
1071 % 2.09 style class `style' declaration.
1072 % \changes{v0.2a}{1993/11/14}
1073 %         {Added \cs{RequirePackage} \cs{@unusedoptionlist} stuff.}
1074 % \changes{v0.2b}{1993/11/15}
1075 %         {Modified to match \cs{ProcessOption*}}
1076 % \changes{v0.2d}{1993/11/18}
1077 %         {Modified \cs{RequirePackage} stuff.}
1078 % \changes{v0.2n}{1993/12/09}
1079 %         {input 209 compatibility file.}
1080 % \changes{v0.2o}{1993/12/13}
1081 %         {compatibility file now latex209.sty.}
1082 % \changes{v0.2q}{1993/12/17}
1083 %         {Match Alan's new code.}
1084 % \changes{v0.2u}{1994/01/21}
1085 %         {compatibility file now latex209.def.}
1086 %    \begin{macrocode}
1087 \def\documentstyle{%
1088   \makeatletter\input{latex209.def}\makeatother
1089   \documentclass}
1090 \@onlypreamble\documentstyle
1091 %    \end{macrocode}
1092 % \end{macro}
1094 % \begin{macro}{\RequirePackage}
1095 % Load package if not already loaded.
1096 %    \begin{macrocode}
1097 \def\RequirePackage{%
1098   \@fileswithoptions\@pkgextension}
1099 \@onlypreamble\RequirePackage
1100 %    \end{macrocode}
1101 % \end{macro}
1103 % \begin{macro}{\LoadClass}
1104 % Load class.
1105 %    \begin{macrocode}
1106 \def\LoadClass{%
1107   \ifx\@currext\@pkgextension
1108      \@latex@error
1109       {\noexpand\LoadClass in package file}%
1110       {You may only use \noexpand\LoadClass in a class file.}%
1111   \fi
1112   \@fileswithoptions\@clsextension}
1113 \@onlypreamble\LoadClass
1114 %    \end{macrocode}
1115 % \end{macro}
1117 % \begin{macro}{\@loadwithoptions}
1118 % \changes{v1.0t}{1995/11/14}{macro added}
1119 % Pass the current option list on to a class or package.
1120 % |#1| is |\@|\emph{cls-or-pkg}|extension|,
1121 % |#2| is |\RequirePackage| or |\LoadClass|,
1122 % |#3| is the class or package to be loaded.
1123 %    \begin{macrocode}
1124 \def\@loadwithoptions#1#2#3{%
1125   \expandafter\let\csname opt@#3.#1\expandafter\endcsname
1126        \csname opt@\@currname.\@currext\endcsname
1127    #2{#3}}
1128 \@onlypreamble\@loadwithoptions
1129 %    \end{macrocode}
1130 % \end{macro}
1133 % \begin{macro}{\LoadClassWithOptions}
1134 % \changes{v1.0t}{1995/11/14}{macro added}
1135 % Load class `|#1|' with the current option list.
1136 %    \begin{macrocode}
1137 \def\LoadClassWithOptions{%
1138   \@loadwithoptions\@clsextension\LoadClass}
1139 \@onlypreamble\LoadClassWithOptions
1140 %    \end{macrocode}
1141 % \end{macro}
1143 % \begin{macro}{\RequirePackageWithOptions}
1144 % \changes{v1.0t}{1995/11/14}{macro added}
1145 % \changes{v1.0v}{1996/10/04}{Reset \cs{@unprocessedoptions} for /2269}
1146 % Load package `|#1|' with the current option list.
1147 %    \begin{macrocode}
1148 \def\RequirePackageWithOptions{%
1149   \AtEndOfPackage{\let\@unprocessedoptions\relax}%
1150   \@loadwithoptions\@pkgextension\RequirePackage}
1151 \@onlypreamble\RequirePackageWithOptions
1152 %    \end{macrocode}
1153 % \end{macro}
1155 % \begin{macro}{\usepackage}
1156 %    To begin with, |\usepackage| produces an error.  This is reset by
1157 %    |\documentclass|.
1158 % \changes{v0.2o}{1993/12/13}
1159 %         {Fixed error handling}
1160 % \changes{v1.0h}{1994/05/23}{Remove argument if possible}
1161 %    \begin{macrocode}
1162 \def\usepackage#1#{%
1163   \@latex@error
1164     {\noexpand \usepackage before \string\documentclass}%
1165     {\noexpand \usepackage may only appear in the document
1166       preamble, i.e.,\MessageBreak
1167       between \noexpand\documentclass and
1168       \string\begin{document}.}%
1169   \@gobble}
1170 \@onlypreamble\usepackage
1171 %    \end{macrocode}
1172 % \end{macro}
1174 % \begin{macro}{\NeedsTeXFormat}
1175 % Check that the document is running on the correct system.
1176 % \changes{v0.2a}{1993/11/14}
1177 %         {made more robust for alternative syntax for other formats.}
1178 % \changes{v0.2c}{1993/11/17}
1179 %         {Name changed from \cs{NeedsFormat}}
1180 % \changes{v0.2d}{1993/11/18}
1181 %         {\cs{fmtname} \cs{fmtversion} not \cs{@}\ldots}
1182 %    \begin{macrocode}
1183 \def\NeedsTeXFormat#1{%
1184   \def\reserved@a{#1}%
1185   \ifx\reserved@a\fmtname
1186     \expandafter\@needsformat
1187   \else
1188      \@latex@error{This file needs format `\reserved@a'%
1189        \MessageBreak but this is `\fmtname'}{%
1190        The current input file will not be processed
1191        further,\MessageBreak
1192        because it was written for some other flavor of
1193        TeX.\MessageBreak\@ehd}%
1194 %    \end{macrocode}
1195 %    If the file is not meant to be processed by \LaTeXe{} we stop
1196 %    inputting it, but we do not end the run. We just end inputting
1197 %    the current file.
1198 % \changes{v1.0h}{1994/05/23}
1199 %     {Don't stop completely when format is wrong}
1200 %    \begin{macrocode}
1201      \endinput \fi}
1202 \@onlypreamble\NeedsTeXFormat
1203 %    \end{macrocode}
1205 %    \begin{macrocode}
1206 \def\@needsformat{%
1207   \@ifnextchar[%]
1208     \@needsf@rmat
1209     {}}
1210 \@onlypreamble\@needsformat
1211 %    \end{macrocode}
1213 % \changes{v1.0b}{1994/05/04}
1214 %         {Changed wording of the warning}
1215 %    \begin{macrocode}
1216 \def\@needsf@rmat[#1]{%
1217     \@ifl@t@r\fmtversion{#1}{}%
1218     {\@latex@warning@no@line
1219         {You have requested release `#1' of LaTeX,\MessageBreak
1220          but only release `\fmtversion' is available}}}
1221 \@onlypreamble\@needsf@rmat
1222 %    \end{macrocode}
1223 % \end{macro}
1225 % \begin{macro}{\zap@space}
1226 % |\zap@space foo|\meta{space}|\@empty| removes all spaces from |foo|
1227 % that are not protected by |{ }| groups.
1228 %    \begin{macrocode}
1229 \def\zap@space#1 #2{%
1230   #1%
1231   \ifx#2\@empty\else\expandafter\zap@space\fi
1232   #2}
1233 %    \end{macrocode}
1234 % \end{macro}
1236 % \begin{macro}{\@fileswithoptions}
1237 % The common part of |\documentclass| and |\usepackage|.
1238 %    \begin{macrocode}
1239 \def\@fileswithoptions#1{%
1240   \@ifnextchar[%]
1241     {\@fileswith@ptions#1}%
1242     {\@fileswith@ptions#1[]}}
1243 \@onlypreamble\@fileswithoptions
1244 %    \end{macrocode}
1246 % \changes{v0.2f}{1993/11/22}
1247 %         {Made the default [] not [\cs{@unknownversion}]}
1248 % \changes{v1.1h}{2007/08/05}
1249 %         {Prevent loss of brackets PR/3965}
1250 %    \begin{macrocode}
1251 \def\@fileswith@ptions#1[#2]#3{%
1252   \@ifnextchar[%]
1253   {\@fileswith@pti@ns#1[{#2}]#3}%
1254   {\@fileswith@pti@ns#1[{#2}]#3[]}}
1255 \@onlypreamble\@fileswith@ptions
1256 %    \end{macrocode}
1257 % Then we do some work.
1259 % First of all, we define the global variables.
1260 % Then we look to see if the file has already been loaded.
1261 % If it has, we check that it was first loaded with at least the current
1262 % options.
1263 % If it has not, we add the current options to the package options,
1264 % set the default version to be |0000/00/00|, and load the file if we
1265 % can find it.
1266 % Then we check the version number.
1268 % Finally, we restore the old file name, reset the default option,
1269 % and we set the catcode of |@|.
1271 % For classes, we can immediately process the file. For other types,
1272 % |#2| could be a comma separated list, so loop through, processing
1273 % each one separately.
1274 % \changes{v0.2q}{1993/12/17}
1275 %         {Add \cs{@compatibility} hook}
1276 % \changes{v0.2s}{1994/01/17}
1277 %         {Modify to reduce parameter stack usage}
1278 % \changes{v0.2y}{1994/02/07}
1279 %         {Run \cs{@compatibility} on the first class to start
1280 %          (not the first to finish) }
1281 % \changes{v0.2z}{1994/02/10}
1282 %         {Renamed \cs{@compatibility} to \cs{@documentclasshook}.
1283 %          ASAJ.}
1284 % \changes{v1.1h}{2007/08/05}
1285 %         {Prevent loss of brackets PR/3965}
1286 % \changes{v2.1b}{2016/11/09}
1287 %         {Improve \cs{ifx} tests PR/4497}
1288 %    \begin{macrocode}
1289 %</2ekernel>
1290 %<latexrelease>\IncludeInRelease{2017/01/01}%
1291 %<latexrelease>        {\@fileswith@pti@ns}{ifx tests in \@fileswith@pti@ns}%
1292 %<*2ekernel|latexrelease>
1293 \def\@fileswith@pti@ns#1[#2]#3[#4]{%
1294   \ifx#1\@clsextension
1295     \ifx\@classoptionslist\relax
1296       \xdef\@classoptionslist{\zap@space#2 \@empty}%
1297       \def\reserved@a{%
1298         \@onefilewithoptions#3[{#2}][{#4}]#1%
1299         \@documentclasshook}%
1300     \else
1301       \def\reserved@a{%
1302         \@onefilewithoptions#3[{#2}][{#4}]#1}%
1303     \fi
1304   \else
1305 %    \end{macrocode}
1306 % build up a list of calls to |\@onefilewithoptions|
1307 % (one for each package) without thrashing the parameter stack.
1308 %    \begin{macrocode}
1309     \def\reserved@b##1,{%
1310 %    \end{macrocode}
1311 % If |#1| is |\@nnil| we have reached the end of the list 
1312 % (older version used |\@nil| here but |\@nil| is undefined so |\ifx| 
1313 % equal to all undefined commands)
1314 %    \begin{macrocode}
1315       \ifx\@nnil##1\relax\else
1316 %    \end{macrocode}
1317 %  If |\ifx\@nnil##1\n@nil| is true then |#1| is (presumably) empty
1318 % (Older code used |\relax| which is slighly easier to get into |#1|
1319 % by mistake, which would spoil this test.)
1320 %    \begin{macrocode}
1321         \ifx\@nnil##1\@nnil\else
1322 %    \end{macrocode}
1324 %    \begin{macrocode}
1325          \noexpand\@onefilewithoptions##1[{#2}][{#4}]%
1326          \noexpand\@pkgextension
1327         \fi
1328         \expandafter\reserved@b
1329       \fi}%
1330       \edef\reserved@a{\zap@space#3 \@empty}%
1331       \edef\reserved@a{\expandafter\reserved@b\reserved@a,\@nnil,}%
1332   \fi
1333   \reserved@a}
1334 %</2ekernel|latexrelease>
1335 %    \end{macrocode}
1337 %    \begin{macrocode}
1338 %<latexrelease>\EndIncludeInRelease
1339 %<latexrelease>\IncludeInRelease{0000/00/00}%
1340 %<latexrelease>        {\@fileswith@pti@ns}{ifx tests in \@fileswith@pti@ns}%
1341 %<latexrelease>\def\@fileswith@pti@ns#1[#2]#3[#4]{%
1342 %<latexrelease>  \ifx#1\@clsextension
1343 %<latexrelease>    \ifx\@classoptionslist\relax
1344 %<latexrelease>      \xdef\@classoptionslist{\zap@space#2 \@empty}%
1345 %<latexrelease>      \def\reserved@a{%
1346 %<latexrelease>        \@onefilewithoptions#3[{#2}][{#4}]#1%
1347 %<latexrelease>        \@documentclasshook}%
1348 %<latexrelease>    \else
1349 %<latexrelease>      \def\reserved@a{%
1350 %<latexrelease>        \@onefilewithoptions#3[{#2}][{#4}]#1}%
1351 %<latexrelease>    \fi
1352 %<latexrelease>  \else
1353 %<latexrelease>    \def\reserved@b##1,{%
1354 %<latexrelease>      \ifx\@nil##1\relax\else
1355 %<latexrelease>        \ifx\relax##1\relax\else
1356 %<latexrelease>         \noexpand\@onefilewithoptions##1[{#2}][{#4}]%
1357 %<latexrelease>         \noexpand\@pkgextension
1358 %<latexrelease>        \fi
1359 %<latexrelease>        \expandafter\reserved@b
1360 %<latexrelease>      \fi}%
1361 %<latexrelease>      \edef\reserved@a{\zap@space#3 \@empty}%
1362 %<latexrelease>      \edef\reserved@a{%
1363 %<latexrelease>        \expandafter\reserved@b\reserved@a,\@nil,}%
1364 %<latexrelease>  \fi
1365 %<latexrelease>  \reserved@a}
1366 %<*2ekernel>
1367 %    \end{macrocode}
1369 %    \begin{macrocode}
1370 \@onlypreamble\@fileswith@pti@ns
1371 %    \end{macrocode}
1373 % Have the main argument as |#1|, so we only need one |\expandafter|
1374 % above.
1375 % \changes{v0.2a}{1993/11/14}
1376 %         {Moved resetting of \cs{default@ds}, \cs{ds@} and
1377 %         \cs{@declaredoptions} here, from the end of
1378 %         \cs{ProcessOptions}.}
1379 % \changes{v0.2f}{1993/11/22}
1380 %         {Made the initial version [] not [\cs{@unknownversion}]}
1381 % \changes{v0.2m}{1993/12/07}
1382 %         {Reset \cs{CurrentOption}}
1383 %    \begin{macrocode}
1384 \def\@onefilewithoptions#1[#2][#3]#4{%
1385   \@pushfilename
1386   \xdef\@currname{#1}%
1387   \global\let\@currext#4%
1388   \expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
1389   \let\CurrentOption\@empty
1390   \@reset@ptions
1391   \makeatletter
1392 %    \end{macrocode}
1393 % Grab everything in a macro, so the parameter stack is popped before
1394 % any processing begins.
1395 % \changes{v0.2s}{1994/01/17}
1396 %         {Modify to reduce parameter stack usage}
1397 % \changes{v1.1b}{1998/05/07}
1398 %         {Modify help message for latex/2805}
1399 %    \begin{macrocode}
1400   \def\reserved@a{%
1401     \@ifl@aded\@currext{#1}%
1402       {\@if@ptions\@currext{#1}{#2}{}%
1403         {\@latex@error
1404             {Option clash for \@cls@pkg\space #1}%
1405             {The package #1 has already been loaded
1406              with options:\MessageBreak
1407              \space\space[\@ptionlist{#1.\@currext}]\MessageBreak
1408              There has now been an attempt to load it
1409               with options\MessageBreak
1410              \space\space[#2]\MessageBreak
1411              Adding the global options:\MessageBreak
1412              \space\space
1413                   \@ptionlist{#1.\@currext},#2\MessageBreak
1414              to your \noexpand\documentclass declaration may fix this.%
1415              \MessageBreak
1416              Try typing \space <return> \space to proceed.}}}%
1417       {\@pass@ptions\@currext{#2}{#1}%
1418 %    \end{macrocode}
1419 % \changes{v0.3c}{1994/03/12}
1420 %         {Do not use \cs{@pr@videpackage} to avoid typeout}
1421 %    \begin{macrocode}
1422        \global\expandafter
1423        \let\csname ver@\@currname.\@currext\endcsname\@empty
1424        \InputIfFileExists
1425          {\@currname.\@currext}%
1426          {}%
1427          {\@missingfileerror\@currname\@currext}%
1428 %    \end{macrocode}
1429 % |\@unprocessedoptions| will generate an error for each specified
1430 % option in a package unless a |\ProcessOptions| has appeared in the
1431 % package file.
1432 % \changes{v0.2v}{1994/01/29}
1433 %         {All options raise error if no \cs{ProcessOptions} appears}
1434 % \changes{v0.2x}{1994/02/02}
1435 %         {Only run the hook and options check if the file was loaded.}
1436 %    \begin{macrocode}
1437     \let\@unprocessedoptions\@@unprocessedoptions
1438     \csname\@currname.\@currext-h@@k\endcsname
1439     \expandafter\let\csname\@currname.\@currext-h@@k\endcsname
1440               \@undefined
1441     \@unprocessedoptions}
1442 %    \end{macrocode}
1444 %    \begin{macrocode}
1445     \@ifl@ter\@currext{#1}{#3}{}%
1446       {\@latex@warning@no@line
1447          {You have requested,\on@line,
1448           version\MessageBreak
1449             `#3' of \@cls@pkg\space #1,\MessageBreak
1450           but only version\MessageBreak
1451            `\csname ver@#1.\@currext\endcsname'\MessageBreak
1452           is available}}%
1453 %    \end{macrocode}
1454 % \changes{v0.2c}{1993/11/17}
1455 %         {Added trap for two \cs{LoadClass} commands.}
1456 %    \begin{macrocode}
1457     \ifx\@currext\@clsextension\let\LoadClass\@twoloadclasserror\fi
1458     \@popfilename
1459     \@reset@ptions}%
1460   \reserved@a}
1461 \@onlypreamble\@onefilewithoptions
1462 %    \end{macrocode}
1463 % \end{macro}
1465 % \begin{macro}{\@@fileswith@pti@ns}
1466 % Save the definition (for error checking).
1467 % \changes{v0.2c}{1993/11/17}
1468 %         {Macro added}
1469 %    \begin{macrocode}
1470 \let\@@fileswith@pti@ns\@fileswith@pti@ns
1471 \@onlypreamble\@@fileswith@pti@ns
1472 %    \end{macrocode}
1473 % \end{macro}
1475 % \begin{macro}{\@reset@ptions}
1476 % Reset the default option, and clear lists of declared options.
1477 % \changes{v0.2a}{1993/11/14}{macro added}
1478 %    \begin{macrocode}
1479 \def\@reset@ptions{%
1480   \global\ifx\@currext\@clsextension
1481     \let\default@ds\OptionNotUsed
1482    \else
1483     \let\default@ds\@unknownoptionerror
1484   \fi
1485   \global\let\ds@\@empty
1486   \global\let\@declaredoptions\@empty}
1487 \@onlypreamble\@reset@ptions
1488 %    \end{macrocode}
1489 % \end{macro}
1491 % \subsection{Hooks}
1493 % Allow code do be saved to be executed at specific later times.
1495 % Save things in macros, I considered using toks registers, (and
1496 % |\addto@hook| from the NFSS code, that would require stacking the
1497 % contents in the case of required packages, so just generate a new
1498 % macro for each package.
1499 % \begin{macro}{\@begindocumenthook}
1500 % \changes{v1.0s}{1995/10/20}
1501 %         {Make setting conditional, for autoload version}
1502 % \begin{macro}{\@enddocumenthook}
1503 % Stuff to appear at the beginning or end of the document.
1504 %    \begin{macrocode}
1505 \ifx\@begindocumenthook\@undefined
1506   \let\@begindocumenthook\@empty
1508 \let\@enddocumenthook\@empty
1509 %    \end{macrocode}
1510 % \end{macro}
1511 % \end{macro}
1513 % \begin{macro}{\g@addto@macro}
1514 % Globally add to the end of a macro.
1515 % \changes{v0.2a}{1993/11/14}{Made global}
1516 % \changes{v0.2w}{1994/01/31}
1517 %     {Use toks register to avoid `hash' problems}
1518 % \changes{v1.0o}{1995/05/17}
1519 %     {Make long for latex/1522}
1520 % \changes{v1.0w}{1996/12/17}
1521 %     {Use \cs{begingroup} to save making a mathord}
1522 % \changes{v1.0x}{1997/02/05}
1523 %     {missing percent /2402}
1524 %    \begin{macrocode}
1525 \long\def\g@addto@macro#1#2{%
1526   \begingroup
1527     \toks@\expandafter{#1#2}%
1528     \xdef#1{\the\toks@}%
1529   \endgroup}
1530 %    \end{macrocode}
1531 % \end{macro}
1533 % \begin{macro}{\AtEndOfPackage}
1534 % \begin{macro}{\AtEndOfClass}
1535 % \begin{macro}{\AtBeginDocument}
1536 % \begin{macro}{\AtEndDocument}
1537 % The access functions.
1538 % \changes{v0.2a}{1993/11/14}
1539 %         {Included extension in the generated macro name for package
1540 %         and class hooks.}
1541 %    \begin{macrocode}
1542 \def\AtEndOfPackage{%
1543   \expandafter\g@addto@macro\csname\@currname.\@currext-h@@k\endcsname}
1544 \let\AtEndOfClass\AtEndOfPackage
1545 \@onlypreamble\AtEndOfPackage
1546 \@onlypreamble\AtEndOfClass
1547 %    \end{macrocode}
1549 %    \begin{macrocode}
1550 \def\AtBeginDocument{\g@addto@macro\@begindocumenthook}
1551 \def\AtEndDocument{\g@addto@macro\@enddocumenthook}
1552 \@onlypreamble\AtBeginDocument
1553 %    \end{macrocode}
1554 % \end{macro}
1555 % \end{macro}
1556 % \end{macro}
1557 % \end{macro}
1560 % \begin{macro}{\@cls@pkg}
1561 %    The current file type.
1562 % \changes{v0.2i}{1993/12/03}
1563 %         {Name changed to avoid clash with output routine.}
1564 %    \begin{macrocode}
1565 \def\@cls@pkg{%
1566   \ifx\@currext\@clsextension
1567     document class%
1568   \else
1569     package%
1570   \fi}
1571 \@onlypreamble\@cls@pkg
1572 %    \end{macrocode}
1573 % \end{macro}
1575 % \begin{macro}{\@unknownoptionerror}
1576 % Bad option.
1577 %    \begin{macrocode}
1578 \def\@unknownoptionerror{%
1579   \@latex@error
1580     {Unknown option `\CurrentOption' for \@cls@pkg\space`\@currname'}%
1581     {The option `\CurrentOption' was not declared in
1582      \@cls@pkg\space`\@currname', perhaps you\MessageBreak
1583       misspelled its name.
1584      Try typing \space <return>
1585      \space to proceed.}}
1586 \@onlypreamble\@unknownoptionerror
1587 %    \end{macrocode}
1588 % \end{macro}
1590 % \begin{macro}{\@@unprocessedoptions}
1591 % Declare an error for each option, unless a |\ProcessOptions| occurred.
1592 % \changes{v0.2v}{1994/01/29}
1593 %         {Macro added.}
1594 % \changes{v1.0t}{1995/11/14}{Allow empty option}
1595 %    \begin{macrocode}
1596 \def\@@unprocessedoptions{%
1597   \ifx\@currext\@pkgextension
1598     \edef\@curroptions{\@ptionlist{\@currname.\@currext}}%
1599     \@for\CurrentOption:=\@curroptions\do{%
1600         \ifx\CurrentOption\@empty\else\@unknownoptionerror\fi}%
1601   \fi}
1602 \@onlypreamble\@unprocessedoptions
1603 \@onlypreamble\@@unprocessedoptions
1604 %    \end{macrocode}
1605 % \end{macro}
1607 % \begin{macro}{\@badrequireerror}
1608 % |\RequirePackage| or |\LoadClass| occurs in the options section.
1609 % \changes{v0.2c}{1993/11/17}
1610 %         {Macro added}
1611 %    \begin{macrocode}
1612 \def\@badrequireerror#1[#2]#3[#4]{%
1613   \@latex@error
1614     {\noexpand\RequirePackage or \noexpand\LoadClass
1615          in Options Section}%
1616     {The \@cls@pkg\space `\@currname' is defective.\MessageBreak
1617      It attempts to load `#3' in the options section, i.e.,\MessageBreak
1618      between \noexpand\DeclareOption and \string\ProcessOptions.}}
1619 \@onlypreamble\@badrequireerror
1620 %    \end{macrocode}
1621 % \end{macro}
1623 % \begin{macro}{\@twoloadclasserror}
1624 % Two |\LoadClass| in a class.
1625 % \changes{v0.2c}{1993/11/17}
1626 %         {Macro added}
1627 %    \begin{macrocode}
1628 \def\@twoloadclasserror{%
1629   \@latex@error
1630     {Two \noexpand\LoadClass commands}%
1631     {You may only use one \noexpand\LoadClass in a class file}}
1632 \@onlypreamble\@twoloadclasserror
1633 %    \end{macrocode}
1634 % \end{macro}
1636 % \begin{macro}{\@twoclasseserror}
1637 % Two |\documentclass| or |\documentstyle|.
1638 % \changes{v0.2h}{1993/11/28}
1639 %         {Macro added}
1640 %    \begin{macrocode}
1641 \def\@twoclasseserror#1#{%
1642   \@latex@error
1643     {Two \noexpand\documentclass or \noexpand\documentstyle commands}%
1644     {The document may only declare one class.}\@gobble}
1645 \@onlypreamble\@twoclasseserror
1646 %    \end{macrocode}
1647 % \end{macro}
1649 % \subsection{Providing shipment}
1651 % \begin{macro}{\two@digits}
1652 % Prefix a number less than 10 with `0'.
1653 %    \begin{macrocode}
1654 \def\two@digits#1{\ifnum#1<10 0\fi\number#1}
1655 %    \end{macrocode}
1656 % \end{macro}
1658 %  \begin{macro}{\filecontents}
1659 %  \begin{macro}{\endfilecontents}
1660 %    This environment implements inline files.
1661 %    The star-form does not write extra comments into the file.
1663 % \changes{v0.2h}{1993/11/28}
1664 %         {Don't globally allocate a write stream (always use 15)}
1665 % \changes{v0.2r}{1993/12/19}{Different message when ignoring a file}
1666 % \changes{v0.3g}{1994/04/11}
1667 %         {Add star form,
1668 %          dont write \cs{endinput} at the end of the file.}
1669 % \changes{v1.0c}{1994/05/11}
1670 %         {Add checks for form feed and tab}
1671 % \changes{v1.0m}{1995/04/21}
1672 %         {Close input check stream: latex/1487}
1673 % \changes{v1.0p}{1995/05/25}{Delete \cs{filec@ntents} after preamble}
1674 %    \begin{macrocode}
1675 \begingroup%
1676 \catcode`\*=11 %
1677 \catcode`\^^M\active%
1678 \catcode`\^^L\active\let^^L\relax%
1679 \catcode`\^^I\active%
1680 %    \end{macrocode}
1682 %    \begin{macrocode}
1683 \gdef\filecontents{\@tempswatrue\filec@ntents}%
1684 \gdef\filecontents*{\@tempswafalse\filec@ntents}%
1685 %    \end{macrocode}
1687 %    \begin{macrocode}
1688 \gdef\filec@ntents#1{%
1689   \openin\@inputcheck#1 %
1690   \ifeof\@inputcheck%
1691     \@latex@warning@no@line%
1692         {Writing file `\@currdir#1'}%
1693 %    \end{macrocode}
1695 % \changes{v1.0y}{1997/10/10}
1696 %         {\cs{reserved@c} not \cs{verbatim@out} to save a csname}
1697 %    \begin{macrocode}
1698     \chardef\reserved@c15 %
1699     \ch@ck7\reserved@c\write%
1700     \immediate\openout\reserved@c#1\relax%
1701   \else%
1702 %    \end{macrocode}
1704 % \changes{v1.0y}{1997/10/10}
1705 %         {Use \cs{@gobbletwo}}
1706 %    \begin{macrocode}
1707     \closein\@inputcheck%
1708     \@latex@warning@no@line%
1709             {File `#1' already exists on the system.\MessageBreak%
1710              Not generating it from this source}%
1711     \let\write\@gobbletwo%
1712     \let\closeout\@gobble%
1713   \fi%
1714   \if@tempswa%
1715 %    \end{macrocode}
1717 % \changes{v1.0y}{1997/10/10}
1718 %         {\cs{@currenvir} in banner}
1719 %    \begin{macrocode}
1720     \immediate\write\reserved@c{%
1721       \@percentchar\@percentchar\space%
1722           \expandafter\@gobble\string\LaTeX2e file `#1'^^J%
1723       \@percentchar\@percentchar\space  generated by the %
1724         `\@currenvir' \expandafter\@gobblefour\string\newenvironment^^J%
1725       \@percentchar\@percentchar\space from source `\jobname' on %
1726          \number\year/\two@digits\month/\two@digits\day.^^J%
1727       \@percentchar\@percentchar}%
1728   \fi%
1729   \let\do\@makeother\dospecials%
1730 %    \end{macrocode}
1732 % \changes{v1.0y}{1997/10/10}
1733 %     {Check for text before or after \cs{end} environment. latex/2636}
1734 %    \begin{macrocode}
1735   \edef\E{\@backslashchar end\string{\@currenvir\string}}%
1736   \edef\reserved@b{%
1737     \def\noexpand\reserved@b%
1738          ####1\E####2\E####3\relax}%
1739   \reserved@b{%
1740     \ifx\relax##3\relax%
1741 %    \end{macrocode}
1742 % There was no |\end{filecontents}|
1743 %    \begin{macrocode}
1744       \immediate\write\reserved@c{##1}%
1745     \else%
1746 %    \end{macrocode}
1747 % There was a |\end{filecontents}|, so stop this time.
1748 %    \begin{macrocode}
1749       \edef^^M{\noexpand\end{\@currenvir}}%
1750       \ifx\relax##1\relax%
1751       \else%
1752 %    \end{macrocode}
1753 % Text before the |\end|, write it with a warning.
1754 %    \begin{macrocode}
1755           \@latex@warning{Writing text `##1' before %
1756              \string\end{\@currenvir}\MessageBreak as last line of #1}%
1757         \immediate\write\reserved@c{##1}%
1758       \fi%
1759       \ifx\relax##2\relax%
1760       \else%
1761 %    \end{macrocode}
1762 % Text after the |\end|, ignore it with a warning.
1763 %    \begin{macrocode}
1764          \@latex@warning{%
1765            Ignoring text `##2' after \string\end{\@currenvir}}%
1766       \fi%
1767     \fi%
1768     ^^M}%
1769 %    \end{macrocode}
1771 %    \begin{macrocode}
1772   \catcode`\^^L\active%
1773   \let\L\@undefined%
1774   \def^^L{\@ifundefined L^^J^^J^^J}%
1775   \catcode`\^^I\active%
1776   \let\I\@undefined%
1777   \def^^I{\@ifundefined I\space\space}%
1778   \catcode`\^^M\active%
1779   \edef^^M##1^^M{%
1780     \noexpand\reserved@b##1\E\E\relax}}%
1781 \endgroup%
1782 %    \end{macrocode}
1784 %    \begin{macrocode}
1785 \begingroup
1786 \catcode`|=\catcode`\%
1787 \catcode`\%=12
1788 \catcode`\*=11
1789 \gdef\@percentchar{%}
1790 \gdef\endfilecontents{|
1791   \immediate\closeout\reserved@c
1792   \def\T##1##2##3{|
1793   \ifx##1\@undefined\else
1794     \@latex@warning@no@line{##2 has been converted to Blank ##3e}|
1795   \fi}|
1796   \T\L{Form Feed}{Lin}|
1797   \T\I{Tab}{Spac}|
1798   \immediate\write\@unused{}}
1799 \global\let\endfilecontents*\endfilecontents
1800 \@onlypreamble\filecontents
1801 \@onlypreamble\endfilecontents
1802 \@onlypreamble\filecontents*
1803 \@onlypreamble\endfilecontents*
1804 \endgroup
1805 \@onlypreamble\filec@ntents
1806 %    \end{macrocode}
1807 % \end{macro}
1808 % \end{macro}
1811 % \changes{v0.2f}{1993/11/22}
1812 %         {\cs{@unknownversion} removed}
1813 % \changes{v1.0j}{1994/10/18}
1814 %         {Move \cs{listfiles} to ltfiles.dtx}
1816 %    \begin{macrocode}
1817 %</2ekernel>
1818 %    \end{macrocode}
1820 % \section{After Preamble}
1821 % Finally we declare a package that allows all the commands declared
1822 % above to be |\@onlypreamble| to be used after |\begin{document}|.
1823 % \changes{v0.3f}{1994/03/16}
1824 %         {Add pkgindoc package}
1825 % \changes{v1.1a}{1998/03/21}
1826 %         {Correct to new onlypreamble command list}
1827 %    \begin{macrocode}
1828 %<*afterpreamble>
1829 \NeedsTeXFormat{LaTeX2e}
1830 \ProvidesPackage{pkgindoc}
1831          [1994/10/20 v1.1 Package Interface in Document (DPC)]
1832 \def\reserved@a#1\do\@classoptionslist#2\do\filec@ntents#3\relax{%
1833   \gdef\@preamblecmds{#1#3}}
1834 \expandafter\reserved@a\@preamblecmds\relax
1835 %</afterpreamble>
1836 %    \end{macrocode}
1838 % \Finale