I want an easy (automatic) way to copy all image files called by latex into as single directory. A similar issue was addressed here: Create list of all external files used by master LaTeX document? and I like the solution proposed by @imriss except that it requires all files to reside in the same directory as the tex file to work. Some of my image file reside elsewhere and are accessed through TEXINPUTS and are not found by this technique because the dep file produced by snapshot only contains the names of the files, not their path.
Building of @muzimuzhi Z's comment and @imriss' answer to the question Create list of all external files used by master LaTeX document?, here is way to copy all external files used by a latex doc to the directory
img, based on a choice of file extensions.
Starting with a latex file
pdflatex -recover file
file.fls. Create a file, say
copy_fig_fls.py, containing the following python code:
"""Copy figures used by document.""" import os import shutil FLS_FILE = 'file.fls' TARGET_DIR = 'img/' EXTENSIONS = ['pdf', 'png', 'jpg'] def copy_image_files(): with open(FLS_FILE, 'r') as f: for line in f: if 'INPUT' not in line: continue source = line.split(' ').rstrip() _, e = os.path.splitext(source) e = e.lower()[1:] if e in EXTENSIONS: shutil.copy(source, TARGET_DIR) if __name__ == '__main__': copy_image_files()
Run it by typing
It will copy all the files used by
file.tex with extensions listed in the
EXTENSIONS variable into the
img directory, irrespective of where the original image file resides, in the current directory or elsewhere.