Style: apply black

This commit is contained in:
2019-05-14 06:55:56 +02:00
parent 7097801306
commit 09b04d2703
35 changed files with 533 additions and 354 deletions

View File

@@ -8,7 +8,8 @@
from mapytex.calculus.core.operator import OPERATORS
__all__ = ['tree2tex']
__all__ = ["tree2tex"]
def plus2tex(left, right):
r""" + rendering
@@ -51,6 +52,7 @@ def plus2tex(left, right):
return f"{left_} {right_}"
def minus2tex(left, right):
r""" - rendering
@@ -64,7 +66,7 @@ def minus2tex(left, right):
"""
try:
right_need_parenthesis = False
if OPERATORS[right.node]["precedence"] < OPERATORS['-']["precedence"]:
if OPERATORS[right.node]["precedence"] < OPERATORS["-"]["precedence"]:
right_need_parenthesis = True
except AttributeError:
right_ = right.__tex__
@@ -76,6 +78,7 @@ def minus2tex(left, right):
return f"- {right_}"
def mul2tex(left, right):
r""" * rendering
@@ -101,14 +104,16 @@ def mul2tex(left, right):
right_ = render_with_parenthesis(right, "*")
display_time = True
if (right_[0].isalpha() and (left_.isnumeric() or left_.isdecimal())) or \
right_[0] == '(':
display_time = False
if (right_[0].isalpha() and (left_.isnumeric() or left_.isdecimal())) or right_[
0
] == "(":
display_time = False
if display_time:
return f"{left_} \\times {right_}"
return f"{left_}{right_}"
def div2tex(left, right):
r""" / rendering
@@ -137,6 +142,7 @@ def div2tex(left, right):
return "\\frac{" + left_ + "}{" + right_ + "}"
def pow2tex(left, right):
r""" ^ rendering
@@ -159,7 +165,7 @@ def pow2tex(left, right):
"""
try:
left_need_parenthesis = False
if OPERATORS[left.node]["precedence"] < OPERATORS['^']["precedence"]:
if OPERATORS[left.node]["precedence"] < OPERATORS["^"]["precedence"]:
left_need_parenthesis = True
except AttributeError:
left_ = left.__tex__
@@ -185,7 +191,10 @@ def render_with_parenthesis(subtree, operator):
subtree.node
except AttributeError:
try:
if OPERATORS[subtree.MAINOP]["precedence"] < OPERATORS[operator]["precedence"]:
if (
OPERATORS[subtree.MAINOP]["precedence"]
< OPERATORS[operator]["precedence"]
):
subtree_need_parenthesis = True
except (AttributeError, KeyError):
pass
@@ -200,13 +209,8 @@ def render_with_parenthesis(subtree, operator):
return subtree_
OPERATOR2TEX = {
"+": plus2tex,
"-": minus2tex,
"*": mul2tex,
"/": div2tex,
"^": pow2tex,
}
OPERATOR2TEX = {"+": plus2tex, "-": minus2tex, "*": mul2tex, "/": div2tex, "^": pow2tex}
def tree2tex(tree):
r""" Convert a tree into its tex version