# Hook into \input (or any underlying command) in order to allow transparent preprocessing

Which command would be most suitable to be hooked in order to preprocess input before it is passed to TeX?

Input file:

\begin{document}
\input{a}
\end{document}


Seen by TeX (after a file a_pp.tex has been created):

\begin{document}
\input{a_pp}
\end{document}


What about \include, \bibliography, or even other means of including files?

Note that the preprocessing is to be applied only to files that are interpreted/compiled by TeX directly, not to files that are read and parsed by some macro.

This is to move towards Forward-inverse search using SyncTeX with the precison of a single word.

-

## 1 Answer

The filehook package gives you the options to do something at the beginning or end of each \input and \include.

For instance you could use \AtBeginEveryFile to have some arbitrary code called whenever a file is included.

-
This is amazing, thank you! –  krlmlr Jun 14 '12 at 12:19
You should thank Martin Scharrer who wrote the package! –  Seamus Jun 14 '12 at 12:21
True. It is so much easier to use packages that define a clear interface for a certain aspects, than having to delve into TeX internals. Thanks a lot, @MartinScharrer! –  krlmlr Jun 14 '12 at 12:27