Debian Codegraph @

texmf-dist/tex/latex/filehook/filehook-2020.sty

raw
1 %% Copyright (c) 2011-2022 by Martin Scharrer <[email protected]>
2 %% ----------------------------------------------------------------------
3 %% This work may be distributed and/or modified under the
4 %% conditions of the LaTeX Project Public License, either version 1.3
5 %% of this license or (at your option) any later version.
6 %% The latest version of this license is in
7 %% http://www.latex-project.org/lppl.txt
8 %% and version 1.3 or later is part of all distributions of LaTeX
9 %% version 2005/12/01 or later.
10 %%
11 %% This work has the LPPL maintenance status `maintained'.
12 %%
13 %% The Current Maintainer of this work is Martin Scharrer.
14 %%
15 %% This work consists of the files filehook.dtx and filehook.ins
16 %% and the derived files filehook.sty, filehook-fink.sty,
17 %% filehook-listings.sty, filehook-memoir.sty, filehook-scrlfile.sty
18 %% and pgf-filehook.sty
19 %%
20 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
21 \ProvidesPackage{filehook-2020}[% filehook subpackage, do not load directly
22 2022/10/25
23 v0.8b
24 Hooks for input files]
25 \DeclareOption{force}{}
26 \ProcessOptions\relax
27 \begingroup
28 \gdef\filehook@csuse#1{\ifcsname #1\endcsname\csname #1\expandafter\endcsname\fi}
29 \expandafter\ifx\csname csuse\endcsname\relax
30 \expandafter\ifx\csname ifcsname\endcsname\relax
31 \gdef\filehook@csuse#1{\expandafter\ifx\csname #1\endcsname\relax\else\csname #1\expandafter\endcsname\fi}
32 \fi
33 \else
34 \global\let\filehook@csuse\csuse
35 \fi
36 \endgroup
37 \def\filehook@include@atbegin#1{%
38 \filehook@csuse{\filehook@include@atbegin@#1}%
39 \filehook@include@@atbegin
40 }
41 \def\filehook@include@@atbegin{}
42 \def\filehook@include@atend#1{%
43 \filehook@include@@atend
44 \filehook@csuse{\filehook@include@atend@#1}%
45 }
46 \def\filehook@include@@atend{}
47 \def\filehook@include@after#1{%
48 \filehook@include@@after
49 \filehook@csuse{\filehook@include@after@#1}%
50 }
51 \def\filehook@include@@after{}
52 \def\filehook@input@atbegin#1{%
53 \filehook@csuse{\filehook@input@atbegin@\filehook@ensureext{#1}}%
54 \filehook@input@@atbegin
55 }
56 \def\filehook@input@@atbegin{}
57 \def\filehook@input@atend#1{%
58 \filehook@input@@atend
59 \filehook@csuse{\filehook@input@atend@\filehook@ensureext{#1}}%
60 }
61 \def\filehook@input@@atend{}
62 \def\filehook@atbegin#1{%
63 \filehook@csuse{\filehook@atbegin@\filehook@ensureext{#1}}%
64 \filehook@@atbegin
65 }
66 \def\filehook@@atbegin{}
67 \def\filehook@atend#1{%
68 \filehook@@atend
69 \filehook@csuse{\filehook@atend@\filehook@ensureext{#1}}%
70 }
71 \def\filehook@@atend{}
72 \def\filehook@every@atbegin#1{%
73 \filehook@every@@atbegin
74 }
75 \def\filehook@every@@atbegin{}
76 \def\filehook@every@atend#1{%
77 \filehook@every@@atend
78 }
79 \def\filehook@every@@atend{}
80 \def\filehook@include@atbegin@{filehook@include@atbegin@}
81 \def\filehook@include@atend@{filehook@include@atend@}
82 \def\filehook@include@after@{filehook@include@after@}
83 \def\filehook@input@atbegin@{filehook@input@atbegin@}
84 \def\filehook@input@atend@{filehook@input@atend@}
85 \def\filehook@input@after@{filehook@input@after@}
86 \def\filehook@atbegin@{filehook@atbegin@}
87 \def\filehook@atend@{filehook@atend@}
88 \def\filehook@after@{filehook@after@}
89 \def\filehook@append{\g@addto@macro}
90 \long\def\filehook@appendwarg#1#2{%
91 \begingroup
92 \toks@\expandafter{#1{##1}#2}%
93 \edef\@tempa{\the\toks@}%
94 \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
95 \endgroup
96 }
97 \long\def\filehook@prefix#1#2{%
98 \begingroup
99 \@temptokena{#2}%
100 \toks@\expandafter{#1}%
101 \xdef#1{\the\@temptokena\the\toks@}%
102 \endgroup
103 }
104 \long\def\filehook@prefixwarg#1#2{%
105 \begingroup
106 \@temptokena{#2}%
107 \toks@\expandafter{#1{##1}}%
108 \edef\@tempa{\the\@temptokena\the\toks@}%
109 \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
110 \endgroup
111 }
112 \def\filehook@addtohook#1#2#3{%
113 \begingroup
114 \edef\@tempa{#3}%
115 \edef\@tempa{#2\filehook@ensureext{\@tempa}}%
116 \@ifundefined{\@tempa}{\global\@namedef{\@tempa}{}}{}%
117 \expandafter\endgroup
118 \expandafter#1\csname\@tempa\endcsname
119 }
120 \newcommand*\AtBeginOfIncludes{%
121 \filehook@append\filehook@include@@atbegin
122 }
123 \newcommand*\AtEndOfIncludes{%
124 \filehook@prefix\filehook@include@@atend
125 }
126 \newcommand*\AfterIncludes{%
127 \filehook@prefix\filehook@include@@after
128 }
129 \newcommand*\AtBeginOfIncludeFile[1]{%
130 \filehook@addtohook\filehook@append\filehook@include@atbegin@{\filehook@ensuretex{#1}}%
131 }
132 \newcommand*\AtEndOfIncludeFile[1]{%
133 \filehook@addtohook\filehook@prefix\filehook@include@atend@{\filehook@ensuretex{#1}}%
134 }
135 \newcommand*\AfterIncludeFile[1]{%
136 \filehook@addtohook\filehook@prefix\filehook@include@after@{\filehook@ensuretex{#1}}%
137 }
138 \newcommand*\AtBeginOfInputs{%
139 \filehook@append\filehook@input@@atbegin
140 }
141 \newcommand*\AtEndOfInputs{%
142 \filehook@prefix\filehook@input@@atend
143 }
144 \newcommand*\AtBeginOfInputFile{%
145 \filehook@addtohook\filehook@append\filehook@input@atbegin@
146 }
147 \newcommand*\AtEndOfInputFile{%
148 \filehook@addtohook\filehook@prefix\filehook@input@atend@
149 }
150 \newcommand*\AtBeginOfFiles{%
151 \filehook@append\filehook@@atbegin
152 }
153 \newcommand*\AtEndOfFiles{%
154 \filehook@prefix\filehook@@atend
155 }
156 \newcommand*\AtBeginOfEveryFile{%
157 \filehook@append\filehook@every@@atbegin
158 }
159 \newcommand*\AtEndOfEveryFile{%
160 \filehook@prefix\filehook@every@@atend
161 }
162 \newcommand*\AtBeginOfFile{%
163 \filehook@addtohook\filehook@append\filehook@atbegin@
164 }
165 \newcommand*\AtEndOfFile{%
166 \filehook@addtohook\filehook@prefix\filehook@atend@
167 }
168 \newcommand*\AtBeginOfClassFile{%
169 \@ifnextchar*
170 {\AtBeginOfXFile@star\@clsextension}%
171 {\AtBeginOfXFile@normal\@clsextension}%
172 }
173 \newcommand*\AtBeginOfPackageFile{%
174 \@ifnextchar*
175 {\AtBeginOfXFile@star\@pkgextension}%
176 {\AtBeginOfXFile@normal\@pkgextension}%
177 }
178 \def\AtBeginOfXFile@star#1*#2{%
179 \@ifl@aded{#1}{#2}%
180 {\@firstofone}%
181 {\AtBeginOfXFile@normal{#1}{#2}}%
182 }
183 \def\AtBeginOfXFile@normal#1#2{%
184 \AtBeginOfFile{#2.#1}%
185 }
186 \newcommand*\AtEndOfClassFile{%
187 \@ifnextchar*
188 {\AtEndOfXFile@star\@clsextension}%
189 {\AtEndOfXFile@normal\@clsextension}%
190 }
191 \newcommand*\AtEndOfPackageFile{%
192 \@ifnextchar*
193 {\AtEndOfXFile@star\@pkgextension}%
194 {\AtEndOfXFile@normal\@pkgextension}%
195 }
196 \def\AtEndOfXFile@star#1*#2{%
197 \@ifl@aded{#1}{#2}%
198 {\@firstofone}%
199 {\AtEndOfXFile@normal{#1}{#2}}%
200 }
201 \long\def\AtEndOfXFile@normal#1#2#3{%
202 \AtEndOfFile{#2.#1}{\AtEndOfPackage{#3}}%
203 }
204 \newcommand*\ClearHook{%
205 \begingroup
206 \def\filehook@prefix##1##2{%
207 \gdef##1{}%
208 \endgroup
209 }%
210 \let\filehook@append\filehook@prefix
211 }
212 \def\DEPRECATED@input@#1{%
213 \@ifnextchar\clearpage
214 {%
215 \filehook@every@atbegin{#1}%
216 \filehook@include@atbegin{#1}%
217 \filehook@orig@@input@{#1}%
218 \filehook@include@atend{#1}%
219 \clearpage
220 \filehook@include@after{#1}%
221 \filehook@every@atend{#1}%
222 \@gobble
223 }%
224 {\filehook@orig@@input@{#1}}%
225 }
226 \def\filehook@@iinput#1{%
227 \filehook@every@atbegin{#1}%
228 \filehook@input@atbegin{#1}%
229 \filehook@orig@@iinput{#1}%
230 \filehook@input@atend{#1}%
231 \filehook@every@atend{#1}%
232 }
233 \def\filehook@ensureext#1{%
234 \expandafter\filehook@@ensureext#1\empty.tex\empty\empty
235 }
236 \def\filehook@@ensureext#1.#2\empty#3\empty{#1.#2}
237 \def\filehook@ensuretex#1{%
238 \expandafter\filehook@@ensuretex#1\empty.tex\empty\empty
239 }
240 \def\filehook@@ensuretex#1.tex\empty#2\empty{#1.tex}
241 \def\filehook@set@CurrentFile{%
242 \edef\filehook@CurrentFile{%
243 \ifx\CurrentFilePath\empty
244 \else
245 \CurrentFilePath/%
246 \fi
247 \CurrentFile
248 }%
249 }
250 \AddToHook{include/before}{%
251 \filehook@set@CurrentFile
252 \filehook@include@atbegin{\filehook@CurrentFile}%
253 }
254 \AddToHook{include/end}{%
255 \filehook@set@CurrentFile
256 \filehook@include@atend{\filehook@CurrentFile}%
257 }
258 \AddToHook{include/after}{%
259 \filehook@set@CurrentFile
260 \filehook@include@after{\filehook@CurrentFile}%
261 }
262 \begingroup
263 \edef\dottex{\expandafter\expandafter\expandafter\@gobble\expandafter\string\csname.tex\endcsname}
264 \expandafter
265 \gdef\expandafter\filehook@istexfile\expandafter#\expandafter1\expandafter{%
266 \expandafter\expandafter\expandafter\filehook@istexfile@\expandafter#\expandafter1\expandafter\empty\dottex\empty\empty\@nil
267 }
268 \expandafter\gdef\expandafter\filehook@istexfile@\expandafter#\expandafter1\dottex\empty#2\empty#3\@nil{%
269 \begingroup
270 \def\@tempa{#2}%
271 \ifx\@tempa\empty
272 \endgroup
273 \expandafter\@secondoftwo
274 \else
275 \endgroup
276 \expandafter\@firstoftwo
277 \fi
278 }
279 \endgroup
280 \AddToHook{file/before}{%
281 \filehook@set@CurrentFile
282 \filehook@every@atbegin{\filehook@CurrentFile}%
283 \filehook@istexfile\filehook@CurrentFile{\filehook@input@atbegin{\filehook@CurrentFile}}{}%
284 \filehook@atbegin{\filehook@CurrentFile}%
285 }
286 \AddToHook{file/after}{%
287 \filehook@set@CurrentFile
288 \filehook@atend{\filehook@CurrentFile}%
289 \filehook@istexfile\filehook@CurrentFile{\filehook@input@atend{\filehook@CurrentFile}}{}%
290 \filehook@every@atend{\filehook@CurrentFile}%
291 }
292 \endinput
293 %%
294 %% End of file `filehook-2020.sty'.