一个简单的python脚本,把latex项目的调用资源放在同一级,以便arxiv
据说上传arxiv时所有资源需要在同一目录,也就是不能有文件夹(只是据说,有人说有文件夹也行,我没试过),所以写了一个简单的小脚本把latex项目的资源(主要是图片)放在和.tex一个路径下:
import os
import shutil
tex_file='main.tex'
img_folder='imgs'
encoding_type='utf-8'
with open(tex_file,'r',encoding=encoding_type) as f:
lines=f.readlines()
with open('after'+tex_file,'w',encoding=encoding_type) as f:
for line in lines:
if img_folder in line:
start_idx=line.find(img_folder)
end_idx=len(line)
for i in range(start_idx,len(line)):
if line[i]=='}':
end_idx=i
break
img_path=line[start_idx:end_idx]
'''print(img_path)
assert 0>1'''
shutil.copy(img_path,img_path.replace('/','-'))
new_line=line[0:start_idx]+img_path.replace('/','-')+line[end_idx:]
f.write(new_line)
else:
f.write(line)