summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/filehook/filehook.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/filehook/filehook.sty')
-rw-r--r--Master/texmf-dist/tex/latex/filehook/filehook.sty453
1 files changed, 271 insertions, 182 deletions
diff --git a/Master/texmf-dist/tex/latex/filehook/filehook.sty b/Master/texmf-dist/tex/latex/filehook/filehook.sty
index ba3aee1e82d..9ed1ecb4648 100644
--- a/Master/texmf-dist/tex/latex/filehook/filehook.sty
+++ b/Master/texmf-dist/tex/latex/filehook/filehook.sty
@@ -1,4 +1,4 @@
-%% Copyright (c) 2010 by Martin Scharrer <martin@scharrer-online.de>
+%% Copyright (c) 2010-2011 by Martin Scharrer <martin@scharrer-online.de>
%% -----------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
@@ -18,157 +18,58 @@
%% This work consists of the files filehook.dtx, filehook.ins
%% and the derived file filehook.sty.
%%
-%% $Id: filehook.dtx 1926 2010-12-20 23:11:20Z martin $
+%% $Id: filehook.dtx 2005 2011-01-03 22:53:56Z martin $
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{filehook}
- [2010/12/20 v0.3 Hooks for input files]
+ [2011/01/03 v0.4 Hooks for input files]
\newif\iffilehook@force
\DeclareOption{force}{\filehook@forcetrue}
\ProcessOptions\relax
-\let\filehook@orig@@input@\@input@
-\let\filehook@orig@@iinput\@iinput
-\def\@input@#1{%
- \@ifnextchar\clearpage
- {\filehook@include@atbegin{#1}%
- \filehook@orig@@input@{#1}%
- \filehook@include@atend{#1}%
- \clearpage
- \filehook@include@after{#1}%
- \@gobble
- }%
- {\filehook@orig@@input@{#1}}%
-}
-\def\@iinput#1{%
- \filehook@input@atbegin{#1}%
- \filehook@orig@@iinput{#1}%
- \filehook@input@atend{#1}%
-}
-\begingroup
-
-\long\def\latex@InputIfFileExists#1#2{%
- \IfFileExists{#1}%
- {#2\@addtofilelist{#1}%
- \@@input\@filef@und
- }%
-}
-\long\def\memoir@InputIfFileExists#1#2{%
- \IfFileExists{#1}%
- {#2\@addtofilelist{#1}\m@matbeginf{#1}%
- \@@input \@filef@und
- \m@matendf{#1}%
- \killm@matf{#1}}%
-}
-\long\def\scrlfile@InputIfFileExists#1#2{%
- \begingroup\expandafter\expandafter\expandafter\endgroup
- \expandafter\ifx\csname #1-@alias\endcsname\relax
- \expandafter\@secondoftwo
- \else
- \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
- \expandafter\@firstoftwo
- \fi
- {%
- \expandafter\InputIfFileExists\expandafter{\csname
- #1-@alias\endcsname}{#2}%
- }%
- {\IfFileExists{#1}{%
- \scr@load@hook{before}{#1}%
- #2\@addtofilelist{#1}%
- \@@input \@filef@und
- \scr@load@hook{after}{#1}%
- }}%
-}
-\ifx\InputIfFileExists\scrlfile@InputIfFileExists
-
-\long\gdef\InputIfFileExists#1#2{%
- \begingroup\expandafter\expandafter\expandafter\endgroup
- \expandafter\ifx\csname #1-@alias\endcsname\relax
- \expandafter\@secondoftwo
- \else
- \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
- \expandafter\@firstoftwo
- \fi
- {%
- \expandafter\InputIfFileExists\expandafter{\csname
- #1-@alias\endcsname}{#2}%
- }%
- {\IfFileExists{#1}{%
- \scr@load@hook{before}{#1}%
- #2\@addtofilelist{#1}%
- \filehook@atbegin{#1}%
- \@@input \@filef@und
- \filehook@atend{#1}%
- \scr@load@hook{after}{#1}%
- }}%
-}
-
-\PackageInfo{filehook}{Package 'scrlfile' detected and compensated for.}
-
-\else
-
-\ifx\InputIfFileExists\memoir@InputIfFileExists
- \AtEndOfPackage{%
- \AtBeginOfFiles{\m@matbeginf{#1}}%
- \AtEndOfFiles{\m@matendf{#1}\killm@matf{#1}}%
- }
- \PackageInfo{filehook}{Detected 'memoir' class: the memoir hooks will be moved to the 'At...OfFiles' hooks.}
-\else
-\ifx\InputIfFileExists\latex@InputIfFileExists
-\else
- \@ifpackageloaded{scrlfile}{%
- \PackageWarning{filehook}{Detected 'scrlfile' package with unknown definition of \string\InputIfFileExists}%
- }{}%
-
- \@ifclassloaded{memoir}{%
- \PackageWarning{filehook}{Detected 'memoir' class with unknown definition of \string\InputIfFileExists}%
- }{}%
-
- \iffilehook@force
- \PackageWarning{filehook}
- {Changed definition of \string\InputIfFileExists\space detected!^^J%
- The 'force' option is in effect and therefore this macros is redefined.
- This might break other packages or code}%
- \else
- \PackageError{filehook}
- {Changed definition of \string\InputIfFileExists\space detected!^^J%
- Use the 'force' option to force the redefinition of this macro.^^J%
- This might break other packages or code}%
- \fi
-\fi
-\fi
-
-\long\gdef\InputIfFileExists#1#2{%
- \IfFileExists{#1}%
- {#2\@addtofilelist{#1}%
- \filehook@atbegin{#1}%
- \@@input\@filef@und
- \filehook@atend{#1}%
- }%
-}
-
-\fi
-
-\endgroup
\def\filehook@include@atbegin#1{%
+ \let\InputIfFileExists\filehook@@InputIfFileExists
\@nameuse{\filehook@include@atbegin@#1}%
+ \filehook@include@@atbegin
}
+\def\filehook@include@@atbegin{}
\def\filehook@include@atend#1{%
+ \filehook@include@@atend
\@nameuse{\filehook@include@atend@#1}%
}
+\def\filehook@include@@atend{}
\def\filehook@include@after#1{%
+ \filehook@include@@after
\@nameuse{\filehook@include@after@#1}%
}
+\def\filehook@include@@after{}
\def\filehook@input@atbegin#1{%
- \@nameuse{\filehook@input@atbegin@#1}%
+ \let\InputIfFileExists\filehook@@InputIfFileExists
+ \@nameuse{\filehook@input@atbegin@\filehook@ensureext{#1}}%
+ \filehook@input@@atbegin
}
+\def\filehook@input@@atbegin{}
\def\filehook@input@atend#1{%
- \@nameuse{\filehook@input@atend@#1}%
+ \filehook@input@@atend
+ \@nameuse{\filehook@input@atend@\filehook@ensureext{#1}}%
}
+\def\filehook@input@@atend{}
\def\filehook@atbegin#1{%
- \@nameuse{\filehook@atbegin@#1}%
+ \@nameuse{\filehook@atbegin@\filehook@ensureext{#1}}%
+ \filehook@@atbegin
}
+\def\filehook@@atbegin{}
\def\filehook@atend#1{%
- \@nameuse{\filehook@atend@#1}%
+ \filehook@@atend
+ \@nameuse{\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@}
@@ -201,89 +102,277 @@
\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@appendwarg\filehook@include@atbegin
+ \filehook@append\filehook@include@@atbegin
}
\newcommand*\AtEndOfIncludes{%
- \filehook@prefixwarg\filehook@include@atend
+ \filehook@prefix\filehook@include@@atend
}
\newcommand*\AfterIncludes{%
- \filehook@prefixwarg\filehook@include@after
+ \filehook@prefix\filehook@include@@after
}
\newcommand*\AtBeginOfIncludeFile[1]{%
- \@ifundefined{\filehook@include@atbegin@#1.tex}%
- {\long\global\@namedef{\filehook@include@atbegin@#1.tex}}%
- {\expandafter\filehook@append\csname\filehook@include@atbegin@#1.tex\endcsname}%
+ \filehook@addtohook\filehook@append\filehook@include@atbegin@{\filehook@ensuretex{#1}}%
}
\newcommand*\AtEndOfIncludeFile[1]{%
- \@ifundefined{\filehook@include@atend@#1.tex}%
- {\long\global\@namedef{\filehook@include@atend@#1.tex}}%
- {\expandafter\filehook@prefix\csname\filehook@include@atend@#1.tex\endcsname}%
+ \filehook@addtohook\filehook@prefix\filehook@include@atend@{\filehook@ensuretex{#1}}%
}
-\newcommand*\AfterOfIncludeFile[1]{%
- \@ifundefined{\filehook@include@after@#1.tex}%
- {\long\global\@namedef{\filehook@include@after@#1.tex}}%
- {\expandafter\filehook@prefix\csname\filehook@include@after@#1.tex\endcsname}%
+\newcommand*\AfterIncludeFile[1]{%
+ \filehook@addtohook\filehook@prefix\filehook@include@after@{\filehook@ensuretex{#1}}%
}
\newcommand*\AtBeginOfInputs{%
- \filehook@appendwarg\filehook@input@atbegin
+ \filehook@append\filehook@input@@atbegin
}
\newcommand*\AtEndOfInputs{%
- \filehook@prefixwarg\filehook@input@atend
+ \filehook@prefix\filehook@input@@atend
}
-\newcommand*\AtBeginOfInputFile[1]{%
- \@ifundefined{\filehook@input@atbegin@#1}%
- {\long\global\@namedef{\filehook@input@atbegin@#1}}%
- {\expandafter\filehook@append\csname\filehook@input@atbegin@#1\endcsname}%
+\newcommand*\AtBeginOfInputFile{%
+ \filehook@addtohook\filehook@append\filehook@input@atbegin@
}
-\newcommand*\AtEndOfInputFile[1]{%
- \@ifundefined{\filehook@input@atend@#1}%
- {\long\global\@namedef{\filehook@input@atend@#1}}%
- {\expandafter\filehook@prefix\csname\filehook@input@atend@#1\endcsname}%
+\newcommand*\AtEndOfInputFile{%
+ \filehook@addtohook\filehook@prefix\filehook@input@atend@
}
\newcommand*\AtBeginOfFiles{%
- \filehook@appendwarg\filehook@atbegin
+ \filehook@append\filehook@@atbegin
}
\newcommand*\AtEndOfFiles{%
- \filehook@prefixwarg\filehook@atend
+ \filehook@prefix\filehook@@atend
}
-\newcommand*\AtBeginOfFile[1]{%
- \@ifundefined{\filehook@atbegin@#1}%
- {\long\global\@namedef{\filehook@atbegin@#1}}%
- {\expandafter\filehook@append\csname\filehook@atbegin@#1\endcsname}%
+\newcommand*\AtBeginOfEveryFile{%
+ \filehook@append\filehook@every@@atbegin
}
-\newcommand*\AtEndOfFile[1]{%
- \@ifundefined{\filehook@atend@#1}%
- {\long\global\@namedef{\filehook@atend@#1}}%
- {\expandafter\filehook@prefix\csname\filehook@atend@#1\endcsname}%
+\newcommand*\AtEndOfEveryFile{%
+ \filehook@prefix\filehook@every@@atend
}
-\newcommand*\AtBeginOfPackageFile[1]{%
- \AtBeginOfFile{#1.\@pkgextension}%
+\newcommand*\AtBeginOfFile{%
+ \filehook@addtohook\filehook@append\filehook@atbegin@
}
-\newcommand*\AtEndOfPackageFile{%
- \@ifnextchar*\AtEndOfPackageFile@star\AtEndOfPackageFile@normal
+\newcommand*\AtEndOfFile{%
+ \filehook@addtohook\filehook@prefix\filehook@atend@
+}
+\newcommand*\AtBeginOfClassFile{%
+ \@ifnextchar*
+ {\AtBeginOfXFile@star\@clsextension}%
+ {\AtBeginOfXFile@normal\@clsextension}%
}
-\def\AtEndOfPackageFile@star*#1#2{%
- \@ifpackageloaded{#1}%
- {#2}%
- {\AtEndOfPackageFile@normal{#1}{#2}}%
+\newcommand*\AtBeginOfPackageFile{%
+ \@ifnextchar*
+ {\AtBeginOfXFile@star\@pkgextension}%
+ {\AtBeginOfXFile@normal\@pkgextension}%
}
-\def\AtEndOfPackageFile@normal#1#2{%
- \AtEndOfFile{#1.\@pkgextension}{\AtEndOfPackage{#2}}%
+\def\AtBeginOfXFile@star#1*#2{%
+ \@ifl@aded{#1}{#2}%
+ {\@firstofone}%
+ {\AtBeginOfXFile@normal{#1}{#2}}%
}
-\newcommand*\AtBeginOfClassFile[1]{%
- \AtBeginOfFile{#1.\@clsextension}%
+\def\AtBeginOfXFile@normal#1#2{%
+ \AtBeginOfFile{#2.#1}%
}
\newcommand*\AtEndOfClassFile{%
- \@ifnextchar*\AtEndOfClassFile@star\AtEndOfClassFile@normal
+ \@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}}%
+}
+\def\AtEndOfXFile@normal#1#2#3{%
+ \AtEndOfFile{#2.#1}{\AtEndOfPackage{#3}}%
+}
+\let\filehook@orig@@input@\@input@
+\let\filehook@orig@@iinput\@iinput
+\def\@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\AtEndOfClassFile@star*#1#2{%
- \@ifclassloaded{#1}%
- {#2}%
- {\AtEndOfClassFile@normal{#1}{#2}}%
+\def\filehook@@iinput#1{%
+ \filehook@every@atbegin{#1}%
+ \filehook@input@atbegin{#1}%
+ \filehook@orig@@iinput{#1}%
+ \filehook@input@atend{#1}%
+ \filehook@every@atend{#1}%
+}
+\let\@iinput\filehook@@iinput
+\def\filehook@swap#1#2{#2#1}
+\def\filehook@ensureext#1{%
+ \expandafter\filehook@@ensureext#1\empty.tex\empty\empty
}
-\def\AtEndOfClassFile@normal#1#2{%
- \AtEndOfFile{#1.\@clsextension}{\AtEndOfClass{#2}}%
+\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}
+\long\def\latex@InputIfFileExists#1#2{%
+ \IfFileExists{#1}%
+ {#2\@addtofilelist{#1}%
+ \@@input\@filef@und
+ }%
+}
+\long\gdef\filehook@default@InputIfFileExists#1#2{%
+ \IfFileExists{#1}%
+ {\expandafter\filehook@swap
+ \expandafter{\@filef@und}%
+ {#2\@addtofilelist{#1}%
+ \filehook@every@atbegin{#1}%
+ \filehook@atbegin{#1}%
+ \@@input}%
+ \filehook@atend{#1}%
+ \filehook@every@atend{#1}%
+ }%
+}
+\long\gdef\filehook@@default@InputIfFileExists#1#2{%
+ \let\InputIfFileExists\filehook@InputIfFileExists
+ \IfFileExists{#1}%
+ {\expandafter\filehook@swap
+ \expandafter{\@filef@und}%
+ {#2\@addtofilelist{#1}%
+ \filehook@atbegin{#1}%
+ \@@input}%
+ \filehook@atend{#1}%
+ }%
+}
+\long\def\scrlfile@InputIfFileExists#1#2{%
+ \begingroup\expandafter\expandafter\expandafter\endgroup
+ \expandafter\ifx\csname #1-@alias\endcsname\relax
+ \expandafter\@secondoftwo
+ \else
+ \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
+ \expandafter\@firstoftwo
+ \fi
+ {%
+ \expandafter\InputIfFileExists\expandafter{\csname
+ #1-@alias\endcsname}{#2}%
+ }%
+ {\IfFileExists{#1}{%
+ \scr@load@hook{before}{#1}%
+ #2\@addtofilelist{#1}%
+ \@@input \@filef@und
+ \scr@load@hook{after}{#1}%
+ }}%
+}
+\long\def\filehook@scrlfile@InputIfFileExists#1#2{%
+ \begingroup\expandafter\expandafter\expandafter\endgroup
+ \expandafter\ifx\csname #1-@alias\endcsname\relax
+ \expandafter\@secondoftwo
+ \else
+ \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
+ \expandafter\@firstoftwo
+ \fi
+ {%
+ \expandafter\InputIfFileExists\expandafter{\csname
+ #1-@alias\endcsname}{#2}%
+ }%
+ {\IfFileExists{#1}{%
+ \expandafter\filehook@swap
+ \expandafter{\@filef@und}%
+ {\scr@load@hook{before}{#1}%
+ #2\@addtofilelist{#1}%
+ \filehook@every@atbegin{#1}%
+ \filehook@atbegin{#1}%
+ \@@input}%
+ \filehook@atend{#1}%
+ \filehook@every@atend{#1}%
+ \scr@load@hook{after}{#1}%
+ }}%
+}
+\long\def\filehook@@scrlfile@InputIfFileExists#1#2{%
+ \let\InputIfFileExists\filehook@InputIfFileExists
+ \begingroup\expandafter\expandafter\expandafter\endgroup
+ \expandafter\ifx\csname #1-@alias\endcsname\relax
+ \expandafter\@secondoftwo
+ \else
+ \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
+ \expandafter\@firstoftwo
+ \fi
+ {%
+ \expandafter\InputIfFileExists\expandafter{\csname
+ #1-@alias\endcsname}{#2}%
+ }%
+ {\IfFileExists{#1}{%
+ \expandafter\filehook@swap
+ \expandafter{\@filef@und}%
+ {\scr@load@hook{before}{#1}%
+ #2\@addtofilelist{#1}%
+ \filehook@atbegin{#1}%
+ \@@input}%
+ \filehook@atend{#1}%
+ \scr@load@hook{after}{#1}%
+ }}%
+}
+\AtBeginOfPackageFile*{scrlfile}{%
+ \let\InputIfFileExists\latex@InputIfFileExists
+}%
+\AtEndOfPackageFile*{scrlfile}{%
+ \RequirePackage{filehook-scrlfile}%
+}%
+\AtBeginOfPackageFile*{fink}{%
+ \RequirePackage{kvoptions}%
+ \begingroup
+ \let\InputIfFileExists\latex@InputIfFileExists
+}%
+\AtEndOfPackageFile*{fink}{%
+ \edef\@tempa{\noexpand\PassOptionsToPackage{mainext=\fnk@mainext,maindir=\fnk@maindir}{currfile}}%
+ \expandafter\endgroup\@tempa
+ \RequirePackage{filehook-fink}%
+}%
+\AtBeginOfClassFile*{memoir}{%
+ \let\filehook@@InputIfFileExists\latex@InputIfFileExists
+ \let\InputIfFileExists\latex@InputIfFileExists
+ \let\@iinput\filehook@orig@@iinput
+}%
+\AtEndOfClassFile*{memoir}{%
+ \let\@iinput\filehook@@iinput
+ \RequirePackage{filehook-memoir}%
+}%
+\ifcase
+ \ifx\InputIfFileExists\filehook@InputIfFileExists 0\else
+ \ifx\InputIfFileExists\latex@InputIfFileExists 1\else
+ \iffilehook@force 1\else
+ 9%
+ \fi\fi\fi
+\relax% 0
+\or% 1
+ \let\filehook@InputIfFileExists\filehook@default@InputIfFileExists
+ \let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists
+ \let\InputIfFileExists\filehook@InputIfFileExists
+ \iffilehook@force
+ \PackageWarning{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
+ The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}%
+ \fi
+\else
+ \PackageError{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
+ Use the 'force' option of 'filehook' to overwrite it.}{}%
+\fi
+\AtBeginDocument{%
+ \ifx\InputIfFileExists\filehook@InputIfFileExists\else
+ \PackageWarning{filehook}{Macro \string\InputIfFileExists\space got redefined after 'filehook' was loaded.^^J%
+ Certain file hooks might now be dysfunctional!}
+ \fi
}
\endinput
%%