Render momonial and multiply with scalar
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
from mapytex.calculus.core.tree import Tree
|
||||
from .mo import MO, MOnumber, MOstr
|
||||
from .exceptions import MOError
|
||||
from ..renders import tree2txt, tree2tex
|
||||
|
||||
__all__ = ["MOMonomial"]
|
||||
|
||||
@@ -27,6 +28,10 @@ class MOMonomial(MO):
|
||||
<MOMonomial 4x^2>
|
||||
>>> MOMonomial(4, "x", 1)
|
||||
<MOMonomial 4x>
|
||||
>>> MOMonomial(1, "x", 2)
|
||||
<MOMonomial x^2>
|
||||
>>> MOMonomial(1, "x", 1)
|
||||
<MOMonomial x>
|
||||
>>> MOMonomial(4, 3, 1)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
@@ -79,6 +84,39 @@ class MOMonomial(MO):
|
||||
self._variable,
|
||||
)
|
||||
|
||||
@property
|
||||
def __txt__(self):
|
||||
try:
|
||||
if self._coefficient == 1:
|
||||
try:
|
||||
return tree2txt(self.value.right_value)
|
||||
except AttributeError:
|
||||
return str(self.value.right_value)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return tree2txt(self.value)
|
||||
except AttributeError:
|
||||
return str(self.value)
|
||||
|
||||
@property
|
||||
def __tex__(self):
|
||||
try:
|
||||
if self._coefficient == 1:
|
||||
try:
|
||||
return tree2tex(self.value.right_value)
|
||||
except AttributeError:
|
||||
return str(self.value.right_value)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return tree2tex(self.value)
|
||||
except AttributeError:
|
||||
return str(self.value)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
|
Reference in New Issue
Block a user