HowTo Get LaTeX code of original formula (without expand/simplify)?

20 views
Skip to first unread message

Michał Pawłowski

unread,
Feb 11, 2021, 1:09:53 PM2/11/21
to sympy
Hi.

I'd like to get LaTeX code of formula, but without simplification or expanding. I.E:

formula_1 = '2+x+x**2'

print(latex(expand(formula_1))) <- this works but it sorts the formula

print(latex(???)) -> 2+x+x^{2} #HOW TO GET THIS?

Thanks
Mike.

Aaron Meurer

unread,
Feb 11, 2021, 2:16:57 PM2/11/21
to sympy
SymPy generally doesn't keep track of the order that an input expression was created in. The best you can get is something like this

latex(sympify('2+x+x**2', evaluate=False), order='none')

The limitation here is that evaluate=False is not generally going to survive if you call some other function or combine with some other expression.

Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/05e496b0-d426-448e-b0b0-421b177314f5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages