Latex pylatex 数学方程:我想使用 python 将方程添加到 table。例如求和

Latex pylatex Math Equation: I want to add equations to a table using python. eg Summation

我的目标是创建一个动态 table,我将从我的数据库中获取值并使用迭代在 table 中创建多行。我目前不知道是否可以使用 'pylatex'。我现在关心的是使用 python.

在我的 pdf 中创建一个数学方程式

下面你可以一窥我在做什么。

from pylatex import Document, Section, Subsection, Tabular
from pylatex import Math, TikZ, Axis, Plot, Figure, Matrix, Alignat
from pylatex.utils import italic, bold
...
...
with doc.create(Subsection('Math Equations')):
        doc.append('Attempt to create dynamic table i.e creating dynamic rows depending on the number of rows in Database, and displaying those values in PDF Table. \n \n')
        with doc.create(Tabular('|p{3cm}|p{7cm}|p{3cm}|')) as table:
            table.add_hline()
            table.add_row((bold('ID'), bold('Equation'), bold('Result')))
            table.add_hline()
            table.add_row('1',Math(inline=False, data="\sum(a+b)", escape=None),'Result')
            table.add_hline()
            for x in range(0, 3):
                table.add_row((bold(x), bold(x+1), bold(x+2)))
                table.add_hline()

期望:

我也在乳胶中尝试过“pythontex”,其中使用 \sum_(a+b) 创建方程很容易,用于求和,但创建动态 tables 似乎很困难或不可能.

期待您的建议。 :)

我在使用 pylatex 时很快学到的一个技巧是在 pylatex 不足时使用 NoEscape 将原始 LaTeX 嵌入到文档中:

from pylatex import Document, Section, Subsection, Tabular, NoEscape
from pylatex import Math, TikZ, Axis, Plot, Figure, Matrix, Alignat
from pylatex.utils import italic, bold
...
...
with doc.create(Subsection('Math Equations')):
    doc.append('Attempt to create dynamic table i.e creating dynamic rows depending on the number of rows in Database, and displaying those values in PDF Table. \n \n')
    with doc.create(Tabular('|p{3cm}|p{7cm}|p{3cm}|')) as table:
        table.add_hline()
        table.add_row((bold('ID'), bold('Equation'), bold('Result')))
        table.add_hline()
        table.add_row('1', NoEscape(r"$$\sum(a+b)$$"), 'Result')
        table.add_hline()
        for x in range(0, 3):
            table.add_row((bold(x), bold(x+1), bold(x+2)))
            table.add_hline()

这里我使用显示方程,你也可以使用内联公式和单个 $.