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