# Automatically copying over files required to compile a tex file

I want a command which takes as input, a tex file, and a list of directories. It should (recursively) identify any files the tex file depends on (`\include` or `\includegraphics`) and copy them into the current directory.

The advantage of this is the ability to reuse and modify material from old papers and talks to new ones (without destroying the old ones).

Typical scenario: I want to give a talk which introduces the same material as a previous talk. I copy the beamer presentation from the previous talk and strip out the irrelevant stuff. Now I manually copy over the images I want to keep. I then modify some of those images and create the rest of the presentation...

Does this exist already?

-
It looks like you're heading for a crazy workflow here. Why not just keep all of the dependencies of your talk together in the same directory (perhaps with components in subdirectories) from the outset? Then you can archive it (e.g. zip or tar). When you want to create a derived talk you can unzip a fresh copy and adjust it to suit. You're trying to automate a task that you should probably be doing yourself (losing as much time as it would take to track it down in the filesystem anyway) as you go. Am I missing the point? –  qubyte Mar 8 '12 at 10:13
I talk about tilings, and can easily have up to 80 images. If I had all the extra images from the last talk I gave too I'd get lost trying to work in that directory. I just want something to either copy over only files I need, or toss out the ones I didn't after copying over the directory like you said. –  Alejandro Mar 8 '12 at 17:03
for the graphics, you could keep them all in a master directory, and just tell the `graphicx` package the path at the beginning of each document. for the `tex` files, this sounds like a scripting job, either with `perl` or `bash` –  cmhughes Mar 8 '12 at 19:12
I have to admit, I'm still confused. I'd put all the images in a subdirectory. In a future version of the talk, I'd make a copy of the original (remember everything contained in a single directory with subdirectories), and as I add/remove images includes from the TeX file I'd add/delete them from the images subdirectory. In the case of an original talk, the task is limited to copying images into the images subdirectory. You'd do this as you go along. –  qubyte Mar 9 '12 at 6:29

Try `latexmk`, it has a `-dependents` (or `-deps-out=`) option that lists (or writes to a file) the files required for compiling the document. Together with some scripting, this can be used to strip all unnecessary files.