#!/usr/bin/env python # encoding: utf-8 from .operator import Operator, save_mainOp class Mul(Operator): """ The operator * >>> mul = op.mul >>> mul '*' >>> mul(1, 2) 2 >>> mul.__tex__('1','2') '1 \\times 2' >>> mul.__tex__('2','a') '2 a' >>> mul.__txt__('1','2') '1 * 2' >>> mul.__txt__('2','a') '2 a' >>> mul.__txt__('a','2') 'a * 2' >>> mul.__tex__('1','-2') '1 \\times (-2)' """ _CARACT = { "operator" : "*", \ "name" : "mul",\ "priority" : 4, \ "arity" : 2, \ "actions" : ("__mul__","__rmul__"), \ "txt" : "{op1} * {op2}",\ "tex" : "{op1} \\times {op2}",\ } def __init__(self): """ Initiate Mul Operator """ super(Mul, self).__init__(**self._CARACT) # TODO: Add self.visibility |sam. nov. 8 17:00:08 CET 2014 self.visibility = 1 def is_visible(self, op1, op2): """ Tells whether self has to be visible or not :param op1: left operande :param op2: rigth operande """ # TODO: À finir!!! |lun. mars 9 00:03:40 CET 2015 if type(op2) == int: # op2 est maintenant une chaine de caractères return True elif op2.isdecimal(): return True elif op2.isalpha(): return False elif op2[0].isdecimal(): return True elif op2[0] == "(" and not ("+" in op2 or "-" in op2[3:]): return True # Giga bricolage... elif "frac" in op2: return True else: return False def _render(self, link, *args): op1 = self.l_parenthesis(args[0], True) op2 = self.r_parenthesis(args[1], True) if not self.is_visible(op1, op2): ans = "{op1} {op2}".format(op1 = op1, op2 = op2) else: ans = link.format(op1 = op1, op2 = op2) ans = save_mainOp(ans, self) return ans # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: # cursor: 16 del