首页 > 解决方案 > 使用 python 导出 Sympy 乳胶

问题描述

我正在尝试使用以下 python 代码

已解决(@TheFool 提示):通过将 latex() 放入 print 函数,它可以工作。

from sympy import *
from sympy.printing.mathml import mathml
init_printing(use_unicode=True) # allow LaTeX printing

# independent variables
x, y, z = symbols('x y z', real = True)

# parameters
nu, rho = symbols('nu rho', real = True, constant = True, positive = True)

# dependent variables
u, v, w = symbols('u v w', real = True, cls = Function)

print(latex(diff(u(x,y,z),x)))

输出看起来像 '\\frac{\\partial}{\\partial x} u{\\left (x,y,z \\right )}'.

如何删除输出开头和结尾处的额外反斜杠和引号?

标签: pythonlatexsympy

解决方案


您是否尝试过包括:..?

from sympy import init_printing
init_printing() 

查看 sympy 打印选项的文档。看起来 init_printing 是正确输出的方法。

http://docs.sympy.org/latest/tutorial/printing.html


推荐阅读