• Tidak ada hasil yang ditemukan

The filehook Package

N/A
N/A
Nguyễn Gia Hào

Academic year: 2023

Membagikan "The filehook Package"

Copied!
35
0
0

Teks penuh

(1)

The filehook Package

Martin Scharrer

martin@scharrer-online.de http://www.ctan.org/pkg/filehook

Version v0.5b – 2011/07/18

Abstract

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.

1 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

\AtBeginDocument{TEX code}.

This package provides hooks for files read by the LATEX macros\input,\include and\InputIfFileExistsas well as (since v0.3 from 2010/12/20) for class and pack- age files, i.e. macros\documentclass,\LoadClassWithOptionsand\LoadClass as well as\usepackage,\RequirePackageWithOptionsand\RequirePackage. Note that\InputIfFileExists, and therefore its hooks, is used by the aforemen- tioned macros. In v0.4 from 2011/03/01 special hooks where added which are ex- ecuted for every read file, but will not be executed a second time by the internal

\InputIfFileExistsinside\inputand\include.

For all files a ‘AtBegin’ and a ‘AtEnd’ hook is installed. For\includefiles there is also a ‘After’ hook which it is executedafterthe page break (\clearpage) is inserted by the\includecode. In contrast, the ‘AtEnd’ hook is executed before the trailing page break and the ‘AtBegin’ hook is executed after theleadingpage 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.

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.

Older versions of this package provided the file name as argument#1for 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 section5for information

(2)

2 Usage

The below macros can be used to add material (TEX code) to the related hooks. All

‘AtBegin’ macros willappendthe code to the hooks, but the ‘AtEnd’ and ‘After’ macros willprefixthe 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.

Every File

\AtBeginOfEveryFile{TEX code}

\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\clearpagein\include. The

\AtEndOfFilesis executed before it, which can cause issues with page headers and footers. A workaround, e.g. done by older versions of thecurrfilepackage, is to execute the code twice for include files: once in theincluderelated hooks and once in theOfFileshooks.

A better solution for this problem was added in v0.4 from 2011/01/03: the EveryFilehooks will be executed exactly once for every file, independent if it is read using\input,\includeor\InputIfFileExists. Special care is taken to suppress them for the\InputIfFileExistsinside\inputand\include.

These hooks are located around the more specific hooks: For\inputfiles the

‘Begin’ hook is executed before the\AtBeginOfInputshook and the ‘End’ hook after the\AtEndOfInputs. Similarly, for\includefiles the ‘Begin’ hook is executed be- fore the\AtBeginOfIncludeshook and the ‘End’ hook after the\AfterIncludes (!). For files read by\InputIfFileExists(e.g. also for\usepackage, etc.) they are executed before and after the\AtBeginOfFilesand\AtEndOfFileshooks, respectively. Note that the\AtBeginOfEveryFile hook is executed before the

\AtBeginOfPackageFile/\AtBeginOfClassFilehooks and that the\AtEndOfEveryFile hook is executed also before the hooks\AtEndOfPackageFile/\AtEndOfClassFile. Therefore the ‘Every’ and ‘PackageFile’/‘ClassFile’ hooks do not nest correctly like all other hooks do.

All Files

\AtBeginOfFiles{TEX code}

\AtEndOfFiles{TEX code}

These macros add the given{code〉}to two hooks executed for all files read us- ing the\InputIfFileExistsmacro. This macro is used internally by the\input,

\includeand\usepackage/\RequirePackagemacros. Packages and classes might

(3)

use it to include additional or auxiliary files. Authors can exclude those files from the hooks by using the following code instead:

\IfFileExists{file name〉}{\@input\@filef@und}{}

\AtBeginOfFile{file name〉}{TEX code}

\AtEndOfFile{file name〉}{TEX code}

Like the\...OfIncludeFile{file name〉}{TEX code}macros above, just for ‘all’

read files. If the〈file name〉does not include a file extension it will be set to ‘.tex’.

The ‘all files’ hooks are closer to the file content than the\inputand\include hook, i.e. the\AtBeginOfFilescomesafter the\AtBeginOfIncludesand the

\AtEndOfFilescomesbeforethe\AtEndOfIncludeshook.

The following figure shows the positions of the hooks inside the macro:

\InputIfFileExists:

Hook: AtBeginOfEveryFile Hook: AtBeginOfFile{file name〉} Hook: AtBeginOfFiles

Content

Hook: AtEndOfFiles

Hook: AtEndOfFile{file name〉} Hook: AtEndOfEveryFile

Include Files

\AtBeginOfIncludes{TEX code}

\AtEndOfIncludes{TEX code}

\AfterIncludes{TEX code}

As described above the ‘AtEnd’ hook is executed before and the ‘After’ hook is executed after the trailing\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.

\AtBeginOfIncludeFile{file name〉}{TEX code}

\AtEndOfIncludeFile{file name〉}{TEX code}

\AfterIncludeFile{file name〉}{TEX code}

These file-specific macros take the two arguments. The〈code〉is only executed for the file with the given〈file name〉and only if it is read using\include. The〈file name〉should be identical to the name used for\includeand not include the ‘.tex’ extension. Files with a different extension are neither supported by\includenor this hooks.

The following figure shows the positions of the hooks inside the macro:

(4)

\include:

\clearpage (implicit) Hook: AtBeginOfEveryFile

Hook: AtBeginOfIncludeFile{file name〉} Hook: AtBeginOfIncludes

\InputIfFileExists:

Hook: AtBeginOfFile{file name〉} Hook: AtBeginOfFiles

Content

Hook: AtEndOfFiles

Hook: AtEndOfFile{file name〉} Hook: AtEndOfIncludes

Hook: AtEndOfIncludeFile{file name〉}

\clearpage (implicit) Hook: AfterIncludes

Hook: AfterIncludeFile{file name〉} Hook: AtEndOfEveryFile

Input Files

\AtBeginOfInputs{TEX code}

\AtEndOfInputs{TEX code}

Like the\...OfIncludes{code}macros above, just for file read using\input.

\AtBeginOfInputFile{file name〉}{TEX code}

\AtEndOfInputFile{file name〉}{TEX code}

Like the\...OfIncludeFile{file name〉}{code}macros above, just for file read using\input. If the〈file name〉does not include a file extension it will be set to

‘.tex’.

The following figure shows the positions of the hooks inside the macro:

\input:

Hook: AtBeginOfEveryFile

Hook: AtBeginOfInputFile{file name〉} Hook: AtBeginOfInputs

\InputIfFileExists:

Hook: AtBeginOfFile{file name〉} Hook: AtBeginOfFiles

Content

Hook: AtEndOfFiles

Hook: AtEndOfFile{file name〉} Hook: AtEndOfInputs

Hook: AtEndOfInputFile{file name〉} Hook: AtEndOfEveryFile

(5)

Package Files

\AtBeginOfPackageFile*{package name〉}{TEX code}

\AtEndOfPackageFile*{package name〉}{TEX code}

This macros install the given〈TEX code〉in the ‘AtBegin’ and ‘AtEnd’ hooks of the given package file. The\AtBeginOfPackageFilesimply executes\AtBeginOfFile{package name〉.sty}{TEXcode}. Special care is taken to ensure that the ‘AtEnd’ code is exe- cutedafterany code installed by the package itself using the LATEX macro\AtEndOfPackage. Note that it is therefore executed after the ‘AtEndOfEveryFile’ hook. 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:

\usepackage/\RequirePackage/\RequirePackageWithOptions:

