Debian Codegraph @

texmf-dist/tex/latex/filehook/filehook-2019.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-2019}[% filehook subpackage, do not load directly
22 2022/10/25
23 v0.8b
24 Hooks for input files]
25 \newif\iffilehook@force
26 \DeclareOption{force}{\filehook@forcetrue}
27 \ProcessOptions\relax
28 \newif\iffilehook@newfmt
29 \@ifl@t@r\fmtversion{2019/10/01}{\filehook@newfmttrue}{\filehook@newfmtfalse}
30 \def\filehook@let#1#2{%
31 \expandafter\ifx\csname #2\space\endcsname\relax
32 \expandafter\let\csname #1\expandafter\endcsname\csname #2\endcsname
33 \else
34 \expandafter\def\csname #1\expandafter\endcsname\expandafter{\expandafter\protect\csname #1\space\endcsname}%
35 \expandafter\let\csname #1\space\expandafter\endcsname\csname #2\space\endcsname
36 \fi
37 }
38 \def\filehook@glet#1#2{%
39 \expandafter\ifx\csname #2\space\endcsname\relax
40 \expandafter\global\expandafter\let\csname #1\expandafter\endcsname\csname #2\endcsname
41 \else
42 \expandafter\global\expandafter\def\csname #1\expandafter\endcsname\expandafter{\expandafter\protect\csname #1\space\endcsname}%
43 \expandafter\global\expandafter\let\csname #1\space\expandafter\endcsname\csname #2\space\endcsname
44 \fi
45 }
46 \def\filehook@cmp#1#2{%
47 \expandafter\ifx\csname #2\space\endcsname\relax
48 \expandafter\ifx\csname #1\expandafter\endcsname\csname #2\endcsname
49 \expandafter\expandafter\expandafter\@firstoftwo
50 \else
51 \expandafter\expandafter\expandafter\@secondoftwo
52 \fi
53 \else
54 \expandafter\ifx\csname #1\space\expandafter\endcsname\csname #2\space\endcsname
55 \expandafter\expandafter\expandafter\@firstoftwo
56 \else
57 \expandafter\expandafter\expandafter\@secondoftwo
58 \fi
59 \fi
60 }
61 \begingroup
62 \gdef\filehook@csuse#1{\ifcsname #1\endcsname\csname #1\expandafter\endcsname\fi}
63 \expandafter\ifx\csname csuse\endcsname\relax
64 \expandafter\ifx\csname ifcsname\endcsname\relax
65 \gdef\filehook@csuse#1{\expandafter\ifx\csname #1\endcsname\relax\else\csname #1\expandafter\endcsname\fi}
66 \fi
67 \else
68 \global\let\filehook@csuse\csuse
69 \fi
70 \endgroup
71 \def\filehook@include@atbegin#1{%
72 \filehook@let{InputIfFileExists}{filehook@@InputIfFileExists}%
73 \filehook@csuse{\filehook@include@atbegin@#1}%
74 \filehook@include@@atbegin
75 }
76 \def\filehook@include@@atbegin{}
77 \def\filehook@include@atend#1{%
78 \filehook@include@@atend
79 \filehook@csuse{\filehook@include@atend@#1}%
80 }
81 \def\filehook@include@@atend{}
82 \def\filehook@include@after#1{%
83 \filehook@include@@after
84 \filehook@csuse{\filehook@include@after@#1}%
85 }
86 \def\filehook@include@@after{}
87 \def\filehook@input@atbegin#1{%
88 \filehook@let{InputIfFileExists}{filehook@@InputIfFileExists}%
89 \filehook@csuse{\filehook@input@atbegin@\filehook@ensureext{#1}}%
90 \filehook@input@@atbegin
91 }
92 \def\filehook@input@@atbegin{}
93 \def\filehook@input@atend#1{%
94 \filehook@input@@atend
95 \filehook@csuse{\filehook@input@atend@\filehook@ensureext{#1}}%
96 }
97 \def\filehook@input@@atend{}
98 \def\filehook@atbegin#1{%
99 \filehook@csuse{\filehook@atbegin@\filehook@ensureext{#1}}%
100 \filehook@@atbegin
101 }
102 \def\filehook@@atbegin{}
103 \def\filehook@atend#1{%
104 \filehook@@atend
105 \filehook@csuse{\filehook@atend@\filehook@ensureext{#1}}%
106 }
107 \def\filehook@@atend{}
108 \def\filehook@every@atbegin#1{%
109 \filehook@every@@atbegin
110 }
111 \def\filehook@every@@atbegin{}
112 \def\filehook@every@atend#1{%
113 \filehook@every@@atend
114 }
115 \def\filehook@every@@atend{}
116 \def\filehook@include@atbegin@{filehook@include@atbegin@}
117 \def\filehook@include@atend@{filehook@include@atend@}
118 \def\filehook@include@after@{filehook@include@after@}
119 \def\filehook@input@atbegin@{filehook@input@atbegin@}
120 \def\filehook@input@atend@{filehook@input@atend@}
121 \def\filehook@input@after@{filehook@input@after@}
122 \def\filehook@atbegin@{filehook@atbegin@}
123 \def\filehook@atend@{filehook@atend@}
124 \def\filehook@after@{filehook@after@}
125 \def\filehook@append{\g@addto@macro}
126 \long\def\filehook@appendwarg#1#2{%
127 \begingroup
128 \toks@\expandafter{#1{##1}#2}%
129 \edef\@tempa{\the\toks@}%
130 \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
131 \endgroup
132 }
133 \long\def\filehook@prefix#1#2{%
134 \begingroup
135 \@temptokena{#2}%
136 \toks@\expandafter{#1}%
137 \xdef#1{\the\@temptokena\the\toks@}%
138 \endgroup
139 }
140 \long\def\filehook@prefixwarg#1#2{%
141 \begingroup
142 \@temptokena{#2}%
143 \toks@\expandafter{#1{##1}}%
144 \edef\@tempa{\the\@temptokena\the\toks@}%
145 \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
146 \endgroup
147 }
148 \def\filehook@addtohook#1#2#3{%
149 \begingroup
150 \edef\@tempa{#3}%
151 \edef\@tempa{#2\filehook@ensureext{\@tempa}}%
152 \@ifundefined{\@tempa}{\global\@namedef{\@tempa}{}}{}%
153 \expandafter\endgroup
154 \expandafter#1\csname\@tempa\endcsname
155 }
156 \newcommand*\AtBeginOfIncludes{%
157 \filehook@append\filehook@include@@atbegin
158 }
159 \newcommand*\AtEndOfIncludes{%
160 \filehook@prefix\filehook@include@@atend
161 }
162 \newcommand*\AfterIncludes{%
163 \filehook@prefix\filehook@include@@after
164 }
165 \newcommand*\AtBeginOfIncludeFile[1]{%
166 \filehook@addtohook\filehook@append\filehook@include@atbegin@{\filehook@ensuretex{#1}}%
167 }
168 \newcommand*\AtEndOfIncludeFile[1]{%
169 \filehook@addtohook\filehook@prefix\filehook@include@atend@{\filehook@ensuretex{#1}}%
170 }
171 \newcommand*\AfterIncludeFile[1]{%
172 \filehook@addtohook\filehook@prefix\filehook@include@after@{\filehook@ensuretex{#1}}%
173 }
174 \newcommand*\AtBeginOfInputs{%
175 \filehook@append\filehook@input@@atbegin
176 }
177 \newcommand*\AtEndOfInputs{%
178 \filehook@prefix\filehook@input@@atend
179 }
180 \newcommand*\AtBeginOfInputFile{%
181 \filehook@addtohook\filehook@append\filehook@input@atbegin@
182 }
183 \newcommand*\AtEndOfInputFile{%
184 \filehook@addtohook\filehook@prefix\filehook@input@atend@
185 }
186 \newcommand*\AtBeginOfFiles{%
187 \filehook@append\filehook@@atbegin
188 }
189 \newcommand*\AtEndOfFiles{%
190 \filehook@prefix\filehook@@atend
191 }
192 \newcommand*\AtBeginOfEveryFile{%
193 \filehook@append\filehook@every@@atbegin
194 }
195 \newcommand*\AtEndOfEveryFile{%
196 \filehook@prefix\filehook@every@@atend
197 }
198 \newcommand*\AtBeginOfFile{%
199 \filehook@addtohook\filehook@append\filehook@atbegin@
200 }
201 \newcommand*\AtEndOfFile{%
202 \filehook@addtohook\filehook@prefix\filehook@atend@
203 }
204 \newcommand*\AtBeginOfClassFile{%
205 \@ifnextchar*
206 {\AtBeginOfXFile@star\@clsextension}%
207 {\AtBeginOfXFile@normal\@clsextension}%
208 }
209 \newcommand*\AtBeginOfPackageFile{%
210 \@ifnextchar*
211 {\AtBeginOfXFile@star\@pkgextension}%
212 {\AtBeginOfXFile@normal\@pkgextension}%
213 }
214 \def\AtBeginOfXFile@star#1*#2{%
215 \@ifl@aded{#1}{#2}%
216 {\@firstofone}%
217 {\AtBeginOfXFile@normal{#1}{#2}}%
218 }
219 \def\AtBeginOfXFile@normal#1#2{%
220 \AtBeginOfFile{#2.#1}%
221 }
222 \newcommand*\AtEndOfClassFile{%
223 \@ifnextchar*
224 {\AtEndOfXFile@star\@clsextension}%
225 {\AtEndOfXFile@normal\@clsextension}%
226 }
227 \newcommand*\AtEndOfPackageFile{%
228 \@ifnextchar*
229 {\AtEndOfXFile@star\@pkgextension}%
230 {\AtEndOfXFile@normal\@pkgextension}%
231 }
232 \def\AtEndOfXFile@star#1*#2{%
233 \@ifl@aded{#1}{#2}%
234 {\@firstofone}%
235 {\AtEndOfXFile@normal{#1}{#2}}%
236 }
237 \long\def\AtEndOfXFile@normal#1#2#3{%
238 \AtEndOfFile{#2.#1}{\AtEndOfPackage{#3}}%
239 }
240 \newcommand*\ClearHook{%
241 \begingroup
242 \def\filehook@prefix##1##2{%
243 \gdef##1{}%
244 \endgroup
245 }%
246 \let\filehook@append\filehook@prefix
247 }
248 \let\filehook@orig@@input@\@input@
249 \let\filehook@orig@@iinput\@iinput
250 \def\@input@#1{%
251 \@ifnextchar\clearpage
252 {%
253 \filehook@every@atbegin{#1}%
254 \filehook@include@atbegin{#1}%
255 \filehook@orig@@input@{#1}%
256 \filehook@include@atend{#1}%
257 \clearpage
258 \filehook@include@after{#1}%
259 \filehook@every@atend{#1}%
260 \@gobble
261 }%
262 {\filehook@orig@@input@{#1}}%
263 }
264 \def\filehook@@iinput#1{%
265 \filehook@every@atbegin{#1}%
266 \filehook@input@atbegin{#1}%
267 \filehook@orig@@iinput{#1}%
268 \filehook@input@atend{#1}%
269 \filehook@every@atend{#1}%
270 }
271 \let\@iinput\filehook@@iinput
272 \def\filehook@swap#1#2{#2#1}
273 \def\filehook@ensureext#1{%
274 \expandafter\filehook@@ensureext#1\empty.tex\empty\empty
275 }
276 \def\filehook@@ensureext#1.#2\empty#3\empty{#1.#2}
277 \def\filehook@ensuretex#1{%
278 \expandafter\filehook@@ensuretex#1\empty.tex\empty\empty
279 }
280 \def\filehook@@ensuretex#1.tex\empty#2\empty{#1.tex}
281 \iffilehook@newfmt
282 \expandafter\def\expandafter\latex@InputIfFileExists\expandafter{%
283 \expandafter\protect\csname InputIfFileExists\space\endcsname
284 }
285 \expandafter\long\expandafter\def\csname latex@InputIfFileExists\space\endcsname#1#2{%
286 \IfFileExists{#1}%
287 {%
288 \expandafter\@swaptwoargs\expandafter
289 {\@filef@und}{#2\@addtofilelist{#1}\@@input}}}
290 \else
291 \long\def\latex@InputIfFileExists#1#2{%
292 \IfFileExists{#1}%
293 {#2\@addtofilelist{#1}%
294 \@@input\@filef@und
295 }%
296 }
297 \fi
298 \DeclareRobustCommand\filehook@default@InputIfFileExists[2]{%
299 \IfFileExists{#1}%
300 {\expandafter\filehook@swap
301 \expandafter{\@filef@und}%
302 {#2\@addtofilelist{#1}%
303 \filehook@every@atbegin{#1}%
304 \filehook@atbegin{#1}%
305 \@@input}%
306 \filehook@atend{#1}%
307 \filehook@every@atend{#1}%
308 }%
309 }
310 \filehook@glet{filehook@default@InputIfFileExists}{filehook@default@InputIfFileExists}%
311 \DeclareRobustCommand\filehook@@default@InputIfFileExists[2]{%
312 \filehook@let{InputIfFileExists}{filehook@InputIfFileExists}%
313 \IfFileExists{#1}%
314 {\expandafter\filehook@swap
315 \expandafter{\@filef@und}%
316 {#2\@addtofilelist{#1}%
317 \filehook@atbegin{#1}%
318 \@@input}%
319 \filehook@atend{#1}%
320 }%
321 }
322 \filehook@glet{filehook@@default@InputIfFileExists}{filehook@@default@InputIfFileExists}%
323 \AtBeginOfPackageFile{scrlfile}{%
324 \filehook@glet{InputIfFileExists}{latex@InputIfFileExists}%
325 }%
326 \AtEndOfPackageFile*{scrlfile}{%
327 \RequirePackage{filehook-scrlfile}%
328 }%
329 \AtBeginOfPackageFile*{fink}{%
330 \RequirePackage{kvoptions}%
331 \begingroup
332 \filehook@let{InputIfFileExists}{latex@InputIfFileExists}%
333 }%
334 \AtEndOfPackageFile*{fink}{%
335 \edef\@tempa{\noexpand\PassOptionsToPackage{mainext=\fnk@mainext,maindir=\fnk@maindir}{currfile}}%
336 \expandafter\endgroup\@tempa
337 \RequirePackage{filehook-fink}%
338 }%
339 \AtBeginOfClassFile{memoir}{%
340 \filehook@let{InputIfFileExists}{latex@InputIfFileExists}%
341 \let\@iinput\filehook@orig@@iinput
342 }%
343 \AtEndOfClassFile*{memoir}{%
344 \let\@iinput\filehook@@iinput
345 \RequirePackage{filehook-memoir}%
346 }%
347 \filehook@cmp{InputIfFileExists}{filehook@InputIfFileExists}%
348 {}% already set up
349 {%
350 \filehook@cmp{InputIfFileExists}{latex@InputIfFileExists}%
351 {%
352 \filehook@let{filehook@InputIfFileExists}{filehook@default@InputIfFileExists}%
353 \filehook@let{filehook@@InputIfFileExists}{filehook@@default@InputIfFileExists}%
354 \filehook@let{InputIfFileExists}{filehook@InputIfFileExists}%
355 }%
356 {%
357 \iffilehook@force
358 \filehook@let{filehook@InputIfFileExists}{filehook@default@InputIfFileExists}%
359 \filehook@let{filehook@@InputIfFileExists}{filehook@@default@InputIfFileExists}%
360 \filehook@let{InputIfFileExists}{filehook@InputIfFileExists}%
361 \PackageWarning{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
362 The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}%
363 \else
364 \PackageError{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
365 Use the 'force' option of 'filehook' to overwrite it.}{}%
366 \fi
367 }%
368 }%
369 \AtBeginDocument{%
370 % Check if definition got changed again. For the new LaTeX format we check again \InputIfFileExists<space>,
371 % for the old format to \InputIfFileExists directly.
372 \filehook@cmp{InputIfFileExists}{filehook@InputIfFileExists}{}{%
373 \PackageWarning{filehook}{Macro \string\InputIfFileExists\space got redefined after 'filehook' was loaded.^^J%
374 Certain file hooks might now be dysfunctional!}%
375 }%
376 }
377 \endinput
378 %%
379 %% End of file `filehook-2019.sty'.