14

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?

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

4

Have you tried to include:.. ?

from sympy import init_printing init_printing() 

check out the ducumentation on sympy`s print options. It looks like the init_printing is the way to go for proper output.

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

1 Comment

plus one: Thank you for the hint.
2

When you write the output on a file with

out_file = open("output.txt","w") out_file.write(latex(diff(u(x,y,z),x))) out_file.close() 

They will look like you want them.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.