summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/koma-script/scrlfile.dtx
blob: b2953f4b62f05039b9d45f8db47725ba3d72406a (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
% \CheckSum{263}
% \iffalse meta-comment
% ======================================================================
% scrlfile.dtx
% Copyright (c) Markus Kohm, 2002-2007
%
% This file is part of the LaTeX2e KOMA-Script bundle.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3b of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3b or later is part of all distributions of LaTeX 
% version 2005/12/01 or later and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of all files listed in manifest.txt.
% ----------------------------------------------------------------------
% scrlfile.dtx
% Copyright (c) Markus Kohm, 2002-2007
%
% Dieses Werk darf nach den Bedingungen der LaTeX Project Public Lizenz,
% Version 1.3b, verteilt und/oder veraendert werden.
% Die neuste Version dieser Lizenz ist
%   http://www.latex-project.org/lppl.txt
% und Version 1.3b ist Teil aller Verteilungen von LaTeX
% Version 2005/12/01 oder spaeter und dieses Werks.
%
% Dieses Werk hat den LPPL-Verwaltungs-Status "author-maintained"
% (allein durch den Autor verwaltet).
%
% Der Aktuelle Verwalter und Autor dieses Werkes ist Markus Kohm.
% 
% Dieses Werk besteht aus den in manifest.txt aufgefuehrten Dateien.
% ======================================================================
% \fi
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \iffalse
%%% From File: scrlfile.dtx
%<*driver|scrlfile|load>
% \fi
\def\scrlfileversion{2007/12/18 v2.98}
% \iffalse
%</driver|scrlfile|load>
%<*driver>
% \fi
\ProvidesFile{scrlfile.dtx}[%
% \iffalse
%</driver>
%<*driver|scrlfile>
%<scrlfile>\ProvidesPackage{scrlfile}[%
% \fi
  \scrlfileversion\space KOMA-Script package (loading files)]
% \iffalse
%</driver|scrlfile>
%<*driver>
\IfFileExists{scrdoc.cls}{%
  \documentclass[halfparskip-]{scrdoc}
}{%
  \documentclass{ltxdoc}
}
\providecommand*{\KOMAScript}{\textsf{KOMA-Script}}
\usepackage[german,english]{babel}
\CodelineIndex
\RecordChanges
\GetFileInfo{scrlfile.dtx}
\title{\KOMAScript{} \partname\ \texttt{\filename}%
  \thanks{This file is version \fileversion\ of file \texttt{\filename}.}}  
\date{\filedate}
\author{Markus Kohm\thanks{mailto:komascript@gmx.info}~\thanks{Parts of
    description sections of the documentation where written by Jens-Uwe
    Morawski.}}

\begin{document}
  \maketitle
  \begin{abstract}
    This package provides hooks before and after loading files, packages or
    classes. It also provides a hook after the last \cs{clearpage} of the
    document. It allowes to replace files, packages and classes by other
    files, packages and classes. It is inteded to be used by package and class
    authors but may also be used by \LaTeX{} users.
  \end{abstract}

  \section{Legal Note}
  This is the only part of \KOMAScript{} you are allowed to
  redistribute without all the other files of \KOMAScript.  You are
  allowed to redistribute and/or modifie the files
  ``\texttt{scrlogo.dtx}'', ``\texttt{scrlfile.dtx}'' and
  ``\texttt{scrlfile.ins}'' under the conditions of \LaTeX{} Project
  Public License, either version 1.3b of this license or (at your
  option) any later version.  The latest version of this license is in
  \mbox{http://www.latex-project.org/lppl.txt} and version 1.3b or
  later is part of all distributions of \LaTeX{} version 2005/12/01 or
  later.  You are not allowed to distribute one of the three files
  ``\texttt{scrlogo.dtx}'', ``\texttt{scrlfile.dtx}'' and
  ``\texttt{scrlfile.ins}'' without the others but all these files
  together.
  
  \KOMAScript{} is a versatile bundle of \LaTeX{} classes and
  packages. Large german and english manuals, both with more than
  200~pages, are part of \KOMAScript{} bundle.  You can find a longer
  version of the \textsf{scrlfile}-documentation at the \KOMAScript{}
  manuals. 
  
  You can find the latest version of \KOMAScript{} bundle and
  \texttt{scrlfile} at
  \mbox{CTAN:/macros/latex/contrib/supported/koma-script/} in the
  course of which ``CTAN:'' is a short hand synonym for directory
  ``tex-archive'' at every CTAN server and mirror, e.g.\ 
  \mbox{ftp://ftp.dante.de/tex-archive/}.  See
  \mbox{http://www.ctan.org} for a list of CTAN servers and mirrors.

  \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \selectlanguage{english}
%
% \changes{v2.95}{2002/06/11}{%
%   First version split from hugh scrclass.dtx}
%
%
% \section[Hook loading files, packages or classes]{%
%   Hooks loading files, packages or classes\footnote{You'll find a
%   short version of \textsf{scrlfile} documentation here. A longer
%   version may be found at english and german \KOMAScript{} manual.}}
%
% The introduction of \LaTeXe{} in 1994 brought many changes in the
% handling with \LaTeX-extensions.  Today the package author has many
% macros in order to determine if another package or class is employed
% and whether specific options are used.  The author can load other
% packages or can specify options in the the case the package is loaded
% later.  This has led to the expectation that the order of
% package-loading will be not important.  But this hope has not been
% fulfilled, since often different packages define or redefine one macro
% again and again.  In such a case the order of package-loading becomes
% very important.  For the user it is sometimes difficult to understand
% the behaviour and in some cases the user wants only react on the
% loading of a package.  This is also not really simple.
%     
% Assuming the simple example that loads the package \textsf{longtable}
% with a \KOMAScript{} document-class employed.  The \textsf{longtable}
% package defines table captions suitable for the standard classes, but
% the captions are totally unsuitable for documents using \KOMAScript{}
% and thus the provided configuration commands have no influence.  In
% order to solve this problem the commands which are responsible for the
% table captions of the \textsf{longtable} package have to be
% re-defined.  But at the moment when the \textsf{longtable} is loaded
% the \KOMAScript{} class is already processed.
% 
% The only chance for \KOMAScript{} was to delay the re-definition until
% the begin of the document with help of the macro |\AtBeginDocument|.
% If the user wants to change the definitions too, it is recommended to
% do this in the preamble of the document.  But this is impossible since
% later at |\begin{document}| \KOMAScript will again overwrite the
% user-definition with its own.  Therefore the user has to delay his
% definition with \verb|\AtBeginDocument| as well.
%
% However, \KOMAScript{} shouldn't delay the re-definition until
% |\begin{document}|.  It would be enough to delay until the package
% \textsf{longtable} has been loaded.  But unfortunately the basic
% \LaTeX{} does not define appropriate commands.  The package
% \textsf{scrlfile} provides redress here.
%  
% Likewise, it might be conceivable that before a package is loaded one
% would like to save the definition of a macro in a help-macro, in order
% to restore its meaning after the package has been loaded.  The package
% \textsf{scrlfile} allows this too.
%  
% The employment of \textsf{scrlfile} is not limited to package
% dependencies only.  Even dependencies with any other file can be
% attended.  For example the user can be warned if the not uncritical
% file \texttt{french.ldf} has been loaded.
% 
% Though the package is particularly interesting for package authors,
% there are of course applications for normal \LaTeX{} users too.
% Therefore this chapter gives and explains examples for both groups of
% users.
%
%
% \DescribeMacro{\BeforeFile}
% \DescribeMacro{\AfterFile}
% The command \cs{BeforeFile}\marg{file}\marg{instructions} enables to
% execute \meta{instructions} the next time the \meta{file} is
% loaded.  In the same way works \cs{AfterFile}, but here the
% \meta{instructions} will be executed after the \meta{file} has
% been loaded.  If \meta{file} will never be loaded then the
% \meta{instructions} will never be executed.
%
% In order to implement those features \textsf{scrlfile} re-defines
% the well known \LaTeX{} command \cs{InputIfFileExists}.  If this
% macro has not the expected definition \textsf{scrlfile} gives a
% warning.  This is for the case that in future \LaTeX{} versions the
% macro can have a different definition or an other package has
% already re-defined it.
%
% The command \cs{InputIfFileExists} is used everytime \LaTeX{} has to
% load a file.  This is independent from whether the actual command
% was \cs{LoadClass}, \cs{documentclass}, \cs{usepackage},
% \cs{RequiresPackage}, or \cs{include}. Exclusively the command
% \begin{verbatim}
%   \input foo
% \end{verbatim}\vspace{-\baselineskip}%
% loads the file \meta{foo} without to utilize
% \cs{InputIfFileExists}. Therefore one should always use 
% \begin{verbatim}
%   \input{foo}
% \end{verbatim}\vspace{-\baselineskip}%
% instead. Notice the parentheses surrounding the file name!
%
% \DescribeMacro{\BeforeClass}
% \DescribeMacro{\BeforePackage}
% The command \cs{BeforeClass}\marg{class}\marg{instructions} and the
% command \cs{BeforePackage}\marg{package}\marg{instructions} work
% the same way like the above described \cs{BeforeFile}.  The only
% difference is that the document \meta{class} and the \LaTeX{}
% \meta{package} are specified with their names and not with their
% file names.  That means the file extensions ``\texttt{.cls}'' and
% ``\texttt{.sty}'' have to be omitted.
%
% \DescribeMacro{\AfterClass}
% \DescribeMacro{\AfterClass*}
% \DescribeMacro{\AfterPackage}
% \DescribeMacro{\AfterPackage*}
% The command \cs{AfterClass}\marg{class}\marg{instructions} and the
% command \cs{AfterPackage}\marg{package}\marg{instructions} work the
% same way like command \cs{AfterFile}.  The only difference is that
% the document \meta{class} and the \LaTeX{} \meta{package} are
% specified with their names and not with their file names.  That
% means the file extensions ``\texttt{.cls}'' and ``\texttt{.sty}''
% have to be omitted.  The starred versions execute the
% \meta{instructions} not only next time the class or package is
% loaded, but also immediately if the class or package has been loaded
% already.
%
% \DescribeMacro{\ReplaceInput}
% The command \cs{ReplaceInput}\marg{name of file to be replaced}\marg{name of
% replacement file} sets up an replacement. Whenever \LaTeX{} is told to input
% the file with \meta{name of file to be replaced} it will input the file with
% \meta{name of replacement file} instead. With this you may even teill \LaTeX
% to input e.g. ``\texttt{\cs{jobname}.xua}'' instead of
% ``\texttt{\cs{jobname.aux}}'' using:
% \begin{verbatim}
%   \ReplaceInput{\jobname.aux}{\jobname.xua}
% \end{verbatim}\vspace{-\baselineskip}
% If you replace a replacement file both, the first replaced file and the
% replacement file will be replaced by the new replacement file. So
% \begin{verbatim}
%   \ReplaceInput{\jobname.aux}{\jobname.xua}
%   \ReplaceInput{\jobname.xua}{\jobname.uxa}
% \end{verbatim}\vspace{-\baselineskip}
% will replace ``\texttt{\cs{jobname}.aux}'' and ``\texttt{\cs{jobname}.xua}''
% by ``\texttt{\cs{jobname}.uxa}''. But ring replacement like
% \begin{verbatim}
%   \ReplaceInput{\jobname.aux}{\jobname.xua}
%   \ReplaceInput{\jobname.xua}{\jobname.aux}
% \end{verbatim}\vspace{-\baselineskip}
% would result in an stack size error. So you cannot input an already replaced
% file using \LaTeX{} commands.
%
% \DescribeMacro{\ReplaceClass}
% \DescribeMacro{\ReplacePackage}
% You should not replace a class or package using \cs{ReplaceInput}. If you do
% so, you'll get errors because of not matching class names. But you may use
% \cs{ReplaceClass}\marg{name of class to be replaced}\marg{name of
% replacement class} and \cs{ReplacePackage}\marg{name of package to be
% replaced}\marg{name of replacement package} instead. With this commands like
% \cs{documentclass}\marg{name of class to be replaced} would work like
% \cs{documentclass}\marg{name of replacement class}. Effected commands are
% \cs{LoadClass}, \cs{LoadClassWithOptions}, \cs{documentclass},
% \cs{RequirePackage}, \cs{RequirePackageWithOptions}, \cs{usepackage}.
%
% Note: The replacement class or package will be loaded with the same option
% list the replaced class or package would have been. If you replace a
% class or package with a class or package that does not know the options of
% the replaced class or package, you may declare the missing options using
% \cs{BeforeClass} and \cs{BeforePackage}.
%
% If you e.g. want to load package \texttt{newfoo} instead of package
% \texttt{oldfoo} you may use:
% \begin{verbatim}
%   \ReplacePackage{oldfoo}{newfoo}
% \end{verbatim}\vspace{-\baselineskip}
% And if the old package had an option \texttt{oldopt} but the new package
% does not you may use
% \begin{verbatim}
%   \BeforePackage{newfoo}{%
%     \DeclareOption{oldopt}{%
%       \PackageInfo{newfoo}{option ``oldopt'' not supported}%
%     }%
%   }
% \end{verbatim}\vspace{-\baselineskip}
% If new option \texttt{newopt} should be used instead of \texttt{oldopt} you
% may use:
% \begin{verbatim}
%   \BeforePackage{newfoo}{%
%     \DeclareOption{oldopt}{%
%       \ExecuteOption{newopt}%
%     }%
%   }
% \end{verbatim}\vspace{-\baselineskip}
% You may also set new default options using:
% \begin{verbatim}
%   \BeforePackage{newfoo}{%
%     \DeclareOption{oldopt}{%
%       \ExecuteOption{newopt}%
%     }%
%     \PassOptionsToPackage{newdefoptA,newdefoptB}{newfoo}%
%   }
% \end{verbatim}\vspace{-\baselineskip}
% or simply
% \begin{verbatim}
%   \BeforePackage{newfoo}{%
%     \DeclareOption{oldopt}{%
%       \ExecuteOption{newopt}%
%     }%
%   }
%   \PassOptionsToPackage{newdefoptA,newdefoptB}{newfoo}%
% \end{verbatim}\vspace{-\baselineskip}
% 
% Note: To replace classes you have to load \textsf{scrlfile} using
% \cs{RequirePackage} before loading the class.
%
% \DescribeMacro{\BeforeClosingMainAux}
% The command \cs{BeforeClosingMainAux}\marg{instructions}
% works different from all the commands above. Is isn't a
% load-file-hook. Package authors often have the problem, that they
% need to write something to \texttt{aux}-file after output of the
% last page. This is often done with:
% \begin{flushleft}
% |  \AtEndDocument{\if@filesw|\\
% |      \write\@auxout{%|\\
% |        |\texttt{\emph{Write this to aux.}}\\
% |      }%|\\
% |    \fi}|
% \end{flushleft}
% But this fails, if the last \cs{shipout} was already done
% e.g. because of someone used a different solution:
% \begin{flushleft}
% |  \AtEndDocument{\if@filesw\clearpage|\\
% |      \immediate\write\@auxout{%|\\
% |        |\texttt{\emph{Write this to aux.}}\\
% |      }%|\\
% |    \fi}|
% \end{flushleft}
% The best solution would be to immediate write to \texttt{aux}-file
% just after the \cs{clearpage} and before closing \texttt{aux}-file
% at \cs{end\{document\}}. That's the goal of
% \cs{BeforeClosingMainAux}:
% \begin{flushleft}
% |  \BeforeClosingMainAux{\if@filesw|\\
% |      \immediate\write\@auxout{%|\\
% |        |\texttt{\emph{Write this to aux.}}\\
% |      }%|\\
% |    \fi}|
% \end{flushleft}
% This even works, if \cs{clearpage} at \cs{end\{document\}} will not
% result in \cs{shipout} or if typessetting code\,---\,even
% \cs{clearpage}\,---\,has been used at \cs{AtEndDocument}.
%
% The \cs{BeforeClosingMainAux} hook should not be used for code that
% does any typesetting since the result of \cs{BeforeClosingMainAux}
% would be unpredictable.
%
%
% \StopEventually{\PrintIndex\PrintChanges}
%
% \iffalse
%<*scrlfile>
% \fi
%
% \subsection{Preamble}
%
% First of all we show the package and version at terminal and
% log-file:
%    \begin{macrocode}
\typeout{Package scrlfile, \csname ver@scrlfile.sty\endcsname%
  ^^J\@spaces\@spaces\@spaces\@spaces\space\space 
  Copyright (C) Markus Kohm^^J}
%    \end{macrocode}
%
%
% \subsection{Options}
%
% Currently there are no options.
%    \begin{macrocode}
\ExecuteOptions{}
\ProcessOptions\relax
%    \end{macrocode}
%
%
% \subsection{The macros}
%
%  \begin{macro}{\InputIfFileExists}
%    \changes{v2.96}{2006/07/19}{replacement code added}
% \LaTeX{} uses this macro for loading files with
% \cs{input}\marg{filename}, \cs{include}, \cs{LoadClass},
% \cs{LoadClassWithOptions}, \cs{documentclass}, \cs{documentstyle},
% \cs{RequirePackage}, \cs{usepackage}. Only
% \cs{input}~\meta{filename} loads \meta{filename} without using
% \cs{InputIfFileExists}.
%
% Because of this, it's very easy to add stuff before and after
% loading a file. We simply change this macro and add to
% macros\,---\,one before loading the file and one after loading the
% file. But before we redefine the macro, we test, if the macro was
% defined like we expected. \LaTeX{} will warn, if not.
%    \begin{macrocode}
\CheckCommand{\InputIfFileExists}[2]{%
  \IfFileExists{#1}%
    {#2\@addtofilelist{#1}\@@input \@filef@und}}
%    \end{macrocode}
% Now we can redefine the macro like described above:
%    \begin{macrocode}
\renewcommand{\InputIfFileExists}[2]{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname #1-@alias\endcsname\relax
    \expandafter\@secondoftwo
  \else
    \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
    \expandafter\@firstoftwo
  \fi
  {%
    \expandafter\InputIfFileExists\expandafter{\csname
      #1-@alias\endcsname}{#2}%
  }%
  {\IfFileExists{#1}{%
      \scr@load@hook{before}{#1}%
      #2\@addtofilelist{#1}%
      \@@input \@filef@und
      \scr@load@hook{after}{#1}%
    }}%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@loadwithoptions}
%    \changes{v2.96}{2006/07/19}{new redefinition}
%  \begin{macro}{\scr@loadwithoptions}
%    \changes{v2.96}{2006/07/19}{new helper macro}
%  \begin{macro}{\scr@@loadwithoptions}
%    \changes{v2.97a}{2007/03/07}{new helper macro}
% \LaTeX{} uses this macro for loading classes and packages using
% \cs{LoadClassWithOptions} or \cs{RequirePackageWithOptions}. We simply say
% now: if the class or package should be replaced by another, try it again
% with the replacement name. The stack is used. This will result in an
% error if the replacements are nested too deep. This should be, because it
% will also result in an error using ring replacements.
%    \begin{macrocode}
\newcommand*{\scr@@loadwithoptions}{}
\newcommand*{\scr@loadwithoptions}{}
\let\scr@loadwithoptions\@loadwithoptions
\renewcommand*{\@loadwithoptions}[3]{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname #3.#1-@aliasname\endcsname\relax
    \def\scr@@loadwithoptions{\scr@loadwithoptions{#1}{#2}{#3}}%
  \else
    \scr@replacefile@msg{\csname #3.#1-@aliasname\endcsname.#1}{#3.#1}% 
    \def\scr@@loadwithoptions{%
      \@loadwithoptions{#1}{#2}{\csname #3.#1-@aliasname\endcsname}%
    }%
  \fi
  \scr@@loadwithoptions
}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\@onefilewithoption}
%    \changes{v2.96}{2006/07/19}{new redefinition}
%  \begin{macro}{\scr@onefilewithoption}
%    \changes{v2.96}{2006/07/19}{new helper macro}
%  \begin{macro}{\scr@@onefilewithoption}
%    \changes{v2.98}{2007/12/18}{new helper macro}
% \LaTeX{} uses this macro for loading classes and packages using
% \cs{LoadClass}, \cs{documentclass}, \cs{RequirePackage}, and
% \cs{usepackage}. We simply say now: if the class or package should be
% replaced by another, try it again with the replacement name. The stack is
% used. This will result in an error if the replacements are nested too
% deep. This should be, because it will also result in an error using ring
% replacements.
%    \begin{macrocode}
\newcommand*{\scr@onefilewithoptions}{}
\let\scr@onefilewithoptions\@onefilewithoptions
\def\@onefilewithoptions#1[#2][#3]#4{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname #1.#4-@aliasname\endcsname\relax
%    \end{macrocode}
% Do this ridiculous definition and call outside of \cs{ifx}\dots\cs{fi}
% because of some errornous packages like some versions of
% \textsf{breakurl}. This does not avoid an error, but the message about
% unclosed \cs{if} will be outside of \textsf{scrlfile}.
%    \begin{macrocode}
    \def\scr@@onefilewithoptions{\scr@onefilewithoptions{#1}}%
  \else
    \scr@replacefile@msg{\csname #1.#4-@aliasname\endcsname.#4}{#1.#4}%
    \edef\scr@@onefilewithoptions{%
      \noexpand\@onefilewithoptions{\csname #1.#4-@aliasname\endcsname}}%
  \fi
  \scr@@onefilewithoptions[{#2}][{#3}]{#4}%
}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\ReplaceInput}
%    \changes{v2.96}{2006/07/19}{new command}
% Defining the replacement by definition of \cs{\#1-@alias}.
%    \begin{macrocode}
\newcommand*{\ReplaceFile}[2]{%
  \expandafter\edef\csname #1-@alias\endcsname{#2}%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ReplacePackage}
%    \changes{v2.96}{2006/07/19}{new command}
%  \begin{macro}{\ReplaceClass}
%    \changes{v2.96}{2006/07/19}{new command}
%  \begin{macro}{\@replacefilewithext}
%    \changes{v2.96}{2006/07/19}{new helper command}
% Note that replacing a package or class will not replace the input of the
% file of the package or class but only the input of package or class.
%    \begin{macrocode}
\newcommand*{\@replacefilewithext}[3]{%
  \expandafter\edef\csname #1.#3-@aliasname\endcsname{#2}%
}
\newcommand*{\ReplacePackage}[2]{%
  \@replacefilewithext{#1}{#2}\@pkgextension
}
\newcommand*{\ReplaceClass}[2]{%
  \@replacefilewithext{#1}{#2}\@clsextension
}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\scr@replacefile@msg}
%    \changes{v2.96}{2006/07/19}{new helper command}
%    \changes{v2.98}{2007/12/18}{spellfix}
% Last but not least \textsf{scrlfile} will write a message to the log file at
% every replacement.
%    \begin{macrocode}
\newcommand*{\scr@replacefile@msg}[2]{%
  \PackageInfo{scrlfile}{inputing `#1' instead of `#2'}%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\scr@load@hook}
% This macro simply calls a load-file-hook, either the \emph{before}
% or the \emph{after} one, if the hook exists. After calling the hook
% it will be deleted. First argument is the type of hook
% (\meta{before} or \meta{after}), second argument is a filename. 
%    \begin{macrocode}
\newcommand*{\scr@load@hook}[2]{%
  \@ifundefined{#2-@#1}{}{%
    \@nameuse{#2-@#1}%
    \expandafter\let\csname #2-@#1\endcsname=\relax}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\scr@set@load@hook}
% This command adds stuff to a load-file-hook, either the
% \emph{before} or the \emph{after} one. First argument is the type of
% hook (\meta{before} or \meta{after}), second is a filename. There's
% a third argument not parsed by the macro itself but
% \cs{g@addto@macro}. This third argument is the stuff, which will be
% added to the hook. Because of using \cs{g@addto@macro} the hook must
% be defined. So we define it, if it isn't.
%    \begin{macrocode}
\newcommand*{\scr@set@load@hook}[2]{%
  \@ifundefined{#2-@#1}{\@namedef{#2-@#1}{}}{}%
  \expandafter\g@addto@macro\csname #2-@#1\endcsname}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\BeforeFile}
%  \begin{macro}{\AfterFile}
%  \begin{macro}{\BeforeClass}
%  \begin{macro}{\AfterClass}
%  \begin{macro}{\@AfterClass}
%  \begin{macro}{\@sAfterClass}
%  \begin{macro}{\BeforePackage}
%  \begin{macro}{\AfterPackage}
%  \begin{macro}{\@AfterPackage}
%  \begin{macro}{\@sAfterPackage}
% These macros add stuff to a load-file-hook of a file, class or
% package. First argument is the name of the file (with extension),
% class (without extension) or package (without extension). There's a
% second argument parsed by wether the macros themself nor
% \cs{scr@set@load@hook} but \cs{g@addto@macro}. See
% \cs{scr@set@load@hook} for more information. The star-forms
% \cs{AfterClass*} and \cs{AfterPackage*} does the action immediate,
% if the class or package was already loaded.
%    \begin{macrocode}
\newcommand*{\BeforeFile}{\scr@set@load@hook{before}}
\newcommand*{\AfterFile}{\scr@set@load@hook{after}}
\newcommand*{\BeforeClass}[1]{%
  \scr@set@load@hook{before}{#1.\@clsextension}}
\newcommand*{\AfterClass}{%
  \@ifstar {\@sAfterClass}{\@AfterClass}}
\newcommand*{\@AfterClass}[1]{%
  \scr@set@load@hook{after}{#1.\@clsextension}}
\newcommand*{\@sAfterClass}[1]{%
  \begingroup
    \@ifclassloaded{#1}{%
      \aftergroup\@secondoftwo
    }{%
      \aftergroup\@AfterClass
    }%
  \endgroup
  {#1}%
}
\newcommand*{\BeforePackage}[1]{%
  \scr@set@load@hook{before}{#1.\@pkgextension}}
\newcommand*{\AfterPackage}{%
  \@ifstar {\@sAfterPackage}{\@AfterPackage}}
\newcommand*{\@AfterPackage}[1]{%
  \scr@set@load@hook{after}{#1.\@pkgextension}}
\newcommand*{\@sAfterPackage}[1]{%
  \begingroup
    \@ifpackageloaded{#1}{%
      \aftergroup\@secondoftwo
    }{%
      \aftergroup\@AfterPackage
    }%
  \endgroup
  {#1}%
}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\BeforeClosingMainAux}
%    \changes{v2.95}{2002/09/03}{new}
% This is completly different. First we have to establish a new hook
% at \cs{end\{document\}}, just after closing the group and after the
% final \cs{clearpage}.
%    \begin{macrocode}
\AtEndDocument{%
  \let\scr@saved@checkend=\@checkend
  \renewcommand*{\@checkend}[1]{%
    \def\reserved@a{#1}\def\reserved@b{document}%
    \scr@saved@checkend{#1}%
    \ifx\reserved@a\reserved@b
      \let\scr@saved@clearpage=\clearpage
      \renewcommand*{\clearpage}{\scr@saved@clearpage
        \scr@hook@bcma\let\clearpage=\scr@saved@clearpage}%
    \fi%
  }%
}
%    \end{macrocode}
%  \begin{macro}{\scr@saved@checkend}
%    \changes{v2.95}{2002/09/03}{new (internal)}
% You may see above, that we need a save-to macro.
%    \begin{macrocode}
\newcommand*{\scr@saved@checkend}{}
%    \end{macrocode}
%  \end{macro}
%  \begin{macro}{\scr@hook@bcma}
%    \changes{v2.95}{2002/09/03}{new (internal)}
% We also need a macro, that saves the commands at the hook and is
% extendable using \cs{g@addto@macro}. Here we also warn, if we detect
% one more \cs{newpage}\,---\,maybe at a \cs{clearpage} or
% \cs{cleardoublepage}.
%    \begin{macrocode}
\newcommand*{\scr@hook@bcma}{%
  \renewcommand*{\BeforeClosingMainAux}[1]{##1}%
  \renewcommand*{\newpage}{%
    \PackageError{%
      scrlfile%
    }{%
      \string\newpage\space at \string\BeforeClosingMainAux
    }{%
      You should never use \string\newpage\space or
      \string\clear(double)page or other output material at the\MessageBreak
      argument of \string\BeforeClosingMainAux!\MessageBreak
      If you'll continue, the \string\newpage\space will be ignored to
      avoid corruption of\MessageBreak
      every prior use of \string\BeforeClosingMainAux.
    }%
  }%
}
%    \end{macrocode}
%  \end{macro}
% Now we are able to write the user command.
%    \begin{macrocode}
\newcommand*{\BeforeClosingMainAux}{%
  \g@addto@macro\scr@hook@bcma%
}
%    \end{macrocode}
%  \end{macro}
%
% \Finale
%
% \iffalse
%</scrlfile>
%<*load>
% Used at \KOMAScript{} classes.
%    \begin{macrocode}
\edef\@tempa{\noexpand\RequirePackage{scrlfile}[\scrlfileversion]}
\@tempa
%    \end{macrocode}
%</load>
% \fi
%
\endinput
%
% end of file `scrlfile.dtx'

%%% Local Variables:
%%% mode: doctex
%%% TeX-master: t
%%% End: