派拉泰克斯:Pyratex.errors.CompilerError:找不到LaTex编译器

2024-06-14 06:57:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行here中的确切代码,以获得pylatex工作的示例。在

在我工作的目录中,我已从链接复制和粘贴:

from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex


def fill_document(doc):
    """Add a section, a subsection and some text to the document.

    :param doc: the document
    :type doc: :class:`pylatex.document.Document` instance
    """
    with doc.create(Section('A section')):
        doc.append('Some regular text and some ')
        doc.append(italic('italic text. '))

        with doc.create(Subsection('A subsection')):
            doc.append('Also some crazy characters: $&#{}')


if __name__ == '__main__':
    # Basic document
    doc = Document('basic')
    fill_document(doc)

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

    # Document with `\maketitle` command activated
    doc = Document()

    doc.preamble.append(Command('title', 'Awesome Title'))
    doc.preamble.append(Command('author', 'Anonymous author'))
    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))

    fill_document(doc)

    doc.generate_pdf('basic_maketitle', clean_tex=False)

    # Add stuff to the document
    with doc.create(Section('A second section')):
        doc.append('Some text.')

    doc.generate_pdf('basic_maketitle2', clean_tex=False)
    tex = doc.dumps()  # The document as string in LaTeX syntax

我总是得到错误:

^{pr2}$

你可以看到我根据别人的建议尝试过的一些事情: 1如果我在这个目录中打开一个python控制台,然后键入:

from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex

没有错误,表示导入成功。在

  1. 我看到了另一个建议,即必须安装perl:

    在本地主机:测试1$perl—version:返回有关perl的信息

  2. 我已经按照StackOverflow的其他地方的建议指定了编译器:'文档生成\u pdf(clean_-tex=False,compiler='pdflatex')'

我还能做什么?最终的目标是我用python生成了字符串和一个图像,我想把它们都放到PDF和格式中,以防有更好的替代方案供大家参考。P、 我知道tex堆栈交换,但我特别需要一种让latex与python交互的方法,这就是我为什么要问这个问题的原因。在


Tags: textfromimportdocwithsectiondocumentcommand