diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/filehook/filehook.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/filehook/filehook.dtx | 158 |
1 files changed, 138 insertions, 20 deletions
diff --git a/Master/texmf-dist/source/latex/filehook/filehook.dtx b/Master/texmf-dist/source/latex/filehook/filehook.dtx index b6539936c87..3b7544dcbed 100644 --- a/Master/texmf-dist/source/latex/filehook/filehook.dtx +++ b/Master/texmf-dist/source/latex/filehook/filehook.dtx @@ -19,7 +19,7 @@ %% This work consists of the files filehook.dtx, filehook.ins %% and the derived file filehook.sty. %% -%% $Id: standalone.dtx 1803 2010-04-03 13:59:44Z martin $ +%% $Id: filehook.dtx 1905 2010-12-08 18:57:34Z martin $ % \fi % % \iffalse @@ -29,12 +29,12 @@ %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{filehook} %<*package> - [2010/04/08 v0.1 Hooks for input files] + [2010/12/08 v0.2 Hooks for input files] %</package> % %<*driver> \documentclass{ltxdoc} -\usepackage{filehook}[2010/04/08] +\usepackage{filehook}[2010/12/06] \usepackage{ifpdf} \usepackage{hyperref} \EnableCrossrefs @@ -49,7 +49,7 @@ %</driver> % \fi % -% \CheckSum{278} +% \CheckSum{365} % % \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 @@ -69,6 +69,7 @@ % % % \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.} % % \GetFileInfo{filehook.dtx} % @@ -169,7 +170,41 @@ % % \StopEventually{} % +% \section{Compatibility Issues with other Packages} +% The |filehook| package might clash with other packages or classes which also redefine |\InputIfFileExists|. +% Special compatibility code is in place for the known packages listed below (in their current implementation). +% If any other unknown definition is found a warning will be printed and the macro will be overwritten. +% Any previous modifications will be lost, which will most likely break the other package. +% 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 |\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 |\documentclass| using |\RequirePackage| to enable the file hooks also for these files. +% +% \subsection*{memoir} +% The |memoir| class redefines |\InputIfFileExists| to add own hooks identical to the |At...OfFiles| hooks (there called |\AtBeginFile| and |\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 |\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. +% +% \subsection*{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 |\InputIfFileExists| macro. +% +% \subsection*{listings} +% The \pkg{listings} package uses |\input| inside \cs{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 (|\input|, |\@input|, |\@@input| (\TeX's |\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 |\input| to |\@input| for \cs{lstinputlisting}: |{\let\input\@input\lstinputlisting{...}}|. % +% % \section{Implementation}\label{sec:impl} % % \iffalse @@ -220,28 +255,108 @@ % % \begin{macro}{\InputIfFileExists} % This macro is redefined for the general file hooks. -% The original definition is not saved away and called by the new definition, because +% 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 (|\@@input|). -% To be compatible with the similar \pkg{fink} package its code inserted into this macro is kept if the package -% was loaded beforehand. % +% Alternatives definitions of \cs{InputIfFileExists} are defined here for comparison. +% This is done inside a group to keep them only temporary. +% \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}% + }}% +} +% \end{macrocode} +% +% If the |scrlfile| package definition is detected the |filehook|s are added +% to that definition. Unfortunately the |\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 |\InputIfFileExists| macro this code will not be executed and +% the general clause below will kick in. % \begin{macrocode} -\ifcase0% - \ifx\fink@input\@undefined 1\else - \ifx\fink@input\relax 1\fi\fi -\relax -\long\def\InputIfFileExists#1#2{% - \IfFileExists{#1}{% - #2\@addtofilelist{#1}% - \fink@prepare{#1}% - \filehook@atbegin{#1}% - \expandafter\fink@input% - \expandafter\fink@restore\expandafter{\finkpath}% - \filehook@atend{#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.} + +% \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. +% \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 -\long\def\InputIfFileExists#1#2{% +% \end{macrocode} +% +% 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{macrocode} +\ifx\InputIfFileExists\latex@InputIfFileExists +\else + \PackageWarning{filehook} + {Changed definition of \string\InputIfFileExists\space detected!^^J% + This macro will be redefined and this might break other packages or code.}% +\fi +\fi + +\long\gdef\InputIfFileExists#1#2{% \IfFileExists{#1}% {#2\@addtofilelist{#1}% \filehook@atbegin{#1}% @@ -249,7 +364,10 @@ \filehook@atend{#1}% }% } + \fi + +\endgroup % \end{macrocode} % \end{macro} % |