Debian Codegraph @

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

raw
1 % \iffalse^^A meta-comment
2 % ======================================================================
3 % scrlfile-hook.dtx
4 % Copyright (c) Markus Kohm, 2021-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 %
23 %%% From File: $Id: scrlfile-hook.dtx$
24 %<*dtx>
25 \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
26 \begingroup
27 \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
28 \filedate$Date: 2022-06-05 12:38:02 +0200 (So, 05. Jun 2022) $
29 \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
30 \filerevision$Revision: 3874 $
31 \edef\reserved@a{%
32 \noexpand\endgroup
33 \noexpand\ProvidesFile{scrlfile-hook.dtx}%
34 [\filedate\space\filerevision\space
35 KOMA-Script package source
36 }%
37 \reserved@a
38 %</dtx>
39 %<package&current>\ProvidesPackage{scrlfile-hook}[%
40 %<package&3.34>\ProvidesPackage{scrlfile-hook-3.34}[%
41 %!KOMAScriptVersion
42 %<package> package
43 (using LaTeX hooks)]
44 %<*dtx>
45 \ifx\documentclass\undefined
46 \input scrdocstrip.tex
47 \@@input scrkernel-version.dtx
48 \@@input scrstrip.inc
49 \KOMAdefVariable{COPYRIGHTFROM}{2002}
50 \generate{\usepreamble\defaultpreamble
51 \file{scrlfile-hook.sty}{%
52 \from{scrlfile-hook.dtx}{package,current}%
53 \from{scrlogo.dtx}{logo}%
54 }%
55 \file{scrlfile-hook-3.34.sty}{%
56 \from{scrlfile-hook.dtx}{package,3.34}%
57 \from{scrlogo.dtx}{logo}%
58 }%
59 }%
60 \@@input scrstrop.inc
61 \else
62 \let\endbatchfile\relax
63 \fi
64 \endbatchfile
65 \documentclass[USenglish]{l3doc}% Using class for documentation of expl3 style packages.
66 \usepackage{babel}
67 \expandafter\let\expandafter\nodriver\csname iffalse\endcsname
68 \expandafter\let\expandafter\endnodriver\csname fi\endcsname
69 \makeatletter\input{scrlogo.dtx}\makeatother
70 \CodelineIndex
71
72 \begin{document}
73 \DocInput{scrlfile-hook.dtx}
74 \end{document}
75 %</dtx>
76 % \fi^^A meta-comment
77 %
78 % \changes{v3.32}{2020/08/25}{new (sub-)package}
79 % \changes{v3.36}{2022/02/03}{use new documentation style}
80 % \changes{v3.36}{2022/02/03}{using \file{scrlogo.dtx} to define the logo}
81 %
82 % \GetFileInfo{scrlfile-hook.dtx}
83 % \title{\pkg{scrlfile} \KOMAScript{} Sub-Packages \pkg{scrlfile-hook} and
84 % \pkg{scrlfile-hook-3.34}}
85 % \author{\href{mailto:[email protected]}{Markus Kohm}}
86 % \date{Revision \fileversion{} of \filedate}
87 % \maketitle
88 % \begin{abstract}
89 % This package provides hooks before and after loading files, packages or
90 % classes. It also provides a hook after the last \cs{clearpage} of the
91 % document. It allowes to replace files, packages and classes by other
92 % files, packages and classes. It is inteded to be used by package and class
93 % authors but may also be used by \LaTeX{} users.
94 % \end{abstract}
95 % \tableofcontents
96 %
97 %
98 % \section{User Manual}
99 %
100 % \pkg{scrlfile-hook} implements the \LaTeX-hook-based part of
101 % \pkg{scrlfile}. \pkg{scrlfile-hook-3.34} is a variant for \LaTeX{} kernel
102 % versions before 2021/06/01.
103 %
104 % There isn't any user manual for the user level \LaTeXe{} commands in this
105 % file. Please see the manual of \pkg{scrlfile} for more information about
106 % \pkg{scrlfile-hook} and \pkg{scrlfile-hook-3.34}.
107 %
108 % This section, however, contains the user manual of the \LaTeX3{} package
109 % author commands.
110 %
111 % \begin{function}[TF, added = 2020-08-26]
112 % {\scrlfile_if_class_loaded:n,\scrlfile_if_package_loaded:n}
113 % \begin{syntax}
114 % \cs{scrlfile_if_class_loaded:nTF} \Arg{class name} \Arg{true code} \Arg{false code}
115 % \cs{scrlfile_if_package_loaded:nTF} \Arg{package name} \Arg{true code} \Arg{false code}
116 % \end{syntax}
117 % Tests if the class \meta{class name} resp. the package \meta{package name}
118 % has been loaded completely. It runs the \Arg{true code} only, if the input
119 % of the class file with the name \meta{class
120 % name}\file{.}\cs{@clsextension} resp. the package file with the name
121 % \meta{package name}\file{.}\cs{@pkgextension} has already been
122 % finished. It runs the \Arg{false code}, if the class or package has not
123 % been loaded or the input of the class or package file is still in
124 % progress.
125 % \end{function}
126 %
127 %
128 % \MaybeStop{\PrintIndex}
129 %
130 % \section{Implementation of \pkg{scrlfile-hook}}
131 %
132 % \begin{macrocode}
133 %<@@=scrlfile>
134 % \end{macrocode}
135 %
136 % Test whether the used \LaTeX{} provides all commands we need.
137 % \changes{v3.34}{2021/04/21}{make it more robust agains not recommended
138 % direct usage}
139 % \changes{v3.35}{2021/10/31}{new file version because \LaTeX{} kernel
140 % 2021/11/15 has changed the field order of gerneric hooks}
141 % \changes{v3.36}{2022/02/03}{package name in messages fixed}
142 % \begin{macrocode}
143 \@ifundefined{IfFormatAtLeastTF}{%
144 \PackageError{scrlfile-hook}{not recommended usage of package}{%
145 It seems this package has been loaded directly using a LaTeX
146 version\MessageBreak
147 prior to 2020-10-01. This is not recommended. Please always load
148 package\MessageBreak
149 scrlfile instead of scrlfile-hook.\MessageBreak
150 If you would continue, I will try to load scrlfile-patcholdlatex%
151 }%
152 \RequirePackage{scrlfile-patcholdlatex}\endinput
153 }{%
154 \IfFormatAtLeastTF{2020/10/01}{%
155 \IfFormatAtLeastTF{2021/11/15}{%
156 %<*3.34>
157 \PackageError{scrlfile-hook-3.34}{LaTeX too new for this package}{%
158 It seems this package has ben loaded directly using a LaTeX
159 version\MessageBreak
160 newer than 2021-06-01. This is not recommended. Please always load
161 package\MessageBreak
162 scrlfile instead of scrlfile-hook-3.34.\MessageBreak
163 If you would continue, I will try to load scrlfile-hook%
164 }%
165 \RequirePackage{scrlfile-hook}\endinput
166 %</3.34>
167 }{%
168 %<*current>
169 \PackageError{scrlfile-hook}{LaTeX too old for this package}{%
170 It seems this package has been loaded directly using LaTeX
171 version\MessageBreak
172 prior to 2021-11-15. This is not recommended. Please always load
173 package\MessageBreak
174 scrlfile instead of scrlfile-hook.\MessageBreak
175 If you would continue, I will try to load scrlfile-hook-3.34%
176 }%
177 \RequirePackage{scrlfile-hook-3.34}\endinput
178 %</current>
179 }%
180 }{%
181 \PackageError{scrlfile-hook}{LaTeX too old for this package}{%
182 It seems this package has been loaded directly using a LaTeX
183 version\MessageBreak
184 prior to 2020-10-01. This is not recommended. Please always load
185 package\MessageBreak
186 scrlfile instead of scrlfile-hook.\MessageBreak
187 If you would continue, I will try to load scrlfile-patcholdlatex%
188 }%
189 \RequirePackage{scrlfile-patcholdlatex}\endinput
190 }%
191 }
192 % \end{macrocode}
193 %
194 %
195 % \subsection{Before and After Commands}
196 %
197 % The hook implementation is based on a \LaTeX{} version that provides
198 % \LaTeX3. So it makes sense to use it.
199 %
200 % \begin{macrocode}
201 \ExplSyntaxOn
202 % \end{macrocode}
203 %
204 % \begin{macro}[updated = 2021-10-31]{\BeforeFile}
205 % The hook version of this command is just a wrapper to the corresponding
206 % \LaTeX{} file hooks. It supports a mandatory \meta{file} argument, an
207 % optional \meta{label} argument and a mandatory \meta{hook code} argument.
208 % From \LaTeX{} kernel version 2021/11/15 the hook has
209 % been changed from \texttt{file/before/\meta{file name}} to
210 % \texttt{file/\meta{file name}/before}.
211 % \begin{macrocode}
212 \NewDocumentCommand \BeforeFile { m }
213 {
214 %<3.34> \AddToHook { file / before / #1 }
215 %<current> \AddToHook { file / #1 / before }
216 }
217 % \end{macrocode}
218 % \end{macro}
219 %
220 % \begin{macro}[updated = 2021-10-31]{\AfterFile}
221 % The hook version of this command is just a wrapper to the corresponding
222 % \LaTeX{} file hooks. It supports a mandatory \meta{file} argument, an
223 % optional \meta{label} argument and a mandatory \meta{hook code} argument.
224 % From \LaTeX{} kernel version 2021/11/15 the hook has
225 % been changed from \texttt{file/after/\meta{file name}} to
226 % \texttt{file/\meta{file name}/after}.
227 % \begin{macrocode}
228 \NewDocumentCommand \AfterFile { m }
229 {
230 %<3.34> \AddToHook { file / after / #1 }
231 %<current> \AddToHook { file / #1 / after }
232 }
233 % \end{macrocode}
234 % \end{macro}
235 %
236 % \begin{macro}{\BeforeClass,\BeforePackage}
237 % The hook version of these commands are also wrappers to the
238 % \texttt{file/before} hooks, because the \meta{code} should also be executed
239 % already in the class or package context.
240 % \begin{macrocode}
241 \NewDocumentCommand \BeforeClass { m }
242 {
243 \BeforeFile { #1.\@clsextension }
244 }
245 \NewDocumentCommand \BeforePackage { m }
246 {
247 \BeforeFile { #1.\@pkgextension }
248 }
249 % \end{macrocode}
250 % \end{macro}
251 %
252 % \begin{macro}[updated = 2021-10-31, updated = 2021-11-09]
253 % {\AfterAtEndOfClass,\AfterAtEndOfPackage}
254 % \changes{v3.35}{2021/10/31}{field order of generic hooks changed in
255 % \LaTeX{} 2021/11/15}
256 % \changes{v3.35}{2021/11/09}{hooks became one-time hooks in
257 % \LaTeX{} 2021/11/15}
258 % With version 3.32 the syntax of these commands have been changed. Now, there
259 % is also a star variant, that runs the \meta{code} immediately if the class
260 % or package has already been loaded completely. Otherwise and in the normal
261 % variant the \meta{code} is added to the \texttt{class/after} or
262 % \texttt{package/after} hook, because this hook is used outside the context
263 % of the class or package and after the \cs{AtEndOfClass} or
264 % \cs{AtEndOfPackage} code.
265 % From \LaTeX{} kernel version 2021/11/15 the hooks has
266 % been changed from \texttt{class/after/\meta{class name}} to
267 % \texttt{class/\meta{class name}/after} and from
268 % \texttt{package/after/\meta{package name}} to
269 % \texttt{package/\meta{package name}/after}. Additionally the hooks became
270 % one-time hooks. So they are executed immediately, if the class or package
271 % has already been loaded. Because of this, we additionally have to test this
272 % case in the non star variant.
273 % \begin{macrocode}
274 \NewDocumentCommand \AfterAtEndOfClass { s m o +m }
275 {
276 \IfBooleanTF { #1 }
277 {
278 \scrlfile_if_class_loaded:nTF { #2 }
279 { #4 }
280 %<3.34> { \hook_gput_code:nnn { class / after / #2 } { #3 } { #4 } }
281 %<current> { \hook_gput_code:nnn { class / #2 / after } { #3 } { #4 } }
282 }
283 %<3.34> { \hook_gput_code:nnn { class / after / #2 } { #3 } { #4 } }
284 %<*current>
285 {
286 \scrlfile_if_class_loaded:nF
287 { #2 }
288 { \hook_gput_code:nnn { class / #2 / after } { #3 } { #4 } }
289 }
290 %</current>
291 }
292 \NewDocumentCommand \AfterAtEndOfPackage { s m o +m }
293 {
294 \IfBooleanTF { #1 }
295 {
296 \scrlfile_if_package_loaded:nTF { #2 }
297 { #4 }
298 %<3.34> { \hook_gput_code:nnn { package / after / #2 } { #3 } { #4 } }
299 %<current> { \hook_gput_code:nnn { package / #2 / after } { #3 } { #4 } }
300 }
301 %<3.34> { \hook_gput_code:nnn { package / after / #2 } { #3 } { #4 } }
302 %<*current>
303 {
304 \scrlfile_if_package_loaded:nF
305 { #2 }
306 { \hook_gput_code:nnn { package / #2 / after } { #3 } { #4 } }
307 }
308 %</current>
309 }
310 % \end{macrocode}
311 % \end{macro}
312 %
313 % \begin{variable}[added = 2020-06-26,
314 % updated = 2021-01-01]{\g__scrlfile_input_file_seq}
315 % \changes{3.33}{2021/01/01}{message definition moved outside function}
316 % \cs{g__scrlfile_input_file_seq} is a sequence of active file inputs (without
317 % path information). Two global hooks are used to setup the sequence. The new
318 % conditional tests if a file is in the sequence. And a message is defined for
319 % the case of more pops than pushs to the stack.
320 % \begin{macrocode}
321 \seq_new:N \g__scrlfile_input_file_seq
322 \hook_gput_code:nnn { file / before } { . }
323 { \seq_gpush:Nx \g__scrlfile_input_file_seq { \CurrentFile } }
324 \msg_new:nnn { scrlfile-hook } { too-many-pops }
325 {
326 More~file~names~popped~from~stack~than~put~to.~
327 This~should~never~happen.~
328 However,~it~could~happen~if~scrlfile-hook~is~loaded~by~another~
329 package~or~class.~In~this~case~some~packages~or~classes~are~not~
330 recognised~correctly.
331 }
332 \hook_gput_code:nnn { file / after } { . }
333 {
334 \seq_gpop:NNF \g__scrlfile_input_file_seq \l_tmpa_seq
335 {
336 \msg_warning:nn { scrlfile-hook } { too-many-pops }
337 }
338 }
339 % \end{macrocode}
340 % Unfortunately we need an ugly hack to initialise the stack using an internal
341 % kernel variable. This is a no go but I do not know a better solution for
342 % this, because loading of the package could be done late.
343 % \begin{description}
344 % \item[ToDo:] Decide, if the second or fourth token is correct. If fourth,
345 % \cs{CurrentFile} has to be used always instead of \cs{CurrentFileUsed}.
346 % \end{description}
347 % \begin{macrocode}
348 \cs_if_exist:NTF \g__filehook_input_file_seq
349 {
350 \seq_map_inline:Nn \g__filehook_input_file_seq
351 {
352 \seq_gput_right:Nx \g__scrlfile_input_file_seq
353 { \tl_item:nn { #1 } { 2 } }
354 }
355 }
356 {
357 \seq_gpush:Nx \g__scrlfile_input_file_seq { }
358 \cs_if_exist:NTF \CurrentFileUsed
359 { \seq_gpush:Nx \g__scrlfile_input_file_seq { \CurrentFileUsed } }
360 { \seq_gpush:Nx \g__scrlfile_input_file_seq { \CurrentFile } }
361 }
362 % \end{macrocode}
363 % \end{variable}
364 % \begin{function}[TF, added = 2020-06-26]{\@@_if_loading:n}
365 % Test if the file name is in the file name list.
366 % \begin{macrocode}
367 \prg_new_protected_conditional:Npnn \__scrlfile_if_loading:n #1 { T, F, TF }
368 {
369 \str_set:Nx \l_tmpa_str { #1 }
370 \seq_if_in:NxTF \g__scrlfile_input_file_seq { \str_use:N \l_tmpa_str }
371 { \prg_return_true: }
372 { \prg_return_false: }
373 }
374 % \end{macrocode}
375 % \end{function}
376 %
377 % \begin{function}[TF, added = 2020/08/22]
378 % {\scrlfile_if_class_loaded:n,\scrlfile_if_package_loaded:n}
379 % \cs{scrlfile_if_class_loaded:nTF} is similar to \cs{@ifclassloaded} and
380 % \cs{scrlfile_if_package_loaded:nTF} is similar to \cs{@ifpackageloaded} but in
381 % opposite to those they test, if the class or package has been loaded
382 % completely.
383 % \begin{macrocode}
384 \prg_new_protected_conditional:Npnn \scrlfile_if_class_loaded:n #1 { T, F, TF }
385 {
386 \@ifclassloaded { #1 }
387 {
388 \__scrlfile_if_loading:nTF { #1.\@clsextension }
389 { \prg_return_false: }
390 { \prg_return_true: }
391 }
392 {
393 \prg_return_false:
394 }
395 }
396 \prg_new_protected_conditional:Npnn \scrlfile_if_package_loaded:n #1 { T, F, TF }
397 {
398 \@ifpackageloaded { #1 }
399 {
400 \__scrlfile_if_loading:nTF { #1.\@pkgextension }
401 { \prg_return_false: }
402 { \prg_return_true: }
403 }
404 {
405 \prg_return_false:
406 }
407 }
408 % \end{macrocode}
409 % \end{function}
410 %
411 % \begin{macro}[updated = 2021-10-31]{\AfterClass,\AfterPackage}
412 % With version 3.32 these do not support plus or exclamation mark variants,
413 % but only the normal and the star variants. Instead of the plus or
414 % exclamation mark variants users should use the star variant of
415 % \cs{AfterAtEndOfClass} and \cs{AfterAtEndOfPackage}. The commands use the
416 % \texttt{file/after} hook, because the user manual declares, that \meta{code}
417 % is used before the code of \cs{AtEndOfClass} or \cs{AtEndOfPackage}.
418 % From \LaTeX{} kernel version 2021/11/15 the hook has
419 % been changed from \texttt{file/after/\meta{file name}} to
420 % \texttt{file/\meta{file name}/after}.
421 % \begin{macrocode}
422 \NewDocumentCommand \scrlfile@AfterClass { s m o +m }
423 {
424 \IfBooleanTF { #1 }
425 {
426 \@ifclassloaded{ #2 }
427 { #4 }
428 {
429 \hook_gput_code:nnn
430 %<3.34> { file / after / #2.\@clsextension }
431 %<current> { file / #2.\@clsextension / after }
432 { #3 }
433 { #4 }
434 }
435 }
436 {
437 %<3.34> \hook_gput_code:nnn { file / after / #2.\@clsextension } { #3 } { #4 }
438 %<current> \hook_gput_code:nnn { file / #2.\@clsextension / after } { #3 } { #4 }
439 }
440 }
441 \NewDocumentCommand \AfterClass { } { \scrlfile@AfterClass }
442 \NewDocumentCommand \scrlfile@AfterPackage { s m o +m }
443 {
444 \IfBooleanTF { #1 }
445 {
446 \@ifpackageloaded{ #2 }
447 { #4 }
448 {
449 \hook_gput_code:nnn
450 %<3.34> { file / after / #2.\@pkgextension }
451 %<current> { file / #2.\@pkgextension / after }
452 { #3 }
453 { #4 }
454 }
455 }
456 {
457 %<3.34> \hook_gput_code:nnn { file / after / #2.\@pkgextension } { #3 } { #4 }
458 %<current> \hook_gput_code:nnn { file / #2.\@pkgextension / after } { #3 } { #4 }
459 }
460 }
461 \NewDocumentCommand \AfterPackage { } { \scrlfile@AfterPackage }
462 % \end{macrocode}
463 % \end{macro}
464 %
465 %
466 % \subsection{File Substitution}
467 %
468 % With new file hooks the substitutions are so easy we even do not need
469 % \LaTeX3 syntax to implement them.
470 %
471 % \begin{macro}{\ReplaceInput}
472 % This is only the simplest wrapper to \cs{declare@file@substitution}.
473 % \begin{macrocode}
474 \NewDocumentCommand{\ReplaceInput}{}{\declare@file@substitution}
475 % \end{macrocode}
476 % \end{macro}
477 %
478 % \begin{macro}{\ReplaceClass}
479 % \begin{macro}{\ReplacePackage}
480 % These are also wrappers to \cs{declare@file@substitution}. But in this case
481 % we also have to add the extension.
482 % \begin{macrocode}
483 \NewDocumentCommand\ReplaceClass{mm}{%
484 \declare@file@substitution{#1.\@clsextension}{#2.\@clsextension}%
485 }
486 \NewDocumentCommand\ReplacePackage{mm}{%
487 \declare@file@substitution{#1.\@pkgextension}{#2.\@pkgextension}%
488 }
489 % \end{macrocode}
490 % \end{macro}
491 % \end{macro}
492 %
493 % \begin{macro}{\UnReplaceInput}
494 % This is the simplest wrapper to \cs{undeclare@file@substitution}.
495 % \begin{macrocode}
496 \NewDocumentCommand{\UnReplaceInput}{}{\undeclare@file@substitution}
497 % \end{macrocode}
498 % \end{macro}
499 %
500 % \begin{macro}{\UnReplaceClass}
501 % \begin{macro}{\UnReplacePackage}
502 % Also very simple but again we have to add the extension.
503 % \begin{macrocode}
504 \NewDocumentCommand\UnReplaceClass{m}{%
505 \undeclare@file@substitution{#1.\@clsextension}%
506 }
507 \NewDocumentCommand\UnReplacePackage{mm}{%
508 \undeclare@file@substitution{#1.\@pkgextension}%
509 }
510 % \end{macrocode}
511 % \end{macro}
512 % \end{macro}
513 %
514 % \subsection{Prevent Package from Loading}
515 %
516 % To store and reset the hole list of prevents we use a comma separated
517 % list. So we need again use \LaTeX3.
518 %
519 % \begin{variable}[added = 2020-09-02]{\g__scrlfile_prevents_clist}
520 % This local variable stores the list of files, that should be prevented from
521 % loading. It is needed to stay compatible with old \file{scrlfile}. Without
522 % this compatibility purpose we would be able to use simple wrappers to
523 % \cs{disable@package@load} and \cs{reenable@package@load}.
524 % \begin{macrocode}
525 \clist_new:N \g__scrlfile_prevent_clist
526 % \end{macrocode}
527 % \end{variable}
528 %
529 % \begin{macro}{\PreventPackageFromLoading}
530 % This is more than a wrapper to \cs{disable@package@load} because we have to
531 % manage an internal list and it is documented, that the re-enabling does not
532 % undefine the \meta{alternate-code} setting but only disables it. So we have
533 % to extra store it. Note: Local loading of packages does not make sense, so
534 % local changes of the prevent list also does not make sense. Therefore this
535 % is a global acting command!
536 % \begin{macrocode}
537 \NewDocumentCommand \PreventPackageFromLoading { s +o m }
538 {
539 \clist_set:Nx \l__scrlfile_package_clist { #3 }
540 \clist_map_inline:Nn \l__scrlfile_package_clist
541 {
542 \@ifpackageloaded { ##1 }
543 {
544 \IfBooleanTF { #1 } { \msg_info:nnn } { \msg_warning:nnn }
545 { scrlfile } { no-prevent-for-already-loaded } { ##1 }
546 }
547 {
548 \clist_if_in:NnF \g__scrlfile_prevent_clist { ##1 }
549 { \clist_gput_right:Nn \g__scrlfile_prevent_clist { ##1 } }
550 \tl_if_exist:cF { g__scrlfile_exclude_package_##1_tl }
551 {
552 \tl_new:c { g__scrlfile_exclude_package_##1_tl }
553 }
554 \IfValueT { #2 }
555 {
556 \tl_gput_right:cn { g__scrlfile_exclude_package_##1_tl } { #2 }
557 }
558 \disable@package@load { ##1 }
559 { \tl_use:c { g__scrlfile_exclude_package_##1_tl } }
560 }
561 }
562 \clist_clear:N \l__scrlfile_package_clist
563 }
564 % \end{macrocode}
565 %
566 % \begin{macro}{\l__scrlfile_package_clist}
567 % One local variable is used to process the \meta{package-list} argument of
568 % \cs{PreventPackageFromLoading}.
569 % \begin{macrocode}
570 \clist_new:N \l__scrlfile_package_clist
571 % \end{macrocode}
572 % \end{macro}
573 %
574 % And here comes the message, that could be used either as a warning or as an
575 % info.
576 % \begin{macrocode}
577 \msg_new:nnn { scrlfile } { no-prevent-for-already-loaded }
578 {
579 Cannot~prevent~package~`#1'~from~being~loaded,~
580 because~it~has~been~loaded~already~before~line~\msg_line_number:
581 }
582 % \end{macrocode}
583 % \end{macro}
584 %
585 % \begin{macro}{\StorePreventPackageFromLoading}
586 % This simply copies the internal \texttt{clist} to a macro.
587 % \begin{macrocode}
588 \NewDocumentCommand \StorePreventPackageFromLoading { m }
589 { \edef #1 { \clist_use:Nn \g__scrlfile_prevent_clist { , } } }
590 % \end{macrocode}
591 % \end{macro}
592 %
593 % \begin{macro}{\ResetPreventPackageFromLoading}
594 % Map the internal list to a function that re-enables the package. At the end
595 % the internal list is cleared.
596 % \begin{macrocode}
597 \NewDocumentCommand \ResetPreventPackageFromLoading {}
598 {
599 \clist_map_function:NN \g__scrlfile_prevent_clist \reenable@package@load
600 \clist_gclear:N \g__scrlfile_prevent_clist
601 }
602 % \end{macrocode}
603 % \end{macro}
604 %
605 % \begin{macro}{\UnPreventPackageFromLoading}
606 % Here again the argument is a \meta{package-list} not only one
607 % \meta{package}. So we have to build a local \texttt{clist} and walk through
608 % it.
609 % \begin{macrocode}
610 \NewDocumentCommand \UnPreventPackageFromLoading { s m }
611 {
612 \clist_set:Nx \l__scrlfile_package_clist { #2 }
613 \clist_map_inline:Nn \l__scrlfile_package_clist
614 {
615 \clist_if_in:NnT \g__scrlfile_prevent_clist { ##1 }
616 {
617 \clist_gremove_all:Nn \g__scrlfile_prevent_clist { ##1 }
618 \reenable@package@load { ##1 }
619 \IfBooleanT { #1 }
620 { \cs_undefine:c { g__scrlfile_exclude_package_##1_tl } }
621 }
622 }
623 }
624 % \end{macrocode}
625 % \end{macro}
626 %
627 %
628 % \subsection{Extra Document Hooks}
629 %
630 % \begin{macro}{\BeforeClosingMainAux}
631 % \changes{v3.32}{2020/09/10}{optional argument added}
632 % Here we cannot simply wrap this to the hook
633 % \texttt{enddocument/afterlastpage}, because it is documented, that inside
634 % the \meta{code} \cs{protected@write} is replaced by
635 % \cs{immediate@protected@write}. So we have to take extra care to it.
636 % \begin{macrocode}
637 \NewDocumentCommand \BeforeClosingMainAux { o m }
638 {
639 \hook_gput_code:nnn { enddocument / afterlastpage } { #1 }
640 {
641 \debug_suspend:
642 \RenewDocumentCommand \BeforeClosingMainAux { m } { ##1 }
643 \cs_set_eq:NN \__scrlfile_protected@write:Nnn \protected@write
644 \cs_set_eq:NN \protected@write \protected@immediate@write
645 #2
646 \cs_set_eq:NN \protected@write \__scrlfile_protected@write:Nnn
647 \debug_resume:
648 }
649 }
650 % \end{macrocode}
651 % \end{macro}
652 %
653 % \begin{macro}{\AfterReadingMainAux}
654 % \changes{v3.32}{2020/09/10}{optional argument added}
655 % Here we the exact same problem as with \cs{BeforeClosingMainAux}.
656 % \begin{macrocode}
657 \NewDocumentCommand \AfterReadingMainAux { o m }
658 {
659 \hook_gput_code:nnn { enddocument / afteraux } { #1 }
660 {
661 \debug_suspend:
662 \RenewDocumentCommand \AfterReadingMainAux { m } { ##1 }
663 \cs_set_eq:NN \__scrlfile_protected@write:Nnn \protected@write
664 \cs_set_eq:NN \protected@write \protected@immediate@write
665 #2
666 \cs_set_eq:NN \protected@write \__scrlfile_protected@write:Nnn
667 \debug_resume:
668 }
669 }
670 % \end{macrocode}
671 % \end{macro}
672 %
673 % \begin{macrocode}
674 \ExplSyntaxOff
675 % \end{macrocode}
676 %
677 % \subsection{Kernel Extensions not Using \LaTeX3}
678 %
679 % \begin{macro}{\protected@immediate@write}
680 % Like \LaTeX{} kernel's |\protected@write| but using |\immediate\write|. In
681 % this case it is even not a good idea to protect |\thepage|!
682 % \begin{macrocode}
683 \ProvideDocumentCommand\protected@immediate@write{m+m+m}
684 {%
685 \begingroup
686 #2%
687 \let\protect\@unexpandable@protect
688 \edef\reserved@a{\immediate\write#1{#3}}%
689 \reserved@a
690 \endgroup
691 \if@nobreak\ifvmode\nobreak\fi\fi
692 }
693 % \end{macrocode}
694 % \end{macro}
695 %
696 % \Finale
697 % \PrintChanges
698 %
699 % \endinput
700 % Local Variables:
701 % mode: doctex
702 % ispell-local-dictionary: "en_US"
703 % eval: (flyspell-mode 1)
704 % TeX-master: t
705 % TeX-engine: luatex-dev
706 % 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"))
707 % End: