0

我目前正在开发一个项目(在 Python 中),该项目需要从各种结果中编译 PDF 报告。这些结果存储为变量,并通过在整个 .tex 文件中替换关键字插入到 .tex 的副本中,使用以下命令:

replacements = {'TITLEPLACEHOLDER':experiment_name}

with open(latex_file) as infile, open(latex_file_output, 'w') as outfile:
    for line in infile:
        for src, target in replacements.items():
            line = line.replace(src, target)
        outfile.write(line)

之后,我有一个 .tex 文件,其中包含我的替换项,我们称该文件为“my-latex-file-copy.tex”。

在与新的 .tex 文件相同的文件夹中,有一个 .bib 导入到 .tex 中,还有一个 IMAGES 文件夹,其中插入了各种图像到 .tex 中。

此时我被卡住了,我需要使用新的 .tex 编译 PDF,其中将包括 .bib 和图像。此 PDF 的输出目录之前已声明为字符串。

我认为执行以下操作会起作用:

replacements = {'TITLEPLACEHOLDER':experiment_name}

doc = Document()

with open(latex_file) as infile, open(latex_file_output, 'w') as outfile:
    for line in infile:
        for src, target in replacements.items():
            line = line.replace(src, target)
        outfile.write(line)
    
doc.append(NoEscape(outfile))

doc.generate_pdf(clean_tex=False,silent=True,compiler='pdflatex')

但不幸的是,它要么创建一个包含与 .tex 文件(未格式化)相同的文本的 PDF,要么返回以下错误:

CalledProcessError: Command '['pdflatex', '--interaction=nonstopmode', 'C:\\Users\\me\\Documents\\University\\project\\predict\\default_filepath.tex']' returned non-zero exit status 1.

任何帮助将不胜感激:)

4

0 回答 0