Debian Codegraph @

texmf-dist/source/latex/koma-script/scrlfile-patcholdlatex.dtx

raw
1 % \iffalse^^A meta-comment
2 % ======================================================================
3 % scrlfile-patcholdlatex.dtx
4 % Copyright (c) Markus Kohm, 2002-2022
5 %
6 % This file is part of the work `scrlfile' which is part of the LaTeX2e
7 % KOMA-Script bundle.
8 %
9 % This work may be distributed and/or modified under the conditions of
10 % the LaTeX Project Public License, version 1.3c of the license.
11 % The latest version of this license is in
12 % http://www.latex-project.org/lppl.txt
13 % and version 1.3c or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later and of this work.
15 %
16 % This work has the LPPL maintenance status "author-maintained".
17 %
18 % The Current Maintainer and author of this work is Markus Kohm.
19 %
20 % This work consists of all files listed in MANIFEST.md.
21 % ======================================================================
22 %%% From File: $Id: scrlfile-patcholdlatex.dtx 3874 2022-06-05 10:38:02Z kohm $
23 %<*dtx>
24 \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
25 \begingroup
26 \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
27 \filedate$Date: 2022-06-05 12:38:02 +0200 (So, 05. Jun 2022) $
28 \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
29 \filerevision$Revision: 3874 $
30 \edef\reserved@a{%
31 \noexpand\endgroup
32 \noexpand\ProvidesFile{scrlfile-patcholdlatex.dtx}%
33 [\filedate\space\filerevision\space
34 KOMA-Script package source
35 }%
36 \reserved@a
37 %</dtx>
38 %<package>\ProvidesPackage{scrlfile-patcholdlatex}[%
39 %!KOMAScriptVersion
40 %<package> package
41 (patching old LaTeX kernels)]
42 %<*dtx>
43 \ifx\documentclass\undefined
44 \input scrdocstrip.tex
45 \@@input scrkernel-version.dtx
46 \@@input scrstrip.inc
47 \KOMAdefVariable{COPYRIGHTFROM}{2002}
48 \generate{\usepreamble\defaultpreamble
49 \file{scrlfile-patcholdlatex.sty}{%
50 \from{scrlfile-patcholdlatex.dtx}{package}%
51 \from{scrlogo.dtx}{logo}%
52 }%
53 }
54 \@@input scrstrop.inc
55 \else
56 \let\endbatchfile\relax
57 \fi
58 \endbatchfile
59 \documentclass[USenglish]{koma-script-source-doc}
60 \usepackage{babel}
61 \begin{document}
62 \DocInput{scrlfile-patcholdlatex.dtx}
63 \end{document}
64 %</dtx>
65 % \fi^^A meta-comment
66 %
67 % \changes{v2.95}{2002/06/11}{First version split from hugh scrclass.dtx}
68 % \changes{v3.24}{2017/05/06}{standalone manual removed}
69 % \changes{v3.32}{2020/09/02}{new (sub)-package}
70 % \changes{v3.36}{2022/02/03}{switch over from \cls*{scrdoc} to
71 % \cls*{koma-script-source-doc}}
72 % \changes{v3.36}{2022/02/03}{using \file{scrlogo.dtx} to define the logo}
73 %
74 % \GetFileInfo{scrlfile-patcholdlatex.dtx}
75 % \title{\pkg*{scrlfile} \KOMAScript{} Sub-Package \pkg*{scrlfile-patcholdlatex}}
76 % \author{\href{mailto:[email protected]}{Markus Kohm}}
77 % \date{Revision \fileversion{} of \filedate}
78 % \maketitle
79 % \begin{abstract}
80 % This package provides hooks before and after loading files, packages or
81 % classes. It also provides a hook after the last \cs{clearpage} of the
82 % document. It allowes to replace files, packages and classes by other
83 % files, packages and classes. It is inteded to be used by package and class
84 % authors but may also be used by \LaTeX{} users.
85 % \end{abstract}
86 % \tableofcontents
87 %
88 %
89 % \section{User Manual}
90 %
91 % \pkg*{scrlfile-patcholdlatex} implements the part of \pkg*{scrlfile}
92 % that patches old \LaTeX{} kernels.
93 %
94 % There isn't any user manual for the user level \LaTeXe{} commands in this
95 % file. Please see the manual of \pkg*{scrlfile} for more information about
96 % \pkg*{scrlfile-patcholdlatex}.
97 %
98 % \MaybeStop{\PrintIndex}
99 %
100 % \section{Implementation of \pkg*{scrlfile-patcholdlatex}}
101 %
102 %
103 % \subsection{Patching \LaTeX{} Kernel Macros}
104 %
105 % Test whether the used \LaTeX{} is old enough.
106 % \changes{v3.34}{2021/04/21}{make it more robust agains not recommended
107 % direct usage}
108 % \changes{3.35}{2021/10/31}{\LaTeX{} kernel change results in new variant of
109 % \pkg*{scrfile-hook}}
110 % \begin{macrocode}
111 \@ifundefined{IfFormatAtLeastTF}{}{%
112 \IfFormatAtLeastTF{2020/10/01}{%
113 \PackageError{scrlfile-hook}{LaTeX too young for this package}{%
114 It seems this package has been loaded directly using a LaTeX
115 version\MessageBreak
116 2020-10-01 or newer. This is not recommended. Please always load
117 package\MessageBreak
118 scrlfile instead of scrlfile-patcholdlatex.\MessageBreak
119 If you would continue, I will try to load scrlfile-hook%
120 \IfFormatAtLeast{2021/11/15}{}{-3.34}%
121 }%
122 \IfFormatAtLeastTF{2021/11/15}{%
123 \RequirePackage{scrlfile-hook}%
124 }{%
125 \RequirePackage{scrlfile-hook-3.34}%
126 }%
127 \endinput
128 }{}%
129 }
130 % \end{macrocode}
131 %
132 % \begin{command}{\InputIfFileExists}
133 % \changes{v2.96}{2006/07/19}{replacement code added}
134 % \LaTeX{} uses this macro for loading files with
135 % \cs{input}\marg{filename}, \cs{include}, \cs{LoadClass},
136 % \cs{LoadClassWithOptions}, \cs{documentclass}, \cs{documentstyle},
137 % \cs{RequirePackage}, \cs{usepackage}. Only
138 % \cs{input}~\meta{filename} loads \meta{filename} without using
139 % \cs{InputIfFileExists}.
140 %
141 % Because of this, it's very easy to add stuff before and after
142 % loading a file. We simply change this macro and add to
143 % macros\,---\,one before loading the file and one after loading the
144 % file. But before we redefine the macro, we test, if the macro was
145 % defined like we expected. \LaTeX{} will warn, if not.
146 % \changes{v3.27}{2019/10/06}{\LaTeX{} 2019-10-01 changed the definition}
147 %
148 % \changes{v3.28}{2019/11/21}{support for \cls{memoir}}
149 % With \cls{memoir} their is a special case. It also redefines
150 % \cs{InputIfFileExists}. As shown in the source of the class it does so
151 % because \pkg*{scrlfile} does it. However it does it not compatible with
152 % \pkg*{scrlfile} and it does not emulate \pkg*{scrlfile} as it do for
153 % other packages. So if you try to use \pkg*{scrlfile} with memoir,
154 % \pkg*{scrbase} has to take care to \cls{memoir}. And in oposit to
155 % \pkg*{scrlfile} \cls{memoir} does not always fix the argument order bug
156 % of \LaTeX{} but do so only for the implementation of \LaTeX{} 2019-10-01.
157 % So in case of \cls{memoir} we just patch every version of it without
158 % testing.
159 % \begin{macrocode}
160 \@ifclassloaded{memoir}{%
161 \PackageInfo{scrlfile}{class `memoir' detected.\MessageBreak
162 Using a compatible redefinition of \string\InputIfFileExists,\MessageBreak
163 but always robust and with the fix of the\MessageBreak
164 argument order bug even for old versions of the\MessageBreak
165 LaTeX kernel%
166 }%
167 }{%
168 \long\def\reserved@a#1#2{%
169 \IfFileExists{#1}%
170 {#2\@addtofilelist{#1}\@@input \@filef@und}}%
171 \ifx\reserved@a\InputIfFileExists\else
172 \expandafter\CheckCommand\expandafter*\expandafter\InputIfFileExists
173 \expandafter{%
174 \expandafter\protect\csname InputIfFileExists \endcsname
175 }%
176 \expandafter\CheckCommand \csname InputIfFileExists \endcsname[2]{%
177 \IfFileExists {#1}{%
178 \expandafter \@swaptwoargs \expandafter {\@filef@und }%
179 {#2\@addtofilelist {#1}\@@input }%
180 }%
181 }%
182 \fi
183 }
184 % \end{macrocode}
185 % Now we can redefine the macro like described above:
186 % \begin{macrocode}
187 \expandafter\renewcommand\expandafter*\expandafter\InputIfFileExists
188 \expandafter{\expandafter
189 \protect\csname InputIfFileExists \endcsname}%
190 \expandafter\long\expandafter\def\csname InputIfFileExists \endcsname#1#2{%
191 \begingroup\expandafter\expandafter\expandafter\endgroup
192 \expandafter\ifx\csname #1-@alias\endcsname\relax
193 \expandafter\@secondoftwo
194 \else
195 \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
196 \expandafter\@firstoftwo
197 \fi
198 {%
199 \expandafter\InputIfFileExists\expandafter{\csname
200 #1-@alias\endcsname}{#2}%
201 }%
202 {\IfFileExists{#1}{%
203 \expandafter\scr@input@withhook\expandafter{\@filef@und}{#1}{#2}%
204 }}%
205 }
206 % \end{macrocode}
207 % \begin{macro}{\scr@input@withhook}
208 % \changes{v3.27}{2019/03/28}{added}
209 % \changes{v3.28}{2019/11/21}{support for \cls{memoir}}
210 % We need a new internal, because of expanding \cs{@file@und} before inputting
211 % the file.
212 % \begin{macrocode}
213 \@ifclassloaded{memoir}{%
214 \newcommand{\scr@input@withhook}[3]{%
215 \scr@load@hook{before}{#2}%
216 #3\@addtofilelist{#2}%
217 \@ifundefined{m@matbeginf}{}{\m@matbeginf{#2}}%
218 \@@input #1%
219 \@ifundefined{m@matendf}{}{\m@matendf{#2}}%
220 \@ifundefined{killm@matf}{}{\killm@matf{#2}}%
221 \scr@load@hook{after}{#2}%
222 }%
223 }{%
224 \newcommand{\scr@input@withhook}[3]{%
225 \scr@load@hook{before}{#2}%
226 #3\@addtofilelist{#2}%
227 \@@input #1%
228 \scr@load@hook{after}{#2}%
229 }%
230 }
231 % \end{macrocode}
232 % \end{macro}^^A \scr@input@withhook
233 % \end{command}^^A \InputIfFileExists
234 %
235 % \begin{macro}{\@loadwithoptions}
236 % \changes{v2.96}{2006/07/19}{re-implementation}
237 % \begin{macro}{\scr@loadwithoptions}
238 % \changes{v2.96}{2006/07/19}{added}
239 % \begin{macro}{\scr@@loadwithoptions}
240 % \changes{v2.97a}{2007/03/07}{added}
241 % \LaTeX{} uses this macro for loading classes and packages using
242 % \cs{LoadClassWithOptions} or \cs{RequirePackageWithOptions}. We simply say
243 % now: if the class or package should be replaced by another, try it again
244 % with the replacement name. The stack is used. This will result in an
245 % error if the replacements are nested too deep. This should be, because it
246 % will also result in an error using ring replacements.
247 % \begin{macrocode}
248 \newcommand*{\scr@@loadwithoptions}{}
249 \newcommand*{\scr@loadwithoptions}{}
250 \let\scr@loadwithoptions\@loadwithoptions
251 \renewcommand*{\@loadwithoptions}[3]{%
252 \begingroup\expandafter\expandafter\expandafter\endgroup
253 \expandafter\ifx\csname #3.#1-@aliasname\endcsname\relax
254 \def\scr@@loadwithoptions{\scr@loadwithoptions{#1}{#2}{#3}}%
255 \else
256 \scr@replacefile@msg{\csname #3.#1-@aliasname\endcsname.#1}{#3.#1}%
257 \def\scr@@loadwithoptions{%
258 \@loadwithoptions{#1}{#2}{\csname #3.#1-@aliasname\endcsname}%
259 }%
260 \fi
261 \scr@@loadwithoptions
262 }
263 % \end{macrocode}
264 % \end{macro}^^A \scr@@loadwithoptions
265 % \end{macro}^^A \scr@loadwithoptions
266 % \end{macro}^^A \@loadwithoptions
267 %
268 % \begin{macro}{\@onefilewithoption}
269 % \changes{v2.96}{2006/07/19}{re-implementation}
270 % \begin{macro}{\scr@onefilewithoption}
271 % \changes{v2.96}{2006/07/19}{added}
272 % \begin{macro}{\scr@@onefilewithoption}
273 % \changes{v2.98}{2007/12/18}{added}
274 % \LaTeX{} uses this macro for loading classes and packages using
275 % \cs{LoadClass}, \cs{documentclass}, \cs{RequirePackage}, and
276 % \cs{usepackage}. We simply say now: if the class or package should be
277 % replaced by another, try it again with the replacement name. The stack is
278 % used. This will result in an error if the replacements are nested too
279 % deep. This should be, because it will also result in an error using ring
280 % replacements.
281 % \begin{macrocode}
282 \newcommand*{\scr@onefilewithoptions}{}
283 \let\scr@onefilewithoptions\@onefilewithoptions
284 \def\@onefilewithoptions#1[#2][#3]#4{%
285 \begingroup\expandafter\expandafter\expandafter\endgroup
286 \expandafter\ifx\csname #1.#4-@aliasname\endcsname\relax
287 % \end{macrocode}
288 % Do this ridiculous definition and call outside of \cs{ifx}\dots\cs{fi}
289 % because of some errornous packages like some versions of
290 % \pkg{breakurl}. This does not avoid an error, but the message about
291 % unclosed \cs{if} will be outside of \pkg*{scrlfile}.
292 % \begin{macrocode}
293 \def\scr@@onefilewithoptions{\scr@onefilewithoptions{#1}}%
294 \else
295 \scr@replacefile@msg{\csname #1.#4-@aliasname\endcsname.#4}{#1.#4}%
296 \edef\scr@@onefilewithoptions{%
297 \noexpand\@onefilewithoptions{\csname #1.#4-@aliasname\endcsname}}%
298 \fi
299 \scr@@onefilewithoptions[{#2}][{#3}]{#4}%
300 \scr@load@hook{lateafter}{#1.#4}%
301 }
302 % \end{macrocode}
303 % \end{macro}^^A \scr@@onefilewithoption
304 % \end{macro}^^A \scr@onefilewithoption
305 % \end{macro}^^A \@onefilewithoption
306 %
307 % \begin{macro}{\scr@replacefile@msg}
308 % \changes{v2.96}{2006/07/19}{added}
309 % \changes{v2.98}{2007/12/18}{spellfix}
310 % Last but not least \pkg*{scrlfile} will write a message to the log file at
311 % every replacement.
312 % \begin{macrocode}
313 \newcommand*{\scr@replacefile@msg}[2]{%
314 \PackageInfo{scrlfile}{inputing `#1' instead of `#2'}%
315 }
316 % \end{macrocode}
317 % \end{macro}^^A \scr@replacefile@msg
318 %
319 % \begin{macro}{\scr@load@hook}
320 % \changes{v3.27a}{2019/10/16}{workaround for strange handling of
321 % \cs{AtEndOfPackage} hook in \cs{@onefilewithoptions}}
322 % This macro simply calls a load-file-hook, either the \emph{before}
323 % or the \emph{after} one, if the hook exists. After calling the hook
324 % it will be deleted. First argument is the type of hook
325 % (\meta{before} or \meta{after}), second argument is a filename.
326 % \begin{macrocode}
327 \newcommand*{\scr@load@hook}[2]{%
328 % \end{macrocode}
329 % \begin{macro}{\scrlfile@cmp@hook}
330 % \changes{v3.27a}{2019/10/23}{renamed}
331 % \begin{macro}{\scrlfile@hookname}
332 % \changes{v3.27a}{2019/10/23}{renamed}
333 % \changes{v3.29}{2020/06/01}{do the class and package load hooks only in the
334 % document preamble}^^A --> https://komascript.de/node/2274
335 % Workaround for strange handling of the \cs{AtEndOfPackage} hook in
336 % \cs{@onefilewithoptions} (becomes \cs{@empty}, if the package already has
337 % been loaded and is not loaded again). This workaround is not nice but
338 % smart. Before loading a file it defines a marker macro and undefines it
339 % later. To decide whether to define or remove the marker, two local macros
340 % are used \cs{scrlfile@hookname} and \cs{scrlfile@cmp@hook}. The first has
341 % the name of the current hook from the first argument. The other is a compare
342 % string. The first one is also valid while processing the hook, but only in
343 % the document preamble. The names are very unique, so we do not reserve them
344 % using \cs{newcommand} outside. The name of the marker is less
345 % unique. Nevertheless it is not reserved.
346 % Note: For recursive loading of files this does not work. But this also does
347 % not matter, because it is needed only for packages and classes, which are
348 % never loaded recursive. For the same reason from \KOMAScript{} 3.29 this is
349 % only used inside the document preamble. After the document preamble it can
350 % be dangerous, e.g., inside a |tabular| or |array|.
351 % \begin{macrocode}
352 \ifx\@begindocumenthook\@undefined\else
353 \edef\scrlfile@hookname{#1}%
354 \def\scrlfile@cmp@hook{before}%
355 \ifx\scrlfile@hookname\scrlfile@cmp@hook
356 \expandafter\def\csname #2-l@ading\endcsname{#2}%
357 \fi
358 \let\scrlfile@cmp@hook\@undefined
359 \fi
360 \@ifundefined{#2-@#1}{}{%
361 \@nameuse{#2-@#1}%
362 \expandafter\let\csname #2-@#1\endcsname\relax
363 }%
364 % \end{macrocode}
365 % The hook could destroy \cs{scrlfile@hookname} so define it again:
366 % \begin{macrocode}
367 \ifx\@begindocumenthook\@undefined\else
368 \edef\scrlfile@hookname{#1}%
369 \def\scrlfile@cmp@hook{after}%
370 \ifx\scrlfile@hookname\scrlfile@cmp@hook
371 \expandafter\let\csname #2-l@ading\endcsname\@undefined
372 \fi
373 \let\scrlfile@cmp@hook\@undefined
374 \let\scrlfile@hookname\@undefined
375 \fi
376 }
377 % \end{macrocode}
378 % \end{macro}^^A \scrlfile@hookname
379 % \end{macro}^^A \scrlfile@cmp@hook
380 % \end{macro}^^A \scr@load@hook
381 %
382 % \begin{macro}{\scr@set@load@hook}
383 % This command adds stuff to a load-file-hook, either the
384 % \emph{before} or the \emph{after} one. First argument is the type of
385 % hook (\meta{before} or \meta{after}), second is a filename. There's
386 % a third argument not parsed by the macro itself but
387 % \cs{g@addto@macro}. This third argument is the stuff, which will be
388 % added to the hook. Because of using \cs{g@addto@macro} the hook must
389 % be defined. So we define it, if it isn't.
390 % \begin{description}
391 % \item[ToDo:] Handling/ignoring an optional argument to make it more
392 % compatible with \LaTeX's new \cs{AddToHook}.
393 % \end{description}
394 % \begin{macrocode}
395 \newcommand*{\scr@set@load@hook}[2]{%
396 \@ifundefined{#2-@#1}{\@namedef{#2-@#1}{}}{}%
397 \expandafter\g@addto@macro\csname #2-@#1\endcsname
398 }
399 % \end{macrocode}
400 % \end{macro}^^A \scr@set@load@hook
401 %
402 %
403 % \subsection{Before and After Commands}
404 %
405 % \begin{command}{\BeforeFile,\AfterFile}
406 % Just add code to the \emph{before} or \emph{after} hook of a file. The
407 % arguments are:
408 % \begin{description}
409 % \item[\meta{file name}:] mandatory argument with the file name as given by
410 % \cs{InputIfFileExists}.
411 % \item[\meta{code}:] this argument is not processed by \cs{BeforeFile} or
412 % \cs{AfterFile} but the internal \cs{scr@set@load@hook}. It is the code
413 % that should be added to either the \emph{before} or the \emph{after} hook.
414 % \end{description}
415 % \begin{macrocode}
416 \newcommand*{\BeforeFile}{\scr@set@load@hook{before}}
417 \newcommand*{\AfterFile}{\scr@set@load@hook{after}}
418 % \end{macrocode}
419 % \end{command}^^A \BeforeFile,\AfterFile
420 %
421 % \begin{command}{\BeforeClass}
422 % \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
423 % \cs{kernel@ifnextchar}}
424 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
425 % This is quite simple. It only has to add code to the \emph{before} hook
426 % already known by \cs{BeforeFile}. The arguments are:
427 % \begin{description}
428 % \item[\meta{package name}:] mandatory argument.
429 % \item[\meta{code}:] this argument is processed not by \cs{BeforeClass} but
430 % by the internal \cs{scr@set@load@hook} (see above), that will add the code
431 % to the \emph{before} hook of file \meta{code}\texttt{.cls} (or whatever the
432 % package extension is).
433 % \end{description}
434 % \begin{macrocode}
435 \newcommand*{\BeforeClass}[1]{%
436 \scr@set@load@hook{before}{#1.\@clsextension}%
437 }
438 % \end{macrocode}
439 % \end{command}^^A \BeforeClass
440 %
441 % \begin{command}{\AfterClass}
442 % \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
443 % \cs{kernel@ifnextchar}}
444 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
445 % \changes{v3.32}{2020/09/02}{plus and exclamation mark variants removed}
446 % \begin{command}{\AfterAtEndOfClass}
447 % \changes{v3.32}{2020/09/02}{star variant replaces the exclamation mark
448 % variant of \cs{AfterClass}}
449 % These are more complicated. There are four forms:
450 % \begin{description}
451 % \item[\cs{AfterClass}] corresponds to \cs{AfterFile}. So the code will be
452 % added to the usual \emph{after} hook and the code is exexuted before code
453 % added by the class itself using \cs{AtEndOfClass}. Argument procession
454 % will be done by \cs{@AfterClass}.
455 % \item[\cs{AfterAtEndOfClass}] This uses the \emph{lateafter} hook, which
456 % is executed after the class has been loaded completely inclusive the
457 % execution of \cs{AtEndOfClass} code. However, the code will never be
458 % executed, if the class will not be loaded (again). But it does nothing,
459 % if the class has already been loaded. The arguments are:
460 % \begin{description}
461 % \item[\meta{class name}] mandatory argument
462 % \item[\meta{code}:] this argument is processed not by \cs{BeforeClass}
463 % but by the internal \cs{scr@set@load@hook} (see above), that will add
464 % the code to the \emph{lateafter} hook of file \meta{code}\texttt{.cls}
465 % (or whatever the class extension is), or by \cs{@gobble}.
466 % \end{description}
467 % \item[\cs{AfterClass*}] like \cs{AfterClass}, but if loading of the
468 % class has already began, the code will be executed immediately. So, if
469 % the command is used inside the class it is simply
470 % \cs{@firstofone}. Argument procession will be done by \cs{@sAfterClass}.
471 % \item[\cs{AfterAtEndOfClass*}] like \cs{AfterClass*}, but the code will be
472 % executed immediately only if the class already has been loaded
473 % completely. Inside \cs{AtEndOfClass} the code is executed after every all
474 % the \cs{AtEndOfClass} code. Argument procession will be done by
475 % \cs{@xAfterClass}.
476 % \end{description}
477 % \begin{macrocode}
478 \newcommand*{\scrlfile@AfterClass}{%
479 \kernel@ifstar \@sAfterClass\@AfterClass
480 }
481 \newcommand*{\AfterClass}{\scrlfile@AfterClass}
482 % \end{macrocode}
483 % \begin{macro}{\@AfterClass}
484 % \cs{AfterClass}\marg{class name}\marg{code}.
485 % It uses \cs{scr@set@load@hook} to add \meta{code} to the
486 % \emph{after} hook. The second argument will be processed by
487 % \cs{scr@set@load@hook}.
488 % \begin{macrocode}
489 \newcommand*{\@AfterClass}[1]{%
490 \scr@set@load@hook{after}{#1.\@clsextension}%
491 }
492 % \end{macrocode}
493 % \end{macro}^^A \@AfterClass
494 % \begin{macro}{\@sAfterClass}
495 % \changes{v3.27a}{2019/10/16}{group removed}
496 % This is the internal implementation of:
497 % \cs{AfterClass*}\marg{class name}\marg{code}.
498 % It tests, whether or not \LaTeX{} thinks that the class
499 % has already been loaded, but this only means whether or not the class
500 % loading has already been started. If so, it immediately executes the next
501 % argument. If not, is uses \cs{@AfterClass} to execute the \meta{code}
502 % after loading the class.
503 % \begin{macrocode}
504 \newcommand*{\@sAfterClass}[1]{%
505 \@ifclassloaded{#1}{%
506 \@secondoftwo
507 }{%
508 \@AfterClass
509 }%
510 {#1}%
511 }
512 % \end{macrocode}
513 % \end{macro}^^A \@sAfterClass
514 % \begin{macrocode}
515 \newcommand*{\AfterAtEndOfClass}{%
516 \kernel@ifstar \@sAfterAtEndOfClass\@AfterAtEndOfClass
517 }
518 % \end{macrocode}
519 % \begin{macro}{\@AfterAtEndOfClass}
520 % \changes{v3.32}{2020/09/02}{added}
521 % Note that \cs{AfterAtEndOfClass} executed the \meta{code} after each try
522 % to load a class, even if the class has already been loaded and you try
523 % to load it again.
524 % \begin{macrocode}
525 \newcommand*{\@AfterAtEndOfClass}[1]{%
526 \scr@set@load@hook{lateafter}{#1.\@clsextension}%
527 }
528 % \end{macrocode}
529 % \begin{macro}{\@sAfterAtEndOfClass}
530 % \changes{v3.09}{2011/03/09}{added}
531 % \changes{v3.27}{2019/08/26}{using inside class fixed}
532 % \changes{v3.27a}{2019/10/15}{renamed from \cs{@@@AfterClass}}
533 % \changes{v3.27a}{2019/10/16}{usage of \emph{l@ading} marker}
534 % \changes{v3.27a}{2019/10/16}{group removed}
535 % \changes{v3.32}{2020/09/02}{renamed from \cs{@xAfterClass}}
536 % This is the internal implementation of:
537 % \cs{AfterClass!}\marg{class name}\marg{code}. Note, that the exclamation
538 % mark has not already read. So the arguments are:
539 % \begin{description}
540 % \item[\texttt{!}:] static exclamation mark, to be ignored.
541 % \item[\meta{class name}] mandatory argument
542 % \item[\meta{code}:] this argument is processed not by \cs{BeforeClass} but
543 % by the internal \cs{@sAfterClass} or \cs{@AfterClass} (see above).
544 % \end{description}
545 % There are two differences to \cs{@pAfterClass}:
546 % \begin{enumerate}
547 % \item In case of \cs{\meta{class name}.cls-l@ading} is defined (and not
548 % \cs{relax}), while loading a class, it used \cs{AfterAtEndOfClass}
549 % instead of \cs{AfterClass} to add \meta{code} to the \emph{lateafter}
550 % hook instead of the \emph{after} hook.
551 % \item In case of \cs{\meta{class name}.cls-l@ading} is undefined (or
552 % \cs{relax}) it also has to test, whether or not the class has already
553 % been loaded. If so, it uses \cs{@sAfterClass} to execute the \meta{code}
554 % immediately, otherwise it uses \cs{AfterAtEndOfClass} to add the
555 % \meta{code} to the \emph{lateafter} hook.
556 % \end{enumerate}
557 % So it is more like (the not existing) \cs{AfterAtEndOfClass+} than
558 % \cs{AfterAtEndOfClass*}.
559 % \begin{macrocode}
560 \newcommand*{\@sAfterAtEndOfClass}[1]{%
561 \@ifundefined{#1.\@clsextension-l@ading}{%
562 \@ifclassloaded{#1}{%
563 \@secondoftwo
564 }{%
565 \@AfterAtEndOfClass
566 }%
567 }{%
568 \@AfterAtEndOfClass
569 }%
570 {#1}%
571 }
572 % \end{macrocode}
573 % \end{macro}^^A \@sAfterAtEndOfClass
574 % \end{macro}^^A \@AfterAtEndOfClass
575 % \end{command}^^A \AfterAtEndOfClass
576 % \end{command}^^A \AfterClass
577 %
578 % \begin{command}{\BeforePackage}
579 % This is quite simple. It only has to add code to the \emph{before} hook
580 % already known by \cs{BeforeFile}. The arguments are:
581 % \begin{description}
582 % \item[\meta{package name}:] mandatory argument.
583 % \item[\meta{code}:] this argument is processed not by \cs{BeforePackage} but
584 % by the internal \cs{scr@set@load@hook} (see above), that will add the code
585 % to the \emph{before} hook of file \meta{code}\texttt{.sty} (or whatever the
586 % package extension is).
587 % \end{description}
588 % \begin{macrocode}
589 \newcommand*{\BeforePackage}[1]{%
590 \scr@set@load@hook{before}{#1.\@pkgextension}%
591 }
592 % \end{macrocode}
593 % \end{command}^^A \BeforePackage
594 %
595 % \begin{command}{\AfterPackage}
596 % \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
597 % \cs{kernel@ifnextchar}}
598 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
599 % \begin{command}{\AfterAtEndOfPackage}
600 % These are more complicated. There are four forms:
601 % \begin{description}
602 % \item[\cs{AfterPackage}] corresponds to \cs{AfterFile}. So the code will be
603 % added to the usual \emph{after} hook and the code is exexuted before code
604 % added by the package itself using \cs{AtEndOfPackage}. Argument procession
605 % will be done by \cs{@AfterPackage}.
606 % \item[\cs{AfterAtEndOfPackage}] This uses the \emph{lateafter} hook, which
607 % is executed after the package has been loaded completely inclusive the
608 % execution of \cs{AtEndOfPackage} code. However, the code will never be
609 % executed, if the package will not be loaded (again). But it does nothing,
610 % if the package has already been loaded. The arguments are:
611 % \begin{description}
612 % \item[\meta{package name}] mandatory argument
613 % \item[\meta{code}:] this argument is processed not by \cs{BeforePackage}
614 % but by the internal \cs{scr@set@loaf@hook} (see above), that will add
615 % the code to the \emph{lateafter} hook of file \meta{code}\texttt{.sty}
616 % (or whatever the package extension is), or by \cs{@gobble}.
617 % \end{description}
618 % \item[\cs{AfterPackage*}] like \cs{AfterPackage}, but if loading of the
619 % package has already began, the code will be executed immediately. So, if
620 % the command is used inside the package it is simply
621 % \cs{@firstofone}..
622 % \item[\cs{AfterAtEndOfPackage*}] like \cs{AfterPackage*}, but the code will
623 % be executed immediately only if the package already has been loaded
624 % completely. Inside \cs{AtEndOfPackage} the code is executed after every
625 % all the \cs{AtEndOfPackage} code.
626 % \end{description}
627 % \begin{macrocode}
628 \newcommand*{\scrlfile@AfterPackage}{%
629 \kernel@ifstar \@sAfterPackage\@AfterPackage
630 }
631 \newcommand*{\AfterPackage}{\scrlfile@AfterPackage}
632 % \end{macrocode}
633 % \begin{macro}{\@AfterPackage}
634 % This is the internal implementation of:
635 % \cs{AfterPackage}\marg{package name}\marg{code}.
636 % It uses \cs{scr@set@load@hook} to add \meta{code} to the
637 % \emph{after} hook. The second argument will be processed by
638 % \cs{scr@set@load@hook}.
639 % \begin{macrocode}
640 \newcommand*{\@AfterPackage}[1]{%
641 \scr@set@load@hook{after}{#1.\@pkgextension}%
642 }
643 % \end{macrocode}
644 % \end{macro}^^A \@AfterPackage
645 % \begin{macro}{\@sAfterPackage}
646 % \changes{v3.27a}{2019/10/16}{group removed}
647 % This is the internal implementation of:
648 % \cs{AfterPackage*}\marg{package name}\marg{code}.
649 % It tests, whether or not \LaTeX{} thinks that the package
650 % has already been loaded, but this only means whether or not the package
651 % loading has already been started. If so, it immediately executes the next
652 % argument. If not, is uses \cs{@AfterPackage} to execute the \meta{code}
653 % after loading the package.
654 % \begin{macrocode}
655 \newcommand*{\@sAfterPackage}[1]{%
656 \@ifpackageloaded{#1}{%
657 \@secondoftwo
658 }{%
659 \@AfterPackage
660 }%
661 {#1}%
662 }
663 % \end{macrocode}
664 % \end{macro}^^A \@sAfterPackage
665 % \begin{macrocode}
666 \newcommand*{\AfterAtEndOfPackage}{%
667 \kernel@ifstar \@sAfterAtEndOfPackage\@AfterAtEndOfPackage
668 }
669 % \end{macrocode}
670 % \begin{macro}{\@sAfterAtEndOfPackage}
671 % \changes{v3.09}{2011/03/09}{added}
672 % \changes{v3.27}{2019/08/26}{using inside package fixed}
673 % \changes{v3.27a}{2019/10/15}{renamed from \cs{@@@AfterPackage}}
674 % \changes{v3.27a}{2019/10/16}{usage of \emph{l@ading} marker}
675 % \changes{v3.27a}{2019/10/16}{group removed}
676 % \changes{v3.32}{2020/09/02}{renamed from \cs{@xAfterPackage}}
677 % This is the internal implementation of:
678 % \cs{AfterAtEndOfPackage*}\marg{package name}\marg{code}.
679 % \begin{macrocode}
680 \newcommand*{\@sAfterAtEndOfPackage}[1]{%
681 \@ifundefined{#1.\@pkgextension-l@ading}{%
682 \@ifpackageloaded{#1}{%
683 \@secondoftwo
684 }{%
685 \@@AfterAtEndOfPackage
686 }%
687 }{%
688 \@@AfterAtEndOfPackage
689 }%
690 {#1}%
691 }
692 % \end{macrocode}
693 % \end{macro}^^A \@sAfterAtEndOfPackage
694 % \begin{macro}{\@AfterAtEndOfPackage}
695 % \changes{v3.32}{2020/09/02}{added}
696 % \begin{macro}{\@@AfterAtEndOfPackage}
697 % \changes{v3.27a}{2019/10/15}{added}
698 % \changes{v3.27a}{2019/10/16}{group removed}
699 % \changes{v3.32}{2020/09/02}{renamed from \cs{@AfterAtEndOfPackage}}
700 % Note that until 3.27a \cs{AfterAtEndOfPackage} executed the \meta{code}
701 % after each try to load a package, even if the package has already been
702 % loaded and you've try to load it again. Since 3.27a this is the
703 % functionality of \cs{@AfterAtEndOfPackage}. \cs{AfterAtEndOfPackage} now
704 % does not do anything for already loaded packages or while loading the
705 % package.
706 % \begin{macrocode}
707 \newcommand*{\@AfterAtEndOfPackage}[1]{%
708 \@ifpackageloaded{#1}{%
709 \@ifundefined{#1.\@pkgextension-l@ading}{%
710 \@gobbletwo
711 }{%
712 \@@AfterAtEndOfPackage
713 }%
714 }{%
715 \@@AfterAtEndOfPackage
716 }%
717 {#1}%
718 }
719 \newcommand*{\@@AfterAtEndOfPackage}[1]{%
720 \scr@set@load@hook{lateafter}{#1.\@pkgextension}%
721 }
722 % \end{macrocode}
723 % \end{macro}^^A \@@AfterAtEndOfPackage
724 % \end{macro}^^A \@AfterEndOfPackage
725 % \end{command}^^A \AfterAtEndOfPackage
726 % \end{command}^^A \AfterPackage
727 %
728 %
729 % \subsection{File Substitution}
730 %
731 % \begin{command}{\ReplaceInput}
732 % \changes{v2.96}{2006/07/19}{added}
733 % \changes{v3.12}{2013/11/15}{implemented}
734 % Defining the replacement by definition of \cs{\#1-@alias}.
735 % \begin{macrocode}
736 \newcommand*{\ReplaceInput}[2]{%
737 \expandafter\edef\csname #1-@alias\endcsname{#2}%
738 }
739 % \end{macrocode}
740 % \begin{command}{\ReplaceFile}
741 % \changes{v2.96}{2006/07/19}{added}
742 % \changes{v3.12}{2013/11/15}{throw error}
743 % Sorry, but I've implemented the wrong command some time ago.
744 % \begin{macrocode}
745 \newcommand*{\ReplaceFile}{%
746 \PackageError{scrlfile}{%
747 usage of not documented command `\string\ReplaceFile'%
748 }{%
749 Command `\string\ReplaceFile' has been implemented accidentally in
750 KOMA-Script 2.96\MessageBreak
751 and replaced by `\string\ReplaceInput' in KOMA-Script 3.12.\MessageBreak
752 You should replace `\string\ReplaceFile' by `\string\ReplaceInput' to
753 avoid this error\MessageBreak
754 message%
755 }%
756 \ReplaceInput
757 }
758 % \end{macrocode}
759 % \end{command}^^A \ReplaceFile
760 % \end{command}^^A \ReplaceInput
761 %
762 % \begin{command}{\UnReplaceInput}
763 % \changes{v3.12}{2013/11/15}{added}
764 % Do not longer replace a file.
765 % \begin{macrocode}
766 \newcommand*{\UnReplaceInput}[1]{%
767 \ifcsname #1-@alias\endcsname
768 \expandafter\let\csname #1-@alias\endcsname\relax
769 \fi
770 }
771 % \end{macrocode}
772 % \end{command}^^A \UnReplaceInput
773 %
774 % \begin{command}{\ReplacePackage,\ReplaceClass}
775 % \changes{v2.96}{2006/07/19}{added}
776 % \begin{macro}{\@replacefilewithext}
777 % \changes{v2.96}{2006/07/19}{added}
778 % \changes{v3.32}{2020/09/09}{works global}
779 % Note that replacing a package or class will not replace the input of the
780 % file of the package or class but only the input of package or class.
781 % \begin{macrocode}
782 \newcommand*{\@replacefilewithext}[3]{%
783 \expandafter\xdef\csname #1.#3-@aliasname\endcsname{#2}%
784 }
785 \newcommand*{\ReplacePackage}[2]{%
786 \@replacefilewithext{#1}{#2}\@pkgextension
787 }
788 \newcommand*{\ReplaceClass}[2]{%
789 \@replacefilewithext{#1}{#2}\@clsextension
790 }
791 % \end{macrocode}
792 % \end{macro}^^A \@replacefilewithext
793 % \end{command}^^A\ReplacePackage,\ReplaceClass
794 %
795 % \begin{command}{\UnReplacePackage,\UnReplaceClass}
796 % \changes{v3.12}{2013/11/15}{added}
797 % \begin{macro}{\@unreplacefilewithext}
798 % \changes{v3.12}{2013/11/15}{added}
799 % \changes{v3.32}{2020/09/09}{works global}
800 % Do not nolonger replace a class or package.
801 % \begin{macrocode}
802 \newcommand*{\@unreplacefilewithext}[2]{%
803 \ifcsname #1.#2-@aliasname\endcsname
804 \expandafter\global\expandafter\let\csname #1.#2-@aliasname\endcsname\relax
805 \fi
806 }
807 \newcommand*{\UnReplacePackage}[1]{%
808 \@unreplacefilewithext{#1}\@pkgextension
809 }
810 \newcommand*{\UnReplaceClass}[1]{%
811 \@unreplacefilewithext{#1}\@clsextension
812 }
813 % \end{macrocode}
814 % \end{macro}^^A \@unreplacefilewithext
815 % \end{command}^^A \UnReplacePackage,\UnReplaceClass
816 %
817 %
818 % \subsection{Prevent Package from Loading}
819 %
820 % \begin{command}{\PreventPackageFromLoading}
821 % \changes{v3.08}{2010/11/04}{added}
822 % \changes{v3.11a}{2012/06/13}{write fault error in \cs{MessageBreak} fixed}
823 % \changes{v3.12}{2012/06/15}{new star version allowes empty argument with
824 % info instead of warning}
825 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
826 % \changes{v3.32}{2020/09/09}{works global}
827 % \begin{macro}{\@PreventPackageFromLoading}
828 % \changes{v3.12}{2012/06/15}{added}
829 % \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
830 % \cs{kernel@ifnextchar}}
831 % \begin{macro}{\@@PreventPackageFromLoading}
832 % \changes{v3.12}{2013/11/22}{added}
833 % \changes{v3.12}{2013/11/22}{\cs{usepackage} before \cs{documentclass}
834 % fixed}
835 % \begin{macro}{\scrlfile@excludedpackages}
836 % \changes{v3.08}{2010/11/04}{added}
837 % \begin{macro}{\scrlfile@saved@RequirePackage}
838 % \changes{v3.08}{2010/11/04}{added}
839 % \begin{macrocode}
840 \newcommand*{\scrlfile@excludedpackages}{}
841 \let\scrlfile@excludedpackages\@empty
842 \newcommand*{\scrlfile@saved@RequirePackage}{}
843 \newcommand*{\PreventPackageFromLoading}{%
844 \kernel@ifstar{\@PreventPackageFromLoading\PackageInfo}%
845 {\@PreventPackageFromLoading\PackageWarning}%
846 }
847 \newcommand*{\@PreventPackageFromLoading}[1]{%
848 \kernel@ifnextchar [%]
849 {\@@PreventPackageFromLoading#1}{\@@PreventPackageFromLoading#1[]}%
850 }
851 \newcommand*{\@@PreventPackageFromLoading}{}
852 \def\@@PreventPackageFromLoading#1[#2]#3{%
853 % \end{macrocode}
854 % We do nothing, if the argument was empty:
855 % \begin{macrocode}
856 \edef\reserved@b{\zap@space#3 \@empty}%
857 \ifx \reserved@b\@empty
858 #1{scrlfile}{%
859 \string\PreventPackageFromLoading\space with empty packages\MessageBreak
860 argument ignored%
861 }%
862 \else
863 % \end{macrocode}
864 % If the argument was not empty we first need to patch \cs{RequirePackage} and
865 % maybe \cs{usepackage} too.
866 % \begin{macrocode}
867 \ifx\scrlfile@excludedpackages\@empty
868 \global\let\scrlfile@saved@RequirePackage\RequirePackage
869 \global\let\RequirePackage\scrlfile@RequirePackage
870 \def\reserved@a##1##{%
871 \@latex@error
872 {\noexpand \usepackage before \string\documentclass}%
873 {\noexpand \usepackage may only appear in the document
874 preamble, i.e.,\MessageBreak
875 between \noexpand\documentclass and
876 \string\begin{document}.}%
877 \@gobble}%
878 \ifx\reserved@a\usepackage\else
879 \ifx\usepackage\scrlfile@saved@RequirePackage\else
880 \PackageWarning{scrlfile}{%
881 Maybe serious problem: unexpected definition of\MessageBreak
882 \string\usepackage
883 }%
884 \fi
885 \global\let\usepackage\RequirePackage
886 \fi
887 \fi
888 % \end{macrocode}
889 % We have to test, if a package was already loaded. Only not yet loaded
890 % packages will be added to the exclusion list. Empty arguments will be
891 % ignored.
892 % \changes{v3.11a}{2012/06/11}{missing \cs{scrlfile@excludedpackages} at
893 % redefinition of \cs{scrlfile@excludedpackages} added}
894 % \changes{v3.26}{2018/08/29}{spurious \cs{expandafter} removed}
895 % \begin{macrocode}
896 \@for\reserved@a:=\reserved@b\do {%
897 \ifx\reserved@a\@empty
898 #1{scrlfile}{%
899 empty package argument for
900 \string\PreventPackageFromLoading\MessageBreak
901 ignored%
902 }%
903 \else
904 \expandafter\@ifpackageloaded\expandafter{\reserved@a}{%
905 #1{scrlfile}{%
906 package `\reserved@a' already loaded.\MessageBreak
907 Cannot prevent it from beeing loaded%
908 }%
909 }{%
910 \ifx\scrlfile@excludedpackages\@empty
911 \global\let\scrlfile@excludedpackages\reserved@a
912 \else
913 \xdef\scrlfile@excludedpackages{\scrlfile@excludedpackages,%
914 \reserved@a}%
915 \fi
916 \if\relax\detokenize{#2}\relax\else
917 \@ifundefined{scrlfile@exclude@package@\reserved@a @do}{%
918 \@namedef{scrlfile@exclude@package@\reserved@a @do}{}%
919 }{}%
920 \expandafter\gdef
921 \csname scrlfile@exclude@package@\reserved@a
922 @do\expandafter\expandafter\expandafter\endcsname
923 \expandafter\expandafter\expandafter{%
924 \csname scrlfile@exclude@package@\reserved@a @do\endcsname
925 #2%
926 }%
927 \fi
928 }%
929 \fi
930 }%
931 % \end{macrocode}
932 % If the exclusion list is still empty (because all packages has been loaded
933 % already), remove the patch:
934 % \begin{macrocode}
935 \ifx\scrlfile@excludedpackages\@empty
936 \ResetPreventPackageFromLoading
937 \fi
938 \fi
939 }
940 \@onlypreamble\PreventPackageFromLoading
941 % \end{macrocode}
942 % \begin{command}{\ResetPreventPackageFromLoading}
943 % \changes{v3.08}{2010/11/04}{added}
944 % \changes{v3.32}{2020/09/09}{works global}
945 % \begin{command}{\StorePreventPackageFromLoading}
946 % \changes{v3.08}{2010/11/04}{added}
947 % These two are very simple
948 % \begin{macrocode}
949 \newcommand*{\ResetPreventPackageFromLoading}{%
950 \global\let\scrlfile@excludedpackages\@empty
951 \ifx\RequirePackage\scrlfile@RequirePackage
952 \ifx\usepackage\RequirePackage
953 \global\let\usepackage\scrlfile@saved@RequirePackage
954 \fi
955 \global\let\RequirePackage\scrlfile@saved@RequirePackage
956 \fi
957 }
958 \@onlypreamble\ResetPreventPackageFromLoading
959 \newcommand*{\StorePreventPackageFromLoading}[1]{%
960 \let#1\scrlfile@excludedpackages
961 }
962 \@onlypreamble\StorePreventPackageFromLoading
963 % \end{macrocode}
964 % \begin{command}{\UnPreventPackageFromLoading}
965 % \changes{v3.12}{2013/11/22}{added}
966 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} durch \cs{kernel@ifstar}
967 % ersetzt}
968 % \changes{v3.32}{2020/09/09}{works global}
969 % \begin{macro}{\@UnPreventPackageFromLoading}
970 % \changes{v3.12}{2013/11/22}{added}
971 % This removes packages from the prevent exclude list. The star variant also
972 % undefines the instead code.
973 % \begin{macrocode}
974 \newcommand*{\UnPreventPackageFromLoading}{%
975 \kernel@ifstar {\@tempswatrue\@UnPreventPackageFromLoading}%
976 {\@tempswafalse\@UnPreventPackageFromLoading}%
977 }
978 \newcommand*{\@UnPreventPackageFromLoading}[1]{%
979 \edef\reserved@b{\zap@space#1 \@empty}%
980 \if@tempswa
981 \@for\reserved@a:=\reserved@b\do {%
982 \ifx\reserved@a\@empty \else
983 \ifcsname scrlfile@exclude@package@\reserved@a @do\endcsname
984 \expandafter\let
985 \csname scrlfile@exclude@package@\reserved@a @do\endcsname
986 \undefined
987 \fi
988 \fi
989 }%
990 \fi
991 \ifcsname scrlfile@excludedpackages\endcsname
992 \let\reserved@a\scrlfile@excludedpackages
993 \let\scrlfile@excludedpackages\@empty
994 \expandafter\@for\expandafter\reserved@c
995 \expandafter:\expandafter=\reserved@a
996 \do{%
997 \ifx\reserved@c\@empty\else
998 \@expandtwoargs\in@{,\reserved@c,}{,\reserved@b,}%
999 \ifin@
1000 \else
1001 \ifx\scrlfile@excludepackages\@empty
1002 \global\let\scrlfile@excludepackages\reserved@c
1003 \else
1004 \xdef\scrlfile@excludedpackages{%
1005 \scrlfile@excludedpackages,\reserved@c
1006 }%
1007 \fi
1008 \fi
1009 \fi
1010 }%
1011 \ifx\scrlfile@excludedpackages\@empty\ResetPreventPackageFromLoading\fi
1012 \fi
1013 }
1014 % \end{macrocode}
1015 % \end{macro}^^A \@UnPreventPackageFromLoading
1016 % \end{command}^^A \UnPreventPackageFromLoading
1017 % \begin{macro}{\scrlfile@RequirePackage}
1018 % \changes{v3.08}{2010/11/04}{added}
1019 % \changes{v3.12}{2013/11/22}{tolerate spaces}
1020 % \changes{v3.12}{2013/11/22}{execute the optional argument of
1021 % \cs{PreventPackageFromLoading}}
1022 % This macro will replace \cs{RequirePackage} whenever the exlude list is not
1023 % empty
1024 % \begin{macrocode}
1025 \newcommand*{\scrlfile@RequirePackage}[2][]{%
1026 \let\reserved@c\@empty
1027 \let\reserved@d\@empty
1028 \edef\reserved@b{\zap@space#2 \@empty}%
1029 \expandafter\@for\expandafter\reserved@b\expandafter:\expandafter=\reserved@b
1030 \do {%
1031 \begingroup
1032 \@tempswatrue
1033 \@for\reserved@a:=\scrlfile@excludedpackages\do {%
1034 \ifx\reserved@a\reserved@b
1035 \@tempswafalse
1036 \fi
1037 }%
1038 \if@tempswa
1039 \xdef\reserved@c{\reserved@c,\reserved@b}%
1040 \else
1041 \ifx\reserved@b\@empty\else
1042 \PackageInfo{scrlfile}{Excluding package `\reserved@b'\MessageBreak
1043 from loading}%
1044 \@ifundefined{scrlfile@exclude@package@\reserved@b @do}{%
1045 }{%
1046 \expandafter\g@addto@macro\expandafter\reserved@d
1047 \csname scrlfile@exclude@package@\reserved@b @do\endcsname
1048 }%
1049 \fi
1050 \fi
1051 \endgroup
1052 }%
1053 \ifx\reserved@c\@empty
1054 \let\reserved@a\scr@gobbleopt
1055 \else
1056 \edef\reserved@a{\noexpand\scrlfile@saved@RequirePackage[#1]{%
1057 \expandafter\@gobble\reserved@c\@empty}}%
1058 \fi
1059 \expandafter\reserved@d
1060 \reserved@a
1061 }
1062 % \end{macrocode}
1063 % \end{macro}^^A \scrlfile@RequirePackage
1064 % \end{command}^^A \StorePreventPackageFromLoading
1065 % \end{command}^^A \ResetPreventPackageFromLoading
1066 % \end{macro}^^A \scrlfile@saved@RequirePackage
1067 % \end{macro}^^A \scrlfile@excludedpackages
1068 % \end{macro}^^A \@@PreventPackageFromLoading
1069 % \end{macro}^^A \@PreventPackageFromLoading
1070 % \end{command}^^A \PreventPackageFromLoading
1071 %
1072 % \begin{macro}{\scr@gobbleopt}
1073 % \changes{v3.08}{2010/11/04}{added}
1074 % \changes{v3.08a}{2011/02/11}{\cs{@gobbleopt} renamed due to compaibility
1075 % problems with \texttt{ntheorem}}
1076 % Eat the optional argument if it exists.
1077 % \begin{macrocode}
1078 \providecommand{\scr@gobbleopt}[1][]{}
1079 % \end{macrocode}
1080 % \end{macro}^^A \scr@gobbleopt
1081 %
1082 % \begin{macro}{\kernel@ifstar}
1083 % \changes{v3.20}{2016/04/12}{added}
1084 % I hope, the \LaTeX{} kernel will define this command in future. But
1085 % nevertheless, there are \LaTeX{} kernels in real live without this
1086 % command. So I do it again if needed:
1087 % \begin{macrocode}
1088 \providecommand*\kernel@ifstar[1]{\kernel@ifnextchar*{\@firstoftwo{#1}}}
1089 % \end{macrocode}
1090 % \end{macro}^^A \kernel@ifstar
1091 %
1092 %
1093 % \subsection{Extra Document Hooks}
1094 %
1095 % \begin{command}{\BeforeClosingMainAux}
1096 % \changes{v2.95}{2002/09/03}{added}
1097 % \begin{command}{\AfterReadingMainAux}
1098 % \changes{v3.03}{2009/03/25}{added}
1099 % These are completly different. First we have to establish a new hook
1100 % at \cs{end\{document\}}, just after closing the group and after the
1101 % final \cs{clearpage}.
1102 % \begin{description}
1103 % \item[ToDo:] Handling/ignoring an optional argument to make them more
1104 % compatible with \LaTeX's new \cs{AddToHook}.
1105 % \end{description}
1106 % \begin{macrocode}
1107 \AtEndDocument{%
1108 \let\scr@saved@checkend=\@checkend
1109 \renewcommand*{\@checkend}[1]{%
1110 \def\reserved@a{#1}\def\reserved@b{document}%
1111 \scr@saved@checkend{#1}%
1112 \ifx\reserved@a\reserved@b
1113 \let\scr@saved@clearpage=\clearpage
1114 \renewcommand*{\clearpage}{\scr@saved@clearpage
1115 \scr@hook@bcma
1116 \scr@restore@newpage
1117 \let\clearpage=\scr@saved@clearpage}%
1118 \fi%
1119 \let\scr@saved@dofilelist\@dofilelist
1120 \def\@dofilelist{%
1121 \scr@hook@acma
1122 \let\@dofilelist\scr@saved@dofilelist
1123 \scr@saved@dofilelist
1124 }%
1125 }%
1126 }
1127 % \end{macrocode}
1128 % \begin{macro}{\scr@saved@checkend}
1129 % \changes{v2.95}{2002/09/03}{added}
1130 % \begin{macro}{\scr@saved@dofilelist}
1131 % \changes{v3.03}{2009/03/25}{added}
1132 % You may see above, that we need save-to macros.
1133 % \begin{macrocode}
1134 \newcommand*{\scr@saved@checkend}{}
1135 \newcommand*{\scr@saved@dofilelist}{}
1136 % \end{macrocode}
1137 % \end{macro}^^A \scr@saved@dofilelist
1138 % \end{macro}^^A \scr@saved@checkend
1139 % \begin{macro}{\scr@redefine@newpage}
1140 % \changes{v3.00}{2008/07/09}{added}
1141 % Some classes (e.g. \cls{letter}) write output to the aux file.
1142 % Because of this, redefinition of \cs{newpage} will only be done, if
1143 % \cs{BeforeClosingMainAux} is used.
1144 % \begin{macro}{\scr@saved@newpage}
1145 % \changes{v3.00}{2008/07/09}{added}
1146 % And \cs{newpage} will be restored after the hook.
1147 % \begin{macro}{\scr@restore@newpage}
1148 % \begin{macrocode}
1149 \newcommand*{\scr@redefine@newpage}{%
1150 \let\scr@saved@newpage\newpage
1151 \def\scr@restore@newpage{%
1152 \renewcommand*{\newpage}{%
1153 \PackageWarningNoLine{%
1154 scrlfile%
1155 }{%
1156 \string\newpage\space at main aux file!\MessageBreak
1157 You have output material at the main aux file.\MessageBreak
1158 Note, that the \string\BeforeClosingMainAux\space commands\MessageBreak
1159 are processed before the output from aux file%
1160 }%
1161 \let\newpage\scr@saved@newpage
1162 \newpage
1163 }%
1164 }%
1165 \renewcommand*{\newpage}{%
1166 \PackageError{%
1167 scrlfile%
1168 }{%
1169 \string\newpage\space at \string\BeforeClosingMainAux
1170 }{%
1171 You should never use \string\newpage\space or
1172 \string\clear(double)page or other output material at the\MessageBreak
1173 argument of \string\BeforeClosingMainAux!\MessageBreak
1174 If you'll continue, the \string\newpage\space will be ignored to
1175 avoid corruption of\MessageBreak
1176 every prior use of \string\BeforeClosingMainAux.
1177 }%
1178 }%
1179 }
1180 \newcommand*{\scr@restore@newpage}{}
1181 % \end{macrocode}
1182 % \end{macro}^^A \scr@restore@newpage
1183 % \end{macro}^^A \scr@saved@newpage
1184 % \end{macro}^^A \scr@redefine@newpage
1185 % \begin{macro}{\scr@hook@bcma}
1186 % \changes{v2.95}{2002/09/03}{added}
1187 % \begin{macro}{\scr@hook@acma}
1188 % \changes{v3.03}{2009/03/25}{added}
1189 % We also need macros, that saves the commands at the hooks and are
1190 % extendable using \cs{g@addto@macro}.
1191 % \begin{macrocode}
1192 \newcommand*{\scr@hook@bcma}{}
1193 \newcommand*{\scr@hook@acma}{}
1194 % \end{macrocode}
1195 % \end{macro}^^A \scr@hook@acma
1196 % \end{macro}^^A \scr@hook@bcma
1197 % Now we are able to write the user command. Here we also warn, if we detect
1198 % one more \cs{newpage}\,---\,maybe at a \cs{clearpage} or
1199 % \cs{cleardoublepage}.
1200 % \begin{macrocode}
1201 \newcommand*{\BeforeClosingMainAux}{%
1202 \ifx\scr@hook@bcma\@empty
1203 \gdef\scr@hook@bcma{%
1204 \renewcommand*{\BeforeClosingMainAux}[1]{####1}%
1205 \let\protected@write\protected@immediate@write
1206 \scr@redefine@newpage
1207 }%
1208 \fi
1209 \g@addto@macro\scr@hook@bcma%
1210 }
1211 \newcommand*{\AfterReadingMainAux}{%
1212 \ifx\scr@hook@acma\@empty
1213 \gdef\scr@hook@acma{%
1214 \renewcommand*{\AfterReadingMainAux}[1]{####1}%
1215 \let\protected@write\protected@immediate@write
1216 }%
1217 \fi
1218 \g@addto@macro\scr@hook@acma%
1219 }
1220 % \end{macrocode}
1221 % \end{command}^^A \AfterReadingMainAux
1222 % \end{command}^^A \BeforeClosingMainAux
1223 %
1224 % \begin{macro}{\protected@immediate@write}
1225 % Like \LaTeX{} kernel's |\protected@write| but using |\immediate\write|. In
1226 % this case it is even not a good idea to protect |\thepage|!
1227 % \begin{macrocode}
1228 \long\def\protected@immediate@write#1#2#3{%
1229 \begingroup
1230 #2%
1231 \let\protect\@unexpandable@protect
1232 \edef\reserved@a{\immediate\write#1{#3}}%
1233 \reserved@a
1234 \endgroup
1235 \if@nobreak\ifvmode\nobreak\fi\fi
1236 }
1237 % \end{macrocode}
1238 % \end{macro}
1239 %
1240 %
1241 % \Finale
1242 % \PrintChanges
1243 % \endinput
1244 % Local Variables:
1245 % mode: doctex
1246 % ispell-local-dictionary: "en_US"
1247 % eval: (flyspell-mode 1)
1248 % TeX-master: t
1249 % TeX-engine: luatex-dev
1250 % eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-alist TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "mkindex %s" TeX-run-index nil t :help "makeindex for dtx"))
1251 % End: