Modify the way ^ is rendering
This commit is contained in:
parent
eff438b930
commit
6763ae6074
@ -161,17 +161,20 @@ def pow2tex(left, right):
|
||||
|
||||
>>> from ..MO import mo
|
||||
>>> pow2tex(mo.MO(2), mo.MO(3))
|
||||
'2 ^ 3'
|
||||
'2^{3}'
|
||||
>>> from ..tree import Tree
|
||||
>>> t = Tree.from_str("1^2")
|
||||
>>> pow2tex(t, mo.MO(3))
|
||||
'1 ^ 2 ^ 3'
|
||||
'1^{2}^{3}'
|
||||
>>> t = Tree.from_str("1^2")
|
||||
>>> pow2tex(mo.MO(3), t)
|
||||
'3^{1^{2}}'
|
||||
>>> t = Tree.from_str("1+2")
|
||||
>>> pow2tex(t, mo.MO(3))
|
||||
'(1 + 2) ^ 3'
|
||||
'(1 + 2)^{3}'
|
||||
>>> t = Tree.from_str("1*2")
|
||||
>>> pow2tex(mo.MO(3), t)
|
||||
'3 ^ (1 \\times 2)'
|
||||
'3^{1 \\times 2}'
|
||||
"""
|
||||
try:
|
||||
left_need_parenthesis = False
|
||||
@ -184,19 +187,15 @@ def pow2tex(left, right):
|
||||
left_ = f"({tree2tex(left)})"
|
||||
else:
|
||||
left_ = tree2tex(left)
|
||||
|
||||
try:
|
||||
right_need_parenthesis = False
|
||||
if OPERATORS[right.node]["precedence"] < OPERATORS['^']["precedence"]:
|
||||
right_need_parenthesis = True
|
||||
right.node
|
||||
except AttributeError:
|
||||
right_ = right.__tex__
|
||||
else:
|
||||
if right_need_parenthesis:
|
||||
right_ = f"({tree2tex(right)})"
|
||||
else:
|
||||
right_ = tree2tex(right)
|
||||
right_ = tree2tex(right)
|
||||
|
||||
return f"{left_} ^ {right_}"
|
||||
return f"{left_}^{{{right_}}}"
|
||||
|
||||
OPERATOR2TEX = {
|
||||
"+": plus2tex,
|
||||
|
@ -176,17 +176,17 @@ def pow2txt(left, right):
|
||||
|
||||
>>> from ..MO import mo
|
||||
>>> pow2txt(mo.MO(2), mo.MO(3))
|
||||
'2 ^ 3'
|
||||
'2^3'
|
||||
>>> from ..tree import Tree
|
||||
>>> t = Tree.from_str("1^2")
|
||||
>>> pow2txt(t, mo.MO(3))
|
||||
'1 ^ 2 ^ 3'
|
||||
'1^2^3'
|
||||
>>> t = Tree.from_str("1+2")
|
||||
>>> pow2txt(t, mo.MO(3))
|
||||
'(1 + 2) ^ 3'
|
||||
'(1 + 2)^3'
|
||||
>>> t = Tree.from_str("1*2")
|
||||
>>> pow2txt(mo.MO(3), t)
|
||||
'3 ^ (1 * 2)'
|
||||
'3^(1 * 2)'
|
||||
"""
|
||||
try:
|
||||
left_need_parenthesis = False
|
||||
@ -211,7 +211,7 @@ def pow2txt(left, right):
|
||||
else:
|
||||
right_ = tree2txt(right)
|
||||
|
||||
return f"{left_} ^ {right_}"
|
||||
return f"{left_}^{right_}"
|
||||
|
||||
OPERATOR2TXT = {
|
||||
"+": plus2txt,
|
||||
|
Loading…
Reference in New Issue
Block a user