[latex3-commits] [git/LaTeX3-latex3-luaotfload] ignorable-dev: adapted filehook version (bb5ee36)

Ulrike Fischer fischer at troubleshooting-tex.de
Sat Aug 17 18:02:40 CEST 2019


Repository : https://github.com/latex3/luaotfload
On branch  : ignorable-dev
Link       : https://github.com/latex3/luaotfload/commit/bb5ee364e0770d35d98ab981bc0cfe3bb2d988fc

>---------------------------------------------------------------

commit bb5ee364e0770d35d98ab981bc0cfe3bb2d988fc
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Sat Aug 17 18:02:40 2019 +0200

    adapted filehook version


>---------------------------------------------------------------

bb5ee364e0770d35d98ab981bc0cfe3bb2d988fc
 texmf/tex/latex/filehook/filehook.sty | 832 ++++++++++++++++++++++++++++++++++
 1 file changed, 832 insertions(+)

diff --git a/texmf/tex/latex/filehook/filehook.sty b/texmf/tex/latex/filehook/filehook.sty
new file mode 100644
index 0000000..c4eed36
--- /dev/null
+++ b/texmf/tex/latex/filehook/filehook.sty
@@ -0,0 +1,832 @@
+%    \begin{macrocode}
+%<!COPYRIGHT>
+\NeedsTeXFormat{LaTeX2e}[1999/12/01]
+\ProvidesPackage{filehook}[%
+%<!DATE>
+%<!VERSION>
+%<*DRIVER>
+    2099/01/01 develop
+%</DRIVER>
+    Hooks for input files]
+%    \end{macrocode}
+%
+%
+% \subsection{Options}
+%    \begin{macrocode}
+\newif\iffilehook at force
+\DeclareOption{force}{\filehook at forcetrue}
+\ProcessOptions\relax
+%    \end{macrocode}
+%
+%
+% \subsection{Initialisation of Hooks}
+% The general hooks are initialised to call the file specific hooks.
+%
+%
+% \begin{macro}{\filehook at csuse}
+%    \begin{macrocode}
+\begingroup
+\gdef\filehook at csuse#1{\ifcsname #1\endcsname\csname #1\expandafter\endcsname\fi}
+\expandafter\ifx\csname csuse\endcsname\relax
+    \expandafter\ifx\csname ifcsname\endcsname\relax
+        \gdef\filehook at csuse#1{\expandafter\ifx\csname #1\endcsname\relax\else\csname #1\expandafter\endcsname\fi}
+    \fi
+\else
+    \global\let\filehook at csuse\csuse
+\fi
+\endgroup
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at include@atbegin}
+%    \begin{macrocode}
+\def\filehook at include@atbegin#1{%
+  \let\InputIfFileExists\filehook@@InputIfFileExists
+  \filehook at csuse{\filehook at include@atbegin@#1}%
+  \filehook at include@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at include@@atbegin}
+%    \begin{macrocode}
+\def\filehook at include@@atbegin{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at include@atend}
+%    \begin{macrocode}
+\def\filehook at include@atend#1{%
+  \filehook at include@@atend
+  \filehook at csuse{\filehook at include@atend@#1}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at include@@atend}
+%    \begin{macrocode}
+\def\filehook at include@@atend{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at include@after}
+%    \begin{macrocode}
+\def\filehook at include@after#1{%
+  \filehook at include@@after
+  \filehook at csuse{\filehook at include@after@#1}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at include@@after}
+%    \begin{macrocode}
+\def\filehook at include@@after{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at input@atbegin}
+%    \begin{macrocode}
+\def\filehook at input@atbegin#1{%
+  \let\InputIfFileExists\filehook@@InputIfFileExists
+  \filehook at csuse{\filehook at input@atbegin@\filehook at ensureext{#1}}%
+  \filehook at input@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at input@@atbegin}
+%    \begin{macrocode}
+\def\filehook at input@@atbegin{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at input@atend}
+%    \begin{macrocode}
+\def\filehook at input@atend#1{%
+  \filehook at input@@atend
+  \filehook at csuse{\filehook at input@atend@\filehook at ensureext{#1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at input@@atend}
+%    \begin{macrocode}
+\def\filehook at input@@atend{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at atbegin}
+%    \begin{macrocode}
+\def\filehook at atbegin#1{%
+  \filehook at csuse{\filehook at atbegin@\filehook at ensureext{#1}}%
+  \filehook@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook@@atbegin}
+%    \begin{macrocode}
+\def\filehook@@atbegin{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at atend}
+%    \begin{macrocode}
+\def\filehook at atend#1{%
+  \filehook@@atend
+  \filehook at csuse{\filehook at atend@\filehook at ensureext{#1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook@@atend}
+%    \begin{macrocode}
+\def\filehook@@atend{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at every@atbegin}
+%    \begin{macrocode}
+\def\filehook at every@atbegin#1{%
+    \filehook at every@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at every@@atbegin}
+%    \begin{macrocode}
+\def\filehook at every@@atbegin{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at every@atend}
+%    \begin{macrocode}
+\def\filehook at every@atend#1{%
+    \filehook at every@@atend
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at every@@atend}
+%    \begin{macrocode}
+\def\filehook at every@@atend{}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+%
+% \subsection{Hook Modification Macros}
+% The following macros are used to modify the hooks, i.e.\ to prefix or append code to them.
+%
+%
+% \subsubsection*{Internal Macros}
+%
+% The macro prefixes for the file specific hooks are stored in macros to reduce the number of
+% tokens in the following macro definitions.
+%    \begin{macrocode}
+\def\filehook at include@atbegin@{filehook at include@atbegin@}
+\def\filehook at include@atend@{filehook at include@atend@}
+\def\filehook at include@after@{filehook at include@after@}
+\def\filehook at input@atbegin@{filehook at input@atbegin@}
+\def\filehook at input@atend@{filehook at input@atend@}
+\def\filehook at input@after@{filehook at input@after@}
+\def\filehook at atbegin@{filehook at atbegin@}
+\def\filehook at atend@{filehook at atend@}
+\def\filehook at after@{filehook at after@}
+%    \end{macrocode}
+%
+%
+% \begin{macro}{\filehook at append}
+% Uses default \LaTeX{} macro.
+%    \begin{macrocode}
+\def\filehook at append{\g at addto@macro}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at appendwarg}
+% Appends code with one macro argument. The |\@tempa| intermediate step is required because of the
+% included |##1| which wouldn't correctly expand otherwise.
+%    \begin{macrocode}
+\long\def\filehook at appendwarg#1#2{%
+  \begingroup
+    \toks@\expandafter{#1{##1}#2}%
+    \edef\@tempa{\the\toks@}%
+    \expandafter\gdef\expandafter#1\expandafter##\expandafter1\expandafter{\@tempa}%
+  \endgroup
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at prefix}
+% Prefixes code to a hook.
+%    \begin{macrocode}
+\long\def\filehook at prefix#1#2{%
+  \begingroup
+    \@temptokena{#2}%
+    \toks@\expandafter{#1}%
+    \xdef#1{\the\@temptokena\the\toks@}%
+  \endgroup
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at prefixwarg}
+% Prefixes code with an argument to a hook.
+%    \begin{macrocode}
+\long\def\filehook at 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
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at addtohook}[3]{Macro which should be used to add the material to the hook}{Macro name prefix}{End of macro name (file name)}
+% The macro first expands the file name (|#3|) to flatten all included macros. An extension is added if missing, as well as the prefix.
+% All modifications of |\@tempa| are made inside a group to keep them local.
+%    \begin{macrocode}
+\def\filehook at addtohook#1#2#3{%
+  \begingroup
+  \edef\@tempa{#3}%
+  \edef\@tempa{#2\filehook at ensureext{\@tempa}}%
+  \@ifundefined{\@tempa}{\global\@namedef{\@tempa}{}}{}%
+  \expandafter\endgroup
+  \expandafter#1\csname\@tempa\endcsname
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsubsection*{User Level Macros}
+% The user level macros simple use the above defined macros on the appropriate hook.
+%
+% \begin{macro}{\AtBeginOfIncludes}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfIncludes{%
+  \filehook at append\filehook at include@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfIncludes}
+%    \begin{macrocode}
+\newcommand*\AtEndOfIncludes{%
+  \filehook at prefix\filehook at include@@atend
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AfterIncludes}
+%    \begin{macrocode}
+\newcommand*\AfterIncludes{%
+  \filehook at prefix\filehook at include@@after
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfIncludeFile}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfIncludeFile[1]{%
+  \filehook at addtohook\filehook at append\filehook at include@atbegin@{\filehook at ensuretex{#1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfIncludeFile}
+%    \begin{macrocode}
+\newcommand*\AtEndOfIncludeFile[1]{%
+  \filehook at addtohook\filehook at prefix\filehook at include@atend@{\filehook at ensuretex{#1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AfterIncludeFile}
+%    \begin{macrocode}
+\newcommand*\AfterIncludeFile[1]{%
+  \filehook at addtohook\filehook at prefix\filehook at include@after@{\filehook at ensuretex{#1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfInputs}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfInputs{%
+  \filehook at append\filehook at input@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfInputs}
+%    \begin{macrocode}
+\newcommand*\AtEndOfInputs{%
+  \filehook at prefix\filehook at input@@atend
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfInputFile}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfInputFile{%
+  \filehook at addtohook\filehook at append\filehook at input@atbegin@
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfInputFile}
+%    \begin{macrocode}
+\newcommand*\AtEndOfInputFile{%
+  \filehook at addtohook\filehook at prefix\filehook at input@atend@
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfFiles}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfFiles{%
+  \filehook at append\filehook@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfFiles}
+%    \begin{macrocode}
+\newcommand*\AtEndOfFiles{%
+  \filehook at prefix\filehook@@atend
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfEveryFile}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfEveryFile{%
+  \filehook at append\filehook at every@@atbegin
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfEveryFile}
+%    \begin{macrocode}
+\newcommand*\AtEndOfEveryFile{%
+  \filehook at prefix\filehook at every@@atend
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfFile}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfFile{%
+  \filehook at addtohook\filehook at append\filehook at atbegin@
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfFile}
+%    \begin{macrocode}
+\newcommand*\AtEndOfFile{%
+  \filehook at addtohook\filehook at prefix\filehook at atend@
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+%
+% \begin{macro}{\AtBeginOfClassFile}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfClassFile{%
+    \@ifnextchar*
+        {\AtBeginOfXFile at star\@clsextension}%
+        {\AtBeginOfXFile at normal\@clsextension}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfPackageFile}
+%    \begin{macrocode}
+\newcommand*\AtBeginOfPackageFile{%
+    \@ifnextchar*
+        {\AtBeginOfXFile at star\@pkgextension}%
+        {\AtBeginOfXFile at normal\@pkgextension}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfXFile at star}[2]{extension}{name}
+% If the class or package is already loaded the code is executed right away.
+% Otherwise it is installed normally.
+%    \begin{macrocode}
+\def\AtBeginOfXFile at star#1*#2{%
+    \@ifl at aded{#1}{#2}%
+        {\@firstofone}%
+        {\AtBeginOfXFile at normal{#1}{#2}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtBeginOfXFile at normal}[2]{extension}{name}
+%    \begin{macrocode}
+\def\AtBeginOfXFile at normal#1#2{%
+    \AtBeginOfFile{#2.#1}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\AtEndOfClassFile}
+%    \begin{macrocode}
+\newcommand*\AtEndOfClassFile{%
+    \@ifnextchar*
+        {\AtEndOfXFile at star\@clsextension}%
+        {\AtEndOfXFile at normal\@clsextension}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfPackageFile}
+%    \begin{macrocode}
+\newcommand*\AtEndOfPackageFile{%
+    \@ifnextchar*
+        {\AtEndOfXFile at star\@pkgextension}%
+        {\AtEndOfXFile at normal\@pkgextension}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\AtEndOfXFile at star}[2]{extension}{name}
+% If the class or package is already loaded the code is executed right away.
+% Otherwise it is installed normally.
+%    \begin{macrocode}
+\def\AtEndOfXFile at star#1*#2{%
+    \@ifl at aded{#1}{#2}%
+        {\@firstofone}%
+        {\AtEndOfXFile at normal{#1}{#2}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\AtEndOfXFile at normal}[2]{extension}{name}
+% Note that \Macro\AtEndOfClass is identical to \Macro\AtEndOfPackage, so no
+% differentiation between classes and packages is needed here.
+%    \begin{macrocode}
+\long\def\AtEndOfXFile at normal#1#2#3{%
+    \AtEndOfFile{#2.#1}{\AtEndOfPackage{#3}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\ClearHook}
+% Clears the hook by temporary redefining the prefix and append macros
+% to do a simple definition to empty.
+%    \begin{macrocode}
+\newcommand*\ClearHook{%
+    \begingroup
+    \def\filehook at prefix##1##2{%
+        \gdef##1{}%
+        \endgroup
+    }%
+    \let\filehook at append\filehook at prefix
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+% \subsection{Installation of Hooks}
+% The \Macro\@input@ and \Macro\@iinput macros from |latex.ltx| are redefined to install the hooks.
+%
+% First the original definitions are saved away.
+% \begin{macro}{\filehook at orig@@input@}
+%    \begin{macrocode}
+\let\filehook at orig@@input@\@input@
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at orig@@iinput}
+%    \begin{macrocode}
+\let\filehook at orig@@iinput\@iinput
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@input@}
+% This macro is redefined for the \Macro\include file hooks.
+% Checks if the next command is \Macro\clearpage which indicates that we are inside \Macro\@include.
+% If so the hooks are installed, otherwise the original macro is used unchanged.
+% For the `after' hook an own \Macro\clearpage is inserted and the original one is gobbled.
+%
+%    \begin{macrocode}
+\def\@input@#1{%
+  \@ifnextchar\clearpage
+    {%
+     \filehook at every@atbegin{#1}%
+     \filehook at include@atbegin{#1}%
+     \filehook at orig@@input@{#1}%
+     \filehook at include@atend{#1}%
+     \clearpage
+     \filehook at include@after{#1}%
+     \filehook at every@atend{#1}%
+     \@gobble
+    }%
+    {\filehook at orig@@input@{#1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@iinput}
+% This macro is redefined for the \Macro\input file hooks.
+% it simply surrounds the original macro with the hooks.
+%    \begin{macrocode}
+\def\filehook@@iinput#1{%
+  \filehook at every@atbegin{#1}%
+  \filehook at input@atbegin{#1}%
+  \filehook at orig@@iinput{#1}%
+  \filehook at input@atend{#1}%
+  \filehook at every@atend{#1}%
+}
+\let\@iinput\filehook@@iinput
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at swap}
+% Auxiliary macro which swaps the two arguments. This is needed to expand
+% \Macro\@filef at und, which is given as first argument but needed then as the second one.
+%    \begin{macrocode}
+\def\filehook at swap#1#2{#2#1}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at ensureext}
+% This macro ensures the existence of a file name extension. If non is given `|.tex|' is
+% added.
+%    \begin{macrocode}
+\def\filehook at ensureext#1{%
+    \expandafter\filehook@@ensureext#1\empty.tex\empty\empty
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook@@ensureext}
+%    \begin{macrocode}
+\def\filehook@@ensureext#1.#2\empty#3\empty{#1.#2}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\filehook at ensuretex}
+% Ensures a `|.tex|' extension, i.e. adds it if missing, even if there is a different one.
+%    \begin{macrocode}
+\def\filehook at ensuretex#1{%
+    \expandafter\filehook@@ensuretex#1\empty.tex\empty\empty
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook@@ensuretex}
+%    \begin{macrocode}
+\def\filehook@@ensuretex#1.tex\empty#2\empty{#1.tex}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% The |filehook| default definition of \Macro\InputIfFileExists is defined here
+% together with alternatives definitions for comparison.
+% There are stored first in a token register and later stored in a macro which is expanded if required.
+% This is always done inside a group to keep them temporary only.
+% The token register is used to avoid doubling of macro argument characters.
+%
+% \begin{macro}{\oldlatex at InputIfFileExists}
+% Original standard \LaTeX\ definition of \Macro\InputIfFileExists.
+%    \begin{macrocode}
+\long\def\oldlatex at InputIfFileExists#1#2{%
+  \IfFileExists{#1}%
+    {#2\@addtofilelist{#1}%
+     \@@input\@filef at und
+    }%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\latex at InputIfFileExists}
+% Standard \`LaTeX\ definition of \Macro\InputIfFileExists starting from LaTeX Kernal 2019/02/07 v1.1n.
+%    \begin{macrocode}
+\long\def\newlatex at InputIfFileExists#1#2{%
+  \IfFileExists{#1}%
+    {%
+  \expandafter\@swaptwoargs\expandafter
+      {\@filef at und}{#2\@addtofilelist{#1}\@@input}}}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\latex at InputIfFileExists}
+% Standard \`LaTeX\ definition of \Macro\InputIfFileExists starting from LaTeX Kernal 2019/02/07 v1.1n.
+%    \begin{macrocode}
+\@ifundefined{swap at args}{%
+  \let\latex at InputIfFileExists\oldlatex at InputIfFileExists
+}{%
+  \let\latex at InputIfFileExists\newlatex at InputIfFileExists
+}%
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\filehook at default@InputIfFileExists}
+%    \begin{macrocode}
+\long\gdef\filehook at default@InputIfFileExists#1#2{%
+  \IfFileExists{#1}%
+    {\expandafter\filehook at swap
+     \expandafter{\@filef at und}%
+     {#2\@addtofilelist{#1}%
+     \filehook at every@atbegin{#1}%
+     \filehook at atbegin{#1}%
+     \@@input}%
+     \filehook at atend{#1}%
+     \filehook at every@atend{#1}%
+    }%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook@@default at InputIfFileExists}
+%    \begin{macrocode}
+\long\gdef\filehook@@default at InputIfFileExists#1#2{%
+  \let\InputIfFileExists\filehook at InputIfFileExists
+  \IfFileExists{#1}%
+    {\expandafter\filehook at swap
+     \expandafter{\@filef at und}%
+     {#2\@addtofilelist{#1}%
+     \filehook at atbegin{#1}%
+     \@@input}%
+     \filehook at atend{#1}%
+    }%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\scrlfile at InputIfFileExists}
+%    \begin{macrocode}
+\long\def\scrlfile at InputIfFileExists#1#2{%
+  \begingroup\expandafter\expandafter\expandafter\endgroup
+  \expandafter\ifx\csname #1- at alias\endcsname\relax
+    \expandafter\@secondoftwo
+  \else
+    \scr at replacefile@msg{\csname #1- at alias\endcsname}{#1}%
+    \expandafter\@firstoftwo
+  \fi
+  {%
+    \expandafter\InputIfFileExists\expandafter{\csname
+      #1- at alias\endcsname}{#2}%
+  }%
+  {\IfFileExists{#1}{%
+      \scr at load@hook{before}{#1}%
+      #2\@addtofilelist{#1}%
+      \@@input \@filef at und
+      \scr at load@hook{after}{#1}%
+    }}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook at scrlfile@InputIfFileExists}
+%    \begin{macrocode}
+\long\def\filehook at scrlfile@InputIfFileExists#1#2{%
+  \begingroup\expandafter\expandafter\expandafter\endgroup
+  \expandafter\ifx\csname #1- at alias\endcsname\relax
+    \expandafter\@secondoftwo
+  \else
+    \scr at replacefile@msg{\csname #1- at alias\endcsname}{#1}%
+    \expandafter\@firstoftwo
+  \fi
+  {%
+    \expandafter\InputIfFileExists\expandafter{\csname
+      #1- at alias\endcsname}{#2}%
+  }%
+  {\IfFileExists{#1}{%
+      \expandafter\filehook at swap
+      \expandafter{\@filef at und}%
+      {\scr at load@hook{before}{#1}%
+      #2\@addtofilelist{#1}%
+      \filehook at every@atbegin{#1}%
+      \filehook at atbegin{#1}%
+      \@@input}%
+      \filehook at atend{#1}%
+      \filehook at every@atend{#1}%
+      \scr at load@hook{after}{#1}%
+    }}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\filehook@@scrlfile at InputIfFileExists}
+%    \begin{macrocode}
+\long\def\filehook@@scrlfile at InputIfFileExists#1#2{%
+  \let\InputIfFileExists\filehook at InputIfFileExists
+  \begingroup\expandafter\expandafter\expandafter\endgroup
+  \expandafter\ifx\csname #1- at alias\endcsname\relax
+    \expandafter\@secondoftwo
+  \else
+    \scr at replacefile@msg{\csname #1- at alias\endcsname}{#1}%
+    \expandafter\@firstoftwo
+  \fi
+  {%
+    \expandafter\InputIfFileExists\expandafter{\csname
+      #1- at alias\endcsname}{#2}%
+  }%
+  {\IfFileExists{#1}{%
+      \expandafter\filehook at swap
+      \expandafter{\@filef at und}%
+      {\scr at load@hook{before}{#1}%
+      #2\@addtofilelist{#1}%
+      \filehook at atbegin{#1}%
+      \@@input}%
+      \filehook at atend{#1}%
+      \scr at load@hook{after}{#1}%
+    }}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\InputIfFileExists}
+% First we test for the |scrlfile| package. The test macro adds the necessary patches if so.
+% In order to also support it when it is loaded afterwards the two hooks below are used to revert the definition
+% before the package and patch it afterwards.
+%    \begin{macrocode}
+\AtBeginOfPackageFile*{scrlfile}{%
+   \let\InputIfFileExists\latex at InputIfFileExists
+}%
+\AtEndOfPackageFile*{scrlfile}{%
+   \RequirePackage{filehook-scrlfile}%
+}%
+%    \end{macrocode}
+% Fink:
+%    \begin{macrocode}
+\AtBeginOfPackageFile*{fink}{%
+   \RequirePackage{kvoptions}%
+   \begingroup
+   \let\InputIfFileExists\latex at InputIfFileExists
+}%
+\AtEndOfPackageFile*{fink}{%
+   \edef\@tempa{\noexpand\PassOptionsToPackage{mainext=\fnk at mainext,maindir=\fnk at maindir}{currfile}}%
+   \expandafter\endgroup\@tempa
+   \RequirePackage{filehook-fink}%
+}%
+%    \end{macrocode}
+% If |memoir| is detected its hooks
+% are added to the appropriate `At...OfFiles' hooks. This works fine because its hooks have the
+% exact same position. Please note that the case when |memoir| is used together with |scrlfile| is not explicitly covered.
+% In this case the |scrlfile| package will overwrite |memoir|s definition.
+%    \begin{macrocode}
+\AtBeginOfClassFile*{memoir}{%
+  \let\filehook@@InputIfFileExists\latex at InputIfFileExists
+  \let\InputIfFileExists\latex at InputIfFileExists
+  \let\@iinput\filehook at orig@@iinput
+}%
+\AtEndOfClassFile*{memoir}{%
+  \let\@iinput\filehook@@iinput
+  \RequirePackage{filehook-memoir}%
+}%
+%    \end{macrocode}
+%
+% Finally, if no specific alternate definition is detected the original \LaTeX\ definition is checked for and a
+% error is given if any other unknown definition is detected.
+% The \opt{force} option will change the error into a warning and overwrite the macro with the default.
+%    \begin{macrocode}
+\ifcase
+    \ifx\InputIfFileExists\filehook at InputIfFileExists 0\else
+    \ifx\InputIfFileExists\newlatex at InputIfFileExists 1\else
+    \ifx\InputIfFileExists\oldlatex at InputIfFileExists 1\else
+    9%
+    \fi\fi\fi
+\relax% 0
+\or% 1
+    \let\filehook at InputIfFileExists\filehook at default@InputIfFileExists
+    \let\filehook@@InputIfFileExists\filehook@@default at InputIfFileExists
+    \let\InputIfFileExists\filehook at InputIfFileExists
+\else
+    \iffilehook at force
+      \let\filehook at InputIfFileExists\filehook at default@InputIfFileExists
+      \let\filehook@@InputIfFileExists\filehook@@default at InputIfFileExists
+      \let\InputIfFileExists\filehook at InputIfFileExists
+      \PackageWarning{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
+                                The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}%
+    \else
+      \PackageError{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
+                                Use the 'force' option of 'filehook' to overwrite it.}{}%
+    \fi
+\fi
+%    \end{macrocode}
+% \end{macro}
+%
+%    \begin{macrocode}
+\AtBeginDocument{%
+    \ifx\InputIfFileExists\filehook at InputIfFileExists\else
+        \PackageWarning{filehook}{Macro \string\InputIfFileExists\space got redefined after 'filehook' was loaded.^^J%
+                                  Certain file hooks might now be dysfunctional!}
+    \fi
+}
+%    \end{macrocode}
+%





More information about the latex3-commits mailing list