def convert_mp()

in src/latex2sympy2_extended/latex2sympy2.py [0:0]


    def convert_mp(self, mp):
        if hasattr(mp, 'mp'):
            mp_left = mp.mp(0)
            mp_right = mp.mp(1)
        else:
            mp_left = mp.mp_nofunc(0)
            mp_right = mp.mp_nofunc(1)

        if mp.MUL() or mp.CMD_TIMES() or mp.CMD_CDOT():
            lh = self.convert_mp(mp_left)
            rh = self.convert_mp(mp_right)

            if (hasattr(lh, 'is_Matrix') and lh.is_Matrix) or (hasattr(rh, 'is_Matrix') and rh.is_Matrix):
                return self.mat_mul_flat(lh, rh)
            else:
                return self.mul_flat(lh, rh)
        elif mp.DIV() or mp.CMD_DIV() or mp.COLON():
            lh = self.convert_mp(mp_left)
            rh = self.convert_mp(mp_right)
            if (hasattr(lh, 'is_Matrix') and lh.is_Matrix) or (hasattr(rh, 'is_Matrix') and rh.is_Matrix):
                return sympy.MatMul(lh, sympy.Pow(rh, -1, evaluate=False), evaluate=False)
            
            # If both are numbers, we convert to sympy.Rational
            elif hasattr(lh, 'is_Integer') and lh.is_Integer and hasattr(rh, 'is_Integer') and rh.is_Integer:
                return sympy.Rational(lh, rh)
            else:
                return sympy.Mul(lh, sympy.Pow(rh, -1, evaluate=False), evaluate=False)
        elif mp.CMD_MOD():
            lh = self.convert_mp(mp_left)
            rh = self.convert_mp(mp_right)
            if (hasattr(rh, 'is_Matrix') and rh.is_Matrix):
                raise Exception("Cannot perform modulo operation with a matrix as an operand")
            else:
                return sympy.Mod(lh, rh, evaluate=False)
        else:
            if hasattr(mp, 'unary'):
                return self.convert_unary(mp.unary())
            else:
                return self.convert_unary(mp.unary_nofunc())