TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Input file:


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


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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.