Commit 1c3dcd99 by Peter Baratta

Some code fixes

Change some `is` comparison to `==`. Also, modify the `render_atom` method.
parent 28a1ca8a
...@@ -177,9 +177,9 @@ def eval_sum(parse_result): ...@@ -177,9 +177,9 @@ def eval_sum(parse_result):
total = 0.0 total = 0.0
current_op = operator.add current_op = operator.add
for token in parse_result: for token in parse_result:
if token is '+': if token == '+':
current_op = operator.add current_op = operator.add
elif token is '-': elif token == '-':
current_op = operator.sub current_op = operator.sub
else: else:
total = current_op(total, token) total = current_op(total, token)
...@@ -195,9 +195,9 @@ def eval_product(parse_result): ...@@ -195,9 +195,9 @@ def eval_product(parse_result):
prod = 1.0 prod = 1.0
current_op = operator.mul current_op = operator.mul
for token in parse_result: for token in parse_result:
if token is '*': if token == '*':
current_op = operator.mul current_op = operator.mul
elif token is '/': elif token == '/':
current_op = operator.truediv current_op = operator.truediv
else: else:
prod = current_op(prod, token) prod = current_op(prod, token)
......
...@@ -253,16 +253,14 @@ def render_atom(children): ...@@ -253,16 +253,14 @@ def render_atom(children):
""" """
Properly handle parens, otherwise this is trivial. Properly handle parens, otherwise this is trivial.
""" """
parens = None if len(children) == 3:
if children[0].latex in "([{":
# then len(children) == 3
parens = children[0].latex
children = [children[1]]
return LatexRendered( return LatexRendered(
children[0].latex, children[1].latex,
parens, parens=children[0].latex,
children[0].tall tall=children[1].tall
) )
else:
return children[0]
def latex_preview(math_expr, variables=(), functions=(), case_sensitive=False): def latex_preview(math_expr, variables=(), functions=(), case_sensitive=False):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment