Better fix to \left \right issue in TexMobject

This commit is contained in:
Grant Sanderson
2018-05-19 11:09:59 -07:00
parent 2a65c93918
commit deef7a4864

View File

@@ -81,17 +81,22 @@ class SingleStringTexMobject(SVGMobject):
tex += filler
if tex == "\\substack":
tex = ""
for t1, t2 in ("\\left", "\\right"), ("\\right", "\\left"):
should_replace = reduce(op.and_, [
t1 in tex,
t2 not in tex,
len(tex) > len(t1) and tex[len(t1)] in ["(){}[]|.\\"]
])
if should_replace:
tex = tex.replace(t1, "\\big")
tex = "\\quad"
if tex == "":
tex = "\\quad"
# Handle imbalanced \left and \right
num_lefts, num_rights = [
len(filter(
lambda s: s[0] in "(){}[]|.\\",
tex.split(substr)[1:]
))
for substr in "\\left", "\\right"
]
if num_lefts != num_rights:
tex = tex.replace("\\left", "\\big")
tex = tex.replace("\\right", "\\big")
return tex
def remove_stray_braces(self, tex):