\InputIfFileExists:

Hook: AtBeginOfEveryFile Hook: AtBeginOfFile{file name〉}

(includes AtBeginOfPackageFile{file name〉}) Hook: AtBeginOfFiles

Content

Hook: AtEndOfFiles

Hook: AtEndOfFile{file name〉} Hook: AtEndOfEveryFile

Hook: AtEndOfPackage (LATEX hook) Hook: AtEndOfPackageFile{file name〉}

Class Files

\AtBeginOfClassFile*{class name〉}{TEX code}

\AtEndOfClassFile*{class name〉}{TEX code}

This macros install the given〈TEX code〉in the ‘AtBegin’ and ‘AtEnd’ hooks of the given class file. They work with classes loaded using\LoadClass,\LoadClassWithOptions and also\documentclass. However, in the latter casefilehookmust be loaded using\RequirePackagebeforehand. The macro\AtBeginOfClassFilesimply executes\AtBeginOfFile{class name〉.cls}{...}. Special care is taken to ensure that the ‘AtEnd’ code is executedafterany code installed by the class itself using the LATEX macro\AtEndOfClass. Note that it is therefore executed after the ‘AtEnd- OfEveryFile’ hook. 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:

(6)

\documentclass/\LoadClass/\LoadClassWithOptions:

\InputIfFileExists:

Hook: AtBeginOfEveryFile Hook: AtBeginOfFile{file name〉}

(includes AtBeginOfClassFile{file name〉}) Hook: AtBeginOfFiles

Content

Hook: AtEndOfFiles

Hook: AtEndOfFile{file name〉} Hook: AtEndOfEveryFile

Hook: AtEndOfClass (LATEX hook) Hook: AtEndOfClassFile{file name〉}

2.1 Clearing Hooks

\ClearHook\At...Of...argument(s) of hook macro

Using this macro existing hooks can be globally cleared, i.e. set to empty. This should New in v0.5

2011/01/09 be used with care because it will also remove all (user level) hook code set by packages into this hook. Note that the special hook code installed by the packagescurrfile andsvn-multias well as the compatibility code described in section4is not affected.

The syntax for this macro is the same as for the normal hook macros only with a leading\ClearHook, where the〈code〉argument is mandatory but its content is ignored. Examples:

\ClearHook\AtBeginOfInputFile{file name〉}{ignored〉}

\ClearHook\AtBeginOfFiles{ignored〉}

(7)

3 PGF Key Interface

An auxiliary packagepgf-filehookis provided which adds support for the versatile pgfkeysinterface. This interface is heavily used bypgf(portable graphics format) and its higher level format TikZ. It allows the definition and execution of styles and commands (macros) using a〈key〉=value〉format. Main benefits over similar formats is the support for a “directory structure” inside the key and the ability to call functions on the value before it gets processed by the key. The main way to define and execute keys is the macro\pgfkeys{key〉=value〉,...}. TikZ provides the similar macro

\tikzstylewhich defaults to the main path ‘/tikz’. More detailed information can be found in the officialpgfmanual.

Allfilehookmacros described in the previous section (\AtXXXOfYYY) can also be accessed using the pgf keys directory ‘/filehook’, where all hook type have an own sub-directory (/filehook/YYY) in which the hooks for this type are located (/filehook/YYY/AtXXX). For example\AtBeginOfInputs{code〉}can also be ac- cessed using

\pgfkeys{/filehook/Inputs/AtBegin={code〉}}

or\AfterIncludeFile{file name〉}{code〉}as

\pgfkeys{/filehook/IncludeFile/After={file name〉}{code〉}}

as well as\AtEndOfClassFile*{file name〉}{code〉}as

\pgfkeys{/filehook/ClassFile/AtEnd=*{file name〉}{code〉}}.

\pgffilehook{key〉=value〉,...}

This macro is like\pgfkeysbut defaults to the ‘/filehook’ directory, so that it can be dropped from the〈key〉. Note thatpgfkeysalso supports to “change the directory”

using〈directory〉/.cd, so that it does not need to be included in further keys. All directories are defined as ‘is family’ so that the/.cdis assumed if the directory is used on its own. For example

\pgfkeys{/filehook/Inputs/AtBegin={code〉},/filehook/Inputs/AtEnd={code〉}}

can be shorten as

\pgffilehook{Inputs,AtBegin={code〉},AtEnd={code〉}}.

Some of the pgf key functions can become useful, e.g. if the hook code should be expanded before it is added to the hook:

\pgffilehook{EveryFile/AtBegin/.expand once={\headertext \currfilename}}

will expand the first macro\headertext(actually the first token) in the hook code once (using\expandafter), but not any other tokens. In this example future changes of\headertextwould not have any effect on the hook code, but\currfilename will be expanded for every file. Other useful functions are ‘.expand twice’ (expand the first token twice) and ‘.expanded’ (expand the whole hook code using\edef).

(8)

4 Compatibility Issues with Classes and other Packages

Thefilehookpackage might clash with other packages or classes which also redefine

\InputIfFileExistsor internal macros used by\includeand\input(which are

\@input@and\@iinput). Special compatibility code is in place for the packages listed below (in their current implementation). If any other unknown definition of

\InputIfFileExistsis 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.

Table1lists all packages and classes which where found do be incompatible. The packagesauxhook,stampinclude,rerunfilecheckandexcludeonlyredefine one or more of the above macros but have been found compatible withfilehook. Please do not hesitate to inform the author offilehookof any encountered problems with other packages.

4.1 Supported Classes and Packages

The following classes and packages are actively supported and should work as normal when used together withfilehook. Please note that most of them are incompatible to each other, whichfilehookmight not fix.

memoir

Thememoirclass redefines\InputIfFileExiststo add own hooks identical to the

‘At...OfFiles’ hooks (there called\AtBeginFileand\AtEndFile). This hooks will be moved to the corresponding ones offilehookand will keep working as normal.

Since v0.4 from 2011/01/03 this modification will be also applied when thefilehook package is loaded (using\RequirePackage)beforethememoirclass. However, the hooks fromfilehookneed to be temporally disabled while reading thememoirclass.

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 thememoirclass file itself. In fact they are used to restore the default definition of\InputIfFileExists at the begin and patch it at the end of the class file. Thefilehookpackage should be loaded either before the class (using\RequirePackage) or directly after it. Because thememoirhook code is moved to thefilehookhooks this class should then be compatible with below packages ifmemoirandfilehookare loaded before them.

scrlfile

Thescrlfilepackage from thekoma-scriptbundle 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. Since v0.4 from 2011/01/03 this modification will be also applied when thescrlfilepackage is loaded afterfilehook.

fink

Thefilehookandcurrfilepackages where written as replacements for thefink package, wherefilehookprovides the necessary hooks forcurrfile. Thefink package has now been deprecated in favour ofcurrfileand should not be used anymore. Thefinkcompatibility code has been removed fromfilehookand both

(9)

Table 1: Incompatible packages and classes

Name Type Note Affected Hooks

paper class withjournaloption All hocks for\include’d files

journal class All hocks for\include’d files

gmparts package \includehooks

newclude package formallyincludex All hocks for\include’d files

cannot be used successfully together as both redefine the\InputIfFileExists macro.

listings

Thelistingspackage uses\inputinside\lstinputlisting. Therefore theInputFile(s) andFile(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), . . . ) will be processed verbatim and typeset as part of the listing. Since v0.4 this macro is automatically patched so\@inputis used instead to avoid this issue.

