从 Python 脚本调用 pdflatex

从 Python 脚本调用 pdflatex

我写了一个 Python 脚本,用于生成 LaTeX 文档。它将其保存到某个文件夹中,然后尝试通过以下方式进行编译:

os.system("pdflatex %s" % filename_tex)

其中filename_tex是刚刚生成的文件的路径。文件没问题,因为我可以在 TeXnicCenter 中打开它,调用 pdflatex 并进行编译。路径/文件名中没有空格。

但是,从脚本中调用它返回

pdflatex: Permission denied: C:\Users\tiger\Desktop\CT_xls_to_latex\output\myfile.tex
pdflatex: Data: C:\Users\tiger\Desktop\CT_xls_to_latex\output\myfile.tex

我确保 pdflatex 没有在后台运行。欢迎提出任何想法。

跟进:

实际上,如果我按原样获取文件路径并将其粘贴到脚本中,那么它就可以起作用:

os.system(r"pdflatex C:\Users\tiger\Desktop\CT_xls_to_latex\output\myfile.tex")

我对这种行为感到非常困惑。为什么 os.system 不喜欢字符串替换?

答案1

我不知道原因是什么但这里有解决办法。

inputted_path = r"\input{"+filepath+"}"
os.system("pdflatex %s" % inputted_path)

相关内容