如何在 Heroku 上安装 LaTeX class?

How to install LaTeX class on Heroku?

我在 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 中的现有文档 classes 之一(例如 \documentclass{article})时,这工作正常,但我想使用自定义文档,称为 res。通常我认为使用自定义 class.

有两种选择
  1. 将 class 文件(在本例中为 res.cls)放在与 .tex 文件相同的文件夹中。对我来说,那将在我的应用程序的模板文件夹中。我试过了,但是 pdflatex 找不到 class 文件。 (估计是因为不是运行在templates文件夹里,而是在一个临时目录下?有没有办法把class文件复制到临时目录下?)

  2. 将 class 文件放入结构为 localtexmf/tex/latex/res.cls 的另一个文件夹中,并使用对 this question。我已经使用 heroku run bash 尝试 运行 Heroku 上的 CLI 指令,但它无法识别 initexmf,而且我不完全确定如何指定相关目录。

如何告诉 pdflatex 在哪里可以找到 class 文件?

2个想法,不知道能不能解决你的问题

首先,尝试将您的 localtexmf 文件夹放在 ~/texmf 中,这是 Linux 系统中的默认本地文件夹(我对 Heroku 了解不多,但它主要是 Linux 系统,对吧?)。

其次,我不使用initexmf,通常使用texhash,它可能在您的系统上可用?

我最终找到 another workaround 来实现我的目标,但我找到的最直接的解决方案是在运行时更改 TEXMFHOME,例如...

TEXMFHOME=/d pdflatex <filename>.tex

...如果你有 /d/tex/latex/res/res.cls.

感谢 cfr 在 tex.stackexchange.com 上提出的建议。