Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Better fix to \left \right issue in TexMobject

Grant Sandersondeef7a486407
diff --git a/mobject/svg/tex_mobject.py b/mobject/svg/tex_mobject.py
index 3c631820e..d9e3de395 100644
--- a/mobject/svg/tex_mobject.py
+++ b/mobject/svg/tex_mobject.py
@@ -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):