A community-maintained Python framework for creating mathematical animations.
Tex working with artifacts
Devin Nealab8b92d122ac
diff --git a/example_scenes/basic.py b/example_scenes/basic.pyindex 67444be34..bc34233c6 100644--- a/example_scenes/basic.py+++ b/example_scenes/basic.py@@ -14,6 +14,15 @@ from manim import *# for a 1920x1080 video)+class TestLatex(Scene):+ def construct(self):+ # mob = SVGMobject("../manim/media/Tex/1e2155e0e4bdc7ad.svg").scale(3)+ # mob.set_color(WHITE)+ # self.play(FadeIn(mob))+ mob = MathTex("a")+ self.play(FadeIn(mob))++class OpeningManim(Scene):def construct(self):title = Tex(r"This is some \LaTeX")diff --git a/example_scenes/opengl.py b/example_scenes/opengl.pyindex d634e9680..48fcc90d4 100644--- a/example_scenes/opengl.py+++ b/example_scenes/opengl.py@@ -8,6 +8,15 @@ from pathlib import Path# Lines that do not yet work with the Community Version are commented.+class TestLatex(Scene):+ def construct(self):+ # mob = OpenGLSVGMobject("../manim/media/Tex/184715fb937073ce.svg").scale(3)+ # mob.set_color(WHITE)+ mob = OpenGLTex("Manim Community").set_width(13)+ self.play(Write(mob))+ self.wait(10)++class InteractiveDevelopment(Scene):def construct(self):circle = OpenGLCircle()diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 13a654403..0835a707e 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -206,7 +206,10 @@ class Mobject(Container):return resultdef __repr__(self):- return str(self.name)+ if config["use_opengl_renderer"]:+ return super().__repr__()+ else:+ return str(self.name)def reset_points(self):"""Sets :attr:`points` to be an empty array."""diff --git a/manim/mobject/svg/opengl_svg_mobject.py b/manim/mobject/svg/opengl_svg_mobject.pynew file mode 100644index 000000000..38830a1d9--- /dev/null+++ b/manim/mobject/svg/opengl_svg_mobject.py@@ -0,0 +1,34 @@+from ..types.opengl_vectorized_mobject import OpenGLVMobject+from ..svg.svg_mobject import SVGMobject+from .style_utils import cascade_element_style, parse_style+from .opengl_svg_path import OpenGLSVGPathMobject+from ...constants import *+++class OpenGLSVGMobject(OpenGLVMobject, SVGMobject):+ def __init__(+ self,+ file_name=None,+ should_center=True,+ height=2,+ width=None,+ unpack_groups=True, # if False, creates a hierarchy of VGroups+ stroke_width=DEFAULT_STROKE_WIDTH,+ fill_opacity=1.0,+ **kwargs,+ ):+ self.def_map = {}+ self.file_name = file_name or self.file_name+ self.ensure_valid_file()+ self.should_center = should_center+ self.unpack_groups = unpack_groups+ OpenGLVMobject.__init__(+ self, stroke_width=stroke_width, fill_opacity=fill_opacity, **kwargs+ )+ self.move_into_position(width, height)++ def init_points(self):+ self.generate_points()++ def path_string_to_mobject(self, path_string: str, style: dict):+ return OpenGLSVGPathMobject(path_string, **parse_style(style))diff --git a/manim/mobject/svg/opengl_svg_path.py b/manim/mobject/svg/opengl_svg_path.pynew file mode 100644index 000000000..0fc872430--- /dev/null+++ b/manim/mobject/svg/opengl_svg_path.py@@ -0,0 +1,16 @@+import numpy as np+from ..types.opengl_vectorized_mobject import OpenGLVMobject+from .svg_path import SVGPathMobject+++class OpenGLSVGPathMobject(OpenGLVMobject, SVGPathMobject):+ def __init__(self, path_string, **kwargs):+ self.path_string = path_string+ OpenGLVMobject.__init__(self, **kwargs)+ self.current_path_start = np.zeros((1, self.dim))++ def init_points(self):+ self.generate_points()++ def start_new_path(self, point):+ SVGPathMobject.start_new_path(self, point)diff --git a/manim/mobject/svg/opengl_tex_mobject.py b/manim/mobject/svg/opengl_tex_mobject.pynew file mode 100644index 000000000..bc006d441--- /dev/null+++ b/manim/mobject/svg/opengl_tex_mobject.py@@ -0,0 +1,607 @@+r"""Mobjects representing text rendered using LaTeX.+++The Tex mobject+++++++++++++++++Just as you can use :class:`~.Text` to add text to your videos, you can use :class:`~.Tex` to insert LaTeX.++.. manim:: HelloLaTeX+ :save_last_frame:++ class HelloLaTeX(Scene):+ def construct(self):+ tex = Tex(r'\LaTeX').scale(3)+ self.add(tex)++Note that we are using a raw string (``r'---'``) instead of a regular string (``'---'``).+This is because TeX code uses a lot of special characters - like ``\`` for example -+that have special meaning within a regular python string. An alternative would have+been to write ``\\`` as in ``Tex('\\LaTeX')``.++The MathTex mobject+++++++++++++++++++++Anything enclosed in ``$`` signs is interpreted as maths-mode:++.. manim:: HelloTex+ :save_last_frame:++ class HelloTex(Scene):+ def construct(self):+ tex = Tex(r'$\xrightarrow{x^2y^3}$ \LaTeX').scale(3)+ self.add(tex)++Whereas in a :class:`~.MathTex` mobject everything is math-mode by default.++.. manim:: MovingBraces++ class MovingBraces(Scene):+ def construct(self):+ text=MathTex(+ "\\frac{d}{dx}f(x)g(x)=", #0+ "f(x)\\frac{d}{dx}g(x)", #1+ "+", #2+ "g(x)\\frac{d}{dx}f(x)" #3+ )+ self.play(Write(text))+ brace1 = Brace(text[1], UP, buff=SMALL_BUFF)+ brace2 = Brace(text[3], UP, buff=SMALL_BUFF)+ t1 = brace1.get_text("$g'f$")+ t2 = brace2.get_text("$f'g$")+ self.play(+ GrowFromCenter(brace1),+ FadeIn(t1),+ )+ self.wait()+ self.play(+ ReplacementTransform(brace1,brace2),+ ReplacementTransform(t1,t2)+ )+ self.wait()+++LaTeX commands and keyword arguments++++++++++++++++++++++++++++++++++++++We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` math-text type, or the ``looparrowright`` arrow.++.. manim:: AMSLaTeX+ :save_last_frame:++ class AMSLaTeX(Scene):+ def construct(self):+ tex = Tex(r'$\mathtt{H} \looparrowright$ \LaTeX').scale(3)+ self.add(tex)++On the manim side, the :class:`~.Tex` class also accepts attributes to change the appearance of the output.+This is very similar to the :class:`~.Text` class. For example, the ``color`` keyword changes the color of the TeX mobject:++.. manim:: LaTeXAttributes+ :save_last_frame:++ class LaTeXAttributes(Scene):+ def construct(self):+ tex = Tex(r'Hello \LaTeX', color=BLUE).scale(3)+ self.add(tex)++Extra LaTeX Packages++++++++++++++++++++++Some commands require special packages to be loaded into the TeX template. For example,+to use the ``mathscr`` script, we need to add the ``mathrsfs`` package. Since this package isn't loaded+into manim's tex template by default, we add it manually:++.. manim:: AddPackageLatex+ :save_last_frame:++ class AddPackageLatex(Scene):+ def construct(self):+ myTemplate = TexTemplate()+ myTemplate.add_to_preamble(r"\usepackage{mathrsfs}")+ tex = Tex(r'$\mathscr{H} \rightarrow \mathbb{H}$}', tex_template=myTemplate).scale(3)+ self.add(tex)++Substrings and parts++++++++++++++++++++++The TeX mobject can accept multiple strings as arguments. Afterwards you can refer to the individual+parts either by their index (like ``tex[1]``), or you can look them up by (parts of) the tex code like+in this example where we set the color of the ``\bigstar`` using :func:`~.set_color_by_tex`:++.. manim:: LaTeXSubstrings+ :save_last_frame:++ class LaTeXSubstrings(Scene):+ def construct(self):+ tex = Tex('Hello', r'$\bigstar$', r'\LaTeX').scale(3)+ tex.set_color_by_tex('igsta', RED)+ self.add(tex)++LaTeX Maths Fonts - The Template Library++++++++++++++++++++++++++++++++++++++++++Changing fonts in LaTeX when typesetting mathematical formulae is a little bit more tricky than+with regular text. It requires changing the template that is used to compile the tex code.+Manim comes with a collection of :class:`~.TexFontTemplates` ready for you to use. These templates will all work+in maths mode:++.. manim:: LaTeXMathFonts+ :save_last_frame:++ class LaTeXMathFonts(Scene):+ def construct(self):+ tex = Tex(r'$x^2 + y^2 = z^2$', tex_template=TexFontTemplates.french_cursive).scale(3)+ self.add(tex)++Manim also has a :class:`~.TexTemplateLibrary` containing the TeX templates used by 3Blue1Brown. One example+is the ctex template, used for typesetting Chinese. For this to work, the ctex LaTeX package+must be installed on your system. Furthermore, if you are only typesetting Text, you probably do not+need :class:`~.Tex` at all, and should use :class:`~.Text` or :class:`~.PangoText` instead.++.. manim:: LaTeXTemplateLibrary+ :save_last_frame:++ class LaTeXTemplateLibrary(Scene):+ def construct(self):+ tex = Tex('Hello 你好 \\LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3)+ self.add(tex)+++Aligning formulae+++++++++++++++++++A :class:`~.MathTex` mobject is typeset in the LaTeX ``align*`` environment. This means you can use the ``&`` alignment+character when typesetting multiline formulae:++.. manim:: LaTeXAlignEnvironment+ :save_last_frame:++ class LaTeXAlignEnvironment(Scene):+ def construct(self):+ tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6').scale(2)+ self.add(tex)+"""++__all__ = [+ "OpenGLTexSymbol",+ "OpenGLSingleStringMathTex",+ "OpenGLMathTex",+ "OpenGLTex",+ "OpenGLBulletedList",+ "OpenGLTitle",+ "OpenGLTexMobject",+ "OpenGLTextMobject",+]+++from functools import reduce+import operator as op++from .style_utils import parse_style+from ... import config, logger+from ...constants import *+from ...mobject.opengl_geometry import OpenGLLine+from ...mobject.svg.opengl_svg_mobject import OpenGLSVGMobject+from ...mobject.svg.opengl_svg_path import OpenGLSVGPathMobject+from ...mobject.types.opengl_vectorized_mobject import OpenGLVGroup+from ...mobject.types.opengl_vectorized_mobject import OpenGLVectorizedPoint+from ...utils.strings import split_string_list_to_isolate_substrings+from ...utils.tex_file_writing import tex_to_svg_file+from ...utils.color import BLACK++# from ...utils.tex import TexTemplate++TEX_MOB_SCALE_FACTOR = 0.05+++class OpenGLTexSymbol(OpenGLSVGPathMobject):+ """Purely a renaming of SVGPathMobject."""++ pass+++class OpenGLSingleStringMathTex(OpenGLSVGMobject):+ """Elementary building block for rendering text with LaTeX.++ Tests+ -----+ Check that creating a :class:`~.SingleStringMathTex` object works::++ >>> SingleStringMathTex('Test')+ SingleStringMathTex('Test')+ """++ def __init__(+ self,+ tex_string,+ stroke_width=0,+ fill_opacity=1.0,+ background_stroke_width=0,+ background_stroke_color=BLACK,+ should_center=True,+ height=None,+ organize_left_to_right=False,+ tex_environment="align*",+ tex_template=None,+ **kwargs,+ ):+ self.organize_left_to_right = organize_left_to_right+ self.tex_environment = tex_environment+ if tex_template is None:+ tex_template = config["tex_template"]+ self.tex_template = tex_template++ assert isinstance(tex_string, str)+ self.tex_string = tex_string+ file_name = tex_to_svg_file(+ self.get_modified_expression(tex_string),+ environment=self.tex_environment,+ tex_template=self.tex_template,+ )+ OpenGLSVGMobject.__init__(+ self,+ file_name=file_name,+ should_center=should_center,+ stroke_width=stroke_width,+ height=height,+ fill_opacity=fill_opacity,+ background_stroke_width=background_stroke_width,+ background_stroke_color=background_stroke_color,+ **kwargs,+ )+ if height is None:+ self.scale(TEX_MOB_SCALE_FACTOR)+ if self.organize_left_to_right:+ self.organize_submobjects_left_to_right()++ def __repr__(self):+ return f"{type(self).__name__}({repr(self.tex_string)})"++ def get_modified_expression(self, tex_string):+ result = tex_string+ result = result.strip()+ result = self.modify_special_strings(result)+ return result++ def modify_special_strings(self, tex):+ tex = self.remove_stray_braces(tex)+ should_add_filler = reduce(+ op.or_,+ [+ # Fraction line needs something to be over+ tex == "\\over",+ tex == "\\overline",+ # Make sure sqrt has overbar+ tex == "\\sqrt",+ # Need to add blank subscript or superscript+ tex.endswith("_"),+ tex.endswith("^"),+ tex.endswith("dot"),+ ],+ )+ if should_add_filler:+ filler = "{\\quad}"+ tex += filler++ if tex == "\\substack":+ tex = "\\quad"++ if tex == "":+ tex = "\\quad"++ # To keep files from starting with a line break+ if tex.startswith("\\\\"):+ tex = tex.replace("\\\\", "\\quad\\\\")++ # Handle imbalanced \left and \right+ num_lefts, num_rights = [+ len([s for s in tex.split(substr)[1:] if s and s[0] in "(){}[]|.\\"])+ for substr in ("\\left", "\\right")+ ]+ if num_lefts != num_rights:+ tex = tex.replace("\\left", "\\big")+ tex = tex.replace("\\right", "\\big")++ for context in ["array"]:+ begin_in = ("\\begin{%s}" % context) in tex+ end_in = ("\\end{%s}" % context) in tex+ if begin_in ^ end_in:+ # Just turn this into a blank string,+ # which means caller should leave a+ # stray \\begin{...} with other symbols+ tex = ""+ return tex++ def remove_stray_braces(self, tex):+ r"""+ Makes :class:`~.MathTex` resilient to unmatched braces.++ This is important when the braces in the TeX code are spread over+ multiple arguments as in, e.g., ``MathTex(r"e^{i", r"\tau} = 1")``.+ """++ # "\{" does not count (it's a brace literal), but "\\{" counts (it's a new line and then brace)+ num_lefts = tex.count("{") - tex.count("\\{") + tex.count("\\\\{")+ num_rights = tex.count("}") - tex.count("\\}") + tex.count("\\\\}")+ while num_rights > num_lefts:+ tex = "{" + tex+ num_lefts += 1+ while num_lefts > num_rights:+ tex = tex + "}"+ num_rights += 1+ return tex++ def get_tex_string(self):+ return self.tex_string++ def path_string_to_mobject(self, path_string, style):+ # Overwrite superclass default to use+ # specialized path_string mobject+ return OpenGLTexSymbol(path_string, **parse_style(style))++ def organize_submobjects_left_to_right(self):+ self.sort(lambda p: p[0])+ return self++ def init_colors(self, propagate_colors=True):+ # OpenGLSVGMobject.init_colors(self, propagate_colors=propagate_colors)+ OpenGLSVGMobject.set_style(+ self,+ fill_color=self.fill_color or self.color,+ fill_opacity=self.fill_opacity,+ stroke_color=self.stroke_color or self.color,+ stroke_width=self.stroke_width,+ stroke_opacity=self.stroke_opacity,+ recurse=propagate_colors,+ )+++class OpenGLMathTex(OpenGLSingleStringMathTex):+ r"""A string compiled with LaTeX in math mode.++ Examples+ --------+ .. manim:: Formula+ :save_last_frame:++ class Formula(Scene):+ def construct(self):+ t = MathTex(r"\int_a^b f'(x) dx = f(b)- f(a)")+ self.add(t)++ Tests+ -----+ Check that creating a :class:`~.MathTex` works::++ >>> MathTex('a^2 + b^2 = c^2')+ MathTex('a^2 + b^2 = c^2')++ """++ def __init__(+ self,+ *tex_strings,+ arg_separator=" ",+ substrings_to_isolate=None,+ tex_to_color_map=None,+ tex_environment="align*",+ **kwargs,+ ):+ self.tex_template = kwargs.pop("tex_template", config["tex_template"])+ self.arg_separator = arg_separator+ self.substrings_to_isolate = (+ [] if substrings_to_isolate is None else substrings_to_isolate+ )+ self.tex_to_color_map = tex_to_color_map+ if self.tex_to_color_map is None:+ self.tex_to_color_map = {}+ self.tex_environment = tex_environment+ tex_strings = self.break_up_tex_strings(tex_strings)+ self.tex_strings = tex_strings+ OpenGLSingleStringMathTex.__init__(+ self,+ self.arg_separator.join(tex_strings),+ tex_environment=self.tex_environment,+ tex_template=self.tex_template,+ **kwargs,+ )+ self.break_up_by_substrings()+ self.set_color_by_tex_to_color_map(self.tex_to_color_map)++ if self.organize_left_to_right:+ self.organize_submobjects_left_to_right()++ def break_up_tex_strings(self, tex_strings):+ substrings_to_isolate = op.add(+ self.substrings_to_isolate, list(self.tex_to_color_map.keys())+ )+ split_list = split_string_list_to_isolate_substrings(+ tex_strings, *substrings_to_isolate+ )+ if self.arg_separator == " ":+ split_list = [str(x).strip() for x in split_list]+ # split_list = list(map(str.strip, split_list))+ split_list = [s for s in split_list if s != ""]+ return split_list++ def break_up_by_substrings(self):+ """+ Reorganize existing submobjects one layer+ deeper based on the structure of tex_strings (as a list+ of tex_strings)+ """+ new_submobjects = []+ curr_index = 0+ for tex_string in self.tex_strings:+ sub_tex_mob = OpenGLSingleStringMathTex(+ tex_string,+ tex_environment=self.tex_environment,+ tex_template=self.tex_template,+ )+ num_submobs = len(sub_tex_mob.submobjects)+ new_index = curr_index + num_submobs+ if num_submobs == 0:+ # For cases like empty tex_strings, we want the corresponding+ # part of the whole MathTex to be a VectorizedPoint+ # positioned in the right part of the MathTex+ sub_tex_mob.submobjects = [OpenGLVectorizedPoint()]+ last_submob_index = min(curr_index, len(self.submobjects) - 1)+ sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT)+ else:+ sub_tex_mob.submobjects = self.submobjects[curr_index:new_index]+ new_submobjects.append(sub_tex_mob)+ curr_index = new_index+ self.submobjects = new_submobjects+ return self++ def get_parts_by_tex(self, tex, substring=True, case_sensitive=True):+ def test(tex1, tex2):+ if not case_sensitive:+ tex1 = tex1.lower()+ tex2 = tex2.lower()+ if substring:+ return tex1 in tex2+ else:+ return tex1 == tex2++ return OpenGLVGroup(+ *[m for m in self.submobjects if test(tex, m.get_tex_string())]+ )++ def get_part_by_tex(self, tex, **kwargs):+ all_parts = self.get_parts_by_tex(tex, **kwargs)+ return all_parts[0] if all_parts else None++ def set_color_by_tex(self, tex, color, **kwargs):+ parts_to_color = self.get_parts_by_tex(tex, **kwargs)+ for part in parts_to_color:+ part.set_color(color)+ return self++ def set_color_by_tex_to_color_map(self, texs_to_color_map, **kwargs):+ for texs, color in list(texs_to_color_map.items()):+ try:+ # If the given key behaves like tex_strings+ texs + ""+ self.set_color_by_tex(texs, color, **kwargs)+ except TypeError:+ # If the given key is a tuple+ for tex in texs:+ self.set_color_by_tex(tex, color, **kwargs)+ return self++ def index_of_part(self, part):+ split_self = self.split()+ if part not in split_self:+ raise ValueError("Trying to get index of part not in MathTex")+ return split_self.index(part)++ def index_of_part_by_tex(self, tex, **kwargs):+ part = self.get_part_by_tex(tex, **kwargs)+ return self.index_of_part(part)++ def sort_alphabetically(self):+ self.submobjects.sort(key=lambda m: m.get_tex_string())+++class OpenGLTex(OpenGLMathTex):+ r"""A string compiled with LaTeX in normal mode.++ Tests+ -----++ Check whether writing a LaTeX string works::++ >>> Tex('The horse does not eat cucumber salad.')+ Tex('The horse does not eat cucumber salad.')++ """++ def __init__(+ self, *tex_strings, arg_separator="", tex_environment="center", **kwargs+ ):+ OpenGLMathTex.__init__(+ self,+ *tex_strings,+ arg_separator=arg_separator,+ tex_environment=tex_environment,+ **kwargs,+ )+++class OpenGLBulletedList(OpenGLTex):+ def __init__(+ self,+ *items,+ buff=MED_LARGE_BUFF,+ dot_scale_factor=2,+ tex_environment=None,+ **kwargs,+ ):+ self.buff = buff+ self.dot_scale_factor = dot_scale_factor+ self.tex_environment = tex_environment+ line_separated_items = [s + "\\\\" for s in items]+ Tex.__init__(+ self, *line_separated_items, tex_environment=tex_environment, **kwargs+ )+ for part in self:+ dot = MathTex("\\cdot").scale(self.dot_scale_factor)+ dot.next_to(part[0], LEFT, SMALL_BUFF)+ part.add_to_back(dot)+ self.arrange(DOWN, aligned_edge=LEFT, buff=self.buff)++ def fade_all_but(self, index_or_string, opacity=0.5):+ arg = index_or_string+ if isinstance(arg, str):+ part = self.get_part_by_tex(arg)+ elif isinstance(arg, int):+ part = self.submobjects[arg]+ else:+ raise TypeError(f"Expected int or string, got {arg}")+ for other_part in self.submobjects:+ if other_part is part:+ other_part.set_fill(opacity=1)+ else:+ other_part.set_fill(opacity=opacity)+++class OpenGLTitle(OpenGLTex):+ def __init__(+ self,+ *text_parts,+ scale_factor=1,+ include_underline=True,+ match_underline_width_to_text=False,+ underline_buff=MED_SMALL_BUFF,+ **kwargs,+ ):+ self.scale_factor = scale_factor+ self.include_underline = include_underline+ self.match_underline_width_to_text = match_underline_width_to_text+ self.underline_buff = underline_buff+ Tex.__init__(self, *text_parts, **kwargs)+ self.scale(self.scale_factor)+ self.to_edge(UP)+ if self.include_underline:+ underline_width = config["frame_width"] - 2+ underline = OpenGLLine(LEFT, RIGHT)+ underline.next_to(self, DOWN, buff=self.underline_buff)+ if self.match_underline_width_to_text:+ underline.match_width(self)+ else:+ underline.width = underline_width+ self.add(underline)+ self.underline = underline+++class OpenGLTexMobject(OpenGLMathTex):+ def __init__(self, *tex_strings, **kwargs):+ logger.warning(+ "TexMobject has been deprecated (due to its confusing name) "+ "in favour of MathTex. Please use MathTex instead!"+ )+ MathTex.__init__(self, *tex_strings, **kwargs)+++class OpenGLTextMobject(OpenGLTex):+ def __init__(self, *text_parts, **kwargs):+ logger.warning(+ "TextMobject has been deprecated (due to its confusing name) "+ "in favour of Tex. Please use Tex instead!"+ )+ Tex.__init__(self, *text_parts, **kwargs)diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.pyindex 2d431019b..6145b982a 100644--- a/manim/mobject/svg/svg_mobject.py+++ b/manim/mobject/svg/svg_mobject.py@@ -22,9 +22,11 @@ from ... import configfrom ...constants import *from ...mobject.geometry import Circlefrom ...mobject.geometry import Rectangle+from ...mobject.opengl_geometry import OpenGLRectanglefrom ...mobject.geometry import RoundedRectanglefrom ...mobject.types.vectorized_mobject import VGroupfrom ...mobject.types.vectorized_mobject import VMobject+from ...mobject.types.opengl_vectorized_mobject import OpenGLVGroupclass SVGMobject(VMobject):@@ -199,9 +201,15 @@ class SVGMobject(VMobject):pass # TODOresult = [m for m in result if m is not None]- self.handle_transforms(element, VGroup(*result))+ if config["use_opengl_renderer"]:+ self.handle_transforms(element, OpenGLVGroup(*result))+ else:+ self.handle_transforms(element, VGroup(*result))if len(result) > 1 and not self.unpack_groups:- result = [VGroup(*result)]+ if config["use_opengl_renderer"]:+ result = [OpenGLVGroup(*result)]+ else:+ result = [VGroup(*result)]if within_defs and element.hasAttribute("id"):# it seems wasteful to throw away the actual element,@@ -399,11 +407,19 @@ class SVGMobject(VMobject):parsed_style["stroke_width"] = stroke_widthif corner_radius == 0:- mob = Rectangle(- width=self.attribute_to_float(rect_element.getAttribute("width")),- height=self.attribute_to_float(rect_element.getAttribute("height")),- **parsed_style,- )+ if config["use_opengl_renderer"]:+ mob = OpenGLRectangle(+ width=self.attribute_to_float(rect_element.getAttribute("width")),+ height=self.attribute_to_float(rect_element.getAttribute("height")),+ **parsed_style,+ )+ else:+ mob = Rectangle(+ width=self.attribute_to_float(rect_element.getAttribute("width")),+ height=self.attribute_to_float(rect_element.getAttribute("height")),+ **parsed_style,+ )+else:mob = RoundedRectangle(width=self.attribute_to_float(rect_element.getAttribute("width")),diff --git a/manim/mobject/svg/svg_path.py b/manim/mobject/svg/svg_path.pyindex 836932d2d..4ccb34422 100644--- a/manim/mobject/svg/svg_path.py+++ b/manim/mobject/svg/svg_path.py@@ -12,6 +12,7 @@ from manim import loggerfrom ...constants import *from ...mobject.types.vectorized_mobject import VMobject+from ... import configdef string_to_numbers(num_string: str) -> List[float]:@@ -99,9 +100,11 @@ class SVGPathMobject(VMobject):command = command.upper()# Keep track of the most recently completed point- start_point = (- self.points[-1] if self.points.shape[0] else np.zeros((1, self.dim))- )+ if config["use_opengl_renderer"]:+ points = self.data["points"]+ else:+ points = self.points+ start_point = points[-1] if points.shape[0] else np.zeros((1, self.dim))# Produce the (absolute) coordinates of the controls and handlesnew_points = self.string_to_points(@@ -126,9 +129,13 @@ class SVGPathMobject(VMobject):returnelif command == "S": # Smooth cubic+ if config["use_opengl_renderer"]:+ points = self.data["points"]+ else:+ points = self.pointsprev_handle = start_pointif prev_command.upper() in ["C", "S"]:- prev_handle = self.points[-2]+ prev_handle = points[-2]for i in range(0, len(new_points), 2):new_handle = 2 * start_point - prev_handleself.add_cubic_bezier_curve_to(@@ -148,7 +155,7 @@ class SVGPathMobject(VMobject):if prev_command.upper() in ["Q", "T"]:# because of the conversion from quadratic to cubic,# our actual previous handle was 3/2 in the direction of p[-2] from p[-1]- prev_quad_handle = 1.5 * self.points[-2] - 0.5 * self.points[-1]+ prev_quad_handle = 1.5 * points[-2] - 0.5 * points[-1]for p in new_points:new_quad_handle = 2 * start_point - prev_quad_handleself.add_quadratic_bezier_curve_to(new_quad_handle, p)diff --git a/manim/opengl/__init__.py b/manim/opengl/__init__.pyindex 09f2aadd8..e275c6a41 100644--- a/manim/opengl/__init__.py+++ b/manim/opengl/__init__.py@@ -3,3 +3,6 @@ from ..mobject.types.opengl_vectorized_mobject import *from ..mobject.opengl_geometry import *from ..mobject.types.opengl_surface import *from ..mobject.opengl_three_dimensions import *+from ..mobject.opengl_three_dimensions import *+from ..mobject.svg.opengl_svg_mobject import *+from ..mobject.svg.opengl_tex_mobject import *