( ):
def print_fractions(expr):
print("({}) * ({})".format(*expr.args))
:
In: expr = sympy.Mul(sympy.S("5/7"), sympy.S("3/4"), evaluate=False)
In: expr
Out: 5*3/(7*4)
In: print_fractions(expr)
Out: (5/7) * (3/4)
srepr, expr, , sympy :
In: sympy.srepr(expr)
Out: 'Mul(Rational(5, 7), Rational(3, 4))'
sympy.Mul __str__:
class MyMul(sympy.Mul):
def __str__(self):
return "({}) * ({})".format(*self.args)
:
In: expr = MyMul(sympy.S("5/7"), sympy.S("3/4"), evaluate=False)
In: print(expr)
Out: (5/7) * (3/4)
Eidt: latex()
, :
class MyMul(Mul):
def _latex(self, _):
return r"\left({} \cdot {}\right)".format(*map(latex, self.args))
:
In: a = S("5/7")
In: b = S("3/4")
In: c = MyMul(a, b, evaluate=False)
In: print(latex(c))
Out: \left(\frac{5}{7} \cdot \frac{3}{4}\right)
, , _latex .