使用 python 的 Sympy 乳胶导出

MrY*_*ath 5 python latex sympy

我正在尝试使用以下 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)))
Run Code Online (Sandbox Code Playgroud)

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

如何删除输出开头和结尾的附加反斜杠和引号?

fin*_*ian 8

from sympy import Matrix, print_latex

X = Matrix([1,2,3])
print_latex(X)
Run Code Online (Sandbox Code Playgroud)

out: \left[\begin{matrix}1\\2\\3\end{matrix}\right]

(只有在笔记本环境中才会这样打印)


The*_*ool 3

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

from sympy import init_printing
init_printing() 
Run Code Online (Sandbox Code Playgroud)

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

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