4.2 Other Classes and Packages

jmlrbook

Thejmlrbookclass from thejmlrbundle 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 becausefilehookis loaded after the class. This should not affect its normal usage. Note that, in theory, the package could be loaded before

\documentclassusing\RequirePackageto enable the file hooks also for these files.

LATEX’s \bibliography

The standard LATEX macro\bibliographyuses the same internal macro\@input@

to read a file as\includedoes. The ‘include’ hooks will also be executed for this .bblfile if the macro is directly followed by\clearpage, because thefilehook code will assume it is executed inside\include. This rare case can be easily avoided by placing a\relaxafter\bibliography{...}.

5 Upgrade Guide

This sections gives information for users of older versions of this package which unfortunately might not be 100% backwards compatible.

(10)

Upgrade to v0.4 - 2011/01/03

• The macro\AfterIncludeFilewas misspelled as\AfterOfIncludeFilein 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 thefilehookpackage from 2011/01/03.

• All general hooks (the one not taking a file argument) used to have an implicit argument#1which was expanded to the file name (i.e. the argument of\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.\currfilename) of the partner packagecurrfile should be used. These macros are available everywhere including in all hocks.

(11)

6 Implementation

6.1 Options

1 \n e w i f\ i f f i l e h o o k @ f o r c e

2 \ D e c l a r e O p t i o n { f o r c e }{\ f i l e h o o k @ f o r c e t r u e }

3 \ P r o c e s s O p t i o n s \r e l a x

6.2 Initialisation of Hooks

The general hooks are initialised to call the file specific hooks.

4 \ @ i f p a c k a g e l o a d e d { e t o o l b o x }{%

5 \let\ f i l e h o o k @ c s u s e \ c s u s e

6 }{%

7 \def\ f i l e h o o k @ c s u s e # 1 { \ i f c s n a m e #1\e n d c s n a m e\.

c s n a m e #1\e x p a n d a f t e r\e n d c s n a m e\fi}

8 }

\filehook@include@atbegin

9 \def\ f i l e h o o k @ i n c l u d e @ a t b e g i n #1{%

10 \let\ I n p u t I f F i l e E x i s t s \ f i l e h o o k @ @ I n p u t I f F i l e E x i s t s

11 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ i n c l u d e @ a t b e g i n @ #1}%

12 \ f i l e h o o k @ i n c l u d e @ @ a t b e g i n

13 }

\filehook@include@@atbegin

14 \def\ f i l e h o o k @ i n c l u d e @ @ a t b e g i n {}

\filehook@include@atend

15 \def\ f i l e h o o k @ i n c l u d e @ a t e n d #1{%

16 \ f i l e h o o k @ i n c l u d e @ @ a t e n d

17 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ i n c l u d e @ a t e n d @ #1}%

18 }

\filehook@include@@atend

19 \def\ f i l e h o o k @ i n c l u d e @ @ a t e n d {}

(12)

\filehook@include@after

20 \def\ f i l e h o o k @ i n c l u d e @ a f t e r #1{%

21 \ f i l e h o o k @ i n c l u d e @ @ a f t e r

22 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ i n c l u d e @ a f t e r @ #1}%

23 }

\filehook@include@@after

24 \def\ f i l e h o o k @ i n c l u d e @ @ a f t e r {}

\filehook@input@atbegin

25 \def\ f i l e h o o k @ i n p u t @ a t b e g i n #1{%

26 \let\ I n p u t I f F i l e E x i s t s \ f i l e h o o k @ @ I n p u t I f F i l e E x i s t s

27 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ i n p u t @ a t b e g i n @ \.

f i l e h o o k @ e n s u r e e x t { # 1 } }%

28 \ f i l e h o o k @ i n p u t @ @ a t b e g i n

29 }

\filehook@input@@atbegin

30 \def\ f i l e h o o k @ i n p u t @ @ a t b e g i n {}

\filehook@input@atend

31 \def\ f i l e h o o k @ i n p u t @ a t e n d #1{%

32 \ f i l e h o o k @ i n p u t @ @ a t e n d

33 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ i n p u t @ a t e n d @ \.

f i l e h o o k @ e n s u r e e x t { # 1 } }%

34 }

\filehook@input@@atend

35 \def\ f i l e h o o k @ i n p u t @ @ a t e n d {}

(13)

\filehook@atbegin

36 \def\ f i l e h o o k @ a t b e g i n #1{%

37 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ a t b e g i n @ \.

f i l e h o o k @ e n s u r e e x t { # 1 } }%

38 \ f i l e h o o k @ @ a t b e g i n

39 }

\filehook@@atbegin

40 \def\ f i l e h o o k @ @ a t b e g i n {}

\filehook@atend

41 \def\ f i l e h o o k @ a t e n d #1{%

42 \ f i l e h o o k @ @ a t e n d

43 \ f i l e h o o k @ c s u s e {\ f i l e h o o k @ a t e n d @ \ f i l e h o o k @ e n s u r e e x t.

{ # 1 } }%

44 }

\filehook@@atend

45 \def\ f i l e h o o k @ @ a t e n d {}

\filehook@every@atbegin

46 \def\ f i l e h o o k @ e v e r y @ a t b e g i n #1{%

47 \ f i l e h o o k @ e v e r y @ @ a t b e g i n

48 }

\filehook@every@@atbegin

49 \def\ f i l e h o o k @ e v e r y @ @ a t b e g i n {}

\filehook@every@atend

50 \def\ f i l e h o o k @ e v e r y @ a t e n d #1{%

51 \ f i l e h o o k @ e v e r y @ @ a t e n d

52 }

(14)

\filehook@every@@atend

53 \def\ f i l e h o o k @ e v e r y @ @ a t e n d {}

6.3 Hook Modification Macros

The following macros are used to modify the hooks, i.e. to prefix or append code to them.

Internal Macros

The macro prefixes for the file specific hooks are stored in macros to reduce the number of tokens in the following macro definitions.

54 \def\ f i l e h o o k @ i n c l u d e @ a t b e g i n @ {.

f i l e h o o k @ i n c l u d e @ a t b e g i n @ }

55 \def\ f i l e h o o k @ i n c l u d e @ a t e n d @ { f i l e h o o k @ i n c l u d e @ a t e n d @ }

56 \def\ f i l e h o o k @ i n c l u d e @ a f t e r @ { f i l e h o o k @ i n c l u d e @ a f t e r @ }

57 \def\ f i l e h o o k @ i n p u t @ a t b e g i n @ { f i l e h o o k @ i n p u t @ a t b e g i n @ }

58 \def\ f i l e h o o k @ i n p u t @ a t e n d @ { f i l e h o o k @ i n p u t @ a t e n d @ }

59 \def\ f i l e h o o k @ i n p u t @ a f t e r @ { f i l e h o o k @ i n p u t @ a f t e r @ }

60 \def\ f i l e h o o k @ a t b e g i n @ { f i l e h o o k @ a t b e g i n @ }

61 \def\ f i l e h o o k @ a t e n d @ { f i l e h o o k @ a t e n d @ }

62 \def\ f i l e h o o k @ a f t e r @ { f i l e h o o k @ a f t e r @ }

\filehook@append

Uses default LATEX macro.

63 \def\ f i l e h o o k @ a p p e n d {\ g @ a d d t o @ m a c r o }

\filehook@appendwarg

Appends code with one macro argument. The\@tempaintermediate step is required because of the included##1which wouldn’t correctly expand otherwise.

