【发布时间】:2017-08-02 05:26:57
【问题描述】:
我有一个托管在 Heroku 上的 Django 应用程序。在其中,我使用用 LaTeX 编写的视图即时生成 pdf,并安装了 Heroku LaTeX buildpack 以使其正常工作。我的 LaTeX 视图如下。
def pdf(request):
context = {}
template = get_template('cv/cv.tex')
rendered_tpl = template.render(context).encode('utf-8')
with tempfile.TemporaryDirectory() as tempdir:
process = Popen(
['pdflatex', '-output-directory', tempdir],
stdin=PIPE,
stdout=PIPE,
)
out, err = process.communicate(rendered_tpl)
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)
return r
当我使用cv.tex 中的现有文档类之一(例如\documentclass{article})时,这可以正常工作,但我想使用一个名为res 的自定义类。通常我认为使用自定义类有两种选择。
将类文件(在本例中为
res.cls)放置在与.tex文件相同的文件夹中。对我来说,这将在我的应用程序的模板文件夹中。我已经尝试过了,但是pdflatex找不到类文件。 (大概是因为不是在templates文件夹下运行,而是在临时目录下运行?有没有办法将class文件复制到临时目录下?)将类文件放在另一个具有
localtexmf/tex/latex/res.cls结构的文件夹中,并使用this question 的答案中概述的方法使pdflatex意识到它。我尝试使用heroku run bash在 Heroku 上运行 CLI 指令,但它无法识别initexmf,而且我不完全确定如何指定相关目录。
我如何告诉pdflatex在哪里可以找到类文件?
【问题讨论】:
标签: django heroku django-templates latex pdflatex