python - 替换行并循环编译乳胶文件
问题描述
我有一个 LaTeX 代码,其中有我单独编译的多个章节。有时我必须编译很多这样的文件,我试图自动化这个过程,而不是取消注释、编译和注释,再次是章节的行。我还必须重命名并将我编译的章节放到另一个文件夹中。
我已经设法为一章编写代码:
import os
texdoc = []
with open('aluno.tex') as fin:
for line in fin:
texdoc.append(line.replace('% \\include{chapters/funcoes}', '\\include{chapters/funcoes}'))
# write back the new document
with open('aluno.tex', 'w') as fout:
for i in range(len(texdoc)):
fout.write(texdoc[i])
os.system("latexmk -pdfxe -c aluno.tex")
with open('aluno.tex', errors="ignore") as fin:
for line in fin:
texdoc.append(line.replace('\\include{chapters/funcoes}', '% \\include{chapters/funcoes}'))
# write back the new document
with open('aluno.tex', 'w', errors="ignore") as fout:
for i in range(len(texdoc)):
fout.write(texdoc[i])
os.rename('aluno.pdf','Introdução às Funções.pdf')
shutil.copy('Introdução às Funções.pdf', 'subfolder', follow_symlinks=True)
os.remove('Introdução às Funções.pdf')
我现在要做的是通过我要编译的章节列表来自动化这个过程。就像是
chapter = ["funcoes","taxa"]
name = ["Introdução às Funções", "Taxa de Variação"]
for j in chapter and k in name
with open('aluno.tex') as fin:
for line in fin:
texdoc.append(line.replace('% \\include{chapters/j}', '\\include{chapters/j}'))
os.rename('aluno.pdf','k.pdf')
我怎样才能用python实现这一点?
解决方案
推荐阅读
- javascript - 检测光谱颜色选择器何时打开
- python - 为什么我的值在运行我的函数后没有改变?
- python - 过滤 DF 中带有一些 NaN 的行
- python - 带有整数 xaxis 的甘特图的 Plotly Express 时间线?
- amazon-web-services - AWS: 502 BadGateway: On Launching "more like this" Ec2 实例
- postgresql - Flask-sqlalchemy 有效地获取按关系排序的查询计数
- php - 无法找到 PHP.ini 用于使用 XAMPP 为 cakePHP 激活 extension=php_intl.dll
- java - Spring @Autowired EntityManager 失败
- node.js - 有什么方法可以识别 NodeJS 中的 SQL Server 存储过程返回的错误
- flutter - Flutter:谷歌创始之选