%% Copyright (c) 2011-2022 by Martin Scharrer <martin.scharrer@web.de>
%% ----------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files filehook.dtx and filehook.ins
%% and the derived files filehook.sty, filehook-fink.sty,
%% filehook-listings.sty, filehook-memoir.sty, filehook-scrlfile.sty
%% and pgf-filehook.sty
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{filehook-2020}[% filehook subpackage, do not load directly
    2022/10/25
    v0.8b
    Hooks for input files]
\DeclareOption{force}{}
\ProcessOptions\relax
\begingroup
\gdef\filehook@csuse#1{\ifcsname #1\endcsname\csname #1\expandafter\endcsname\fi}
\expandafter\ifx\csname csuse\endcsname\relax
    \expandafter\ifx\csname ifcsname\endcsname\relax
        \gdef\filehook@csuse#1{\expandafter\ifx\csname #1\endcsname\relax\else\csname #1\expandafter\endcsname\fi}
    \fi
\else
    \global\let\filehook@csuse\csuse
\fi
\endgroup
\def\filehook@include@atbegin#1{%
  \filehook@csuse{\filehook@include@atbegin@#1}%
  \filehook@include@@atbegin
}
\def\filehook@include@@atbegin{}
\def\filehook@include@atend#1{%
  \filehook@include@@atend
  \filehook@csuse{\filehook@include@atend@#1}%
}
\def\filehook@include@@atend{}
\def\filehook@include@after#1{%
  \filehook@include@@after
  \filehook@csuse{\filehook@include@after@#1}%
}
\def\filehook@include@@after{}
\def\filehook@input@atbegin#1{%
  \filehook@csuse{\filehook@input@atbegin@\filehook@ensureext{#1}}%
  \filehook@input@@atbegin
}
\def\filehook@input@@atbegin{}
\def\filehook@input@atend#1{%
  \filehook@input@@atend
  \filehook@csuse{\filehook@input@atend@\filehook@ensureext{#1}}%
}
\def\filehook@input@@atend{}
\def\filehook@atbegin#1{%
  \filehook@csuse{\filehook@atbegin@\filehook@ensureext{#1}}%
  \filehook@@atbegin
}
\def\filehook@@atbegin{}
\def\filehook@atend#1{%
  \filehook@@atend
  \filehook@csuse{\filehook@atend@\filehook@ensureext{#1}}%
}
\def\filehook@@atend{}
\def\filehook@every@atbegin#1{%
    \filehook@every@@atbegin
}
\def\filehook@every@@atbegin{}
\def\filehook@every@atend#1{%
    \filehook@every@@atend
}
\def\filehook@every@@atend{}
\def\filehook@include@atbegin@{filehook@include@atbegin@}
\def\filehook@include@atend@{filehook@include@atend@}
\def\filehook@include@after@{filehook@include@after@}
\def\filehook@input@atbegin@{filehook@input@atbegin@}
\def\filehook@input@atend@{filehook@input@atend@}
\def\filehook@input@after@{filehook@input@after@}
\def\filehook@atbegin@{filehook@atbegin@}
\def\filehook@atend@{filehook@atend@}
\def\filehook@after@{filehook@after@}
\def\filehook@append{\g@addto@macro}
\long\def\filehook@appendwarg#1#2{%
  \begingroup
    \toks@\expandafter{#1{##1}#2}%
    \edef\@tempa{\the\toks@}%
    \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
  \endgroup
}
\long\def\filehook@prefix#1#2{%
  \begingroup
    \@temptokena{#2}%
    \toks@\expandafter{#1}%
    \xdef#1{\the\@temptokena\the\toks@}%
  \endgroup
}
\long\def\filehook@prefixwarg#1#2{%
  \begingroup
    \@temptokena{#2}%
    \toks@\expandafter{#1{##1}}%
    \edef\@tempa{\the\@temptokena\the\toks@}%
    \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
  \endgroup
}
\def\filehook@addtohook#1#2#3{%
  \begingroup
  \edef\@tempa{#3}%
  \edef\@tempa{#2\filehook@ensureext{\@tempa}}%
  \@ifundefined{\@tempa}{\global\@namedef{\@tempa}{}}{}%
  \expandafter\endgroup
  \expandafter#1\csname\@tempa\endcsname
}
\newcommand*\AtBeginOfIncludes{%
  \filehook@append\filehook@include@@atbegin
}
\newcommand*\AtEndOfIncludes{%
  \filehook@prefix\filehook@include@@atend
}
\newcommand*\AfterIncludes{%
  \filehook@prefix\filehook@include@@after
}
\newcommand*\AtBeginOfIncludeFile[1]{%
  \filehook@addtohook\filehook@append\filehook@include@atbegin@{\filehook@ensuretex{#1}}%
}
\newcommand*\AtEndOfIncludeFile[1]{%
  \filehook@addtohook\filehook@prefix\filehook@include@atend@{\filehook@ensuretex{#1}}%
}
\newcommand*\AfterIncludeFile[1]{%
  \filehook@addtohook\filehook@prefix\filehook@include@after@{\filehook@ensuretex{#1}}%
}
\newcommand*\AtBeginOfInputs{%
  \filehook@append\filehook@input@@atbegin
}
\newcommand*\AtEndOfInputs{%
  \filehook@prefix\filehook@input@@atend
}
\newcommand*\AtBeginOfInputFile{%
  \filehook@addtohook\filehook@append\filehook@input@atbegin@
}
\newcommand*\AtEndOfInputFile{%
  \filehook@addtohook\filehook@prefix\filehook@input@atend@
}
\newcommand*\AtBeginOfFiles{%
  \filehook@append\filehook@@atbegin
}
\newcommand*\AtEndOfFiles{%
  \filehook@prefix\filehook@@atend
}
\newcommand*\AtBeginOfEveryFile{%
  \filehook@append\filehook@every@@atbegin
}
\newcommand*\AtEndOfEveryFile{%
  \filehook@prefix\filehook@every@@atend
}
\newcommand*\AtBeginOfFile{%
  \filehook@addtohook\filehook@append\filehook@atbegin@
}
\newcommand*\AtEndOfFile{%
  \filehook@addtohook\filehook@prefix\filehook@atend@
}
\newcommand*\AtBeginOfClassFile{%
    \@ifnextchar*
        {\AtBeginOfXFile@star\@clsextension}%
        {\AtBeginOfXFile@normal\@clsextension}%
}
\newcommand*\AtBeginOfPackageFile{%
    \@ifnextchar*
        {\AtBeginOfXFile@star\@pkgextension}%
        {\AtBeginOfXFile@normal\@pkgextension}%
}
\def\AtBeginOfXFile@star#1*#2{%
    \@ifl@aded{#1}{#2}%
        {\@firstofone}%
        {\AtBeginOfXFile@normal{#1}{#2}}%
}
\def\AtBeginOfXFile@normal#1#2{%
    \AtBeginOfFile{#2.#1}%
}
\newcommand*\AtEndOfClassFile{%
    \@ifnextchar*
        {\AtEndOfXFile@star\@clsextension}%
        {\AtEndOfXFile@normal\@clsextension}%
}
\newcommand*\AtEndOfPackageFile{%
    \@ifnextchar*
        {\AtEndOfXFile@star\@pkgextension}%
        {\AtEndOfXFile@normal\@pkgextension}%
}
\def\AtEndOfXFile@star#1*#2{%
    \@ifl@aded{#1}{#2}%
        {\@firstofone}%
        {\AtEndOfXFile@normal{#1}{#2}}%
}
\long\def\AtEndOfXFile@normal#1#2#3{%
    \AtEndOfFile{#2.#1}{\AtEndOfPackage{#3}}%
}
\newcommand*\ClearHook{%
    \begingroup
    \def\filehook@prefix##1##2{%
        \gdef##1{}%
        \endgroup
    }%
    \let\filehook@append\filehook@prefix
}
\def\DEPRECATED@input@#1{%
  \@ifnextchar\clearpage
    {%
     \filehook@every@atbegin{#1}%
     \filehook@include@atbegin{#1}%
     \filehook@orig@@input@{#1}%
     \filehook@include@atend{#1}%
     \clearpage
     \filehook@include@after{#1}%
     \filehook@every@atend{#1}%
     \@gobble
    }%
    {\filehook@orig@@input@{#1}}%
}
\def\filehook@@iinput#1{%
  \filehook@every@atbegin{#1}%
  \filehook@input@atbegin{#1}%
  \filehook@orig@@iinput{#1}%
  \filehook@input@atend{#1}%
  \filehook@every@atend{#1}%
}
\def\filehook@ensureext#1{%
    \expandafter\filehook@@ensureext#1\empty.tex\empty\empty
}
\def\filehook@@ensureext#1.#2\empty#3\empty{#1.#2}
\def\filehook@ensuretex#1{%
    \expandafter\filehook@@ensuretex#1\empty.tex\empty\empty
}
\def\filehook@@ensuretex#1.tex\empty#2\empty{#1.tex}
\def\filehook@set@CurrentFile{%
    \edef\filehook@CurrentFile{%
        \ifx\CurrentFilePath\empty
        \else
            \CurrentFilePath/%
        \fi
        \CurrentFile
    }%
}
\AddToHook{include/before}{%
    \filehook@set@CurrentFile
    \filehook@include@atbegin{\filehook@CurrentFile}%
}
\AddToHook{include/end}{%
    \filehook@set@CurrentFile
    \filehook@include@atend{\filehook@CurrentFile}%
}
\AddToHook{include/after}{%
    \filehook@set@CurrentFile
    \filehook@include@after{\filehook@CurrentFile}%
}
\begingroup
\edef\dottex{\expandafter\expandafter\expandafter\@gobble\expandafter\string\csname.tex\endcsname}
\expandafter
\gdef\expandafter\filehook@istexfile\expandafter#\expandafter1\expandafter{%
    \expandafter\expandafter\expandafter\filehook@istexfile@\expandafter#\expandafter1\expandafter\empty\dottex\empty\empty\@nil
}
\expandafter\gdef\expandafter\filehook@istexfile@\expandafter#\expandafter1\dottex\empty#2\empty#3\@nil{%
    \begingroup
    \def\@tempa{#2}%
    \ifx\@tempa\empty
        \endgroup
        \expandafter\@secondoftwo
    \else
        \endgroup
        \expandafter\@firstoftwo
    \fi
}
\endgroup
\AddToHook{file/before}{%
    \filehook@set@CurrentFile
    \filehook@every@atbegin{\filehook@CurrentFile}%
    \filehook@istexfile\filehook@CurrentFile{\filehook@input@atbegin{\filehook@CurrentFile}}{}%
    \filehook@atbegin{\filehook@CurrentFile}%
}
\AddToHook{file/after}{%
    \filehook@set@CurrentFile
    \filehook@atend{\filehook@CurrentFile}%
    \filehook@istexfile\filehook@CurrentFile{\filehook@input@atend{\filehook@CurrentFile}}{}%
    \filehook@every@atend{\filehook@CurrentFile}%
}
\endinput
%%
%% End of file `filehook-2020.sty'.