64 \l o n g\def\ f i l e h o o k @ a p p e n d w a r g # 1 # 2 {%

65 \b e g i n g r o u p

66 \ t o k s @ \e x p a n d a f t e r{ # 1 { # # 1 } # 2 }%

67 \e d e f\ @ t e m p a {\the\ t o k s @ }%

68 \e x p a n d a f t e r\g d e f\e x p a n d a f t e r#1\e x p a n d a f t e r##\.

e x p a n d a f t e r1\e x p a n d a f t e r{\ @ t e m p a }%

69 \e n d g r o u p

70 }

(15)

\filehook@prefix

Prefixes code to a hook.

71 \l o n g\def\ f i l e h o o k @ p r e f i x # 1 # 2 {%

72 \b e g i n g r o u p

73 \ @ t e m p t o k e n a { # 2 }%

74 \ t o k s @ \e x p a n d a f t e r{ # 1 }%

75 \x d e f# 1 { \the\ @ t e m p t o k e n a \the\ t o k s @ }%

76 \e n d g r o u p

77 }

\filehook@prefixwarg

Prefixes code with an argument to a hook.

78 \l o n g\def\ f i l e h o o k @ p r e f i x w a r g # 1 # 2 {%

79 \b e g i n g r o u p

80 \ @ t e m p t o k e n a { # 2 }%

81 \ t o k s @ \e x p a n d a f t e r{ # 1 { # # 1 } }%

82 \e d e f\ @ t e m p a {\the\ @ t e m p t o k e n a \the\ t o k s @ }%

83 \e x p a n d a f t e r\g d e f\e x p a n d a f t e r#1\e x p a n d a f t e r##\.

e x p a n d a f t e r1\e x p a n d a f t e r{\ @ t e m p a }%

84 \e n d g r o u p

85 }

\filehook@addtohook

#1: Macro which should be used to add the material to the hook

#2: Macro name prefix

#3: 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\@tempaare made inside a group to keep them local.

86 \def\ f i l e h o o k @ a d d t o h o o k # 1 # 2 # 3 {%

87 \b e g i n g r o u p

88 \e d e f\ @ t e m p a { # 3 }%

89 \e d e f\ @ t e m p a { # 2 \ f i l e h o o k @ e n s u r e e x t {\ @ t e m p a }}%

90 \ @ i f u n d e f i n e d {\ @ t e m p a }{\g l o b a l\ @ n a m e d e f {\ @ t e m p a.

} { } } { }%

91 \e x p a n d a f t e r\e n d g r o u p

92 \e x p a n d a f t e r#1\c s n a m e\ @ t e m p a \e n d c s n a m e

93 }

User Level Macros

The user level macros simple use the above defined macros on the appropriate hook.

(16)

\AtBeginOfIncludes

94 \n e w c o m m a n d*\ A t B e g i n O f I n c l u d e s {%

95 \ f i l e h o o k @ a p p e n d \ f i l e h o o k @ i n c l u d e @ @ a t b e g i n

96 }

\AtEndOfIncludes

97 \n e w c o m m a n d*\ A t E n d O f I n c l u d e s {%

98 \ f i l e h o o k @ p r e f i x \ f i l e h o o k @ i n c l u d e @ @ a t e n d

99 }

\AfterIncludes

100 \n e w c o m m a n d*\ A f t e r I n c l u d e s {%

101 \ f i l e h o o k @ p r e f i x \ f i l e h o o k @ i n c l u d e @ @ a f t e r

102 }

\AtBeginOfIncludeFile

103 \n e w c o m m a n d*\ A t B e g i n O f I n c l u d e F i l e [ 1 ] {%

104 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ a p p e n d \.

f i l e h o o k @ i n c l u d e @ a t b e g i n @ {\ f i l e h o o k @ e n s u r e t e x.

{ # 1 } }%

105 }

\AtEndOfIncludeFile

106 \n e w c o m m a n d*\ A t E n d O f I n c l u d e F i l e [ 1 ] {%

107 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ p r e f i x \.

f i l e h o o k @ i n c l u d e @ a t e n d @ {\ f i l e h o o k @ e n s u r e t e x { # 1 } }.

%

108 }

\AfterIncludeFile

109 \n e w c o m m a n d*\ A f t e r I n c l u d e F i l e [ 1 ] {%

110 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ p r e f i x \.

f i l e h o o k @ i n c l u d e @ a f t e r @ {\ f i l e h o o k @ e n s u r e t e x { # 1 } }.

%

111 }

(17)

\AtBeginOfInputs

112 \n e w c o m m a n d*\ A t B e g i n O f I n p u t s {%

113 \ f i l e h o o k @ a p p e n d \ f i l e h o o k @ i n p u t @ @ a t b e g i n

114 }

\AtEndOfInputs

115 \n e w c o m m a n d*\ A t E n d O f I n p u t s {%

116 \ f i l e h o o k @ p r e f i x \ f i l e h o o k @ i n p u t @ @ a t e n d

117 }

\AtBeginOfInputFile

118 \n e w c o m m a n d*\ A t B e g i n O f I n p u t F i l e {%

119 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ a p p e n d \.

f i l e h o o k @ i n p u t @ a t b e g i n @

120 }

\AtEndOfInputFile

121 \n e w c o m m a n d*\ A t E n d O f I n p u t F i l e {%

122 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ p r e f i x \.

f i l e h o o k @ i n p u t @ a t e n d @

123 }

\AtBeginOfFiles

124 \n e w c o m m a n d*\ A t B e g i n O f F i l e s {%

125 \ f i l e h o o k @ a p p e n d \ f i l e h o o k @ @ a t b e g i n

126 }

\AtEndOfFiles

127 \n e w c o m m a n d*\ A t E n d O f F i l e s {%

128 \ f i l e h o o k @ p r e f i x \ f i l e h o o k @ @ a t e n d

129 }

(18)

\AtBeginOfEveryFile

130 \n e w c o m m a n d*\ A t B e g i n O f E v e r y F i l e {%

131 \ f i l e h o o k @ a p p e n d \ f i l e h o o k @ e v e r y @ @ a t b e g i n

132 }

\AtEndOfEveryFile

133 \n e w c o m m a n d*\ A t E n d O f E v e r y F i l e {%

134 \ f i l e h o o k @ p r e f i x \ f i l e h o o k @ e v e r y @ @ a t e n d

135 }

\AtBeginOfFile

136 \n e w c o m m a n d*\ A t B e g i n O f F i l e {%

137 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ a p p e n d \.

f i l e h o o k @ a t b e g i n @

138 }

\AtEndOfFile

139 \n e w c o m m a n d*\ A t E n d O f F i l e {%

140 \ f i l e h o o k @ a d d t o h o o k \ f i l e h o o k @ p r e f i x \ f i l e h o o k @ a t e n d @

141 }

\AtBeginOfClassFile

142 \n e w c o m m a n d*\ A t B e g i n O f C l a s s F i l e {%

143 \ @ i f n e x t c h a r *

144 {\ A t B e g i n O f X F i l e @ s t a r \ @ c l s e x t e n s i o n }%

145 {\ A t B e g i n O f X F i l e @ n o r m a l \ @ c l s e x t e n s i o n }%

146 }

\AtBeginOfPackageFile

147 \n e w c o m m a n d*\ A t B e g i n O f P a c k a g e F i l e {%

148 \ @ i f n e x t c h a r *

149 {\ A t B e g i n O f X F i l e @ s t a r \ @ p k g e x t e n s i o n }%

150 {\ A t B e g i n O f X F i l e @ n o r m a l \ @ p k g e x t e n s i o n }%

151 }

(19)

\AtBeginOfXFile@star

#1: extension

#2: name

If the class or package is already loaded the code is executed right away. Otherwise it is installed normally.

152 \def\ A t B e g i n O f X F i l e @ s t a r # 1 * # 2 {%

153 \ @ i f l @ a d e d { # 1 } { # 2 }%

154 {\ @ f i r s t o f o n e }%

155 {\ A t B e g i n O f X F i l e @ n o r m a l { # 1 } { # 2 } }%

156 }

\AtBeginOfXFile@normal

#1: extension

#2: name

157 \def\ A t B e g i n O f X F i l e @ n o r m a l # 1 # 2 {%

158 \ A t B e g i n O f F i l e { # 2 . # 1 }%

159 }

\AtEndOfClassFile

160 \n e w c o m m a n d*\ A t E n d O f C l a s s F i l e {%

161 \ @ i f n e x t c h a r *

162 {\ A t E n d O f X F i l e @ s t a r \ @ c l s e x t e n s i o n }%

163 {\ A t E n d O f X F i l e @ n o r m a l \ @ c l s e x t e n s i o n }%

164 }

\AtEndOfPackageFile

165 \n e w c o m m a n d*\ A t E n d O f P a c k a g e F i l e {%

166 \ @ i f n e x t c h a r *

167 {\ A t E n d O f X F i l e @ s t a r \ @ p k g e x t e n s i o n }%

168 {\ A t E n d O f X F i l e @ n o r m a l \ @ p k g e x t e n s i o n }%

169 }

\AtEndOfXFile@star

#1: extension

#2: name

If the class or package is already loaded the code is executed right away. Otherwise it is installed normally.

(20)

170 \def\ A t E n d O f X F i l e @ s t a r # 1 * # 2 {%

171 \ @ i f l @ a d e d { # 1 } { # 2 }%

172 {\ @ f i r s t o f o n e }%

173 {\ A t E n d O f X F i l e @ n o r m a l { # 1 } { # 2 } }%

174 }

\AtEndOfXFile@normal

#1: extension

#2: name

Note that\AtEndOfClassis identical to\AtEndOfPackage, so no differentiation between classes and packages is needed here.

175 \l o n g\def\ A t E n d O f X F i l e @ n o r m a l # 1 # 2 # 3 {%

176 \ A t E n d O f F i l e { # 2 . # 1 } { \ A t E n d O f P a c k a g e { # 3 } }%

177 }

\ClearHook

Clears the hook by temporary redefining the prefix and append macros to do a simple definition to empty.

178 \n e w c o m m a n d*\ C l e a r H o o k {%

179 \b e g i n g r o u p

180 \def\ f i l e h o o k @ p r e f i x # # 1 # # 2 {%

181 \g d e f# # 1 { }%

182 \e n d g r o u p

183 }%

184 \let\ f i l e h o o k @ a p p e n d \ f i l e h o o k @ p r e f i x

185 }

6.4 Installation of Hooks

The\@input@and\@iinputmacros fromlatex.ltxare redefined to install the hooks.

First the original definitions are saved away.

\filehook@orig@@input@

186 \let\ f i l e h o o k @ o r i g @ @ i n p u t @ \ @ i n p u t @

\filehook@orig@@iinput

187 \let\ f i l e h o o k @ o r i g @ @ i i n p u t \ @ i i n p u t

(21)

\@input@

This macro is redefined for the\includefile hooks. Checks if the next command is\clearpagewhich indicates that we are inside\@include. If so the hooks are installed, otherwise the original macro is used unchanged. For the ‘after’ hook an own\clearpageis inserted and the original one is gobbled.

188 \def\ @ i n p u t @ #1{%

189 \ @ i f n e x t c h a r \c l e a r p a g e

190 {%

191 \ f i l e h o o k @ e v e r y @ a t b e g i n { # 1 }%

192 \ f i l e h o o k @ i n c l u d e @ a t b e g i n { # 1 }%

193 \ f i l e h o o k @ o r i g @ @ i n p u t @ { # 1 }%

194 \ f i l e h o o k @ i n c l u d e @ a t e n d { # 1 }%

195 \c l e a r p a g e

196 \ f i l e h o o k @ i n c l u d e @ a f t e r { # 1 }%

197 \ f i l e h o o k @ e v e r y @ a t e n d { # 1 }%

198 \ @ g o b b l e

199 }%

200 {\ f i l e h o o k @ o r i g @ @ i n p u t @ { # 1 } }%

201 }

\@iinput

This macro is redefined for the\inputfile hooks. it simply surrounds the original macro with the hooks.

202 \def\ f i l e h o o k @ @ i i n p u t #1{%

203 \ f i l e h o o k @ e v e r y @ a t b e g i n { # 1 }%

204 \ f i l e h o o k @ i n p u t @ a t b e g i n { # 1 }%

205 \ f i l e h o o k @ o r i g @ @ i i n p u t { # 1 }%

206 \ f i l e h o o k @ i n p u t @ a t e n d { # 1 }%

207 \ f i l e h o o k @ e v e r y @ a t e n d { # 1 }%

208 }

209 \let\ @ i i n p u t \ f i l e h o o k @ @ i i n p u t

\filehook@swap

Auxiliary macro which swaps the two arguments. This is needed to expand\@filef@und, which is given as first argument but needed then as the second one.

210 \def\ f i l e h o o k @ s w a p # 1 # 2 { # 2 # 1 }

\filehook@ensureext

This macro ensures the existence of a file name extension. If non is given ‘.tex’ is added.

(22)

211 \def\ f i l e h o o k @ e n s u r e e x t #1{%

212 \e x p a n d a f t e r\ f i l e h o o k @ @ e n s u r e e x t #1\e m p t y. tex \.

e m p t y\e m p t y

213 }

\filehook@@ensureext

214 \def\ f i l e h o o k @ @ e n s u r e e x t # 1 . # 2 \e m p t y#3\e m p t y{ # 1 . # 2 }

\filehook@ensuretex

Ensures a ‘.tex’ extension, i.e. adds it if missing, even if there is a different one.

215 \def\ f i l e h o o k @ e n s u r e t e x #1{%

216 \e x p a n d a f t e r\ f i l e h o o k @ @ e n s u r e t e x #1\e m p t y. tex \.

e m p t y\e m p t y

217 }

\filehook@@ensuretex

218 \def\ f i l e h o o k @ @ e n s u r e t e x #1. tex \e m p t y#2\e m p t y{ # 1 . tex } Thefilehookdefault definition of\InputIfFileExistsis defined here to- gether 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.

\latex@InputIfFileExists

Standard LATEX definition of\InputIfFileExists.

219 \l o n g\def\ l a t e x @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

220 \ I f F i l e E x i s t s { # 1 }%

221 { # 2 \ @ a d d t o f i l e l i s t { # 1 }%

222 \ @ @ i n p u t \ @ f i l e f @ u n d

223 }%

224 }

\filehook@default@InputIfFileExists

(23)

225 \l o n g\g d e f\ f i l e h o o k @ d e f a u l t @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

226 \ I f F i l e E x i s t s { # 1 }%

227 {\e x p a n d a f t e r\ f i l e h o o k @ s w a p

228 \e x p a n d a f t e r{\ @ f i l e f @ u n d }%

229 { # 2 \ @ a d d t o f i l e l i s t { # 1 }%

230 \ f i l e h o o k @ e v e r y @ a t b e g i n { # 1 }%

231 \ f i l e h o o k @ a t b e g i n { # 1 }%

232 \ @ @ i n p u t }%

233 \ f i l e h o o k @ a t e n d { # 1 }%

234 \ f i l e h o o k @ e v e r y @ a t e n d { # 1 }%

235 }%

236 }

\filehook@@default@InputIfFileExists

237 \l o n g\g d e f\ f i l e h o o k @ @ d e f a u l t @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

238 \let\ I n p u t I f F i l e E x i s t s \ f i l e h o o k @ I n p u t I f F i l e E x i s t s

239 \ I f F i l e E x i s t s { # 1 }%

240 {\e x p a n d a f t e r\ f i l e h o o k @ s w a p

241 \e x p a n d a f t e r{\ @ f i l e f @ u n d }%

242 { # 2 \ @ a d d t o f i l e l i s t { # 1 }%

243 \ f i l e h o o k @ a t b e g i n { # 1 }%

244 \ @ @ i n p u t }%

245 \ f i l e h o o k @ a t e n d { # 1 }%

246 }%

247 }

\scrlfile@InputIfFileExists

248 \l o n g\def\ s c r l f i l e @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

249 \b e g i n g r o u p\e x p a n d a f t e r\e x p a n d a f t e r\e x p a n d a f t e r\.

e n d g r o u p

250 \e x p a n d a f t e r\ifx\c s n a m e #1 - @ a l i a s \e n d c s n a m e\r e l a x

251 \e x p a n d a f t e r\ @ s e c o n d o f t w o

252 \e l s e

253 \ s c r @ r e p l a c e f i l e @ m s g {\c s n a m e #1 - @ a l i a s \e n d c s n a m e.

} { # 1 }%

254 \e x p a n d a f t e r\ @ f i r s t o f t w o

255 \fi

256 {%

257 \e x p a n d a f t e r\ I n p u t I f F i l e E x i s t s \e x p a n d a f t e r{\.

c s n a m e

258 #1 - @ a l i a s \e n d c s n a m e} { # 2 }%

259 }%

260 {\ I f F i l e E x i s t s { # 1 } {%

261 \ s c r @ l o a d @ h o o k { b e f o r e } { # 1 }%

(24)

263 \ @ @ i n p u t \ @ f i l e f @ u n d

264 \ s c r @ l o a d @ h o o k { a f t e r } { # 1 }%

265 }}%

266 }

\filehook@scrlfile@InputIfFileExists

267 \l o n g\def\ f i l e h o o k @ s c r l f i l e @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

268 \b e g i n g r o u p\e x p a n d a f t e r\e x p a n d a f t e r\e x p a n d a f t e r\.

e n d g r o u p

269 \e x p a n d a f t e r\ifx\c s n a m e #1 - @ a l i a s \e n d c s n a m e\r e l a x

270 \e x p a n d a f t e r\ @ s e c o n d o f t w o

271 \e l s e

272 \ s c r @ r e p l a c e f i l e @ m s g {\c s n a m e #1 - @ a l i a s \e n d c s n a m e.

} { # 1 }%

273 \e x p a n d a f t e r\ @ f i r s t o f t w o

274 \fi

275 {%

276 \e x p a n d a f t e r\ I n p u t I f F i l e E x i s t s \e x p a n d a f t e r{\.

c s n a m e

277 #1 - @ a l i a s \e n d c s n a m e} { # 2 }%

278 }%

279 {\ I f F i l e E x i s t s { # 1 } {%

280 \e x p a n d a f t e r\ f i l e h o o k @ s w a p

281 \e x p a n d a f t e r{\ @ f i l e f @ u n d }%

282 {\ s c r @ l o a d @ h o o k { b e f o r e } { # 1 }%

283 #2\ @ a d d t o f i l e l i s t { # 1 }%

284 \ f i l e h o o k @ e v e r y @ a t b e g i n { # 1 }%

285 \ f i l e h o o k @ a t b e g i n { # 1 }%

286 \ @ @ i n p u t }%

287 \ f i l e h o o k @ a t e n d { # 1 }%

288 \ f i l e h o o k @ e v e r y @ a t e n d { # 1 }%

289 \ s c r @ l o a d @ h o o k { a f t e r } { # 1 }%

290 }}%

291 }

\filehook@@scrlfile@InputIfFileExists

292 \l o n g\def\ f i l e h o o k @ @ s c r l f i l e @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

293 \let\ I n p u t I f F i l e E x i s t s \ f i l e h o o k @ I n p u t I f F i l e E x i s t s

294 \b e g i n g r o u p\e x p a n d a f t e r\e x p a n d a f t e r\e x p a n d a f t e r\.

e n d g r o u p

295 \e x p a n d a f t e r\ifx\c s n a m e #1 - @ a l i a s \e n d c s n a m e\r e l a x

296 \e x p a n d a f t e r\ @ s e c o n d o f t w o

297 \e l s e

298 \ s c r @ r e p l a c e f i l e @ m s g {\c s n a m e #1 - @ a l i a s \e n d c s n a m e.

} { # 1 }%

(25)

299 \e x p a n d a f t e r\ @ f i r s t o f t w o

300 \fi

301 {%

302 \e x p a n d a f t e r\ I n p u t I f F i l e E x i s t s \e x p a n d a f t e r{\.

c s n a m e

303 #1 - @ a l i a s \e n d c s n a m e} { # 2 }%

304 }%

305 {\ I f F i l e E x i s t s { # 1 } {%

306 \e x p a n d a f t e r\ f i l e h o o k @ s w a p

307 \e x p a n d a f t e r{\ @ f i l e f @ u n d }%

308 {\ s c r @ l o a d @ h o o k { b e f o r e } { # 1 }%

309 #2\ @ a d d t o f i l e l i s t { # 1 }%

310 \ f i l e h o o k @ a t b e g i n { # 1 }%

311 \ @ @ i n p u t }%

312 \ f i l e h o o k @ a t e n d { # 1 }%

313 \ s c r @ l o a d @ h o o k { a f t e r } { # 1 }%

314 }}%

315 }

316 \ P r o v i d e s P a c k a g e { f i l e h o o k - m e m o i r } [ 2 0 1 1 / 0 1 / 0 3 v 0.1 .

f i l e h o o k p a t c h for m e m o i r c l a s s ]

317 \ R e q u i r e P a c k a g e { f i l e h o o k }

318 \b e g i n g r o u p

\memoir@InputIfFileExists

319 \l o n g\def\ m e m o i r @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

320 \ I f F i l e E x i s t s { # 1 }%

321 { # 2 \ @ a d d t o f i l e l i s t { # 1 } \ m @ m a t b e g i n f { # 1 }%

322 \ @ @ i n p u t \ @ f i l e f @ u n d

323 \ m @ m a t e n d f { # 1 }%

324 \ k i l l m @ m a t f { # 1 } }%

325 }

326 \i f c a s e

327 \ifx\ I n p u t I f F i l e E x i s t s \ l a t e x @ I n p u t I f F i l e E x i s t s 0\.

e l s e

328 \ifx\ I n p u t I f F i l e E x i s t s \ m e m o i r @ I n p u t I f F i l e E x i s t s .

0\e l s e

329 1%

330 \fi\fi

331 \r e l a x

332 \g l o b a l\let\ f i l e h o o k @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ d e f a u l t @ I n p u t I f F i l e E x i s t s

333 \g l o b a l\let\ f i l e h o o k @ @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ @ d e f a u l t @ I n p u t I f F i l e E x i s t s

334 \g l o b a l\let\ I n p u t I f F i l e E x i s t s \.

(26)

335 \ f i l e h o o k @ a p p e n d w a r g \ f i l e h o o k @ a t b e g i n {\ m @ m a t b e g i n f.

{ # 1 } }%

336 \ f i l e h o o k @ p r e f i x w a r g \ f i l e h o o k @ a t e n d {\ m @ m a t e n d f { # 1 } \.

k i l l m @ m a t f { # 1 } }%

337 \ P a c k a g e I n f o { f i l e h o o k }{ D e t e c t e d ’ memoir ’ c l a s s : the.

m e m o i r h o o k s w i l l be m o v e d to the ‘ At ... OfFiles.

’ h o o k s }

338 \e l s e

339 \ i f f i l e h o o k @ f o r c e

340 \g l o b a l\let\ f i l e h o o k @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ d e f a u l t @ I n p u t I f F i l e E x i s t s

341 \g l o b a l\let\ f i l e h o o k @ @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ @ d e f a u l t @ I n p u t I f F i l e E x i s t s

342 \g l o b a l\let\ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ I n p u t I f F i l e E x i s t s

343 \ P a c k a g e W a r n i n g { f i l e h o o k }{ D e t e c t e d ’ memoir ’ c l a s s.

w i t h u n k n o w n d e f i n i t i o n of \s t r i n g\.

I n p u t I f F i l e E x i s t s .^^ J%

344 The ’ force ’ o p t i o n of ’.

f i l e h o o k ’ is in .

e f f e c t . M a c r o is .

o v e r w r i t t e n w i t h .

d e f a u l t !}%

345 \e l s e

346 \ P a c k a g e E r r o r { f i l e h o o k }{ D e t e c t e d ’ memoir ’ c l a s s .

w i t h u n k n o w n d e f i n i t i o n of \s t r i n g\.

I n p u t I f F i l e E x i s t s .^^ J%

347 Use the ’ force ’ o p t i o n of.

’ f i l e h o o k ’ to .

o v e r w r i t e it . } { }%

348 \fi

349 \fi

350 \e n d g r o u p

351 \ P r o v i d e s P a c k a g e { f i l e h o o k - l i s t i n g s } [ 2 0 1 1 / 0 1 / 0 2 v 0.1 .

P a t c h for l i s t i n g s to a v o i d h o o k s for v e r b a t i m .

i n p u t f i l e s ]

352 \b e g i n g r o u p

353

354 \l o n g\def\ p a t c h #1\def\ l s t @ n e x t # 2 # 3 \ e n d p a t c h {%

355 \ t o k s @ { # 2 }%

356 \e d e f\ @ t e m p a {\the\ t o k s @ }%

357 \def\ @ t e m p b {\i n p u t{ # # # # 1 } }%

358 \ifx\ @ t e m p a \ @ t e m p b

359 \g d e f\ l s t @ I n p u t L i s t i n g # # 1 { # 1 \def\ l s t @ n e x t {\.

@ i n p u t { # # 1 } } # 3 }%

360 \e l s e

361 \ P a c k a g e W a r n i n g { f i l e h o o k - l i s t i n g s }{ To - be -.

p a t c h e d c o d e in m a c r o \s t r i n g\.

(27)

l s t @ I n p u t L i s t i n g was not f o u n d !}%

362 \fi

363 }

364

365 \ @ i f u n d e f i n e d { l s t @ I n p u t L i s t i n g }{%

366 \ P a c k a g e W a r n i n g { f i l e h o o k - l i s t i n g s }{ To - be - p a t c h e d .

M a c r o \s t r i n g\ l s t @ I n p u t L i s t i n g not f o u n d !}%

367 }{}

368

369 \e x p a n d a f t e r\ p a t c h \ l s t @ I n p u t L i s t i n g { # 1 } \ e n d p a t c h

370

371 \e n d g r o u p

372 \ P r o v i d e s P a c k a g e { f i l e h o o k - s c r l f i l e } [ 2 0 1 1 / 0 1 / 0 3 v 0.1 .

f i l e h o o k p a t c h for s c r l f i l e p a c k a g e ]

373 \ R e q u i r e P a c k a g e { f i l e h o o k }

374 \b e g i n g r o u p

\scrlfile@InputIfFileExists

375 \l o n g\def\ s c r l f i l e @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

376 \b e g i n g r o u p\e x p a n d a f t e r\e x p a n d a f t e r\e x p a n d a f t e r\.

e n d g r o u p

377 \e x p a n d a f t e r\ifx\c s n a m e #1 - @ a l i a s \e n d c s n a m e\r e l a x

378 \e x p a n d a f t e r\ @ s e c o n d o f t w o

379 \e l s e

380 \ s c r @ r e p l a c e f i l e @ m s g {\c s n a m e #1 - @ a l i a s \e n d c s n a m e.

} { # 1 }%

381 \e x p a n d a f t e r\ @ f i r s t o f t w o

382 \fi

383 {%

384 \e x p a n d a f t e r\ I n p u t I f F i l e E x i s t s \e x p a n d a f t e r{\.

c s n a m e

385 #1 - @ a l i a s \e n d c s n a m e} { # 2 }%

386 }%

387 {\ I f F i l e E x i s t s { # 1 } {%

388 \ s c r @ l o a d @ h o o k { b e f o r e } { # 1 }%

389 #2\ @ a d d t o f i l e l i s t { # 1 }%

390 \ @ @ i n p u t \ @ f i l e f @ u n d

391 \ s c r @ l o a d @ h o o k { a f t e r } { # 1 }%

392 }}%

393 }

\filehook@scrlfile@InputIfFileExists

(28)

394 \l o n g\def\ f i l e h o o k @ s c r l f i l e @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

395 \b e g i n g r o u p\e x p a n d a f t e r\e x p a n d a f t e r\e x p a n d a f t e r\.

e n d g r o u p

396 \e x p a n d a f t e r\ifx\c s n a m e #1 - @ a l i a s \e n d c s n a m e\r e l a x

397 \e x p a n d a f t e r\ @ s e c o n d o f t w o

398 \e l s e

399 \ s c r @ r e p l a c e f i l e @ m s g {\c s n a m e #1 - @ a l i a s \e n d c s n a m e.

} { # 1 }%

400 \e x p a n d a f t e r\ @ f i r s t o f t w o

401 \fi

402 {%

403 \e x p a n d a f t e r\ I n p u t I f F i l e E x i s t s \e x p a n d a f t e r{\.

c s n a m e

404 #1 - @ a l i a s \e n d c s n a m e} { # 2 }%

405 }%

406 {\ I f F i l e E x i s t s { # 1 } {%

407 \e x p a n d a f t e r\ f i l e h o o k @ s w a p

408 \e x p a n d a f t e r{\ @ f i l e f @ u n d }%

409 {\ s c r @ l o a d @ h o o k { b e f o r e } { # 1 }%

410 #2\ @ a d d t o f i l e l i s t { # 1 }%

411 \ f i l e h o o k @ e v e r y @ a t b e g i n { # 1 }%

412 \ f i l e h o o k @ a t b e g i n { # 1 }%

413 \ @ @ i n p u t }%

414 \ f i l e h o o k @ a t e n d { # 1 }%

415 \ f i l e h o o k @ e v e r y @ a t e n d { # 1 }%

416 \ s c r @ l o a d @ h o o k { a f t e r } { # 1 }%

417 }}%

418 }

\filehook@@scrlfile@InputIfFileExists

419 \l o n g\def\ f i l e h o o k @ @ s c r l f i l e @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

420 \let\ I n p u t I f F i l e E x i s t s \ f i l e h o o k @ I n p u t I f F i l e E x i s t s

421 \b e g i n g r o u p\e x p a n d a f t e r\e x p a n d a f t e r\e x p a n d a f t e r\.

e n d g r o u p

422 \e x p a n d a f t e r\ifx\c s n a m e #1 - @ a l i a s \e n d c s n a m e\r e l a x

423 \e x p a n d a f t e r\ @ s e c o n d o f t w o

424 \e l s e

425 \ s c r @ r e p l a c e f i l e @ m s g {\c s n a m e #1 - @ a l i a s \e n d c s n a m e.

} { # 1 }%

426 \e x p a n d a f t e r\ @ f i r s t o f t w o

427 \fi

428 {%

429 \e x p a n d a f t e r\ I n p u t I f F i l e E x i s t s \e x p a n d a f t e r{\.

c s n a m e

430 #1 - @ a l i a s \e n d c s n a m e} { # 2 }%

431 }%

432 {\ I f F i l e E x i s t s { # 1 } {%

(29)

433 \e x p a n d a f t e r\ f i l e h o o k @ s w a p

434 \e x p a n d a f t e r{\ @ f i l e f @ u n d }%

435 {\ s c r @ l o a d @ h o o k { b e f o r e } { # 1 }%

436 #2\ @ a d d t o f i l e l i s t { # 1 }%

437 \ f i l e h o o k @ a t b e g i n { # 1 }%

438 \ @ @ i n p u t }%

439 \ f i l e h o o k @ a t e n d { # 1 }%

440 \ s c r @ l o a d @ h o o k { a f t e r } { # 1 }%

441 }}%

442 }

If thescrlfilepackage definition is detected thefilehooks are added to that definition. Unfortunately the\scr@load@hook{before}hook is placedbeforenot after the#2\@addtofilelist{#1}code. Otherwise thefilehooks could simply be added to these hooks. Note that this will stop working ifscrlfileever changes its definition of the\InputIfFileExistsmacro.

443 \i f c a s e

444 \ifx\ I n p u t I f F i l e E x i s t s \ l a t e x @ I n p u t I f F i l e E x i s t s 0\.

e l s e

445 \ifx\ I n p u t I f F i l e E x i s t s \ s c r l f i l e @ I n p u t I f F i l e E x i s t s.

0\e l s e

446 1%

447 \fi\fi

448 \r e l a x

449 \g l o b a l\let\ f i l e h o o k @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ s c r l f i l e @ I n p u t I f F i l e E x i s t s

450 \g l o b a l\let\ f i l e h o o k @ @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ @ s c r l f i l e @ I n p u t I f F i l e E x i s t s

451 \g l o b a l\let\ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ I n p u t I f F i l e E x i s t s

452 \ P a c k a g e I n f o { f i l e h o o k }{ P a c k a g e ’ s c r l f i l e ’ d e t e c t e d .

and c o m p e n s a t e d for }%

453 \e l s e

454 \ i f f i l e h o o k @ f o r c e

455 \g l o b a l\let\ f i l e h o o k @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ d e f a u l t @ I n p u t I f F i l e E x i s t s

456 \g l o b a l\let\ f i l e h o o k @ @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ @ d e f a u l t @ I n p u t I f F i l e E x i s t s

457 \g l o b a l\let\ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ I n p u t I f F i l e E x i s t s

458 \ P a c k a g e W a r n i n g { f i l e h o o k }{ D e t e c t e d ’ s c r l f i l e ’ .

p a c k a g e w i t h u n k n o w n d e f i n i t i o n of \s t r i n g\.

I n p u t I f F i l e E x i s t s .^^ J%

459 The ’ force ’ o p t i o n of ’.

f i l e h o o k ’ is in .

e f f e c t . M a c r o is .

o v e r w r i t t e n w i t h .

d e f a u l t !}%

460 \e l s e

(30)

p a c k a g e w i t h u n k n o w n d e f i n i t i o n of \s t r i n g\.

I n p u t I f F i l e E x i s t s .^^ J%

462 Use the ’ force ’ o p t i o n of.

’ f i l e h o o k ’ to .

o v e r w r i t e it . } { }%

463 \fi

464 \fi

465 \e n d g r o u p

466 \ P r o v i d e s P a c k a g e { f i l e h o o k - f i n k } [ 2 0 1 1 / 0 1 / 0 3 v 0.1 .

f i l e h o o k c o m p a t i b i l i t y c o d e for f i n k p a c k a g e ]

467 \ R e q u i r e P a c k a g e { f i l e h o o k }

468 \ R e q u i r e P a c k a g e { c u r r f i l e }%

469

470 \b e g i n g r o u p

471

472 \l o n g\def\ f i n k @ o l d @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

473 \ I f F i l e E x i s t s { # 1 } {%

474 #2\ @ a d d t o f i l e l i s t { # 1 }%

475 \ f i n k @ p r e p a r e { # 1 }%

476 \e x p a n d a f t e r\ f i n k @ i n p u t%

477 \e x p a n d a f t e r\ f i n k @ r e s t o r e \e x p a n d a f t e r{\ f i n k p a t h }}.

%

478 }

479

480 \l o n g\def\ f i n k @ n e w @ I n p u t I f F i l e E x i s t s # 1 # 2 {%

481 \ I f F i l e E x i s t s { # 1 } {%

482 #2\ @ a d d t o f i l e l i s t { # 1 }%

483 \e d e f\ f i n k @ b e f o r e {\n o e x p a n d\ f i n k @ i n p u t { # 1 } }%

484 \e d e f\ f i n k @ a f t e r {\n o e x p a n d\ f i n k @ r e s t o r e {\ f i n k p a t h.

}}%

485 \e x p a n d a f t e r\ f i n k @ b e f o r e \ f i n k @ a f t e r }%

486 }

487

488 \i f c a s e

489 \ifx\ I n p u t I f F i l e E x i s t s \ f i l e h o o k @ I n p u t I f F i l e E x i s t s.

0\e l s e

490 \ifx\ I n p u t I f F i l e E x i s t s \ l a t e x @ I n p u t I f F i l e E x i s t s .

1\e l s e

491 \ifx\ I n p u t I f F i l e E x i s t s \ f i n k @ n e w @ I n p u t I f F i l e E x i s t s.

1\e l s e

492 \ifx\ I n p u t I f F i l e E x i s t s \ f i n k @ o l d @ I n p u t I f F i l e E x i s t s.

1\e l s e

493 1%

494 \fi\fi\fi\fi

495 \r e l a x

496 \or

497 \g l o b a l\let\ f i l e h o o k @ I n p u t I f F i l e E x i s t s \.

f i l e h o o k @ d e f a u l t @ I n p u t I f F i l e E x i s t s

Gambar

Table 1: Incompatible packages and classes

Referensi

Dokumen terkait

Based on the problems above, one way to assist students in developing intellectual intelligence, noble character, and skills in Civic Education learning in the Covid-19 pandemic

yang telah senantiasa memberikan rahmat dan karunianya terhadap penulis, sehingga penulis dapat menyelesaikan tugas akhir ini dan memberikan kemudahan dalam