Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sympy latex export using python

Tags:

I am trying to use the following python code

Solved (Hint by @TheFool): By putting latex() into the print function it works.

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)))

The output looks like '\\frac{\\partial}{\\partial x} u{\\left (x,y,z \\right )}'.

How can I remove the additional backslashes and the quotation marks at the beginning and at the end of the output?

like image 829
MrYouMath Avatar asked May 21 '18 11:05

MrYouMath


1 Answers

from sympy import Matrix, print_latex

X = Matrix([1,2,3])
print_latex(X)

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

(only prints out like that if your in a notebook environment)

like image 90
financial_physician Avatar answered Sep 28 '22 17:09

financial_physician