一个简单的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)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步