I have an expression x*y
. I want to convert it to latex, while substituting numbers instead of variables. So if I want to substitute 10 instead of x
and 20 instead of y
, I would do:
latex((x*y).subs(x=10,y=20))
200
Now the code above returns 200
, so it evaluates 10*20
. But I want the expression after substitution not to be evaluated.
So I want latex function to return 10 \\cdot 20
instead.
In SymPy, according to this answer, one can use UnevaluatedExpr
to wrap the expressions you want to substitute with. And it works like this:
sympy.latex((x*y).subs({x:10,y:sympy.UnevaluatedExpr(20)}))
'10 \\cdot 20'
Is there any alternative to UnevaluatedExpr
in sagemath?
Read more here: Source link