Debian Codegraph @

texmf-dist/source/latex/ncctools/afterpackage.dtx

raw
1 % \iffalse
2 %%
3 %% File: afterpackage.dtx Copyright (C) 2005, 2006 by Alexander I. Rozhenko
4 %%
5 %<package>\NeedsTeXFormat{LaTeX2e}
6 %<package>\ProvidesPackage{afterpackage}
7 %<package> [2006/01/17 v1.1 Apply Commands After Package (NCC)]
8 %
9 % \changes{v1.0}{2005/12/25}{Initial version}
10 % \changes{v1.1}{2006/01/17}{The package renamed to `afterpackage'}
11 %
12 %<*driver>
13 \let\makeindex\relax
14 \documentclass{ltxdoc}
15 \usepackage{afterpackage}
16 \GetFileInfo{afterpackage.sty}
17 \begin{document}
18 \title{The \textsf{afterpackage} package\thanks{This file
19 has version number \fileversion, last
20 revised \filedate.}}
21 \author{Alexander I. Rozhenko\\[email protected]}
22 \date{\filedate}
23 \maketitle
24 \DocInput{afterpackage.dtx}
25 \end{document}
26 %</driver>
27 % \fi
28 % The package allows specify what additional commands should be applied
29 % to a package after its loading. To describe the usability of
30 % the package, consider the task of customization of a number of
31 % packages. Let we need to apply some package-specific code after loading
32 % packages such as customization of their defaults or hooks.
33 % To do this, we need to load all required packages and then apply the
34 % related staff to them. But, sometimes loading of all required packages is
35 % impossible or unnecessary because packages can have options or some of
36 % customized packages are rarely useful.
37 %
38 % The main idea of using this package is to specify how other packages
39 % can be customized in such a way that their customization is applied when
40 % and if customized packages are loaded. All the customization is applied
41 % in the preamble only.
42 %
43 % \DescribeMacro\AfterPackage
44 % To customize a package, load the \textbf{afterpackage} package and
45 % insert any number of the following commands anywhere in the preamble:
46 % \begin{quote}
47 % |\AfterPackage|\marg{package name}\marg{commands}
48 % \end{quote}
49 % The command works as follows: it tests the required package to be
50 % already loaded; if the package is loaded, it directly applies \meta{commands};
51 % otherwise, it collects \meta{commands} in a special macro. The specified
52 % macro will be applied later when the respective package will be loaded.
53 % This operation is executed when the package loading finishes and all
54 % end-of-package hooks are applied. So, the \meta{commands} are applied
55 % \emph{after the end} of respective package.
56 %
57 % \StopEventually{}
58 %
59 % \section{The Implementation}
60 %
61 % \begin{macro}{\AfterPackage}
62 % The command tests the |\ver@|\meta{filename} command to be
63 % defined and considers either collect commands in a special macro
64 % or apply them directly.
65 % \begin{macrocode}
66 %<*package>
67 \newcommand*\AfterPackage[1]{%
68 \expandafter\ifx\csname ver@#1.\@pkgextension\endcsname\relax
69 \@ifundefined{#1.\@pkgextension-@dd}{%
70 \expandafter\let\csname#1.\@pkgextension-@dd\endcsname\@empty
71 \expandafter\@onlypreamble\csname#1.\@pkgextension-@dd\endcsname
72 }{}%
73 \wlog{After Package Info: Collect commands for #1\on@line}%
74 \def\@tempa{%
75 \expandafter\g@addto@macro\csname#1.\@pkgextension-@dd\endcsname}%
76 \else
77 \ATP@apply@info{#1}%
78 \let\@tempa\@firstofone
79 \fi
80 \@tempa
81 }
82 \@onlypreamble\AfterPackage
83 % \end{macrocode}
84 % \end{macro}
85 %
86 % \begin{macro}{\@popfilename}
87 % To apply collected commands to a package, we use the |\@popfilename| hook.
88 % This hook is applied after loading a package. It pops a name of previous
89 % package or class which was active before loading a package. We save
90 % the original value of |\@popfilename| hook in a special macro and
91 % redefine it to execute the |\|\meta{filename}|-@dd| hook before pop of
92 % the previous filename.
93 % \begin{macrocode}
94 \let\ATP@popfilename\@popfilename
95 \@onlypreamble\ATP@popfilename
96 \def\@popfilename{%
97 \@ifundefined{\@currname.\@currext-@dd}{}{%
98 \ATP@apply@info{\@currname}%
99 \csname\@currname.\@currext-@dd\endcsname
100 \expandafter\let\csname\@currname.\@currext-@dd\endcsname\relax
101 }%
102 \ATP@popfilename
103 }
104 % \end{macrocode}
105 % \end{macro}
106 %
107 % \begin{macro}{\ATP@apply@info}
108 % This information message is logged when commands are applied. Its parameter
109 % contains a name of package which commands are customized.
110 % \begin{macrocode}
111 \def\ATP@apply@info#1{%
112 \wlog{After Package Info: Apply commands to #1\on@line}%
113 }
114 \@onlypreamble\ATP@apply@info
115 %</package>
116 % \end{macrocode}
117 % \end{macro}
118 \endinput