我试图使用scons构建LaTeX文档。特别地,我希望scons调用一个生成包含表格的文件的Python程序,该表格作为\input{}插入到主文档中。我已经查看了scons文档,但并不立即清楚我需要做什么。
我的目标实际上是通过这个Makefile来实现的:
document.pdf: table.tex
pdflatex document.tex
table.tex:
python table_generator.py
我怎样在scons中表达这个呢?
这样的代码应该可以解决问题:
env.Command ('document.tex', '', 'python table_generator.py')
env.PDF ('document.pdf', 'document.tex')
这段代码声明 'document.tex' 是通过调用 Python 脚本生成的,并请求从生成的 'document.tex' 文件创建一个 PDF 文档。
请注意,这只是精神上的。它可能需要一些微调。特别是,我不确定您希望对 'document.tex' 的生成具有什么样的语义 - 它应该每次都生成吗?仅在不存在时生成?当某个其他文件更改时?(在这种情况下,您需要将此依赖项添加为 Command() 的第二个参数)。
此外,如果需要,可以使用 Command() 的输出作为 PDF() 的输入。出于清晰起见,我没有这样做。
from subprocess import call
call("python table_generator.py")
call("pdflatex document.tex")