Skip to main content
revised the python script: PEP8, pythonism, constants at top, quicker to modify, shallower indentation
Source Link

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

"""Copy figures used by document.""" import os import shutil   DEP_FILE = './My_Latex_File'main.dep' TARGET_DIR = 'figs_used'other_img/' EXTENSIONS = ['pdf', 'pdf_tex', 'png']   def copy_image_files(): with open(DEP_FILE, 'r') as f:   for line in f:   if '*{file}' not in line:   continue value = line.split('{')[2].split('}') source = value[0]   _, e = os.path.splitext(linesource)   e = e.lower()[1:]   if e not in EXTENSIONS: continue  value = line.split('{')[2].split('}')continue   source = value[0]  print(source)   shutil.copy(source, TARGET_DIR)   if __name__ == '__main__':  breakcopy_image_files() 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

import os import shutil DEP_FILE = './My_Latex_File.dep' TARGET_DIR = 'figs_used/' EXTENSIONS = ['pdf', 'png'] with open(DEP_FILE, 'r') as f: for line in f: if '*{file}' not in line: continue _, e = os.path.splitext(line) e = e.lower() if e not in EXTENSIONS: continue  value = line.split('{')[2].split('}')   source = value[0]  print(source) shutil.copy(source, TARGET_DIR)   break 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

"""Copy figures used by document.""" import os import shutil   DEP_FILE = 'main.dep' TARGET_DIR = 'other_img/' EXTENSIONS = ['pdf', 'pdf_tex', 'png']   def copy_image_files(): with open(DEP_FILE, 'r') as f:   for line in f:   if '*{file}' not in line:   continue value = line.split('{')[2].split('}') source = value[0]   _, e = os.path.splitext(source)   e = e.lower()[1:]   if e not in EXTENSIONS: continue print(source)   shutil.copy(source, TARGET_DIR)  if __name__ == '__main__':  copy_image_files() 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.

revised the python script: PEP8, pythonism, constants at top, quicker to modify, shallower indentation
Source Link

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

import os import shutil linesDEP_FILE = open('./My_Latex_File.dep' TARGET_DIR = 'figs_used/' EXTENSIONS = ['pdf', 'png'] with open(DEP_FILE, 'r') as f: for n, for line in enumerate(lines)f:   if '*{file}' not in line: if ('.png' in continue  _, e = os.path.splitext(line)   or (' e = e.pdf'lower()  if e not in line)EXTENSIONS: continue value = line.split("'{"')[2].split("'}"') source = value[0]  print value[0]   print(source)  shutil.copy('./' + value[0]source, 'figs_used/'TARGET_DIR) break 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

import os import shutil lines = open('./My_Latex_File.dep', 'r') for n, line in enumerate(lines): if '*{file}' in line: if ('.png' in line) or ('.pdf' in line): value = line.split("{")[2].split("}") print value[0]  shutil.copy('./' + value[0], 'figs_used/') 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

import os import shutil DEP_FILE = './My_Latex_File.dep' TARGET_DIR = 'figs_used/' EXTENSIONS = ['pdf', 'png'] with open(DEP_FILE, 'r') as f:  for line in f:   if '*{file}' not in line:  continue  _, e = os.path.splitext(line)    e = e.lower()  if e not in EXTENSIONS: continue value = line.split('{')[2].split('}') source = value[0]    print(source)  shutil.copy(source, TARGET_DIR) break 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.

Source Link
imriss
  • 807
  • 2
  • 7
  • 15

This is a modified version of the @Gonzales answer with an additional python code to copy the figures to a new folder.

After using snapshot package to generate the .dep file:

\RequirePackage{snapshot} \documentclass{article} 

use the following python code (say copy_figs.py) to copy the figures to a separate folder (for example, figs_used):

import os import shutil lines = open('./My_Latex_File.dep', 'r') for n, line in enumerate(lines): if '*{file}' in line: if ('.png' in line) or ('.pdf' in line): value = line.split("{")[2].split("}") print value[0] shutil.copy('./' + value[0], 'figs_used/') 

To run the python code:

c:\Python27\python.exe copy_figs.py 

in the folder where the Latex file is placed. It is assumed the original figures are in figs subfolder, and those figures used in the Latex file are copied to figs_used subfolder. The code copies .png and .pdf figure files.