From c45ff910f0790a3aeeccf10c855910f231a7f9b5 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 8 Apr 2021 14:46:03 -0700 Subject: [PATCH] Remove double brace convention, since it causes errors with a number of tex strings --- example_scenes.py | 30 ++++++++++++++++------------- manimlib/mobject/svg/tex_mobject.py | 6 ++---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/example_scenes.py b/example_scenes.py index a005fee9..10484451 100644 --- a/example_scenes.py +++ b/example_scenes.py @@ -161,20 +161,24 @@ class TexTransformExample(Scene): def construct(self): to_isolate = ["B", "C", "=", "(", ")"] lines = VGroup( - # Surrounding substrings with double braces - # will ensure that those parts are separated - # out in the Tex. For example, here the - # Tex will have 5 submobjects, corresponding - # to the strings [A^2, +, B^2, =, C^2] - Tex("{{A^2}} + {{B^2}} = {{C^2}}"), - Tex("{{A^2}} = {{C^2}} - {{B^2}}"), + # Passing in muliple arguments to Tex will result + # in the same expression as if those arguments had + # been joined together, except that the submobject + # heirarchy of the resulting mobject ensure that the + # Tex mobject has a subject corresponding to + # each of these strings. For example, the Tex mobject + # below will have 5 subjects, corresponding to the + # expressions [A^2, +, B^2, =, C^2] + Tex("A^2", "+", "B^2", "=", "C^2"), + # Likewise here + Tex("A^2", "=", "C^2", "-", "B^2"), # Alternatively, you can pass in the keyword argument # "isolate" with a list of strings that should be out as - # their own submobject. So both lines below are equivalent - # to what you'd get by wrapping every instance of "B", "C" - # "=", "(" and ")" with double braces - Tex("{{A^2}} = (C + B)(C - B)", isolate=to_isolate), - Tex("A = \\sqrt{(C + B)(C - B)}", isolate=to_isolate) + # their own submobject. So the line below is equivalent + # to the commented out line below it. + Tex("A^2 = (C + B)(C - B)", isolate=["A^2", *to_isolate]), + # Tex("A^2", "=", "(", "C", "+", "B", ")", "(", "C", "-", "B", ")"), + Tex("A = \\sqrt{(C + B)(C - B)}", isolate=["A", *to_isolate]) ) lines.arrange(DOWN, buff=LARGE_BUFF) for line in lines: @@ -233,7 +237,7 @@ class TexTransformExample(Scene): # new_line2 and the "\sqrt" from the final line. By passing in, # transform_mismatches=True, it will transform this "^2" part into # the "\sqrt" part. - new_line2 = Tex("{{A}}^2 = (C + B)(C - B)", isolate=to_isolate) + new_line2 = Tex("A^2 = (C + B)(C - B)", isolate=["A", *to_isolate]) new_line2.replace(lines[2]) new_line2.match_style(lines[2]) diff --git a/manimlib/mobject/svg/tex_mobject.py b/manimlib/mobject/svg/tex_mobject.py index 0818c4b1..8cebe1f5 100644 --- a/manimlib/mobject/svg/tex_mobject.py +++ b/manimlib/mobject/svg/tex_mobject.py @@ -172,14 +172,12 @@ class Tex(SingleStringTex): self.organize_submobjects_left_to_right() def break_up_tex_strings(self, tex_strings): - # Separate out anything surrounded in double braces - patterns = ["{{", "}}"] # Separate out any strings specified in the isolate # or tex_to_color_map lists. - patterns.extend([ + patterns = ( "({})".format(re.escape(ss)) for ss in it.chain(self.isolate, self.tex_to_color_map.keys()) - ]) + ) pattern = "|".join(patterns) pieces = [] for s in tex_strings: