我正在尝试使用以下Python代码
已解决(@TheFool 提示):通过将 Latex() 放入打印函数中,它可以工作。
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 )}''
。
如何删除输出开头和结尾处的额外反斜杠和引号?
最佳答案
from sympy import Matrix, print_latex
X = Matrix([1,2,3])
print_latex(X)
输出:\left[\begin{matrix}1\\2\\3\end{matrix}\right]
(只有在笔记本环境中才会这样打印)
关于python - 使用 python 导出 Sympy Latex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50447737/