Luk*_*urn 6 django latex heroku django-templates pdflatex
我在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
Run Code Online (Sandbox Code Playgroud)
当我使用在现有的文档类的一个能正常工作cv.tex(例如\documentclass{article}),但我想用一个自定义,叫做res。通常,我相信使用自定义类有两种选择。
将类文件(res.cls在本例中为)放置在与该.tex文件相同的文件夹中。对我来说,那应该在我应用程序的templates文件夹中。我已经尝试过了,但是pdflatex找不到类文件。(大概是因为它不在模板文件夹中运行,而是在临时目录中运行?是否可以将类文件复制到临时目录中?)
将类文件放在具有该结构的另一个文件夹中localtexmf/tex/latex/res.cls,并pdflatex使用对此问题的答案中概述的方法进行识别。我尝试使用来在Heroku上运行CLI指令heroku run bash,但它不能识别initexmf,而且我不确定如何指定相关目录。
我如何知道pdflatex在哪里可以找到课程文件?
我最终找到了另一种解决方法来实现我的目标,但我发现的最直接的解决方案是TEXMFHOME在运行时进行更改,例如......
TEXMFHOME=/d pdflatex <filename>.tex
Run Code Online (Sandbox Code Playgroud)
...如果你有/d/tex/latex/res/res.cls。
感谢tex.stackexchange.com 上的CFR的建议。
| 归档时间: |
|
| 查看次数: |
465 次 |
| 最近记录: |