diff options
author | Karl Berry <karl@freefriends.org> | 2011-01-05 00:23:17 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-01-05 00:23:17 +0000 |
commit | f421a713f2db99addeedb67a3581160f419a5ac3 (patch) | |
tree | bc20c6816e6dcb38d95aa58c638ef38727736533 /Master | |
parent | be62fd26ebe0decfe5c8abe5ff1fd2e2b00b7254 (diff) |
filehook 0.4 (4jan11)
git-svn-id: svn://tug.org/texlive/trunk@20933 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/latex/filehook/filehook.pdf | bin | 287675 -> 439361 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/filehook/filehook.dtx | 1397 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/filehook/filehook.ins | 8 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/filehook/filehook-fink.sty | 73 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/filehook/filehook-listings.sty | 45 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/filehook/filehook-memoir.sty | 59 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/filehook/filehook-scrlfile.sty | 118 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/filehook/filehook.sty | 453 |
8 files changed, 1643 insertions, 510 deletions
diff --git a/Master/texmf-dist/doc/latex/filehook/filehook.pdf b/Master/texmf-dist/doc/latex/filehook/filehook.pdf Binary files differindex 2b4918c8dac..b911af05491 100644 --- a/Master/texmf-dist/doc/latex/filehook/filehook.pdf +++ b/Master/texmf-dist/doc/latex/filehook/filehook.pdf diff --git a/Master/texmf-dist/source/latex/filehook/filehook.dtx b/Master/texmf-dist/source/latex/filehook/filehook.dtx index 2c385a7bac8..35398cb4fe1 100644 --- a/Master/texmf-dist/source/latex/filehook/filehook.dtx +++ b/Master/texmf-dist/source/latex/filehook/filehook.dtx @@ -1,5 +1,5 @@ % \iffalse meta-comment -%% 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 @@ -19,7 +19,7 @@ %% 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 $ % \fi % % \iffalse @@ -29,18 +29,28 @@ %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{filehook} %<*package> - [2010/12/20 v0.3 Hooks for input files] + [2011/01/03 v0.4 Hooks for input files] %</package> % %<*driver> -\documentclass{ydoc}[2010/12/20] -\usepackage{filehook}[2010/12/08] +\documentclass{ydoc}[2011/01/03] +\usepackage{filehook}[2011/01/03] \usepackage{ifpdf} \usepackage{hyperref} +\usepackage{array} +\usepackage{booktabs} \EnableCrossrefs \CodelineIndex \RecordChanges \providecommand*\pkg{\texttt} +\makeatletter +\providecommand*\tablecaption{% + \@tempdima=\abovecaptionskip + \abovecaptionskip=\belowcaptionskip + \belowcaptionskip=\@tempdima + \caption +} +\makeatother \listfiles \begin{document} \DocInput{filehook.dtx} @@ -50,7 +60,7 @@ %</driver> % \fi % -% \CheckSum{422} +% \CheckSum{939} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -72,6 +82,19 @@ % \changes{v0.1}{2010/04/08}{Initial version} % \changes{v0.2}{2010/12/08}{Added support for 'memoir' class and 'scrlfile' package. Remove support for deprecated 'fink' package.} % \changes{v0.3}{2010/12/20}{Added hooks for package and class files. Changed a warning to an error and added the 'force' option to overwrite this.} +% \changes{v0.4}{2011/01/03}{^^A +% Improved support for 'memoir' class and 'scrlfile' package. +% Added AtBeginOfEveryFile and AtEndOfEveryFile hooks. +% Changed handling of macro arguments in hook code. +% Added filename parsing code to support TeX files with and without extension. +% Added AtBeginOfEveryFile/AtEndOfEveryFile hooks. +% Fixes misspelled \string\AfterOfIncludeFile. +% Added patch for listings \lstinputlistings to avoid hooks for verbatim files. +% Added star argument for AtBeginOfClass and PackageFile. +% Worked on scrlfile and memoir compatibility. +% Readded fink compatibility code. +% Updated documentation. +% } % % \GetFileInfo{filehook.dtx} % @@ -98,82 +121,205 @@ % \vspace{1.2em}% % % \begin{abstract} -% This small package provides hooks for input files. Document and package authors can use these hooks to +% This package provides hooks for input files. Document and package authors can use these hooks to % execute code at begin or the end of specific or all input files. % \end{abstract} % +% % \section{Introduction} % These package changes some internal \LaTeX{} macros used to load input files so that they include `hooks'. % A hook is an (internal) macro executed at specific points. Normally it is initially empty, but can be extended using % an user level macro. The most common hook in \LaTeX{} is the `At-Begin-Document' hook. Code can be added to this hook -% using \Macro{AtBeginDocument}{<\TeX code>}. +% using \Macro\AtBeginDocument{<\TeX code>}. % -% \section{Usage} -% This package provides several groups of hooks: for file read using \Macro{input}, for files read using \Macro{include} and for all read files (i.e.\ all files read using -% \Macro{InputIfFileExists}, which includes package and class files and files falling into the first two groups). Since v0.3 from 2010/12/20 there are also hooks for package and class files. -% All groups include a `AtBegin' and a `AtEnd' macro. The \Macro{include} group has also a `After' hook which -% it is executed \emph{after} the page break (\Macro{clearpage}) is inserted by the \Macro{include} code. In contrast, the `AtEnd' hook is executed before the trailing page break +% +% This package provides hooks for files read by the \LaTeX{} macros \Macro\input, \Macro\include and +% \Macro\InputIfFileExists as well as (since v0.3 from 2010/12/20) for class and package files, +% i.e. macros \Macro\documentclass, \Macro\LoadClassWithOptions and \Macro\LoadClass +% as well as \Macro\usepackage, \Macro\RequirePackageWithOptions and \Macro\RequirePackage. +% Note that \Macro\InputIfFileExists, and therefore its hooks, is used by the aforementioned macros. +% In v0.4 from 2011/03/01 special hooks where added which are executed for every read file, but will not be +% executed a second time by the internal \Macro\InputIfFileExists inside \Macro\input and \Macro\include. +% +% For all files a `AtBegin' and a `AtEnd' hook is installed. For \Macro\include files there is also a `After' hook which +% it is executed \emph{after} the page break (\Macro\clearpage) is inserted by the \Macro\include code. +% In contrast, the `AtEnd' hook is executed before the trailing page break % and the `AtBegin' hook is executed after the \emph{leading} page break. +% The `AtBegin' hook can be used to set macros to file specific values. +% These macros can be reset in the `AtEnd' hook to the parent file values. +% If these macros appear in the page header or footer they need to be reset `After' hook +% to ensure that the correct values are used for the last page. % -% The first three groups includes general and file specific hooks. The general hooks are executed for every file of this group and provide the file name as argument |#1|. -% The file specific ones are only executed for a certain file. The package and class hocks are always specific to one file. +% In addition to general hooks which are executed for all files of there type, +% file specific one can be defined which are only executed for the named file. +% The hooks for classes and packages are always specific to one file. % -% The below macros can be used to add material (\TeX{} code) to the related hooks. All `AtBegin' macros will \emph{append} the code to the hooks, but the -% `AtEnd' and `After' macros will \emph{prefix} the code instead. This ensures that two different packages adding material in `AtBegin'/`AtEnd' pairs do not -% overlap each other. Instead the later used package adds the code closer to the file content, `inside' the material added by the first package. +% Older versions of this package provided the file name as argument |#1| for the general hooks. +% This has been changed in v0.4 from 2011/01/03: the hook code is stored and executed without modifications, +% i.e.\ macro argument characters (|#|) are now handled like normal and don't have to be doubled. +% See section~\ref{sec:upgrade} for information how to upgrade older documents. +% +% \section{Usage} +% The below macros can be used to add material (\TeX{} code) to the related hooks. +% All `AtBegin' macros will \emph{append} the code to the hooks, but the `AtEnd' and `After' macros will \emph{prefix} the code instead. +% This ensures that two different packages adding material in `AtBegin'/`AtEnd' pairs do not overlap each other. +% Instead the later used package adds the code closer to the file content, `inside' the material added by the first package. % Therefore it is safely possible to surround the content of a file with multiple \LaTeX{} environments using multiple `AtBegin'/`AtEnd' macro calls. % If required inside another package a different order can be enforced by using the internal hook macros shown in the implementation section. % +%^^A Some internal macros to draw the hook positions: +% \def\Hook#1{\textsf{Hook: #1}\MacroArgs} +% +% \def\DrawInputIfB#1{% +% \hbox{\vbox{% +% \sffamily +% \hbox{\Macro\InputIfFileExists:}% +% \hbox{\fbox{\vbox{% +% \hbox{\Hook{AtBeginOfFile}{<file name>}}% +% #1% +% \hbox{\Hook{AtBeginOfFiles}}% +% \hbox{\fbox{\emph{Content}}}% +% \vspace{2pt}% +% \hbox{\Hook{AtEndOfFiles}}% +% \hbox{\Hook{AtEndOfFile}{<file name>}}% +% }}}% +% }}% +% }% +% +% \def\DrawInputIf#1{% +% \hbox{\vbox{% +% \sffamily +% \hbox{\Macro\InputIfFileExists:}% +% \hbox{\fbox{\vbox{% +% \hbox{\Hook{AtBeginOfEveryFile}}% +% \hbox{\Hook{AtBeginOfFile}{<file name>}}% +% #1% +% \hbox{\Hook{AtBeginOfFiles}}% +% \hbox{\fbox{\emph{Content}}}% +% \vspace{2pt}% +% \hbox{\Hook{AtEndOfFiles}}% +% \hbox{\Hook{AtEndOfFile}{<file name>}}% +% \hbox{\Hook{AtEndOfEveryFile}}% +% }}}% +% }}% +% }% +% +% +% \subsection*{Every File} +% +% \DescribeMacro{\AtBeginOfEveryFile}{<\TeX\ code>} +% \DescribeMacro{\AtEndOfEveryFile}{<\TeX\ code>} +% Sometime certain code should be executed at the begin and end of every read file, e.g.\ pushing and popping a file stack. +% The `At...OfFiles' hooks already do a good job here. Unfortunately there is the issue with the \Macro\clearpage in \Macro\include. +% The \Macro\AtEndOfFiles is executed before it, which can cause issues with page headers and footers. +% A workaround, e.g.\ done by older versions of the \pkg{currfile} package, is to execute the code twice for include files: +% once in the |include| related hooks and once in the |OfFiles| hooks. +% +% A better solution for this problem was added in v0.4 from 2011/01/03: +% the |EveryFile| hooks will be executed exactly once for every file, independent if it is +% read using \Macro\input, \Macro\include or \Macro\InputIfFileExists. +% Special care is taken to suppress them for the \Macro\InputIfFileExists inside \Macro\input and \Macro\include. +% +% These hooks are located around the more specific hooks: +% For \Macro\input files the `Begin' hook is executed before the \Macro\AtBeginOfInputs hook and the `End' hook after +% the \Macro\AtEndOfInputs. +% Similarly, for \Macro\include files the `Begin' hook is executed before the \Macro\AtBeginOfIncludes hook and the `End' hook after +% the \Macro\AfterIncludes (!). +% For files read by \Macro\InputIfFileExists (e.g. also for \Macro\usepackage, etc.) they are executed before and after the +% \Macro\AtBeginOfFiles and \Macro\AtEndOfFiles hooks, respectively. +% Note that the \Macro\AtBeginOfEveryFile hook is executed before the \Macro\AtBeginOfPackageFile/\Macro\AtBeginOfClassFile hooks +% and that the \Macro\AtEndOfEveryFile hook is executed also before the hooks \Macro\AtEndOfPackageFile/\Macro\AtEndOfClassFile. +% Therefore the `Every' and `PackageFile'/`ClassFile' hooks do not nest correctly like all other hooks do. +% +% +% \subsection*{All Files} +% +% \DescribeMacro{\AtBeginOfFiles}{<\TeX\ code>} +% \DescribeMacro{\AtEndOfFiles}{<\TeX\ code>} +% These macros add the given \marg{code} to two hooks executed for all files read using the \Macro\InputIfFileExists macro. This macro is used internally by the +% \Macro\input, \Macro\include and \Macro\usepackage/\Macro\RequirePackage macros. Packages and classes might use it to include additional or auxiliary files. +% Authors can exclude those files from the hooks by using \Macro\IfFileExists{<file name>}|{\@input\@filef@und}{}| instead. +% +% \DescribeMacro{\AtBeginOfFile}{<file name with extension>}{<\TeX\ code>} +% \DescribeMacro{\AtEndOfFile}{<file name with extension>}{<\TeX\ code>} +% Like the {\Macro{...OfIncludeFile}{<file name>}{<\TeX\ code>}} macros above, just for `all' read files. Here the \meta{file name} should include the file +% extension! +% +% The `all files' hooks are closer to the file content than the \Macro\input and \Macro\include hook, i.e.\ the \Macro\AtBeginOfFiles comes \emph{after} the \Macro\AtBeginOfIncludes and +% the \Macro\AtEndOfFiles comes \emph{before} the \Macro\AtEndOfIncludes hook. +% +% The following figure shows the positions of the hooks inside the macro:\par\medskip +% \centerline{\DrawInputIf{}} +% +% % \subsection*{Include Files} % \DescribeMacro{\AtBeginOfIncludes}{<\TeX\ code>} % \DescribeMacro{\AtEndOfIncludes}{<\TeX\ code>} % \DescribeMacro{\AfterIncludes}{<\TeX\ code>} -% All these macro take one argument (some \TeX{} code) which is added to the specific hook for files read using \Macro{include}. -% The code can use the macro argument |#1| -% which will be expanded to the include \meta{file name}, i.e.\ the hooks are macros with one argument which will be the file name. -% As described above the `AtEnd' hook is executed before and the `After' hook is executed after the trailing \Macro{clearpage}. -% Material which should be (still) valid in the page header or footer of the last page of such an -% file should therefore use the `After' hook. +% As described above the `AtEnd' hook is executed before and the `After' hook is executed after the trailing \Macro\clearpage. +% Note that material which appears in the page header or footer should be updated in the `After' hook, not the `AtEnd' hook, to ensure +% that the old values are still valid for the last page. % % \DescribeMacro{\AtBeginOfIncludeFile}{<file name>}{<\TeX\ code>} % \DescribeMacro{\AtEndOfIncludeFile}{<file name>}{<\TeX\ code>} % \DescribeMacro{\AfterIncludeFile}{<file name>}{<\TeX\ code>} % These file-specific macros take the two arguments. The \meta{code} is only executed for the file with the given \meta{file name} -% and only if it is read using \Macro{include}. It is not allowed to use macro arguments inside the code. -% The \meta{file name} should be identical to the name used for \Macro{include} and not include the `|.tex|' extension. +% and only if it is read using \Macro\include. +% The \meta{file name} should be identical to the name used for \Macro\include and not include the `|.tex|' extension. +% +% The following figure shows the positions of the hooks inside the macro:\par\medskip +% \centerline{\hbox{\vbox{% +% \sffamily +% \hbox{\Macro\include:}% +% \hbox{\fbox{\vbox{% +% \hbox{\Macro\clearpage~~(implicit)}% +% \hbox{\Hook{AtBeginOfEveryFile}}% +% \hbox{\Hook{AtBeginOfIncludeFile}{<file name>}}% +% \hbox{\Hook{AtBeginOfIncludes}}% +% \hbox{\fbox{\DrawInputIfB{}}}% +% \vspace{2pt}% +% \hbox{\Hook{AtEndOfIncludes}}% +% \hbox{\Hook{AtEndOfIncludeFile}{<file name>}}% +% \hbox{\Macro\clearpage~~(implicit)}% +% \hbox{\Hook{AfterIncludes}}% +% \hbox{\Hook{AfterIncludeFile}{<file name>}}% +% \hbox{\Hook{AtEndOfEveryFile}}% +% }}}% +% }}} +% % % \subsection*{Input Files} % % \DescribeMacro{\AtBeginOfInputs}{<\TeX\ code>} % \DescribeMacro{\AtEndOfInputs}{<\TeX\ code>} -% Like the \Macro{...OfIncludes}\marg{code} macros above, just for file read using \Macro{input}. Again, the macro argument |#1| can be used inside the \meta{code} and -% will be expanded to the <file name>. +% Like the \Macro{...OfIncludes}{code} macros above, just for file read using \Macro\input. % % \DescribeMacro{\AtBeginOfInputFile}{<file name>}{<\TeX\ code>} % \DescribeMacro{\AtEndOfInputFile}{<file name>}{<\TeX\ code>} -% Like the \Macro{...OfIncludeFile}\marg{<file name>}\marg{code} macros above, just for file read using \Macro{input}. Here the \meta{file name} should include the file -% extension! The \meta{code} must not include any macro arguments (|#1|). +% Like the \Macro{...OfIncludeFile}{<file name>}{code} macros above, just for file read using \Macro\input. Here the \meta{file name} should include the file +% extension! +% +% The following figure shows the positions of the hooks inside the macro:\par\medskip +% \centerline{\hbox{\vbox{% +% \sffamily +% \hbox{\Macro\input:}% +% \hbox{\fbox{\vbox{% +% \hbox{\Hook{AtBeginOfEveryFile}}% +% \hbox{\Hook{AtBeginOfInputFile}{<file name>}}% +% \hbox{\Hook{AtBeginOfInputs}}% +% \hbox{\fbox{\DrawInputIfB{}}}% +% \vspace{2pt}% +% \hbox{\Hook{AtEndOfInputs}}% +% \hbox{\Hook{AtEndOfInputFile}{<file name>}}% +% \hbox{\Hook{AtEndOfEveryFile}}% +% }}}% +% }}} % -% \subsection*{All Files} -% -% \DescribeMacro{\AtBeginOfFiles}{<\TeX\ code>} -% \DescribeMacro{\AtEndOfFiles}{<\TeX\ code>} -% These macros add the given \marg{code} to two hooks executed for all files read using the \Macro{InputIfFileExists} macro. This macro is used internally by the -% \Macro{input}, \Macro{include} and \Macro{usepackage}/\Macro{RequirePackage} macros. Packages and classes might use it to include additional or auxiliary files. -% Authors can exclude those files from the hooks by using \Macro{IfFileExists}{<file name>}|{\@input\@filef@und}{}| instead. -% -% \DescribeMacro{\AtBeginOfFile}{<file name with extension>}{<\TeX\ code>} -% \DescribeMacro{\AtEndOfFile}{<file name with extension>}{<\TeX\ code>} -% Like the {\expandafter\Macro\csname...OfIncludeFile\endcsname{<file name>}{<\TeX\ code>}} macros above, just for `all' read files. Here the \meta{file name} should include the file -% extension! The \meta{code} must not include any macro arguments (|#1|). -% -% The `all files' hooks are closer to the file content than the \Macro{input} and \Macro{include} hook, i.e.\ the \Macro{AtBeginOfFiles} comes \emph{after} the \Macro{AtBeginOfIncludes} and -% the \Macro{AtEndOfFiles} comes \emph{before} the \Macro{AtEndOfIncludes} hook. % % % \subsection*{Package Files} % -% \DescribeMacro{\AtBeginOfPackageFile}{<package name>}{<\TeX\ code>} +% \DescribeMacro{\AtBeginOfPackageFile}*{<package name>}{<\TeX\ code>} % \DescribeMacro{\AtEndOfPackageFile}*{<package name>}{<\TeX\ code>} % This macros install the given \MacroArgs<\TeX\ code> in the `AtBegin' and `AtEnd' hooks of the given package file. % The \Macro\AtBeginOfPackageFile simply executes \Macro\AtBeginOfFile{<package name>.sty}{<\TeX code>}. @@ -182,59 +328,146 @@ % If the starred version is used and the package is already loaded the code % is executed right away. % +% The following figure shows the positions of the hooks inside the macros:\par\medskip +% \centerline{\hbox{\vbox{% +% \sffamily +% \hbox{\Macro\usepackage/\Macro\RequirePackage/\Macro\RequirePackageWithOptions:}% +% \hbox{\fbox{\vbox{% +% \hbox{\fbox{\DrawInputIf{\hbox{ (includes AtBeginOfPackageFile\MacroArgs{<file name>})}}}}% +% \vspace{2pt}% +% \hbox{\Hook{AtEndOfPackage}~~(\LaTeX\ hook)}% +% \hbox{\Hook{AtEndOfPackageFile}{<file name>}}% +% }}}% +% }}} % % \subsection*{Class Files} % -% \DescribeMacro{\AtBeginOfClassFile}{<class name>}{<\TeX\ code>} +% \DescribeMacro{\AtBeginOfClassFile}*{<class name>}{<\TeX\ code>} % \DescribeMacro{\AtEndOfClassFile}*{<class name>}{<\TeX\ code>} % This macros install the given \MacroArgs<\TeX\ code> in the `AtBegin' and `AtEnd' hooks of the given class file. % They work with classes loaded using \Macro\LoadClass, \Macro\LoadClassWithOptions and also \Macro\documentclass. % However, in the latter case |filehook| must be loaded using \Macro\RequirePackage beforehand. -% The \Macro\AtBeginOfClassFile simply executes \Macro\AtBeginOfFile{<class name>.cls}{<\TeX code>}. +% The macro \Macro\AtBeginOfClassFile simply executes \Macro\AtBeginOfFile{<class name>.cls}{\ldots}. % Special care is taken to ensure that the `AtEnd' code is executed \emph{after} any code installed by the class itself -% using the \LaTeX\ macro \Macro\AtEndOfPackage. +% using the \LaTeX\ macro \Macro\AtEndOfClass. % If the starred version is used and the class is already loaded the code % is executed right away. % +% The following figure shows the positions of the hooks inside the macros:\par\medskip +% \centerline{\hbox{\vbox{% +% \sffamily +% \hbox{\Macro\documentclass/\Macro\LoadClass/\Macro\LoadClassWithOptions:}% +% \hbox{\fbox{\vbox{% +% \hbox{\fbox{\DrawInputIf{\hbox{ (includes AtBeginOfClassFile\MacroArgs{<file name>})}}}}% +% \vspace{2pt}% +% \hbox{\Hook{AtEndOfClass}~~(\LaTeX\ hook)}% +% \hbox{\Hook{AtEndOfClassFile}{<file name>}}% +% }}}% +% }}} % -% \StopEventually{} % -% \section{Compatibility Issues with other Packages} -% The |filehook| package might clash with other packages or classes which also redefine \Macro{InputIfFileExists}. -% Special compatibility code is in place for the known packages listed below (in their current implementation). -% If any other unknown definition is found an error will be raised. The package option `|force|' can be used -% to prevent this and to force the redefinition of this macro. +% \clearpage +% \section{Compatibility Issues with Classes and other Packages} +% The |filehook| package might clash with other packages or classes which also redefine \Macro\InputIfFileExists +% or internal macros used by \Macro\include and \Macro\input (which are \Macro\@input@ and \Macro\@iinput). +% Special compatibility code is in place for the packages listed below (in their current implementation). +% If any other unknown definition of \Macro\InputIfFileExists is found an error will be raised. +% The package option `|force|' can be used to prevent this and to force the redefinition of this macro. % Then any previous modifications will be lost, which will most likely break the other package. +% Table~\ref{tab:incomp} lists all packages and classes which where found do be incompatible. +% The packages \pkg{auxhook}, \pkg{stampinclude}, \pkg{rerunfilecheck} and \pkg{excludeonly} redefine +% one or more of the above macros but have been found compatible with |filehook|. % Please do not hesitate to inform the author of |filehook| of any encountered problems with other packages. % -% \subsection*{jmlrbook} -% The |jmlrbook| class from the |jmlr| bundle temporary redefines \Macro{InputIfFileExists} to import papers. -% The `original' definition is saved away at load time of the package and is used internally by the new definition. -% This means that the hooks will not be active for this imported files because |filehook| is loaded after the class. -% This should not affect its normal usage. -% Note that, in theory, the package could be loaded before \Macro{documentclass} using \Macro{RequirePackage} to enable the file hooks also for these files. +% \subsection{Supported Classes and Packages} +% The following classes and packages are actively supported and should work as normal when used together with |filehook|. +% Please note that most of them are incompatible to each other, which |filehook| might not fix. % -% \subsection*{memoir} -% The |memoir| class redefines \Macro{InputIfFileExists} to add own hooks identical to the |At...OfFiles| hooks (there called \Macro{AtBeginFile} and \Macro{AtEndFile}). +% \subsubsection*{memoir} +% The |memoir| class redefines \Macro\InputIfFileExists to add own hooks identical to the `At...OfFiles' hooks (there called \Macro\AtBeginFile and \Macro\AtEndFile). % This hooks will be moved to the corresponding ones of |filehook| and will keep working as normal. -% -% \subsection*{scrlfile} -% The |scrlfile| package from the \emph{koma-script} bundle redefines \Macro{InputIfFileExists} to allow file name aliases and to also add hooks. +% Since v0.4 from 2011/01/03 this modification will be also applied when the |filehook| package is loaded (using \Macro\RequirePackage) \emph{before} the +% |memoir| class. However, the hooks from |filehook| need to be temporally disabled while reading the |memoir| class. +% They will not be triggered for all files read directly by this class, like configuration and patch files. +% Note that the `At...OfClassFile' hooks still work for the |memoir| class file itself. In fact they are used to restore the default definition of \Macro\InputIfFileExists +% at the begin and patch it at the end of the class file. +% The |filehook| package should be loaded either before the class (using \Macro\RequirePackage) or directly +% after it. Because the |memoir| hook code is moved to the |filehook| hooks this class should then be +% compatible with below packages if |memoir| and |filehook| are loaded before them. +% +% +% \subsubsection*{scrlfile} +% The |scrlfile| package from the \emph{koma-script} bundle redefines \Macro\InputIfFileExists to allow file name aliases and to also add hooks. % If required it should be loaded before |filehook|, which will add its hooks correctly to the modified definition. +% Since v0.4 from 2011/01/03 this modification will be also applied when the |scrlfile| package is loaded after |filehook|. % -% \subsection*{fink} +% +% \subsubsection*{fink} % The |filehook| and |currfile| packages where written as replacements for the |fink| package, where |filehook| provides the necessary hooks for |currfile|. % The |fink| package has now been deprecated in favour of |currfile| and should not be used anymore. The |fink| compatibility code has been removed from |filehook| -% and both cannot be used successfully together as both redefine the \Macro{InputIfFileExists} macro. +% and both cannot be used successfully together as both redefine the \Macro\InputIfFileExists macro. +% % -% \subsection*{listings} -% The \pkg{listings} package uses \Macro{input} inside \Macro{lstinputlisting}. Therefore the |InputFile|(|s|) and |File|(|s|) hooks are also triggered for these files. +% \subsubsection*{listings} +% The \pkg{listings} package uses \Macro\input inside \Macro\lstinputlisting. Therefore the |InputFile|(|s|) and |File|(|s|) hooks are also triggered for these files. % Please note that this hooks are executing inside a verbatim environment. While the code in the hook is not affected (because it was added outside the verbatim -% environment), any further code read using any input macro (\Macro{input}, \Macro{@input}, \Macro{@@input} (\TeX's \Macro{input}), \ldots) will be processed verbatim and typeset -% as part of the listing. A known package suffering from this is \pkg{svn-multi} which loads |.svx| files for every |.tex| file. -% A workaround for this issue is to temporally redefine \Macro{input} to \Macro{@input} for \Macro{lstinputlisting}: |{\let\input\@input\lstinputlisting{...}}|. +% environment), any further code read using any input macro (\Macro\input, \Macro\@input, \Macro\@@input (\TeX's \Macro\input), \ldots) will be processed verbatim and typeset +% as part of the listing. +% Since v0.4 this macro is automatically patched so \Macro\@input is used instead to avoid this issue. % -% +% +% \subsection{Other Classes and Packages} +% +% \subsubsection*{jmlrbook} +% The |jmlrbook| class from the |jmlr| bundle temporary redefines \Macro\InputIfFileExists to import papers. +% The `original' definition is saved away at load time of the package and is used internally by the new definition. +% This means that the hooks will not be active for this imported files because |filehook| is loaded after the class. +% This should not affect its normal usage. +% Note that, in theory, the package could be loaded before \Macro\documentclass using \Macro\RequirePackage to enable the file hooks also for these files. +% +% \subsubsection*{\LaTeX's \textbackslash bibliography} +% The standard \LaTeX\ macro \Macro\bibliography uses the same internal macro \Macro\@input@ to read a file +% as \Macro\include does. +% The `include' hooks will also be executed for this |.bbl| file if the macro is directly followed by \Macro\clearpage, +% because the |filehook| code will assume it is executed inside \Macro\include. +% This rare case can be easily avoided by placing a \Macro\relax after \Macro\bibliography{\ldots}. +% +% +% \begin{table} +% \centering +% \tablecaption{Incompatible packages and classes} +% \label{tab:incomp} +% +% \begin{tabular}{>{\ttfamily}llll} +% \toprule +% Name & Type & Note & Affected Hooks \\ +% \midrule +% paper & class & with \texttt{journal} option & All hocks for \Macro\include\unskip'd files \\ +% journal & class & & All hocks for \Macro\include\unskip'd files \\ +% gmparts & package & & \Macro\include hooks \\ +% newclude & package & formally \texttt{includex} & All hocks for \Macro\include\unskip'd files \\ +% \bottomrule +% \end{tabular} +% \end{table} +% +% \clearpage +% \section{Upgrade Guide} +% \label{sec:upgrade} +% This sections gives information for users of older versions of this package which unfortunately might not be 100\% backwards compatible. +% +% \subsection*{Upgrade to v0.4 - 2011/01/03} +% \begin{itemize} +% \item The macro \Macro\AfterIncludeFile was misspelled as \Macro\AfterOfIncludeFile in the implementation of earlier versions, but not in the documentation. +% This has now be corrected. Please adjust your code to use the correct name and to require the |filehook| package from 2011/01/03. +% \item All general hooks (the one not taking a file argument) used to have an implicit argument |#1| which was expanded to the file name (i.e.\ the argument of \Macro\input etc.). +% This has now be changed, so that macro arguments are not handled special in hook code, which e.g.\ simplifies macro definitions. +% Older hook code might need to change |##| to |#| to compensate for this change. +% If the file name is required the macros (e.g.\ \Macro\currfilename) of the partner package \pkg{currfile} should be used. +% These macros are available everywhere including in all hocks. +% \end{itemize} +% +% \StopEventually{} +% \clearpage % \section{Implementation}\label{sec:impl} % % \iffalse @@ -248,234 +481,152 @@ \ProcessOptions\relax % \end{macrocode} % -% \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. +% +% \subsection{Initialisation of Hooks} +% The general hooks are initialised to call the file specific hooks. +% +% \begin{macro}{\filehook@include@atbegin} % \begin{macrocode} -\let\filehook@orig@@input@\@input@ -\let\filehook@orig@@iinput\@iinput +\def\filehook@include@atbegin#1{% + \let\InputIfFileExists\filehook@@InputIfFileExists + \@nameuse{\filehook@include@atbegin@#1}% + \filehook@include@@atbegin +} % \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{macro}{\filehook@include@@atbegin} +% \begin{macrocode} +\def\filehook@include@@atbegin{} +% \end{macrocode} +% \end{macro} % +% \begin{macro}{\filehook@include@atend} % \begin{macrocode} -\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\filehook@include@atend#1{% + \filehook@include@@atend + \@nameuse{\filehook@include@atend@#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{macro}{\filehook@include@@atend} % \begin{macrocode} -\def\@iinput#1{% - \filehook@input@atbegin{#1}% - \filehook@orig@@iinput{#1}% - \filehook@input@atend{#1}% +\def\filehook@include@@atend{} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@include@after} +% \begin{macrocode} +\def\filehook@include@after#1{% + \filehook@include@@after + \@nameuse{\filehook@include@after@#1}% } % \end{macrocode} % \end{macro} % -% \begin{macro}{\InputIfFileExists} -% This macro is redefined for the general file hooks. -% The original definition is checked but is not saved away and called by the new definition, because -% of the existing complexity. The hooks must be places around the actual input macro (\Macro{@@input}). +% \begin{macro}{\filehook@include@@after} +% \begin{macrocode} +\def\filehook@include@@after{} +% \end{macrocode} +% \end{macro} % -% Alternatives definitions of \cs{InputIfFileExists} are defined here for comparison. -% This is done inside a group to keep them only temporary. +% \begin{macro}{\filehook@input@atbegin} % \begin{macrocode} -\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}% - }}% +\def\filehook@input@atbegin#1{% + \let\InputIfFileExists\filehook@@InputIfFileExists + \@nameuse{\filehook@input@atbegin@\filehook@ensureext{#1}}% + \filehook@input@@atbegin } % \end{macrocode} +% \end{macro} % -% If the |scrlfile| package definition is detected the |filehook|s are added -% to that definition. Unfortunately the \Macro{scr@load@hook}{before} hook is placed \emph{before} -% not after the |#2\@addtofilelist{#1}| code. Otherwise the |filehook|s could simply be added to these hooks. -% Note that should |scrlfile| ever change its \Macro{InputIfFileExists} macro this code will not be executed and -% the general clause below will kick in. +% \begin{macro}{\filehook@input@@atbegin} % \begin{macrocode} -\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}% - }}% +\def\filehook@input@@atbegin{} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@input@atend} +% \begin{macrocode} +\def\filehook@input@atend#1{% + \filehook@input@@atend + \@nameuse{\filehook@input@atend@\filehook@ensureext{#1}}% } - -\PackageInfo{filehook}{Package 'scrlfile' detected and compensated for.} - % \end{macrocode} -% Otherwise the normal |filehook| definition will be set. 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. +% \end{macro} +% +% \begin{macro}{\filehook@input@@atend} % \begin{macrocode} -\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 +\def\filehook@input@@atend{} % \end{macrocode} +% \end{macro} % -% Finally, if no specific alternate definition is detected the original \LaTeX\ definition is checked for and a -% warning is given if any other unknown definition is detected. In this case it will be simply overwritten. +% \begin{macro}{\filehook@atbegin} % \begin{macrocode} -\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}% - }% +\def\filehook@atbegin#1{% + \@nameuse{\filehook@atbegin@\filehook@ensureext{#1}}% + \filehook@@atbegin } - -\fi - -\endgroup % \end{macrocode} % \end{macro} % +% \begin{macro}{\filehook@@atbegin} +% \begin{macrocode} +\def\filehook@@atbegin{} +% \end{macrocode} +% \end{macro} % -% \subsection{Initialisation of Hooks} -% The general hooks are initialised to call the file specific hooks. -% -% \begin{macro}{\filehook@include@atbegin} -% \begin{macro}{\filehook@include@atend} -% \begin{macro}{\filehook@include@after} +% \begin{macro}{\filehook@atend} % \begin{macrocode} -\def\filehook@include@atbegin#1{% - \@nameuse{\filehook@include@atbegin@#1}% -} -\def\filehook@include@atend#1{% - \@nameuse{\filehook@include@atend@#1}% -} -\def\filehook@include@after#1{% - \@nameuse{\filehook@include@after@#1}% +\def\filehook@atend#1{% + \filehook@@atend + \@nameuse{\filehook@atend@\filehook@ensureext{#1}}% } % \end{macrocode} % \end{macro} -% \end{macro} +% +% \begin{macro}{\filehook@@atend} +% \begin{macrocode} +\def\filehook@@atend{} +% \end{macrocode} % \end{macro} % -% \begin{macro}{\filehook@input@atbegin} -% \begin{macro}{\filehook@input@atend} +% \begin{macro}{\filehook@every@atbegin} % \begin{macrocode} -\def\filehook@input@atbegin#1{% - \@nameuse{\filehook@input@atbegin@#1}% -} -\def\filehook@input@atend#1{% - \@nameuse{\filehook@input@atend@#1}% +\def\filehook@every@atbegin#1{% + \filehook@every@@atbegin } % \end{macrocode} % \end{macro} +% +% \begin{macro}{\filehook@every@@atbegin} +% \begin{macrocode} +\def\filehook@every@@atbegin{} +% \end{macrocode} % \end{macro} % -% \begin{macro}{\filehook@atbegin} -% \begin{macro}{\filehook@atend} +% \begin{macro}{\filehook@every@atend} % \begin{macrocode} -\def\filehook@atbegin#1{% - \@nameuse{\filehook@atbegin@#1}% -} -\def\filehook@atend#1{% - \@nameuse{\filehook@atend@#1}% +\def\filehook@every@atend#1{% + \filehook@every@@atend } % \end{macrocode} % \end{macro} +% +% \begin{macro}{\filehook@every@@atend} +% \begin{macrocode} +\def\filehook@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 @@ -501,7 +652,7 @@ % \end{macro} % % \begin{macro}{\filehook@appendwarg} -% Appends code with one macro argument. The \Macro{@tempa} intermediate step is required because of the +% 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@appendwarg#1#2{% @@ -514,9 +665,8 @@ % \end{macrocode} % \end{macro} % -% % \begin{macro}{\filehook@prefix} -% Prefixes code without an argument to a hook. +% Prefixes code to a hook. % \begin{macrocode} \long\def\filehook@prefix#1#2{% \begingroup @@ -542,6 +692,20 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\filehook@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@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 +} +% \end{macrocode} +% \end{macro} % % \subsubsection*{User Level Macros} % The user level macros simple use the above defined macros on the appropriate hook. @@ -549,7 +713,7 @@ % \begin{macro}{\AtBeginOfIncludes} % \begin{macrocode} \newcommand*\AtBeginOfIncludes{% - \filehook@appendwarg\filehook@include@atbegin + \filehook@append\filehook@include@@atbegin } % \end{macrocode} % \end{macro} @@ -557,15 +721,15 @@ % \begin{macro}{\AtEndOfIncludes} % \begin{macrocode} \newcommand*\AtEndOfIncludes{% - \filehook@prefixwarg\filehook@include@atend + \filehook@prefix\filehook@include@@atend } % \end{macrocode} % \end{macro} % -% \begin{macro}{\AfterOfIncludes} +% \begin{macro}{\AfterIncludes} % \begin{macrocode} \newcommand*\AfterIncludes{% - \filehook@prefixwarg\filehook@include@after + \filehook@prefix\filehook@include@@after } % \end{macrocode} % \end{macro} @@ -573,9 +737,7 @@ % \begin{macro}{\AtBeginOfIncludeFile} % \begin{macrocode} \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}}% } % \end{macrocode} % \end{macro} @@ -583,19 +745,15 @@ % \begin{macro}{\AtEndOfIncludeFile} % \begin{macrocode} \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}}% } % \end{macrocode} % \end{macro} % -% \begin{macro}{\AfterOfIncludeFile} +% \begin{macro}{\AfterIncludeFile} % \begin{macrocode} -\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}}% } % \end{macrocode} % \end{macro} @@ -603,7 +761,7 @@ % \begin{macro}{\AtBeginOfInputs} % \begin{macrocode} \newcommand*\AtBeginOfInputs{% - \filehook@appendwarg\filehook@input@atbegin + \filehook@append\filehook@input@@atbegin } % \end{macrocode} % \end{macro} @@ -611,27 +769,23 @@ % \begin{macro}{\AtEndOfInputs} % \begin{macrocode} \newcommand*\AtEndOfInputs{% - \filehook@prefixwarg\filehook@input@atend + \filehook@prefix\filehook@input@@atend } % \end{macrocode} % \end{macro} % % \begin{macro}{\AtBeginOfInputFile} % \begin{macrocode} -\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@ } % \end{macrocode} % \end{macro} % % \begin{macro}{\AtEndOfInputFile} % \begin{macrocode} -\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@ } % \end{macrocode} % \end{macro} @@ -639,7 +793,7 @@ % \begin{macro}{\AtBeginOfFiles} % \begin{macrocode} \newcommand*\AtBeginOfFiles{% - \filehook@appendwarg\filehook@atbegin + \filehook@append\filehook@@atbegin } % \end{macrocode} % \end{macro} @@ -647,121 +801,710 @@ % \begin{macro}{\AtEndOfFiles} % \begin{macrocode} \newcommand*\AtEndOfFiles{% - \filehook@prefixwarg\filehook@atend + \filehook@prefix\filehook@@atend +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\AtBeginOfEveryFile} +% \begin{macrocode} +\newcommand*\AtBeginOfEveryFile{% + \filehook@append\filehook@every@@atbegin +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\AtEndOfEveryFile} +% \begin{macrocode} +\newcommand*\AtEndOfEveryFile{% + \filehook@prefix\filehook@every@@atend } % \end{macrocode} % \end{macro} % % \begin{macro}{\AtBeginOfFile} % \begin{macrocode} -\newcommand*\AtBeginOfFile[1]{% - \@ifundefined{\filehook@atbegin@#1}% - {\long\global\@namedef{\filehook@atbegin@#1}}% - {\expandafter\filehook@append\csname\filehook@atbegin@#1\endcsname}% +\newcommand*\AtBeginOfFile{% + \filehook@addtohook\filehook@append\filehook@atbegin@ } % \end{macrocode} % \end{macro} % % \begin{macro}{\AtEndOfFile} % \begin{macrocode} -\newcommand*\AtEndOfFile[1]{% - \@ifundefined{\filehook@atend@#1}% - {\long\global\@namedef{\filehook@atend@#1}}% - {\expandafter\filehook@prefix\csname\filehook@atend@#1\endcsname}% +\newcommand*\AtEndOfFile{% + \filehook@addtohook\filehook@prefix\filehook@atend@ +} +% \end{macrocode} +% \end{macro} +% +% +% +% \begin{macro}{\AtBeginOfClassFile} +% \begin{macrocode} +\newcommand*\AtBeginOfClassFile{% + \@ifnextchar* + {\AtBeginOfXFile@star\@clsextension}% + {\AtBeginOfXFile@normal\@clsextension}% } % \end{macrocode} % \end{macro} % +% \begin{macro}{\AtBeginOfPackageFile} +% \begin{macrocode} +\newcommand*\AtBeginOfPackageFile{% + \@ifnextchar* + {\AtBeginOfXFile@star\@pkgextension}% + {\AtBeginOfXFile@normal\@pkgextension}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\AtBeginOfXFile@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@star#1*#2{% + \@ifl@aded{#1}{#2}% + {\@firstofone}% + {\AtBeginOfXFile@normal{#1}{#2}}% +} +% \end{macrocode} +% \end{macro} % -% \begin{macro}{\AtBeginOfPackageFile}[1]{package name} -% Simply add the package extension and calls the general macro. +% \begin{macro}{\AtBeginOfXFile@normal}[2]{extension}{name} % \begin{macrocode} -\newcommand*\AtBeginOfPackageFile[1]{% - \AtBeginOfFile{#1.\@pkgextension}% +\def\AtBeginOfXFile@normal#1#2{% + \AtBeginOfFile{#2.#1}% } % \end{macrocode} % \end{macro} % % +% \begin{macro}{\AtEndOfClassFile} +% \begin{macrocode} +\newcommand*\AtEndOfClassFile{% + \@ifnextchar* + {\AtEndOfXFile@star\@clsextension}% + {\AtEndOfXFile@normal\@clsextension}% +} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\AtEndOfPackageFile} % \begin{macrocode} \newcommand*\AtEndOfPackageFile{% - \@ifnextchar*\AtEndOfPackageFile@star\AtEndOfPackageFile@normal + \@ifnextchar* + {\AtEndOfXFile@star\@pkgextension}% + {\AtEndOfXFile@normal\@pkgextension}% } % \end{macrocode} % \end{macro} % -% \begin{macro}{\AtEndOfPackageFile@star}[2]{package name}{code} -% If the package is already loaded the code is executed right away. +% +% \begin{macro}{\AtEndOfXFile@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\AtEndOfPackageFile@star*#1#2{% - \@ifpackageloaded{#1}% - {#2}% - {\AtEndOfPackageFile@normal{#1}{#2}}% +\def\AtEndOfXFile@star#1*#2{% + \@ifl@aded{#1}{#2}% + {\@firstofone}% + {\AtEndOfXFile@normal{#1}{#2}}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\AtEndOfXFile@normal}[2]{extension}{name} +% Note that \Macro\AtEndOfClass is identical to \Macro\AtEndOfPackage, so no +% differenciation between classes and packages is needed here. +% \begin{macrocode} +\def\AtEndOfXFile@normal#1#2#3{% + \AtEndOfFile{#2.#1}{\AtEndOfPackage{#3}}% +} +% \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@orig@@input@} +% \begin{macrocode} +\let\filehook@orig@@input@\@input@ +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@orig@@iinput} +% \begin{macrocode} +\let\filehook@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@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}}% +} +% \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@every@atbegin{#1}% + \filehook@input@atbegin{#1}% + \filehook@orig@@iinput{#1}% + \filehook@input@atend{#1}% + \filehook@every@atend{#1}% } +\let\@iinput\filehook@@iinput % \end{macrocode} % \end{macro} % -% \begin{macro}{\AtEndOfPackageFile@normal}[2]{package name}{code} -% Installs the code at the end of the package file inside a \Macro\AtEndOfPackage -% command to ensure it is executed after any \Macro\AtEndOfPackage code installed -% by the package itself. +% \begin{macro}{\filehook@swap} +% Auxiliary macro which swaps the two arguments. This is needed to expand +% \Macro\@filef@und, which is given as first argument but needed then as the second one. +% \begin{macrocode} +\def\filehook@swap#1#2{#2#1} +% \end{macrocode} +% \end{macro} % -% Note if the package was already loaded or is not loaded at all the installed -% code is never executed. +% \begin{macro}{\filehook@ensureext} +% This macro ensures the existence of a file name extension. If non is given `|.tex|' is +% added. % \begin{macrocode} -\def\AtEndOfPackageFile@normal#1#2{% - \AtEndOfFile{#1.\@pkgextension}{\AtEndOfPackage{#2}}% +\def\filehook@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}{\AtBeginOfClassFile}[1]{class name} -% Simply add the class extension and calls the general macro. +% +% \begin{macro}{\filehook@ensuretex} +% Ensures a `|.tex|' extension, i.e. adds it if missing, even if there is a different one. % \begin{macrocode} -\newcommand*\AtBeginOfClassFile[1]{% - \AtBeginOfFile{#1.\@clsextension}% +\def\filehook@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} % -% \begin{macro}{\AtEndOfClassFile}[2]{class name}{code} +% +% 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}{\latex@InputIfFileExists} +% Standard \LaTeX\ definition of \Macro\InputIfFileExists. % \begin{macrocode} -\newcommand*\AtEndOfClassFile{% - \@ifnextchar*\AtEndOfClassFile@star\AtEndOfClassFile@normal +\long\def\latex@InputIfFileExists#1#2{% + \IfFileExists{#1}% + {#2\@addtofilelist{#1}% + \@@input\@filef@und + }% } % \end{macrocode} % \end{macro} % -% \begin{macro}{\AtEndOfClassFile@star}[2]{class name}{code} -% If the class is already loaded the code is executed right away. -% Otherwise it is installed normally. +% +% \begin{macro}{\filehook@default@InputIfFileExists} % \begin{macrocode} -\def\AtEndOfClassFile@star*#1#2{% - \@ifclassloaded{#1}% - {#2}% - {\AtEndOfClassFile@normal{#1}{#2}}% +\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}% + }% } % \end{macrocode} % \end{macro} % -% \begin{macro}{\AtEndOfClassFile@normal}[2]{class name}{code} -% Installs the code at the end of the class file inside a \Macro\AtEndOfClass -% command to ensure it is executed after any \Macro\AtEndOfClass code installed -% by the class itself. +% \begin{macro}{\filehook@@default@InputIfFileExists} +% \begin{macrocode} +\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}% + }% +} +% \end{macrocode} +% \end{macro} % -% Note if the class was already loaded or is not loaded at all the installed -% code is never executed. +% \begin{macro}{\scrlfile@InputIfFileExists} % \begin{macrocode} -\def\AtEndOfClassFile@normal#1#2{% - \AtEndOfFile{#1.\@clsextension}{\AtEndOfClass{#2}}% +\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}% + }}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@scrlfile@InputIfFileExists} +% \begin{macrocode} +\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}% + }}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@@scrlfile@InputIfFileExists} +% \begin{macrocode} +\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}% + }}% } % \end{macrocode} % \end{macro} % +% \iffalse +%</package> +%<*memoir> +% \fi +% +% \begin{macrocode} +\ProvidesPackage{filehook-memoir}[2011/01/03 v0.1 filehook patch for memoir class] +\RequirePackage{filehook} +\begingroup +% \end{macrocode} +% +% \begin{macro}{\memoir@InputIfFileExists} +% \begin{macrocode} +\long\def\memoir@InputIfFileExists#1#2{% + \IfFileExists{#1}% + {#2\@addtofilelist{#1}\m@matbeginf{#1}% + \@@input \@filef@und + \m@matendf{#1}% + \killm@matf{#1}}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\ifcase + \ifx\InputIfFileExists\latex@InputIfFileExists 0\else + \ifx\InputIfFileExists\memoir@InputIfFileExists 0\else + 1% + \fi\fi +\relax + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \filehook@appendwarg\filehook@atbegin{\m@matbeginf{#1}}% + \filehook@prefixwarg\filehook@atend{\m@matendf{#1}\killm@matf{#1}}% + \PackageInfo{filehook}{Detected 'memoir' class: the memoir hooks will be moved to the `At...OfFiles' hooks} +\else + \iffilehook@force + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageWarning{filehook}{Detected 'memoir' class with unknown definition of \string\InputIfFileExists.^^J% + The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}% + \else + \PackageError{filehook}{Detected 'memoir' class with unknown definition of \string\InputIfFileExists.^^J% + Use the 'force' option of 'filehook' to overwrite it.}{}% + \fi +\fi +% \end{macrocode} +% +% \begin{macrocode} +\endgroup +% \end{macrocode} +% +% \iffalse +%</memoir> +%<*listings> +% \fi +% \begin{macrocode} +\ProvidesPackage{filehook-listings}[2011/01/02 v0.1 Patch for listings to avoid hooks for verbatim input files] +\begingroup + +\long\def\patch#1\def\lst@next#2#3\endpatch{% + \toks@{#2}% + \edef\@tempa{\the\toks@}% + \def\@tempb{\input{####1}}% + \ifx\@tempa\@tempb + \gdef\lst@InputListing##1{#1\def\lst@next{\@input{##1}}#3}% + \else + \PackageWarning{filehook-listings}{To-be-patched code in macro \string\lst@InputListing was not found!}% + \fi +} + +\@ifundefined{lst@InputListing}{% + \PackageWarning{filehook-listings}{To-be-patched Macro \string\lst@InputListing not found!}% +}{} + +\expandafter\patch\lst@InputListing{#1}\endpatch + +\endgroup +% \end{macrocode} +% +% \iffalse +%</listings> +%<*scrlfile> +% \fi +% +% \begin{macrocode} +\ProvidesPackage{filehook-scrlfile}[2011/01/03 v0.1 filehook patch for scrlfile package] +\RequirePackage{filehook} +\begingroup +% \end{macrocode} +% +% \begin{macro}{\scrlfile@InputIfFileExists} +% \begin{macrocode} +\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}% + }}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@scrlfile@InputIfFileExists} +% \begin{macrocode} +\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}% + }}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\filehook@@scrlfile@InputIfFileExists} +% \begin{macrocode} +\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}% + }}% +} +% \end{macrocode} +% \end{macro} +% +% If the |scrlfile| package definition is detected the |filehook|s are added +% to that definition. Unfortunately the \Macro\scr@load@hook{before} hook is placed \emph{before} +% not after the |#2\@addtofilelist{#1}| code. Otherwise the |filehook|s could simply be added to these hooks. +% Note that this will stop working if |scrlfile| ever changes its definition of the \Macro\InputIfFileExists macro. +% \begin{macrocode} +\ifcase + \ifx\InputIfFileExists\latex@InputIfFileExists 0\else + \ifx\InputIfFileExists\scrlfile@InputIfFileExists 0\else + 1% + \fi\fi +\relax + \global\let\filehook@InputIfFileExists\filehook@scrlfile@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@scrlfile@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageInfo{filehook}{Package 'scrlfile' detected and compensated for}% +\else + \iffilehook@force + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageWarning{filehook}{Detected 'scrlfile' package with unknown definition of \string\InputIfFileExists.^^J% + The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}% + \else + \PackageError{filehook}{Detected 'scrlfile' package with unknown definition of \string\InputIfFileExists.^^J% + Use the 'force' option of 'filehook' to overwrite it.}{}% + \fi +\fi +% \end{macrocode} +% +% \begin{macrocode} +\endgroup +% \end{macrocode} +% +% +% \iffalse +%</scrlfile> +%<*fink> +% \fi +% +% \begin{macrocode} +\ProvidesPackage{filehook-fink}[2011/01/03 v0.1 filehook compatibility code for fink package] +\RequirePackage{filehook} +\RequirePackage{currfile}% + +\begingroup + +\long\def\fink@old@InputIfFileExists#1#2{% + \IfFileExists{#1}{% + #2\@addtofilelist{#1}% + \fink@prepare{#1}% + \expandafter\fink@input% + \expandafter\fink@restore\expandafter{\finkpath}}% +} + +\long\def\fink@new@InputIfFileExists#1#2{% + \IfFileExists{#1}{% + #2\@addtofilelist{#1}% + \edef\fink@before{\noexpand\fink@input{#1}}% + \edef\fink@after{\noexpand\fink@restore{\finkpath}}% + \expandafter\fink@before\fink@after}% +} + +\ifcase + \ifx\InputIfFileExists\filehook@InputIfFileExists 0\else + \ifx\InputIfFileExists\latex@InputIfFileExists 1\else + \ifx\InputIfFileExists\fink@new@InputIfFileExists 1\else + \ifx\InputIfFileExists\fink@old@InputIfFileExists 1\else + 1% + \fi\fi\fi\fi +\relax +\or + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageInfo{filehook-fink}{Package 'fink' detected and replaced by 'currfile'}% +\else + \iffilehook@force + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageWarning{filehook-fink}{Detected 'fink' package with unknown definition of \string\InputIfFileExists.^^J% + The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}% + \else + \PackageError{filehook-fink}{Detected 'fink' package with unknown definition of \string\InputIfFileExists.^^J% + Use the 'force' option of 'filehook' to overwrite it.}{}% + \fi +\fi + +\endgroup +% \end{macrocode} +% +% \iffalse +%</fink> +%<*package> +% \fi +% +% +% \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@InputIfFileExists +}% +\AtEndOfPackageFile*{scrlfile}{% + \RequirePackage{filehook-scrlfile}% +}% +% \end{macrocode} +% Fink: +% \begin{macrocode} +\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}% +}% +% \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@InputIfFileExists + \let\InputIfFileExists\latex@InputIfFileExists + \let\@iinput\filehook@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@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 +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\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 +} +% \end{macrocode} % % \iffalse %</package> diff --git a/Master/texmf-dist/source/latex/filehook/filehook.ins b/Master/texmf-dist/source/latex/filehook/filehook.ins index 8f5a7b3a3ba..cbe6aa4c843 100644 --- a/Master/texmf-dist/source/latex/filehook/filehook.ins +++ b/Master/texmf-dist/source/latex/filehook/filehook.ins @@ -3,5 +3,11 @@ % \input docstrip.tex \keepsilent -\generate{\nopreamble\file{filehook.sty}{\from{filehook.dtx}{package}}} +\generate{% + \file{filehook.sty}{\nopreamble\from{filehook.dtx}{package}}% + \file{filehook-scrlfile.sty}{\nopreamble\from{filehook.dtx}{scrlfile}}% + \file{filehook-memoir.sty}{\nopreamble\from{filehook.dtx}{memoir}}% + \file{filehook-listings.sty}{\nopreamble\from{filehook.dtx}{listings}}% + \file{filehook-fink.sty}{\nopreamble\from{filehook.dtx}{fink}}% +} \endbatchfile diff --git a/Master/texmf-dist/tex/latex/filehook/filehook-fink.sty b/Master/texmf-dist/tex/latex/filehook/filehook-fink.sty new file mode 100644 index 00000000000..77e2793d09b --- /dev/null +++ b/Master/texmf-dist/tex/latex/filehook/filehook-fink.sty @@ -0,0 +1,73 @@ +%% Copyright (c) 2010-2011 by Martin Scharrer <martin@scharrer-online.de> +%% ----------------------------------------------------------------- +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/04 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, filehook.ins +%% and the derived file filehook.sty. +%% +%% $Id: filehook.dtx 2005 2011-01-03 22:53:56Z martin $ +\ProvidesPackage{filehook-fink}[2011/01/03 v0.1 filehook compatibility code for fink package] +\RequirePackage{filehook} +\RequirePackage{currfile}% + +\begingroup + +\long\def\fink@old@InputIfFileExists#1#2{% + \IfFileExists{#1}{% + #2\@addtofilelist{#1}% + \fink@prepare{#1}% + \expandafter\fink@input% + \expandafter\fink@restore\expandafter{\finkpath}}% +} + +\long\def\fink@new@InputIfFileExists#1#2{% + \IfFileExists{#1}{% + #2\@addtofilelist{#1}% + \edef\fink@before{\noexpand\fink@input{#1}}% + \edef\fink@after{\noexpand\fink@restore{\finkpath}}% + \expandafter\fink@before\fink@after}% +} + +\ifcase + \ifx\InputIfFileExists\filehook@InputIfFileExists 0\else + \ifx\InputIfFileExists\latex@InputIfFileExists 1\else + \ifx\InputIfFileExists\fink@new@InputIfFileExists 1\else + \ifx\InputIfFileExists\fink@old@InputIfFileExists 1\else + 1% + \fi\fi\fi\fi +\relax +\or + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageInfo{filehook-fink}{Package 'fink' detected and replaced by 'currfile'}% +\else + \iffilehook@force + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageWarning{filehook-fink}{Detected 'fink' package with unknown definition of \string\InputIfFileExists.^^J% + The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}% + \else + \PackageError{filehook-fink}{Detected 'fink' package with unknown definition of \string\InputIfFileExists.^^J% + Use the 'force' option of 'filehook' to overwrite it.}{}% + \fi +\fi + +\endgroup +\endinput +%% +%% End of file `filehook-fink.sty'. diff --git a/Master/texmf-dist/tex/latex/filehook/filehook-listings.sty b/Master/texmf-dist/tex/latex/filehook/filehook-listings.sty new file mode 100644 index 00000000000..e6c394e5489 --- /dev/null +++ b/Master/texmf-dist/tex/latex/filehook/filehook-listings.sty @@ -0,0 +1,45 @@ +%% Copyright (c) 2010-2011 by Martin Scharrer <martin@scharrer-online.de> +%% ----------------------------------------------------------------- +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/04 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, filehook.ins +%% and the derived file filehook.sty. +%% +%% $Id: filehook.dtx 2005 2011-01-03 22:53:56Z martin $ +\ProvidesPackage{filehook-listings}[2011/01/02 v0.1 Patch for listings to avoid hooks for verbatim input files] +\begingroup + +\long\def\patch#1\def\lst@next#2#3\endpatch{% + \toks@{#2}% + \edef\@tempa{\the\toks@}% + \def\@tempb{\input{####1}}% + \ifx\@tempa\@tempb + \gdef\lst@InputListing##1{#1\def\lst@next{\@input{##1}}#3}% + \else + \PackageWarning{filehook-listings}{To-be-patched code in macro \string\lst@InputListing was not found!}% + \fi +} + +\@ifundefined{lst@InputListing}{% + \PackageWarning{filehook-listings}{To-be-patched Macro \string\lst@InputListing not found!}% +}{} + +\expandafter\patch\lst@InputListing{#1}\endpatch + +\endgroup +\endinput +%% +%% End of file `filehook-listings.sty'. diff --git a/Master/texmf-dist/tex/latex/filehook/filehook-memoir.sty b/Master/texmf-dist/tex/latex/filehook/filehook-memoir.sty new file mode 100644 index 00000000000..3cfae9f348a --- /dev/null +++ b/Master/texmf-dist/tex/latex/filehook/filehook-memoir.sty @@ -0,0 +1,59 @@ +%% Copyright (c) 2010-2011 by Martin Scharrer <martin@scharrer-online.de> +%% ----------------------------------------------------------------- +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/04 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, filehook.ins +%% and the derived file filehook.sty. +%% +%% $Id: filehook.dtx 2005 2011-01-03 22:53:56Z martin $ +\ProvidesPackage{filehook-memoir}[2011/01/03 v0.1 filehook patch for memoir class] +\RequirePackage{filehook} +\begingroup +\long\def\memoir@InputIfFileExists#1#2{% + \IfFileExists{#1}% + {#2\@addtofilelist{#1}\m@matbeginf{#1}% + \@@input \@filef@und + \m@matendf{#1}% + \killm@matf{#1}}% +} +\ifcase + \ifx\InputIfFileExists\latex@InputIfFileExists 0\else + \ifx\InputIfFileExists\memoir@InputIfFileExists 0\else + 1% + \fi\fi +\relax + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \filehook@appendwarg\filehook@atbegin{\m@matbeginf{#1}}% + \filehook@prefixwarg\filehook@atend{\m@matendf{#1}\killm@matf{#1}}% + \PackageInfo{filehook}{Detected 'memoir' class: the memoir hooks will be moved to the `At...OfFiles' hooks} +\else + \iffilehook@force + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageWarning{filehook}{Detected 'memoir' class with unknown definition of \string\InputIfFileExists.^^J% + The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}% + \else + \PackageError{filehook}{Detected 'memoir' class with unknown definition of \string\InputIfFileExists.^^J% + Use the 'force' option of 'filehook' to overwrite it.}{}% + \fi +\fi +\endgroup +\endinput +%% +%% End of file `filehook-memoir.sty'. diff --git a/Master/texmf-dist/tex/latex/filehook/filehook-scrlfile.sty b/Master/texmf-dist/tex/latex/filehook/filehook-scrlfile.sty new file mode 100644 index 00000000000..03b19800cc2 --- /dev/null +++ b/Master/texmf-dist/tex/latex/filehook/filehook-scrlfile.sty @@ -0,0 +1,118 @@ +%% Copyright (c) 2010-2011 by Martin Scharrer <martin@scharrer-online.de> +%% ----------------------------------------------------------------- +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/04 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, filehook.ins +%% and the derived file filehook.sty. +%% +%% $Id: filehook.dtx 2005 2011-01-03 22:53:56Z martin $ +\ProvidesPackage{filehook-scrlfile}[2011/01/03 v0.1 filehook patch for scrlfile package] +\RequirePackage{filehook} +\begingroup +\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}% + }}% +} +\ifcase + \ifx\InputIfFileExists\latex@InputIfFileExists 0\else + \ifx\InputIfFileExists\scrlfile@InputIfFileExists 0\else + 1% + \fi\fi +\relax + \global\let\filehook@InputIfFileExists\filehook@scrlfile@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@scrlfile@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageInfo{filehook}{Package 'scrlfile' detected and compensated for}% +\else + \iffilehook@force + \global\let\filehook@InputIfFileExists\filehook@default@InputIfFileExists + \global\let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists + \global\let\InputIfFileExists\filehook@InputIfFileExists + \PackageWarning{filehook}{Detected 'scrlfile' package with unknown definition of \string\InputIfFileExists.^^J% + The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}% + \else + \PackageError{filehook}{Detected 'scrlfile' package with unknown definition of \string\InputIfFileExists.^^J% + Use the 'force' option of 'filehook' to overwrite it.}{}% + \fi +\fi +\endgroup +\endinput +%% +%% End of file `filehook-scrlfile.sty'. 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 %% |