in src/latex2sympy2_extended/latex2sympy2.py [0:0]
def convert_postfix_list(self, arr, i=0):
if i >= len(arr):
raise Exception("Index out of bounds")
res = self.convert_postfix(arr[i])
if isinstance(res, sympy.Expr) or isinstance(res, sympy.Matrix):
if i == len(arr) - 1:
return res # nothing to multiply by
else:
# multiply by next
rh = self.convert_postfix_list(arr, i + 1)
if (hasattr(res, 'is_Matrix') and res.is_Matrix) or (hasattr(rh, 'is_Matrix') and rh.is_Matrix):
return self.mat_mul_flat(res, rh)
# Support for mixed fractions, 2 \frac{1}{2}
elif hasattr(res, 'is_Integer') and res.is_Integer and hasattr(rh, 'is_Rational') and rh.is_Rational and rh.p > 0 and rh.q > 0:
if res < 0:
return sympy.Rational(res*rh.q - rh.p, rh.q)
else:
return sympy.Rational(res*rh.q + rh.p, rh.q)
else:
return self.mul_flat(res, rh)
elif isinstance(res, list) and len(res) == 1: # must be derivative
wrt = res[0]
if i == len(arr) - 1:
raise Exception("Expected expression for derivative")
else:
expr = self.convert_postfix_list(arr, i + 1)
return sympy.Derivative(expr, wrt)
return res