I want to make a package that automatically attaches all essential*) source files to the ouput PDF. I started with the embedfile, filehook and currfile packages and put


in the preamble. So far so easy.

The next step would be to attach image files on invocation of \includegraphics. My first attempt was similar to the solution in embedall:


which has the restriction to only work if the full image file name (like image.png) is given.

I imagine that I would have to patch some macro of graphicx to call \embedfile (or some appropriate hook to be defined) after the full file name has been determined. I had a look into graphics.sty and graphicx.sty, but I was not able to figure out the right patch.

Does anyone have any ideas about that?

*) At this point, "essential" essentially means such files that are considered to contain the document's content.


Sorry, that was easy:


seems to do the job.


I'd use a different patch, hooking where \Gin@setfile adds the file to the file list:







enter image description here

  • What would be the implications/advantages? I reckon this part of the code is not expanded in draft mode. But this is not necessarily what I want. – DLichti May 12 at 20:10
  • @DLichti Isn't that a good reason? Would you embed a file also when draft mode is used? I can't see why. – egreg May 12 at 20:54
  • Even in draft mode, the image file is necessary to reproduce the output including the correctly sized place holder. And if another person wants to finalize the document, then the image file is definitely necessary. Or am I missing something? – DLichti May 12 at 21:05
  • @DLichti In my opinion, if you distribute a version in draft mode, you don't want people to see the image. – egreg May 12 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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