mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Remove double brace convention, since it causes errors with a number of tex strings
This commit is contained in:
parent
15760cf253
commit
c45ff910f0
2 changed files with 19 additions and 17 deletions
|
@ -161,20 +161,24 @@ class TexTransformExample(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
to_isolate = ["B", "C", "=", "(", ")"]
|
to_isolate = ["B", "C", "=", "(", ")"]
|
||||||
lines = VGroup(
|
lines = VGroup(
|
||||||
# Surrounding substrings with double braces
|
# Passing in muliple arguments to Tex will result
|
||||||
# will ensure that those parts are separated
|
# in the same expression as if those arguments had
|
||||||
# out in the Tex. For example, here the
|
# been joined together, except that the submobject
|
||||||
# Tex will have 5 submobjects, corresponding
|
# heirarchy of the resulting mobject ensure that the
|
||||||
# to the strings [A^2, +, B^2, =, C^2]
|
# Tex mobject has a subject corresponding to
|
||||||
Tex("{{A^2}} + {{B^2}} = {{C^2}}"),
|
# each of these strings. For example, the Tex mobject
|
||||||
Tex("{{A^2}} = {{C^2}} - {{B^2}}"),
|
# 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
|
# Alternatively, you can pass in the keyword argument
|
||||||
# "isolate" with a list of strings that should be out as
|
# "isolate" with a list of strings that should be out as
|
||||||
# their own submobject. So both lines below are equivalent
|
# their own submobject. So the line below is equivalent
|
||||||
# to what you'd get by wrapping every instance of "B", "C"
|
# to the commented out line below it.
|
||||||
# "=", "(" and ")" with double braces
|
Tex("A^2 = (C + B)(C - B)", isolate=["A^2", *to_isolate]),
|
||||||
Tex("{{A^2}} = (C + B)(C - B)", isolate=to_isolate),
|
# Tex("A^2", "=", "(", "C", "+", "B", ")", "(", "C", "-", "B", ")"),
|
||||||
Tex("A = \\sqrt{(C + B)(C - B)}", isolate=to_isolate)
|
Tex("A = \\sqrt{(C + B)(C - B)}", isolate=["A", *to_isolate])
|
||||||
)
|
)
|
||||||
lines.arrange(DOWN, buff=LARGE_BUFF)
|
lines.arrange(DOWN, buff=LARGE_BUFF)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
@ -233,7 +237,7 @@ class TexTransformExample(Scene):
|
||||||
# new_line2 and the "\sqrt" from the final line. By passing in,
|
# new_line2 and the "\sqrt" from the final line. By passing in,
|
||||||
# transform_mismatches=True, it will transform this "^2" part into
|
# transform_mismatches=True, it will transform this "^2" part into
|
||||||
# the "\sqrt" part.
|
# 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.replace(lines[2])
|
||||||
new_line2.match_style(lines[2])
|
new_line2.match_style(lines[2])
|
||||||
|
|
||||||
|
|
|
@ -172,14 +172,12 @@ class Tex(SingleStringTex):
|
||||||
self.organize_submobjects_left_to_right()
|
self.organize_submobjects_left_to_right()
|
||||||
|
|
||||||
def break_up_tex_strings(self, tex_strings):
|
def break_up_tex_strings(self, tex_strings):
|
||||||
# Separate out anything surrounded in double braces
|
|
||||||
patterns = ["{{", "}}"]
|
|
||||||
# Separate out any strings specified in the isolate
|
# Separate out any strings specified in the isolate
|
||||||
# or tex_to_color_map lists.
|
# or tex_to_color_map lists.
|
||||||
patterns.extend([
|
patterns = (
|
||||||
"({})".format(re.escape(ss))
|
"({})".format(re.escape(ss))
|
||||||
for ss in it.chain(self.isolate, self.tex_to_color_map.keys())
|
for ss in it.chain(self.isolate, self.tex_to_color_map.keys())
|
||||||
])
|
)
|
||||||
pattern = "|".join(patterns)
|
pattern = "|".join(patterns)
|
||||||
pieces = []
|
pieces = []
|
||||||
for s in tex_strings:
|
for s in tex_strings:
|
||||||
|
|
Loading…
Add table
Reference in a new issue