From deef7a48640750a3ffbfe43faf11a8aede9456ee Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Sat, 19 May 2018 11:09:59 -0700 Subject: [PATCH] Better fix to \left \right issue in TexMobject --- mobject/svg/tex_mobject.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/mobject/svg/tex_mobject.py b/mobject/svg/tex_mobject.py index 3c631820..d9e3de39 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):