3b1b / manim

Animation engine for explanatory math videos
MIT License
60.28k stars 5.7k forks source link

issue with animations contains text .. throws warnings and list index out of range. #1276

Open MohaAmiry opened 3 years ago

MohaAmiry commented 3 years ago

using windows 10, latest miktex with all packages, running on python 3.8.6 -not 3.9.0 because scipy doesn't support it yet-, lastest SoX, latest FFmpeg version.

I installed everything important and having no problem running examples with no texts such as (SquareToCircle), but i get warnings and exceptions when running (WriteStuff) or any other text-containing animation:

image

I tried everything, reinstalled everything.. added all important paths(SoX,MikTeX,FFmpeg), edited some parts of (tex_mobject.py) and didn't work so stepped back,i did everything and nothing worked, what could be the reason of the issue..?

NeoPlato commented 3 years ago

Hey man.

The code works fine for me. What you want to do:

class TexMobject(SingleStringTexMobject):
    CONFIG = {
        "arg_separator": " ",
        "substrings_to_isolate": [],
        "tex_to_color_map": {},
    }

    def __init__(self, *tex_strings, **kwargs):
        digest_config(self, kwargs)
        tex_strings = self.break_up_tex_strings(tex_strings)
        self.tex_strings = tex_strings
        SingleStringTexMobject.__init__(
            self, self.arg_separator.join(tex_strings), **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 submojects one layer
        deeper based on the structure of tex_strings (as a list
        of tex_strings)
        """
        new_submobjects = []
        curr_index = 0
        config = dict(self.CONFIG)
        config["alignment"] = ""
        for tex_string in self.tex_strings:
            sub_tex_mob = SingleStringTexMobject(tex_string, **config)
            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 corresponing
                # part of the whole TexMobject to be a VectorizedPoint
                # positioned in the right part of the TexMobject
                sub_tex_mob.submobjects = [VectorizedPoint()]
                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 VGroup(*[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 Exception("Trying to get index of part not in TexMobject")
        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()
        )

Send your implementation of TexMobject. Open the last file in that traceback; that's where it is.

MohaAmiry commented 3 years ago

i used an online merging website to compare my TexMobject class with yours, and they are absolutely the same, not a single difference.. note: mine is on the left, yours on the right: photo_2020-11-18_23-03-41

so the problem isn't from TexMobject class, do you have any other suggestions? and thank you for your reply :D

NeoPlato commented 3 years ago

Oh yes I have quite a number of suggestions.

I've dug a bit deeper into how Manim handles the svg files it produces.

It's not obvious at first but the UserWarnings in g0-84 refer to ids in the svg file. To see what I'm talking about, open the svg file in a web browser and open the source with Ctrl + U.

This is way deeper than I thought. I think I have a quick fix hack that may ruin the working of the code but have that particular bit work. When I understand this code deeper I'll get back to you

NeoPlato commented 3 years ago

So you have an online merging website?

Here's my svg class. Find yours at manimlib\mobject\svg\svg_mobject.py

class SVGMobject(VMobject):
    CONFIG = {
        "should_center": True,
        "height": 2,
        "width": None,
        # Must be filled in in a subclass, or when called
        "file_name": None,
        "unpack_groups": True,  # if False, creates a hierarchy of VGroups
        "stroke_width": DEFAULT_STROKE_WIDTH,
        "fill_opacity": 1.0,
        # "fill_color" : LIGHT_GREY,
    }

    def __init__(self, file_name=None, **kwargs):
        digest_config(self, kwargs)
        self.file_name = file_name or self.file_name
        self.ensure_valid_file()
        VMobject.__init__(self, **kwargs)
        self.move_into_position()

    def ensure_valid_file(self):
        if self.file_name is None:
            raise Exception("Must specify file for SVGMobject")
        possible_paths = [
            os.path.join(os.path.join("assets", "svg_images"), self.file_name),
            os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".svg"),
            os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".xdv"),
            self.file_name,
        ]
        for path in possible_paths:
            if os.path.exists(path):
                self.file_path = path
                return
        raise IOError("No file matching %s in image directory" %
                      self.file_name)

    def generate_points(self):
        doc = minidom.parse(self.file_path)
        self.ref_to_element = {}
        for svg in doc.getElementsByTagName("svg"):
            mobjects = self.get_mobjects_from(svg)
            if self.unpack_groups:
                self.add(*mobjects)
            else:
                self.add(*mobjects[0].submobjects)
        doc.unlink()

    def get_mobjects_from(self, element):
        result = []
        if not isinstance(element, minidom.Element):
            return result
        if element.tagName == 'defs':
            self.update_ref_to_element(element)
        elif element.tagName == 'style':
            pass  # TODO, handle style
        elif element.tagName in ['g', 'svg', 'symbol']:
            result += it.chain(*[
                self.get_mobjects_from(child)
                for child in element.childNodes
            ])
        elif element.tagName == 'path':
            temp = element.getAttribute('d')
            if temp != '':
                result.append(self.path_string_to_mobject(temp))
        elif element.tagName == 'use':
            result += self.use_to_mobjects(element)
        elif element.tagName == 'rect':
            result.append(self.rect_to_mobject(element))
        elif element.tagName == 'circle':
            result.append(self.circle_to_mobject(element))
        elif element.tagName == 'ellipse':
            result.append(self.ellipse_to_mobject(element))
        elif element.tagName in ['polygon', 'polyline']:
            result.append(self.polygon_to_mobject(element))
        else:
            pass  # TODO
            # warnings.warn("Unknown element type: " + element.tagName)
        result = [m for m in result if m is not None]
        self.handle_transforms(element, VGroup(*result))
        if len(result) > 1 and not self.unpack_groups:
            result = [VGroup(*result)]

        return result

    def g_to_mobjects(self, g_element):
        mob = VGroup(*self.get_mobjects_from(g_element))
        self.handle_transforms(g_element, mob)
        return mob.submobjects

    def path_string_to_mobject(self, path_string):
        return VMobjectFromSVGPathstring(path_string)

    def use_to_mobjects(self, use_element):
        # Remove initial "#" character
        ref = use_element.getAttribute("xlink:href")[1:]
        print("Did anyone call this method? Guys?")
        if ref not in self.ref_to_element:
            warnings.warn("%s not recognized" % ref)
            return VGroup()
        return self.get_mobjects_from(
            self.ref_to_element[ref]
        )

    def attribute_to_float(self, attr):
        stripped_attr = "".join([
            char for char in attr
            if char in string.digits + "." + "-"
        ])
        return float(stripped_attr)

    def polygon_to_mobject(self, polygon_element):
        # TODO, This seems hacky...
        path_string = polygon_element.getAttribute("points")
        for digit in string.digits:
            path_string = path_string.replace(" " + digit, " L" + digit)
        path_string = "M" + path_string
        return self.path_string_to_mobject(path_string)

    # <circle class="st1" cx="143.8" cy="268" r="22.6"/>

    def circle_to_mobject(self, circle_element):
        x, y, r = [
            self.attribute_to_float(
                circle_element.getAttribute(key)
            )
            if circle_element.hasAttribute(key)
            else 0.0
            for key in ("cx", "cy", "r")
        ]
        return Circle(radius=r).shift(x * RIGHT + y * DOWN)

    def ellipse_to_mobject(self, circle_element):
        x, y, rx, ry = [
            self.attribute_to_float(
                circle_element.getAttribute(key)
            )
            if circle_element.hasAttribute(key)
            else 0.0
            for key in ("cx", "cy", "rx", "ry")
        ]
        return Circle().scale(rx * RIGHT + ry * UP).shift(x * RIGHT + y * DOWN)

    def rect_to_mobject(self, rect_element):
        fill_color = rect_element.getAttribute("fill")
        stroke_color = rect_element.getAttribute("stroke")
        stroke_width = rect_element.getAttribute("stroke-width")
        corner_radius = rect_element.getAttribute("rx")

        # input preprocessing
        if fill_color in ["", "none", "#FFF", "#FFFFFF"] or Color(fill_color) == Color(WHITE):
            opacity = 0
            fill_color = BLACK  # shdn't be necessary but avoids error msgs
        if fill_color in ["#000", "#000000"]:
            fill_color = WHITE
        if stroke_color in ["", "none", "#FFF", "#FFFFFF"] or Color(stroke_color) == Color(WHITE):
            stroke_width = 0
            stroke_color = BLACK
        if stroke_color in ["#000", "#000000"]:
            stroke_color = WHITE
        if stroke_width in ["", "none", "0"]:
            stroke_width = 0

        if corner_radius in ["", "0", "none"]:
            corner_radius = 0

        corner_radius = float(corner_radius)

        if corner_radius == 0:
            mob = Rectangle(
                width=self.attribute_to_float(
                    rect_element.getAttribute("width")
                ),
                height=self.attribute_to_float(
                    rect_element.getAttribute("height")
                ),
                stroke_width=stroke_width,
                stroke_color=stroke_color,
                fill_color=fill_color,
                fill_opacity=opacity
            )
        else:
            mob = RoundedRectangle(
                width=self.attribute_to_float(
                    rect_element.getAttribute("width")
                ),
                height=self.attribute_to_float(
                    rect_element.getAttribute("height")
                ),
                stroke_width=stroke_width,
                stroke_color=stroke_color,
                fill_color=fill_color,
                fill_opacity=opacity,
                corner_radius=corner_radius
            )

        mob.shift(mob.get_center() - mob.get_corner(UP + LEFT))
        return mob

    def handle_transforms(self, element, mobject):
        x, y = 0, 0
        try:
            x = self.attribute_to_float(element.getAttribute('x'))
            # Flip y
            y = -self.attribute_to_float(element.getAttribute('y'))
            mobject.shift(x * RIGHT + y * UP)
        except:
            pass

        transform = element.getAttribute('transform')

        try:  # transform matrix
            prefix = "matrix("
            suffix = ")"
            if not transform.startswith(prefix) or not transform.endswith(suffix):
                raise Exception()
            transform = transform[len(prefix):-len(suffix)]
            transform = string_to_numbers(transform)
            transform = np.array(transform).reshape([3, 2])
            x = transform[2][0]
            y = -transform[2][1]
            matrix = np.identity(self.dim)
            matrix[:2, :2] = transform[:2, :]
            matrix[1] *= -1
            matrix[:, 1] *= -1

            for mob in mobject.family_members_with_points():
                mob.points = np.dot(mob.points, matrix)
            mobject.shift(x * RIGHT + y * UP)
        except:
            pass

        try:  # transform scale
            prefix = "scale("
            suffix = ")"
            if not transform.startswith(prefix) or not transform.endswith(suffix):
                raise Exception()
            transform = transform[len(prefix):-len(suffix)]
            scale_values = string_to_numbers(transform)
            if len(scale_values) == 2:
                scale_x, scale_y = scale_values
                mobject.scale(np.array([scale_x, scale_y, 1]), about_point=ORIGIN)
            elif len(scale_values) == 1:
                scale = scale_values[0]
                mobject.scale(np.array([scale, scale, 1]), about_point=ORIGIN)
        except:
            pass

        try:  # transform translate
            prefix = "translate("
            suffix = ")"
            if not transform.startswith(prefix) or not transform.endswith(suffix):
                raise Exception()
            transform = transform[len(prefix):-len(suffix)]
            x, y = string_to_numbers(transform)
            mobject.shift(x * RIGHT + y * DOWN)
        except:
            pass
        # TODO, ...

    def flatten(self, input_list):
        output_list = []
        for i in input_list:
            if isinstance(i, list):
                output_list.extend(self.flatten(i))
            else:
                output_list.append(i)
        return output_list

    def get_all_childNodes_have_id(self, element):
        all_childNodes_have_id = []
        if not isinstance(element, minidom.Element):
            return
        if element.hasAttribute('id'):
            return [element]
        for e in element.childNodes:
            all_childNodes_have_id.append(self.get_all_childNodes_have_id(e))
        return self.flatten([e for e in all_childNodes_have_id if e])

    def update_ref_to_element(self, defs):
        new_refs = dict([(e.getAttribute('id'), e) for e in self.get_all_childNodes_have_id(defs)])
        self.ref_to_element.update(new_refs)

    def move_into_position(self):
        if self.should_center:
            self.center()
        if self.height is not None:
            self.set_height(self.height)
        if self.width is not None:
            self.set_width(self.width)

If these are the same then I'm all out, for now.

MohaAmiry commented 3 years ago

hmm, interesting..

actually there is a single print statement in your code that doesn't have any meaning at all haha, this is it, mine is on the right, yours on the left:

image

but everything else is the same.. :(

but could the problem be from any other class in svg_mobject.py file?

NeoPlato commented 3 years ago

Well it is possible, considering from SVGMobject there's only three levels of inheritance higher. Except it does its own thing with generate_points so I think our issues all line up here.

I have two and a half debugging options for you. In a Python REPL in a working directory that can access manimlib:

>>> from xml.dom import minidom
>>> from manimlib.imports import TextMobject, YELLOW
>>> import os
>>> os.chdir("media\\Tex")
>>> text2 = TextMobject("This is some text",
...                     tex_to_color_map={"text": YELLOW})
Writing "\centering This is some text" to b29a846aa3cb7f8b.tex
Writing "This is some" to 0f84d11d97ba78b5.tex
>>> os.path.exists("b29a846aa3cb7f8b.svg")
True
>>> os.path.abspath("b29a846aa3cb7f8b.svg")
'C:\\Manim\\media\\Tex\\b29a846aa3cb7f8b.svg'        # <--- I copied this path to open in a browser.
>>> text2.show()     #<--- This line should show you a non-blank picture
>>> 

This should look as it is, except obviously for the paths. If not you can use minidom to view the elements and tag names and the attribute tex.ref_to_element and checking all tag names in there, or something.

  1. Use code.interact:
    def use_to_mobjects(self, use_element):
        # Remove initial "#" character
        ref = use_element.getAttribute("xlink:href")[1:]
        if ref not in self.ref_to_element:
            warnings.warn("%s not recognized" % ref)       # <---- Where the error is
            from code import interact
            interact(banner="Entering console now\n", 
                         local={"element": element,
                                    "minidom: minidom,
                                    "expectations": self.ref_to_element})                                                       
            return VGroup()
        return self.get_mobjects_from(
            self.ref_to_element[ref]
        )

If you run either the REPL or the python file it will open that small interactive console where you can see what went wrong. You can see in that case where the reference is not found a VGroup is returned hence the emptiness resulting in the index error.

  1. Set up a debugging session. I use Visual Studio Code so this is relatively easy for me. As the debugger goes through SVGMobject make a watch for self.ref_to_element and see whether the reference is actually added.

    That's just about it. I'm also trying to improve my understanding of this code so the answers are as vague to me too.

NeoPlato commented 3 years ago

Yes! I have the cheat!

from xml.dom import minidom
import os
from manimlib.imports import TextMobject, YELLOW

class CheatedTextMobject(TextMobject):
    def generate_points(self):
        doc = minidom.parse(self.file_path)
        self.ref_to_element = dict((element.getAttribute("id"), element)
                                    for element in doc.getElementsByTagName("path"))
        for svg in doc.getElementsByTagName("svg"):
            mobjects = self.get_mobjects_from(svg)
            if self.unpack_groups:
                self.add(*mobjects)
            else:
                self.add(*mobjects[0].submobjects)
        doc.unlink()

    def update_ref_to_element(self, defs):
        print("Thou hast been overriden and are useless")

os.chdir("media\\Tex")
text2 = CheatedTextMobject("This is some text",
                           tex_to_color_map={"text": YELLOW})
text2.show()

Hope for both our sakes that this works. If it does, yay.

I added the overriden method for update_ref_to_element as proof of concept from my end. Without it actually updating that dictionary even my okay version wouldn't work. Seriously note that this is very illegal manipulation that may help us distinguish whether this is a program issue or a code issue.

NeoPlato commented 3 years ago

This is your error right?

C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-84 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-104 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-105 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-115 not recognized
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-111 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Users\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-109 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-101 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-116 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-120 not recognized
  warnings.warn("%s not recognized" % ref)
MohaAmiry commented 3 years ago

ok there is alot of information you have said but sorry i'm lost!, firstly where is this code located? its not in svg_mobject.py nor text_mobject.py:

>>> from xml.dom import minidom
>>> from manimlib.imports import TextMobject, YELLOW
>>> import os
>>> os.chdir("media\\Tex")
>>> text2 = TextMobject("This is some text",
...                     tex_to_color_map={"text": YELLOW})
Writing "\centering This is some text" to b29a846aa3cb7f8b.tex
Writing "This is some" to 0f84d11d97ba78b5.tex
>>> os.path.exists("b29a846aa3cb7f8b.svg")
True
>>> os.path.abspath("b29a846aa3cb7f8b.svg")
'C:\\Manim\\media\\Tex\\b29a846aa3cb7f8b.svg'        # <--- I copied this path to open in a browser.
>>> text2.show()     #<--- This line should show you a non-blank picture
>>> 

secondly i've tried to use (code.interact) but i get a syntax error like this: image

and even if i close the quotation i get another syntax error: image

and thirdly i can't even start a debugging session in svg_mobject.py, i'm unable to define the reason for that! but this is what i get if i start a debugging session: image

and i also the class (CheatedTextMobject), i couldn't find a method named (generate_points) inside the class ( TextMobject) to edit it the way you did, all i could found similar to your implementation of generate_points was in (SVGMobject) class, and if you wanted me to add the whole class -CheatedTextMobject-, can you tell me exactly where to add it and how to run it with svg_mobject.py code? :(

thank you.

MohaAmiry commented 3 years ago

This is your error right?

C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-84 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-104 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-105 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-115 not recognized
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-111 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Users\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-109 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-101 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-116 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-120 not recognized
  warnings.warn("%s not recognized" % ref)

yes exactly.. and yesterday i came across an article said that this is caused by miktex, how could that be possible? and how does manim communicate with miktex?

NeoPlato commented 3 years ago

Let me start with the easy answer.

Interactive console was my bad. The dictionary wasn't typed well. Yes, I was making a dictionary. The one that would send global attributes to the interactive console.

            interact(banner="Entering console now\n", 
                         local={"element": element,
                                "minidom": minidom,
                                "expectations": self.ref_to_element})                                                       

Let's see, next point.

>>> from xml.dom import minidom
>>> from manimlib.imports import TextMobject, YELLOW
>>> import os
>>> os.chdir("media\\Tex")
>>> text2 = TextMobject("This is some text",
...                     tex_to_color_map={"text": YELLOW})
Writing "\centering This is some text" to b29a846aa3cb7f8b.tex
Writing "This is some" to 0f84d11d97ba78b5.tex
>>> os.path.exists("b29a846aa3cb7f8b.svg")
True
>>> os.path.abspath("b29a846aa3cb7f8b.svg")
'C:\\Manim\\media\\Tex\\b29a846aa3cb7f8b.svg'        # <--- I copied this path to open in a browser.
>>> text2.show()     #<--- This line should show you a non-blank picture
>>> 
>>> "This is my own madness, not in any file on Manim."
>>> "I find it better to treat Manim like Python instead of the other way around"
>>> "I took elements from svg_mobject to make that"
>>> "Also, that's the result of running python.exe in a terminal. It's just Python really."

And as for Pycharm, I can't pretend to understand how debugging works over there. I see you got the breakpoint, but for the rest join the club and embrace StackOverflow as your new best friend.

Lastly, about generate_points, um...

NeoPlato commented 3 years ago

Python inheritance 101:

>>> from manimlib.imports import TextMobject
>>> from pprint import pprint as pp
>>> pp(TextMobject.mro())
[<class 'manimlib.mobject.svg.tex_mobject.TextMobject'>,
 <class 'manimlib.mobject.svg.tex_mobject.TexMobject'>,
 <class 'manimlib.mobject.svg.tex_mobject.SingleStringTexMobject'>,
 <class 'manimlib.mobject.svg.svg_mobject.SVGMobject'>,
 <class 'manimlib.mobject.types.vectorized_mobject.VMobject'>,
 <class 'manimlib.mobject.mobject.Mobject'>,
 <class 'manimlib.container.container.Container'>,
 <class 'object'>]

That's how far implementation of inherited classes goes. Inherited classes share code from their parent classes due to similarity, but can override instance methods for specificity e.g Square feeds Manim cardinal points and VMobject a list of points.

Every class in Manim that has Mobject in its family tree has that generate_points method that actually draws stuff on the screen. Or more specifically, see the text.show() method I called? That image depends on the points contained in the class objects. This is a bit of an overload so if it doesn't make immediate sense; I've been there too.

The reason why I made the separate inheritance class CheatedTextMobject was because I was unsure how it would work from the beginning. For now it does, but my shining talent of not solving problems in the general case will show itself soon. Honestly I don't know yet why the element logic in SVGMobject is as it is yet, so I don't want to touch it now.

As for how you'd use it: Simple answer, take that class and shove it in example_scenes.py. Then create the example_text as an instance of that class instead of the other one i.e.

from manimlib.imports import *  #<--- ish ish, you don't necessarily have to import everything sometimes. Just saying
from xml.dom import minidom

class CheatedTextMobject(TextMobject):
    def generate_points(self):
        doc = minidom.parse(self.file_path)
        self.ref_to_element = dict((element.getAttribute("id"), element)
                                    for element in doc.getElementsByTagName("path"))
        for svg in doc.getElementsByTagName("svg"):
            mobjects = self.get_mobjects_from(svg)
            if self.unpack_groups:
                self.add(*mobjects)
            else:
                self.add(*mobjects[0].submobjects)
        doc.unlink()

    def update_ref_to_element(self, defs):
        print("Thou hast been overriden and are useless")

class WriteStuff(Scene):
    def construct(self):
        example_text = CheatedTextMobject(
            "This is some text",
            tex_to_color_map={"text": YELLOW}
        )
        example_tex = TexMobject(
            "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
        )
        group = VGroup(example_text, example_tex)
        group.arrange(DOWN)
        group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)

        self.play(Write(example_text))
        self.play(Write(example_tex))
        self.wait()
MohaAmiry commented 3 years ago

ok, sorry for late answer, i've been testing your codes and trying to grasp how this thing work the past 4 hours but nothing worked..

i've tested CheatedTextMobject and it gave me the same errors, and i tested interact and found somethings that i don't know if they are useful or not: the variable element isn't defined: image

the attributes list is empty: image

and self is referencing to nothing: image

but man i'm pretty sure it is not a code problem because i downloaded manim again just to make sure that everything is as it supposed to be.. it must be from one of the programs manim needs, isn't my conclusion right?

MohaAmiry commented 3 years ago

ok.. seriously nothing worked with me.. i'm really disappointed because i've been trying for days before i post this.. bro if you understood the problem i would gladly allow you to enter my pc with through a sharing application called anyDisk, it will allow u to control my desktop and do what ever u want..

NeoPlato commented 3 years ago

ok, sorry for late answer, i've been testing your codes and trying to grasp how this thing work the past 4 hours but nothing worked..

i've tested CheatedTextMobject and it gave me the same errors, and i tested interact and found somethings that i don't know if they are useful or not: the variable element isn't defined: image

the attributes list is empty: image

and self is referencing to nothing: image

but man i'm pretty sure it is not a code problem because i downloaded manim again just to make sure that everything is as it supposed to be.. it must be from one of the programs manim needs, isn't my conclusion right?

Okay that's off-putting. Thought I had it with that one.

In code.interact, it should've been use_element instead of element. Wow I make so many slipups.

If the hack didn't work, then it's the svg we're missing. I have one very last solution for you before I genuinely give up. Let me figure out how to get it to you first.

NeoPlato commented 3 years ago
<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.8.2 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='75.144235pt' height='6.861476pt' viewBox='134.238594 -6.861476 75.144235 6.861476'>
<defs>
<path id='g0-84' d='M.547945-6.75467L.358655-4.513076H.607721C.647572-5.031133 .67746-5.738481 .986301-6.07721C1.325031-6.425903 1.892902-6.455791 2.351183-6.455791H2.600249C2.86924-6.455791 3.148194-6.455791 3.148194-6.117061V-.767123C3.148194-.368618 2.749689-.308842 2.391034-.308842C2.261519-.308842 2.132005-.318804 2.032379-.318804H1.703611V-.009963H5.479452V-.318804H4.801993C4.41345-.318804 4.034869-.358655 4.034869-.767123V-6.117061C4.034869-6.405978 4.204234-6.455791 4.582814-6.455791H4.83188C5.290162-6.455791 5.858032-6.425903 6.196762-6.07721C6.505604-5.738481 6.535492-5.031133 6.575342-4.513076H6.824408L6.635118-6.75467H.547945Z'/>
<path id='g0-101' d='M1.115816-2.311333H3.985056C4.094645-2.311333 4.144458-2.381071 4.144458-2.49066C4.144458-3.5467 3.496887-4.463263 2.381071-4.463263C1.155666-4.463263 .278954-3.377335 .278954-2.191781C.278954-1.275218 .787049-.458281 1.663761-.059776C1.892902 .039851 2.161893 .099626 2.410959 .099626H2.440847C3.20797 .099626 3.845579-.328767 4.11457-1.09589C4.124533-1.125778 4.124533-1.165629 4.124533-1.195517C4.124533-1.265255 4.084682-1.315068 4.014944-1.315068C3.865504-1.315068 3.805729-.986301 3.745953-.876712C3.496887-.438356 3.01868-.14944 2.500623-.14944C2.132005-.14944 1.8132-.358655 1.544209-.627646C1.145704-1.085928 1.115816-1.733499 1.115816-2.311333ZM1.125778-2.520548C1.125778-3.287671 1.534247-4.244085 2.351183-4.244085H2.400996C3.377335-4.154421 3.367372-3.118306 3.466999-2.520548H1.125778Z'/>
<path id='g0-104' d='M.318804-6.814446V-6.505604H.468244C.836862-6.505604 1.09589-6.465753 1.09589-5.987547V-.956413C1.09589-.886675 1.105853-.816936 1.105853-.737235C1.105853-.358655 .836862-.318804 .557908-.318804H.318804V-.009963H2.570361V-.318804H2.311333C2.032379-.318804 1.793275-.358655 1.793275-.727273V-2.550436C1.793275-3.267746 2.161893-4.184309 3.148194-4.184309C3.785803-4.184309 3.845579-3.496887 3.845579-3.068493V-.687422C3.845579-.348692 3.556663-.318804 3.247821-.318804H3.068493V-.009963H5.32005V-.318804H5.070984C4.801993-.318804 4.542964-.358655 4.542964-.697385V-2.879203C4.542964-3.20797 4.533001-3.536737 4.383562-3.835616C4.144458-4.273973 3.646326-4.403487 3.188045-4.403487C2.610212-4.403487 1.96264-4.014944 1.77335-3.457036L1.763387-6.924035L.318804-6.814446Z'/>
<path id='g0-105' d='M.368618-4.293898V-3.985056H.557908C.846824-3.985056 1.105853-3.945205 1.105853-3.486924V-.727273C1.105853-.37858 .926526-.318804 .328767-.318804V-.009963H2.470735V-.318804H2.271482C2.012453-.318804 1.77335-.348692 1.77335-.667497V-4.403487L.368618-4.293898ZM1.205479-6.665006C.956413-6.635118 .757161-6.41594 .757161-6.146949C.757161-5.858032 1.006227-5.618929 1.285181-5.618929C1.554172-5.618929 1.8132-5.838107 1.8132-6.146949C1.8132-6.435866 1.564134-6.674969 1.285181-6.674969C1.255293-6.674969 1.235367-6.665006 1.205479-6.665006Z'/>
<path id='g0-109' d='M.318804-4.293898V-3.985056H.468244C.797011-3.985056 1.09589-3.955168 1.09589-3.486924V-.737235C1.09589-.328767 .816936-.318804 .37858-.318804H.318804V-.009963H2.570361V-.318804H2.311333C2.032379-.318804 1.793275-.358655 1.793275-.727273V-2.550436C1.793275-3.277709 2.191781-4.184309 3.148194-4.184309C3.785803-4.184309 3.855542-3.526775 3.855542-3.068493V-.697385C3.855542-.33873 3.556663-.318804 3.227895-.318804H3.078456V-.009963H5.330012V-.318804H5.070984C4.79203-.318804 4.552927-.358655 4.552927-.727273V-2.550436C4.552927-3.277709 4.951432-4.184309 5.907846-4.184309C6.545455-4.184309 6.615193-3.526775 6.615193-3.068493V-.697385C6.615193-.33873 6.316314-.318804 5.987547-.318804H5.838107V-.009963H8.089664V-.318804H7.880448C7.581569-.318804 7.312578-.348692 7.312578-.697385V-2.948941C7.312578-3.317559 7.292653-3.646326 7.053549-3.985056C6.794521-4.313823 6.366127-4.403487 5.967621-4.403487C5.32005-4.403487 4.79203-4.024907 4.523039-3.447073C4.333748-4.154421 3.88543-4.403487 3.198007-4.403487C2.560399-4.403487 1.952677-4.004981 1.743462-3.387298L1.733499-4.403487L.318804-4.293898Z'/>
<path id='g0-111' d='M2.34122-4.463263C1.085928-4.333748 .278954-3.277709 .278954-2.122042C.278954-.996264 1.165629 .099626 2.49066 .099626C3.686177 .099626 4.692403-.876712 4.692403-2.132005C4.692403-3.317559 3.795766-4.473225 2.470735-4.473225C2.430884-4.473225 2.381071-4.463263 2.34122-4.463263ZM1.115816-1.892902V-2.331258C1.115816-3.088418 1.354919-4.244085 2.480697-4.244085C3.287671-4.244085 3.745953-3.566625 3.835616-2.809465C3.855542-2.590286 3.855542-2.381071 3.855542-2.161893C3.855542-1.514321 3.785803-.707347 3.148194-.33873C2.948941-.209215 2.729763-.14944 2.500623-.14944C1.77335-.14944 1.265255-.71731 1.155666-1.494396C1.135741-1.62391 1.135741-1.763387 1.115816-1.892902Z'/>
<path id='g0-115' d='M1.753425-4.463263C1.384807-4.423412 .996264-4.353674 .707347-4.104608C.468244-3.895392 .328767-3.556663 .328767-3.237858C.328767-1.534247 3.098381-2.500623 3.098381-1.006227C3.098381-.398506 2.550436-.119552 2.002491-.119552C1.24533-.119552 .737235-.657534 .597758-1.514321C.577833-1.603985 .56787-1.693649 .448319-1.693649C.368618-1.693649 .328767-1.633873 .328767-1.564134V.009963C.33873 .059776 .368618 .089664 .418431 .099626H.438356C.597758 .099626 .757161-.268991 .876712-.298879H.886675C.966376-.298879 1.235367-.049813 1.444583 .019925C1.613948 .079701 1.793275 .099626 1.972603 .099626C2.799502 .099626 3.58655-.33873 3.58655-1.255293C3.58655-1.912827 3.108344-2.450809 2.450809-2.620174C1.833126-2.789539 .816936-2.789539 .816936-3.516812C.816936-4.124533 1.484433-4.273973 1.92279-4.273973C2.410959-4.273973 3.088418-4.004981 3.088418-3.148194C3.088418-3.058531 3.098381-2.978829 3.20797-2.978829C3.307597-2.978829 3.347447-3.058531 3.347447-3.158157C3.347447-3.20797 3.337484-3.257783 3.337484-3.297634V-4.323786C3.337484-4.383562 3.307597-4.463263 3.227895-4.463263C3.068493-4.463263 2.968867-4.214197 2.859278-4.214197H2.849315C2.769614-4.214197 2.610212-4.343711 2.49066-4.383562C2.311333-4.443337 2.11208-4.473225 1.92279-4.473225C1.863014-4.473225 1.8132-4.463263 1.753425-4.463263Z'/>
<path id='g0-116' d='M1.484433-6.136986C1.484433-5.449564 1.195517-4.204234 .179328-4.204234V-3.985056H1.036115V-1.414695C1.036115-1.085928 1.05604-.757161 1.215442-.468244C1.43462-.069738 1.902864 .099626 2.34122 .099626C3.158157 .099626 3.317559-.816936 3.317559-1.444583V-1.8132H3.068493C3.068493-1.663761 3.078456-1.514321 3.078456-1.354919C3.078456-.916563 2.978829-.14944 2.391034-.14944C1.823163-.14944 1.733499-.836862 1.733499-1.285181V-3.985056H3.148194V-4.293898H1.733499V-6.136986H1.484433Z'/>
<path id='g0-120' d='M.169365-4.293898V-3.985056H.368618C.886675-3.985056 1.026152-3.775841 1.255293-3.486924L2.191781-2.261519C2.231631-2.221669 2.311333-2.141968 2.311333-2.082192C2.30137-2.032379 2.221669-1.952677 2.191781-1.912827C1.594022-1.225405 1.155666-.318804 .119552-.318804V-.009963H1.902864V-.318804C1.713574-.318804 1.613948-.498132 1.613948-.637609C1.613948-.836862 1.763387-.976339 1.882939-1.125778S2.122042-1.43462 2.251557-1.58406C2.331258-1.683686 2.420922-1.77335 2.480697-1.882939C2.729763-1.613948 2.938979-1.295143 3.158157-1.006227L3.347447-.757161C3.387298-.707347 3.457036-.637609 3.457036-.56787C3.457036-.408468 3.237858-.318804 3.098381-.318804V-.009963H5.140722V-.318804H4.961395C4.79203-.318804 4.60274-.328767 4.4533-.408468C4.273973-.498132 4.154421-.687422 4.034869-.836862C3.706102-1.275218 3.35741-1.713574 3.028643-2.15193L2.938979-2.271482C2.919054-2.291407 2.899128-2.321295 2.889166-2.351183C2.889166-2.410959 2.958904-2.470735 2.988792-2.510585L3.297634-2.889166C3.476961-3.108344 3.636364-3.347447 3.845579-3.5467C4.154421-3.825654 4.542964-3.985056 4.961395-3.985056V-4.293898H3.188045V-3.985056C3.387298-3.935243 3.466999-3.835616 3.466999-3.676214C3.466999-3.387298 3.148194-3.128269 2.978829-2.899128C2.909091-2.809465 2.759651-2.600249 2.709838-2.600249C2.650062-2.600249 2.510585-2.82939 2.420922-2.938979C2.201743-3.217933 1.853051-3.576588 1.853051-3.745953C1.853051-3.895392 2.072229-3.975093 2.201743-3.985056V-4.293898H.169365Z'/>
</defs>
<g id='page1'>
<use x='134.238594' y='0' xlink:href='#g0-84'/>
<use x='141.432078' y='0' xlink:href='#g0-104'/>
<use x='146.965527' y='0' xlink:href='#g0-105'/>
<use x='149.732251' y='0' xlink:href='#g0-115'/>
<use x='156.981069' y='0' xlink:href='#g0-105'/>
<use x='159.747793' y='0' xlink:href='#g0-115'/>
<use x='166.996611' y='0' xlink:href='#g0-115'/>
<use x='170.92536' y='0' xlink:href='#g0-111'/>
<use x='175.905464' y='0' xlink:href='#g0-109'/>
<use x='184.205637' y='0' xlink:href='#g0-101'/>
<use x='191.952465' y='0' xlink:href='#g0-116'/>
<use x='195.825879' y='0' xlink:href='#g0-101'/>
<use x='200.252638' y='0' xlink:href='#g0-120'/>
<use x='205.509415' y='0' xlink:href='#g0-116'/>
</g>
</svg>

Take this file info and throw it in an svg file e.g. tex_test.svg, perhaps in the Manim folder. Then in a REPL or anywhere run this:

>>> from manimlib.imports import SVGMobject
>>> svg = SVGMobject(file_name="tex_test.svg")
>>> svg.scale(0.5)
<manimlib.mobject.svg.svg_mobject.SVGMobject object at 0x...>
>>> svg.show()

If this don't work we move on to the programs, which I really don't want to do due to underinformation. This very last test will confirm whether any svg files in the future you'll use will be rendered in Manim.

NeoPlato commented 3 years ago

This is your error right?

C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-84 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-104 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-105 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-115 not recognized
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-111 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Users\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-109 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-101 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-116 not recognized
  warnings.warn("%s not recognized" % ref)
C:\Manim\manimlib\mobject\svg\svg_mobject.py:119: UserWarning: g0-120 not recognized
  warnings.warn("%s not recognized" % ref)

yes exactly.. and yesterday i came across an article said that this is caused by miktex, how could that be possible? and how does manim communicate with miktex?

Manim uses MikTex programs to do file conversions internally, from .tex to .dvi to .svg. That's why you needed the MikTex bin in your path variable.

MohaAmiry commented 3 years ago
<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.8.2 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='75.144235pt' height='6.861476pt' viewBox='134.238594 -6.861476 75.144235 6.861476'>
<defs>
<path id='g0-84' d='M.547945-6.75467L.358655-4.513076H.607721C.647572-5.031133 .67746-5.738481 .986301-6.07721C1.325031-6.425903 1.892902-6.455791 2.351183-6.455791H2.600249C2.86924-6.455791 3.148194-6.455791 3.148194-6.117061V-.767123C3.148194-.368618 2.749689-.308842 2.391034-.308842C2.261519-.308842 2.132005-.318804 2.032379-.318804H1.703611V-.009963H5.479452V-.318804H4.801993C4.41345-.318804 4.034869-.358655 4.034869-.767123V-6.117061C4.034869-6.405978 4.204234-6.455791 4.582814-6.455791H4.83188C5.290162-6.455791 5.858032-6.425903 6.196762-6.07721C6.505604-5.738481 6.535492-5.031133 6.575342-4.513076H6.824408L6.635118-6.75467H.547945Z'/>
<path id='g0-101' d='M1.115816-2.311333H3.985056C4.094645-2.311333 4.144458-2.381071 4.144458-2.49066C4.144458-3.5467 3.496887-4.463263 2.381071-4.463263C1.155666-4.463263 .278954-3.377335 .278954-2.191781C.278954-1.275218 .787049-.458281 1.663761-.059776C1.892902 .039851 2.161893 .099626 2.410959 .099626H2.440847C3.20797 .099626 3.845579-.328767 4.11457-1.09589C4.124533-1.125778 4.124533-1.165629 4.124533-1.195517C4.124533-1.265255 4.084682-1.315068 4.014944-1.315068C3.865504-1.315068 3.805729-.986301 3.745953-.876712C3.496887-.438356 3.01868-.14944 2.500623-.14944C2.132005-.14944 1.8132-.358655 1.544209-.627646C1.145704-1.085928 1.115816-1.733499 1.115816-2.311333ZM1.125778-2.520548C1.125778-3.287671 1.534247-4.244085 2.351183-4.244085H2.400996C3.377335-4.154421 3.367372-3.118306 3.466999-2.520548H1.125778Z'/>
<path id='g0-104' d='M.318804-6.814446V-6.505604H.468244C.836862-6.505604 1.09589-6.465753 1.09589-5.987547V-.956413C1.09589-.886675 1.105853-.816936 1.105853-.737235C1.105853-.358655 .836862-.318804 .557908-.318804H.318804V-.009963H2.570361V-.318804H2.311333C2.032379-.318804 1.793275-.358655 1.793275-.727273V-2.550436C1.793275-3.267746 2.161893-4.184309 3.148194-4.184309C3.785803-4.184309 3.845579-3.496887 3.845579-3.068493V-.687422C3.845579-.348692 3.556663-.318804 3.247821-.318804H3.068493V-.009963H5.32005V-.318804H5.070984C4.801993-.318804 4.542964-.358655 4.542964-.697385V-2.879203C4.542964-3.20797 4.533001-3.536737 4.383562-3.835616C4.144458-4.273973 3.646326-4.403487 3.188045-4.403487C2.610212-4.403487 1.96264-4.014944 1.77335-3.457036L1.763387-6.924035L.318804-6.814446Z'/>
<path id='g0-105' d='M.368618-4.293898V-3.985056H.557908C.846824-3.985056 1.105853-3.945205 1.105853-3.486924V-.727273C1.105853-.37858 .926526-.318804 .328767-.318804V-.009963H2.470735V-.318804H2.271482C2.012453-.318804 1.77335-.348692 1.77335-.667497V-4.403487L.368618-4.293898ZM1.205479-6.665006C.956413-6.635118 .757161-6.41594 .757161-6.146949C.757161-5.858032 1.006227-5.618929 1.285181-5.618929C1.554172-5.618929 1.8132-5.838107 1.8132-6.146949C1.8132-6.435866 1.564134-6.674969 1.285181-6.674969C1.255293-6.674969 1.235367-6.665006 1.205479-6.665006Z'/>
<path id='g0-109' d='M.318804-4.293898V-3.985056H.468244C.797011-3.985056 1.09589-3.955168 1.09589-3.486924V-.737235C1.09589-.328767 .816936-.318804 .37858-.318804H.318804V-.009963H2.570361V-.318804H2.311333C2.032379-.318804 1.793275-.358655 1.793275-.727273V-2.550436C1.793275-3.277709 2.191781-4.184309 3.148194-4.184309C3.785803-4.184309 3.855542-3.526775 3.855542-3.068493V-.697385C3.855542-.33873 3.556663-.318804 3.227895-.318804H3.078456V-.009963H5.330012V-.318804H5.070984C4.79203-.318804 4.552927-.358655 4.552927-.727273V-2.550436C4.552927-3.277709 4.951432-4.184309 5.907846-4.184309C6.545455-4.184309 6.615193-3.526775 6.615193-3.068493V-.697385C6.615193-.33873 6.316314-.318804 5.987547-.318804H5.838107V-.009963H8.089664V-.318804H7.880448C7.581569-.318804 7.312578-.348692 7.312578-.697385V-2.948941C7.312578-3.317559 7.292653-3.646326 7.053549-3.985056C6.794521-4.313823 6.366127-4.403487 5.967621-4.403487C5.32005-4.403487 4.79203-4.024907 4.523039-3.447073C4.333748-4.154421 3.88543-4.403487 3.198007-4.403487C2.560399-4.403487 1.952677-4.004981 1.743462-3.387298L1.733499-4.403487L.318804-4.293898Z'/>
<path id='g0-111' d='M2.34122-4.463263C1.085928-4.333748 .278954-3.277709 .278954-2.122042C.278954-.996264 1.165629 .099626 2.49066 .099626C3.686177 .099626 4.692403-.876712 4.692403-2.132005C4.692403-3.317559 3.795766-4.473225 2.470735-4.473225C2.430884-4.473225 2.381071-4.463263 2.34122-4.463263ZM1.115816-1.892902V-2.331258C1.115816-3.088418 1.354919-4.244085 2.480697-4.244085C3.287671-4.244085 3.745953-3.566625 3.835616-2.809465C3.855542-2.590286 3.855542-2.381071 3.855542-2.161893C3.855542-1.514321 3.785803-.707347 3.148194-.33873C2.948941-.209215 2.729763-.14944 2.500623-.14944C1.77335-.14944 1.265255-.71731 1.155666-1.494396C1.135741-1.62391 1.135741-1.763387 1.115816-1.892902Z'/>
<path id='g0-115' d='M1.753425-4.463263C1.384807-4.423412 .996264-4.353674 .707347-4.104608C.468244-3.895392 .328767-3.556663 .328767-3.237858C.328767-1.534247 3.098381-2.500623 3.098381-1.006227C3.098381-.398506 2.550436-.119552 2.002491-.119552C1.24533-.119552 .737235-.657534 .597758-1.514321C.577833-1.603985 .56787-1.693649 .448319-1.693649C.368618-1.693649 .328767-1.633873 .328767-1.564134V.009963C.33873 .059776 .368618 .089664 .418431 .099626H.438356C.597758 .099626 .757161-.268991 .876712-.298879H.886675C.966376-.298879 1.235367-.049813 1.444583 .019925C1.613948 .079701 1.793275 .099626 1.972603 .099626C2.799502 .099626 3.58655-.33873 3.58655-1.255293C3.58655-1.912827 3.108344-2.450809 2.450809-2.620174C1.833126-2.789539 .816936-2.789539 .816936-3.516812C.816936-4.124533 1.484433-4.273973 1.92279-4.273973C2.410959-4.273973 3.088418-4.004981 3.088418-3.148194C3.088418-3.058531 3.098381-2.978829 3.20797-2.978829C3.307597-2.978829 3.347447-3.058531 3.347447-3.158157C3.347447-3.20797 3.337484-3.257783 3.337484-3.297634V-4.323786C3.337484-4.383562 3.307597-4.463263 3.227895-4.463263C3.068493-4.463263 2.968867-4.214197 2.859278-4.214197H2.849315C2.769614-4.214197 2.610212-4.343711 2.49066-4.383562C2.311333-4.443337 2.11208-4.473225 1.92279-4.473225C1.863014-4.473225 1.8132-4.463263 1.753425-4.463263Z'/>
<path id='g0-116' d='M1.484433-6.136986C1.484433-5.449564 1.195517-4.204234 .179328-4.204234V-3.985056H1.036115V-1.414695C1.036115-1.085928 1.05604-.757161 1.215442-.468244C1.43462-.069738 1.902864 .099626 2.34122 .099626C3.158157 .099626 3.317559-.816936 3.317559-1.444583V-1.8132H3.068493C3.068493-1.663761 3.078456-1.514321 3.078456-1.354919C3.078456-.916563 2.978829-.14944 2.391034-.14944C1.823163-.14944 1.733499-.836862 1.733499-1.285181V-3.985056H3.148194V-4.293898H1.733499V-6.136986H1.484433Z'/>
<path id='g0-120' d='M.169365-4.293898V-3.985056H.368618C.886675-3.985056 1.026152-3.775841 1.255293-3.486924L2.191781-2.261519C2.231631-2.221669 2.311333-2.141968 2.311333-2.082192C2.30137-2.032379 2.221669-1.952677 2.191781-1.912827C1.594022-1.225405 1.155666-.318804 .119552-.318804V-.009963H1.902864V-.318804C1.713574-.318804 1.613948-.498132 1.613948-.637609C1.613948-.836862 1.763387-.976339 1.882939-1.125778S2.122042-1.43462 2.251557-1.58406C2.331258-1.683686 2.420922-1.77335 2.480697-1.882939C2.729763-1.613948 2.938979-1.295143 3.158157-1.006227L3.347447-.757161C3.387298-.707347 3.457036-.637609 3.457036-.56787C3.457036-.408468 3.237858-.318804 3.098381-.318804V-.009963H5.140722V-.318804H4.961395C4.79203-.318804 4.60274-.328767 4.4533-.408468C4.273973-.498132 4.154421-.687422 4.034869-.836862C3.706102-1.275218 3.35741-1.713574 3.028643-2.15193L2.938979-2.271482C2.919054-2.291407 2.899128-2.321295 2.889166-2.351183C2.889166-2.410959 2.958904-2.470735 2.988792-2.510585L3.297634-2.889166C3.476961-3.108344 3.636364-3.347447 3.845579-3.5467C4.154421-3.825654 4.542964-3.985056 4.961395-3.985056V-4.293898H3.188045V-3.985056C3.387298-3.935243 3.466999-3.835616 3.466999-3.676214C3.466999-3.387298 3.148194-3.128269 2.978829-2.899128C2.909091-2.809465 2.759651-2.600249 2.709838-2.600249C2.650062-2.600249 2.510585-2.82939 2.420922-2.938979C2.201743-3.217933 1.853051-3.576588 1.853051-3.745953C1.853051-3.895392 2.072229-3.975093 2.201743-3.985056V-4.293898H.169365Z'/>
</defs>
<g id='page1'>
<use x='134.238594' y='0' xlink:href='#g0-84'/>
<use x='141.432078' y='0' xlink:href='#g0-104'/>
<use x='146.965527' y='0' xlink:href='#g0-105'/>
<use x='149.732251' y='0' xlink:href='#g0-115'/>
<use x='156.981069' y='0' xlink:href='#g0-105'/>
<use x='159.747793' y='0' xlink:href='#g0-115'/>
<use x='166.996611' y='0' xlink:href='#g0-115'/>
<use x='170.92536' y='0' xlink:href='#g0-111'/>
<use x='175.905464' y='0' xlink:href='#g0-109'/>
<use x='184.205637' y='0' xlink:href='#g0-101'/>
<use x='191.952465' y='0' xlink:href='#g0-116'/>
<use x='195.825879' y='0' xlink:href='#g0-101'/>
<use x='200.252638' y='0' xlink:href='#g0-120'/>
<use x='205.509415' y='0' xlink:href='#g0-116'/>
</g>
</svg>

Take this file info and throw it in an svg file e.g. tex_test.svg, perhaps in the Manim folder. Then in a REPL or anywhere run this:

>>> from manimlib.imports import SVGMobject
>>> svg = SVGMobject(file_name="tex_test.svg")
>>> svg.scale(0.5)
<manimlib.mobject.svg.svg_mobject.SVGMobject object at 0x...>
>>> svg.show()

If this don't work we move on to the programs, which I really don't want to do due to underinformation. This very last test will confirm whether any svg files in the future you'll use will be rendered in Manim.

ok listen to what i did to see if it is correct or not, i made a text file inside manim folder and pasted the dvisvgm text, the long text, then i saved it as (tex_test.svg), then i made a python file with your code inside it, the 5 lines code, in manim folder too, but the problem is there is an invalid syntax error and its preventing me from running it: Untitled

but firstly, are my steps correct?

NeoPlato commented 3 years ago

Yes, your steps are correct. But I believe to treat this confusion once and for all I must show you what my output usually looks like. I didn't think you'd take it literally.

image

I run python in a terminal for majority of my testing. Anything that isn't preceded by these ">>>" is the output of the execution of the line before it. Eg:

>>> 1 + 1
2
>>> print("Tom\nHardy")
Tom
Hardy

But for the most part, you got the syntax right. If I must be fully candid, here's the full unambiguous detail.

from manimlib.imports import SVGMobject
svg = SVGMobject(file_name="tex_test.svg")
svg.scale(0.5)
svg.show()

Which should pop up an image if done correctly.

MohaAmiry commented 3 years ago

Yes, your steps are correct. But I believe to treat this confusion once and for all I must show you what my output usually looks like. I didn't think you'd take it literally.

image

I run python in a terminal for majority of my testing. Anything that isn't preceded by these ">>>" is the output of the execution of the line before it. Eg:

>>> 1 + 1
2
>>> print("Tom\nHardy")
Tom
Hardy

But for the most part, you got the syntax right. If I must be fully candid, here's the full unambiguous detail.

from manimlib.imports import SVGMobject
svg = SVGMobject(file_name="tex_test.svg")
svg.scale(0.5)
svg.show()

Which should pop up an image if done correctly.

yes actually this is my first time dealing with terminal commands and libraries files so i'm quite lost, i mean alot... thats why i took your codes as literals haha, but YES!, it actually popped up an image! what does this indicate to? Untitled

NeoPlato commented 3 years ago

It means your programs are generating suspect svg files. Yep, it's a programming issue.

Also, sorry if I assumed you were an intermediate like me. Just that learning Manim minus Python is a recipe for disaster.

Let me see the system commands Manim uses and get back to you soon.

MohaAmiry commented 3 years ago

It means your programs are generating suspect svg files. Yep, it's a programming issue.

Also, sorry if I assumed you were an intermediate like me. Just that learning Manim minus Python is a recipe for disaster.

Let me see the system commands Manim uses and get back to you soon.

it very weird to be a programming issue since my manim files are the most recent uploads! they are about 10 days old maybe, does this mean that 3b1b uploaded a corrupted version of manim mistakely?

NeoPlato commented 3 years ago

I highly doubt that. Then again, I use the June version and simply add new features from newer Manim versions and ManimCommunity to my .py files so I wouldn't know.

NeoPlato commented 3 years ago

Okay I think I got it. And you'll actually get to use the terminal, yay!

Open command prompt by searching 'cmd' in the Start Menu.

Go to the Manim directory by using this command:

cd "D:\Programs\ManimProgs\manim-master". I read the file path from those images.

Take this small Latex code:

\documentclass[preview]{standalone}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\linespread{1}

\begin{document}

\centering This is some text

\end{document}

And throw it in a .tex file the way you did the .svg file. Let's say tex_test.tex

Now you're going to run two commands in the command prompt you just opened. One after the other. Paste the command and press Enter.

  1. latex -interaction=batchmode -halt-on-error -output-directory="" tex_test.tex
  2. dvisvgm tex_test.dvi -n -v 0 -o tex_test.svg

These commands will generate a number of files in the current folder. Don't worry, you can delete them later.

Now use the produced tex_test.svg the way you did just now. If that gives a blank image or raises an error, we can safely blame the programs.

MohaAmiry commented 3 years ago

Okay I think I got it. And you'll actually get to use the terminal, yay!

Open command prompt by searching 'cmd' in the Start Menu.

Go to the Manim directory by using this command:

cd "D:\Programs\ManimProgs\manim-master". I read the file path from those images.

Take this small Latex code:

\documentclass[preview]{standalone}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\linespread{1}

\begin{document}

\centering This is some text

\end{document}

And throw it in a .tex file the way you did the .svg file. Let's say tex_test.tex

Now you're going to run two commands in the command prompt you just opened. One after the other. Paste the command and press Enter.

  1. latex -interaction=batchmode -halt-on-error -output-directory="" tex_test.tex
  2. dvisvgm tex_test.dvi -n -v 0 -o tex_test.svg

These commands will generate a number of files in the current folder. Don't worry, you can delete them later.

Now use the produced tex_test.svg the way you did just now. If that gives a blank image or raises an error, we can safely blame the programs.

yaaay used the terminal with no errors nor cursing lol.. ok i did it and it worked and produced the same image as before but with different name: Untitled

but just to notify, i can't edit the photo with functions like (Crop) unless i save it in my device, and i noticed another thing too.. just for a second when i was resizing the window of the photo, it turned into blank like there was no photo, when i resized it back, it came back to a normal photo.. i tried to compile your code once again to see if this happens once again but it never did.. so i think it is a bug from the photos app it self..

soo what are the conclusions now?

NeoPlato commented 3 years ago

Yeah that photo app can get bothersome sometimes. I use Snip and Sketch to open .png files by default.

As for the rest, I'm very confused right now. The commands in Manim are still similar to the ones in my files, but yours acts differently for some reason. What if you try using that svg in a scene, does that affect anything?

MohaAmiry commented 3 years ago

Yeah that photo app can get bothersome sometimes. I use Snip and Sketch to open .png files by default.

As for the rest, I'm very confused right now. The commands in Manim are still similar to the ones in my files, but yours acts differently for some reason. What if you try using that svg in a scene, does that affect anything?

if you mean make your svg a video, yes it affect everything since my main problem is for a video shows a mathematical formula (WriteStuff example), but i'm curious to see if your code will run as a video, can you provide me with instructions to make it a video?

NeoPlato commented 3 years ago

At least you can reproduce the svg yourself when the error comes by again. Just copy the .tex file produced and run those two commands on it.

As for using the svg to make a video, it would be more optimistic to have the attributes rendered from TextMobject and TexMobject since they produce better results. The svg version is kind of raw and you have to use indexing to achieve the same result as in TextMobject e.g coloring the last word yellow like this:

>>> svg[-4:].set_color(YELLOW)
<manimlib.mobject.types.vectorized_mobject.VGroup object at 0x...>  # Ellipsis stands for some hexadecimal number you'd expect

And as for the svg, I meant this:

class WriteStuff(Scene):
    def construct(self):
        example_text = SVGMobject(file_name="tex_test.svg")
        example_text[-4:].set_color(YELLOW)
        example_tex = TexMobject("\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}")
        group = VGroup(example_text, example_tex)
        group.arrange(DOWN)
        group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)

        self.play(Write(example_text))
        self.play(Write(example_tex))
        self.wait()

Try running that in actual Manim.

MohaAmiry commented 3 years ago

At least you can reproduce the svg yourself when the error comes by again. Just copy the .tex file produced and run those two commands on it.

As for using the svg to make a video, it would be more optimistic to have the attributes rendered from TextMobject and TexMobject since they produce better results. The svg version is kind of raw and you have to use indexing to achieve the same result as in TextMobject e.g coloring the last word yellow like this:

>>> svg[-4:].set_color(YELLOW)
<manimlib.mobject.types.vectorized_mobject.VGroup object at 0x...>  # Ellipsis stands for some hexadecimal number you'd expect

And as for the svg, I meant this:

class WriteStuff(Scene):
    def construct(self):
        example_text = SVGMobject(file_name="tex_test.svg")
        example_text[-4:].set_color(YELLOW)
        example_tex = TexMobject("\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}")
        group = VGroup(example_text, example_tex)
        group.arrange(DOWN)
        group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)

        self.play(Write(example_text))
        self.play(Write(example_tex))
        self.wait()

Try running that in actual Manim.

it actually worked and produced a video like this: image

why did your svg work but the ones in (Example_Scenes) didn't?

NeoPlato commented 3 years ago

I really don't know for sure. What you can do: run the one in example_scenes then, error or not, paste the contents of the svg produced here so I can compare with mine.

MohaAmiry commented 3 years ago

I really don't know for sure. What you can do: run the one in example_scenes then, error or not, paste the contents of the svg produced here so I can compare with mine.

it worked in a sudden :))))))))))) Untitled1

i'm not sure how the F%$# this worked out but listen to what i did: i ran the WriteStuff from example and an error appeared as u see in (1), i went to medie->Tex to see the svg produced but there was many files from other examples, so i deleted all and tried to run WriteStuff again to see the svg for that example, and it worked!!!!! can you please explain to me how could sub-products like the files in Tex folder prevent the example from working?!!!

MohaAmiry commented 3 years ago

idk what happened but something from the things you asked me to do fixed it.. dude you have been more patient and useful than most of the people i know in my life lol.. thank you :D.. but one last thing, did you dive deep deep into manim by your self or used some kind of reference? if you have any references i would be thankful if you provide me with em :D..

NeoPlato commented 3 years ago

I am just as confused as you, my friend. Your laptop just wanted you to feel pain.

idk what happened but something from the things you asked me to do fixed it.. dude you have been more patient and useful than most of the people i know in my life lol.. thank you :D.. but one last thing, did you dive deep deep into manim by your self or used some kind of reference? if you have any references i would be thankful if you provide me with em :D..

Hey, I'm just passing on a favor someone did for me in the past. Ok in that case we never really fixed the problem but I just started using another laptop that didn't have it and that was that. Speaking of which, test some audio and make sure it works. That road can get real messy if it doesn't.

As for learning reference, I did follow the content of Theorem of Beethoven from YouTube and that got me started. But with so many questions and so few answers available online I snapped and decided to learn how to work around everything on my own. I picked up some master courses in Python from a friend and I used that to become a Manim elitist, sort of. The guys who make pull requests all the time have studied the code more than me, but I can do 95% of anything I can think of doing and/or fixing so that's a big win.

My advice for you, learn how Python works. That's the best way to understand what happens in the videos you make. We're all lucky this is Python and not something like C++ or else the noob status would've ended us.

NeoPlato commented 3 years ago

Oh yeah and study the OG's code. He who made it knows it best.

MohaAmiry commented 3 years ago

I have a good deal of experience in other languages such as C# and c++, java, but i never needed to touch a single terminal haha, when i came across manim and found it uses python, i learned it's syntax but needed practice, so i decided to practice on manim while i learn it! ๐Ÿ˜‚.. but seems like this is a mistake and i must learn the terminal commands for python :).. And for OG u mean open graphs right?

NeoPlato commented 3 years ago

Hold on, how did you run executables in C++ then? Didn't that require some terminal to operate?

And Python is usually best described as a scripting language. Logic is closer to English and way easier to learn. Terminal logic is another story, especially if we start on Powershell.

By OG I meant 3blue1brown. The code in that folder? Open graphs what๐Ÿ˜‚

srandres-git commented 3 years ago

Now use the produced tex_test.svg the way you did just now. If that gives a blank image or raises an error, we can safely blame the programs.

Hello. I'm having the same problem and got everything right until this part, but with the code I get this error:

image

I would really appreciate any help you could provide me.

Just to clarify, this is my first encounter with python (and a very frustrating one).

MohaAmiry commented 3 years ago

Hold on, how did you run executables in C++ then? Didn't that require some terminal to operate?

And Python is usually best described as a scripting language. Logic is closer to English and way easier to learn. Terminal logic is another story, especially if we start on Powershell.

By OG I meant 3blue1brown. The code in that folder? Open graphs what๐Ÿ˜‚

I used an IDE, So all i had to do is to press ctrl+f5 ๐ŸŒš

NeoPlato commented 3 years ago

Oh welcome.

Now use the produced tex_test.svg the way you did just now. If that gives a blank image or raises an error, we can safely blame the programs.

Hello. I'm having the same problem and got everything right until this part, but with the code I get this error:

image

I would really appreciate any help you could provide me.

Just to clarify, this is my first encounter with python (and a very frustrating one).

You say this is your first encounter with Python. And you're using Manim? You ain't seen frustration yet!

The deal is simple. Me and the other brother figured out something so we'll just go with that.

  1. Throw this detail in a .tex file, probably in the main folder. Let's say text.tex
\documentclass[preview]{standalone}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\linespread{1}

\begin{document}

\centering This is some text

\end{document}
  1. Run three very simple commands in Powershell or Command Prompt, whichever you open.

a) cd "C:\path\to\saved\tex\file". Slashes the other way for UNIX. b) latex -interaction=batchmode -halt-on-error -output-directory="" text.tex c) dvisvgm text.dvi -n -v 0 -o text.svg

  1. Use the svg something like this:
>>> from manimlib.imports import SVGMobject
>>> svg = SVGMobject(file_name="tex_test.svg")
>>> svg.scale(0.5)
<manimlib.mobject.svg.svg_mobject.SVGMobject object at 0x...>
>>> svg.show()

That's how Manim produces the svg files it uses for TextMobject. Producing the svg manually should tell you if your programs are running as they should.

NeoPlato commented 3 years ago

Hold on, how did you run executables in C++ then? Didn't that require some terminal to operate? And Python is usually best described as a scripting language. Logic is closer to English and way easier to learn. Terminal logic is another story, especially if we start on Powershell. By OG I meant 3blue1brown. The code in that folder? Open graphs what๐Ÿ˜‚

I used an IDE, So all i had to do is to press ctrl+f5 ๐ŸŒš

Fair enough. I use Pluralsight courses so command line arguments were inevitable from my perspective.

srandres-git commented 3 years ago

Use the svg something like this:

>>> from manimlib.imports import SVGMobject
>>> svg = SVGMobject(file_name="tex_test.svg")
>>> svg.scale(0.5)
<manimlib.mobject.svg.svg_mobject.SVGMobject object at 0x...>
>>> svg.show()

Yep, I tried that and got this error: image

That's how Manim produces the svg files it uses for TextMobject. Producing the svg manually should tell you if your programs are running as they should.

So... why it didn't work? I'd already reinstalled manim and MikTek.

NeoPlato commented 3 years ago

Use the svg something like this:

>>> from manimlib.imports import SVGMobject
>>> svg = SVGMobject(file_name="tex_test.svg")
>>> svg.scale(0.5)
<manimlib.mobject.svg.svg_mobject.SVGMobject object at 0x...>
>>> svg.show()

Yep, I tried that and got this error: image

That's how Manim produces the svg files it uses for TextMobject. Producing the svg manually should tell you if your programs are running as they should.

So... why it didn't work? I'd already reinstalled manim and MikTek.

I really have no idea at this point. Mainly cause we never really fixed whatever existing problem that was there, or just because I was pulling educated guesses this whole time.

Just to be sure it's the programs, and just to give you the satisfaction of a working svg file, do this:

<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.8.2 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='75.144235pt' height='6.861476pt' viewBox='134.238594 -6.861476 75.144235 6.861476'>
<defs>
<path id='g0-84' d='M.547945-6.75467L.358655-4.513076H.607721C.647572-5.031133 .67746-5.738481 .986301-6.07721C1.325031-6.425903 1.892902-6.455791 2.351183-6.455791H2.600249C2.86924-6.455791 3.148194-6.455791 3.148194-6.117061V-.767123C3.148194-.368618 2.749689-.308842 2.391034-.308842C2.261519-.308842 2.132005-.318804 2.032379-.318804H1.703611V-.009963H5.479452V-.318804H4.801993C4.41345-.318804 4.034869-.358655 4.034869-.767123V-6.117061C4.034869-6.405978 4.204234-6.455791 4.582814-6.455791H4.83188C5.290162-6.455791 5.858032-6.425903 6.196762-6.07721C6.505604-5.738481 6.535492-5.031133 6.575342-4.513076H6.824408L6.635118-6.75467H.547945Z'/>
<path id='g0-101' d='M1.115816-2.311333H3.985056C4.094645-2.311333 4.144458-2.381071 4.144458-2.49066C4.144458-3.5467 3.496887-4.463263 2.381071-4.463263C1.155666-4.463263 .278954-3.377335 .278954-2.191781C.278954-1.275218 .787049-.458281 1.663761-.059776C1.892902 .039851 2.161893 .099626 2.410959 .099626H2.440847C3.20797 .099626 3.845579-.328767 4.11457-1.09589C4.124533-1.125778 4.124533-1.165629 4.124533-1.195517C4.124533-1.265255 4.084682-1.315068 4.014944-1.315068C3.865504-1.315068 3.805729-.986301 3.745953-.876712C3.496887-.438356 3.01868-.14944 2.500623-.14944C2.132005-.14944 1.8132-.358655 1.544209-.627646C1.145704-1.085928 1.115816-1.733499 1.115816-2.311333ZM1.125778-2.520548C1.125778-3.287671 1.534247-4.244085 2.351183-4.244085H2.400996C3.377335-4.154421 3.367372-3.118306 3.466999-2.520548H1.125778Z'/>
<path id='g0-104' d='M.318804-6.814446V-6.505604H.468244C.836862-6.505604 1.09589-6.465753 1.09589-5.987547V-.956413C1.09589-.886675 1.105853-.816936 1.105853-.737235C1.105853-.358655 .836862-.318804 .557908-.318804H.318804V-.009963H2.570361V-.318804H2.311333C2.032379-.318804 1.793275-.358655 1.793275-.727273V-2.550436C1.793275-3.267746 2.161893-4.184309 3.148194-4.184309C3.785803-4.184309 3.845579-3.496887 3.845579-3.068493V-.687422C3.845579-.348692 3.556663-.318804 3.247821-.318804H3.068493V-.009963H5.32005V-.318804H5.070984C4.801993-.318804 4.542964-.358655 4.542964-.697385V-2.879203C4.542964-3.20797 4.533001-3.536737 4.383562-3.835616C4.144458-4.273973 3.646326-4.403487 3.188045-4.403487C2.610212-4.403487 1.96264-4.014944 1.77335-3.457036L1.763387-6.924035L.318804-6.814446Z'/>
<path id='g0-105' d='M.368618-4.293898V-3.985056H.557908C.846824-3.985056 1.105853-3.945205 1.105853-3.486924V-.727273C1.105853-.37858 .926526-.318804 .328767-.318804V-.009963H2.470735V-.318804H2.271482C2.012453-.318804 1.77335-.348692 1.77335-.667497V-4.403487L.368618-4.293898ZM1.205479-6.665006C.956413-6.635118 .757161-6.41594 .757161-6.146949C.757161-5.858032 1.006227-5.618929 1.285181-5.618929C1.554172-5.618929 1.8132-5.838107 1.8132-6.146949C1.8132-6.435866 1.564134-6.674969 1.285181-6.674969C1.255293-6.674969 1.235367-6.665006 1.205479-6.665006Z'/>
<path id='g0-109' d='M.318804-4.293898V-3.985056H.468244C.797011-3.985056 1.09589-3.955168 1.09589-3.486924V-.737235C1.09589-.328767 .816936-.318804 .37858-.318804H.318804V-.009963H2.570361V-.318804H2.311333C2.032379-.318804 1.793275-.358655 1.793275-.727273V-2.550436C1.793275-3.277709 2.191781-4.184309 3.148194-4.184309C3.785803-4.184309 3.855542-3.526775 3.855542-3.068493V-.697385C3.855542-.33873 3.556663-.318804 3.227895-.318804H3.078456V-.009963H5.330012V-.318804H5.070984C4.79203-.318804 4.552927-.358655 4.552927-.727273V-2.550436C4.552927-3.277709 4.951432-4.184309 5.907846-4.184309C6.545455-4.184309 6.615193-3.526775 6.615193-3.068493V-.697385C6.615193-.33873 6.316314-.318804 5.987547-.318804H5.838107V-.009963H8.089664V-.318804H7.880448C7.581569-.318804 7.312578-.348692 7.312578-.697385V-2.948941C7.312578-3.317559 7.292653-3.646326 7.053549-3.985056C6.794521-4.313823 6.366127-4.403487 5.967621-4.403487C5.32005-4.403487 4.79203-4.024907 4.523039-3.447073C4.333748-4.154421 3.88543-4.403487 3.198007-4.403487C2.560399-4.403487 1.952677-4.004981 1.743462-3.387298L1.733499-4.403487L.318804-4.293898Z'/>
<path id='g0-111' d='M2.34122-4.463263C1.085928-4.333748 .278954-3.277709 .278954-2.122042C.278954-.996264 1.165629 .099626 2.49066 .099626C3.686177 .099626 4.692403-.876712 4.692403-2.132005C4.692403-3.317559 3.795766-4.473225 2.470735-4.473225C2.430884-4.473225 2.381071-4.463263 2.34122-4.463263ZM1.115816-1.892902V-2.331258C1.115816-3.088418 1.354919-4.244085 2.480697-4.244085C3.287671-4.244085 3.745953-3.566625 3.835616-2.809465C3.855542-2.590286 3.855542-2.381071 3.855542-2.161893C3.855542-1.514321 3.785803-.707347 3.148194-.33873C2.948941-.209215 2.729763-.14944 2.500623-.14944C1.77335-.14944 1.265255-.71731 1.155666-1.494396C1.135741-1.62391 1.135741-1.763387 1.115816-1.892902Z'/>
<path id='g0-115' d='M1.753425-4.463263C1.384807-4.423412 .996264-4.353674 .707347-4.104608C.468244-3.895392 .328767-3.556663 .328767-3.237858C.328767-1.534247 3.098381-2.500623 3.098381-1.006227C3.098381-.398506 2.550436-.119552 2.002491-.119552C1.24533-.119552 .737235-.657534 .597758-1.514321C.577833-1.603985 .56787-1.693649 .448319-1.693649C.368618-1.693649 .328767-1.633873 .328767-1.564134V.009963C.33873 .059776 .368618 .089664 .418431 .099626H.438356C.597758 .099626 .757161-.268991 .876712-.298879H.886675C.966376-.298879 1.235367-.049813 1.444583 .019925C1.613948 .079701 1.793275 .099626 1.972603 .099626C2.799502 .099626 3.58655-.33873 3.58655-1.255293C3.58655-1.912827 3.108344-2.450809 2.450809-2.620174C1.833126-2.789539 .816936-2.789539 .816936-3.516812C.816936-4.124533 1.484433-4.273973 1.92279-4.273973C2.410959-4.273973 3.088418-4.004981 3.088418-3.148194C3.088418-3.058531 3.098381-2.978829 3.20797-2.978829C3.307597-2.978829 3.347447-3.058531 3.347447-3.158157C3.347447-3.20797 3.337484-3.257783 3.337484-3.297634V-4.323786C3.337484-4.383562 3.307597-4.463263 3.227895-4.463263C3.068493-4.463263 2.968867-4.214197 2.859278-4.214197H2.849315C2.769614-4.214197 2.610212-4.343711 2.49066-4.383562C2.311333-4.443337 2.11208-4.473225 1.92279-4.473225C1.863014-4.473225 1.8132-4.463263 1.753425-4.463263Z'/>
<path id='g0-116' d='M1.484433-6.136986C1.484433-5.449564 1.195517-4.204234 .179328-4.204234V-3.985056H1.036115V-1.414695C1.036115-1.085928 1.05604-.757161 1.215442-.468244C1.43462-.069738 1.902864 .099626 2.34122 .099626C3.158157 .099626 3.317559-.816936 3.317559-1.444583V-1.8132H3.068493C3.068493-1.663761 3.078456-1.514321 3.078456-1.354919C3.078456-.916563 2.978829-.14944 2.391034-.14944C1.823163-.14944 1.733499-.836862 1.733499-1.285181V-3.985056H3.148194V-4.293898H1.733499V-6.136986H1.484433Z'/>
<path id='g0-120' d='M.169365-4.293898V-3.985056H.368618C.886675-3.985056 1.026152-3.775841 1.255293-3.486924L2.191781-2.261519C2.231631-2.221669 2.311333-2.141968 2.311333-2.082192C2.30137-2.032379 2.221669-1.952677 2.191781-1.912827C1.594022-1.225405 1.155666-.318804 .119552-.318804V-.009963H1.902864V-.318804C1.713574-.318804 1.613948-.498132 1.613948-.637609C1.613948-.836862 1.763387-.976339 1.882939-1.125778S2.122042-1.43462 2.251557-1.58406C2.331258-1.683686 2.420922-1.77335 2.480697-1.882939C2.729763-1.613948 2.938979-1.295143 3.158157-1.006227L3.347447-.757161C3.387298-.707347 3.457036-.637609 3.457036-.56787C3.457036-.408468 3.237858-.318804 3.098381-.318804V-.009963H5.140722V-.318804H4.961395C4.79203-.318804 4.60274-.328767 4.4533-.408468C4.273973-.498132 4.154421-.687422 4.034869-.836862C3.706102-1.275218 3.35741-1.713574 3.028643-2.15193L2.938979-2.271482C2.919054-2.291407 2.899128-2.321295 2.889166-2.351183C2.889166-2.410959 2.958904-2.470735 2.988792-2.510585L3.297634-2.889166C3.476961-3.108344 3.636364-3.347447 3.845579-3.5467C4.154421-3.825654 4.542964-3.985056 4.961395-3.985056V-4.293898H3.188045V-3.985056C3.387298-3.935243 3.466999-3.835616 3.466999-3.676214C3.466999-3.387298 3.148194-3.128269 2.978829-2.899128C2.909091-2.809465 2.759651-2.600249 2.709838-2.600249C2.650062-2.600249 2.510585-2.82939 2.420922-2.938979C2.201743-3.217933 1.853051-3.576588 1.853051-3.745953C1.853051-3.895392 2.072229-3.975093 2.201743-3.985056V-4.293898H.169365Z'/>
</defs>
<g id='page1'>
<use x='134.238594' y='0' xlink:href='#g0-84'/>
<use x='141.432078' y='0' xlink:href='#g0-104'/>
<use x='146.965527' y='0' xlink:href='#g0-105'/>
<use x='149.732251' y='0' xlink:href='#g0-115'/>
<use x='156.981069' y='0' xlink:href='#g0-105'/>
<use x='159.747793' y='0' xlink:href='#g0-115'/>
<use x='166.996611' y='0' xlink:href='#g0-115'/>
<use x='170.92536' y='0' xlink:href='#g0-111'/>
<use x='175.905464' y='0' xlink:href='#g0-109'/>
<use x='184.205637' y='0' xlink:href='#g0-101'/>
<use x='191.952465' y='0' xlink:href='#g0-116'/>
<use x='195.825879' y='0' xlink:href='#g0-101'/>
<use x='200.252638' y='0' xlink:href='#g0-120'/>
<use x='205.509415' y='0' xlink:href='#g0-116'/>
</g>
</svg>

Take this file info and throw it in an svg file e.g. tex_test.svg, perhaps in the Manim folder. Then in a REPL or anywhere run this:

>>> from manimlib.imports import SVGMobject
>>> svg = SVGMobject(file_name="tex_test.svg")
>>> svg.scale(0.5)
<manimlib.mobject.svg.svg_mobject.SVGMobject object at 0x...>
>>> svg.show()

If this don't work we move on to the programs, which I really don't want to do due to underinformation. This very last test will confirm whether any svg files in the future you'll use will be rendered in Manim.

srandres-git commented 3 years ago

Just to be sure it's the programs, and just to give you the satisfaction of a working svg file, do this:

That worked. image

I think I'll have to reinstall everything. Thanks!

Jumper1-rgb commented 3 years ago
  1. Throw this detail in a .tex file, probably in the main folder. Let's say text.tex
\documentclass[preview]{standalone}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\linespread{1}

\begin{document}

\centering This is some text

\end{document}
  1. Run three very simple commands in Powershell or Command Prompt, whichever you open.

a) cd "C:\path\to\saved\tex\file". Slashes the other way for UNIX. b) latex -interaction=batchmode -halt-on-error -output-directory="" text.tex c) dvisvgm text.dvi -n -v 0 -o text.svg

Hello, I have the same problem. I tried that and I compared the contents of the .svg file. mine is on the right, yours on the left: image There is no <defs> in my tex_test.svg file, I think that's the problem, but I don't have the ability to solve it

NeoPlato commented 3 years ago

Yes, that is the exact problem. Paths are indicated to but not defined.

How many LaTeX packages have you installed by now

srandres-git commented 3 years ago

There is no <defs> in my tex_test.svg file, I think that's the problem, but I don't have the ability to solve it

Yep, the same is happening with mine.

Yes, that is the exact problem. Paths are indicated to but not defined.

How many LaTeX packages have you installed by now

Wdym? Are we missing some LaTeX packages?

NeoPlato commented 3 years ago

Assuming you installed Miktex, there's this big list of packages that you must click on to actually install.

This is just a guesstimate from me but what if the packages can't be identified by the LaTeX compiler so the svg doesn't come out right

Jumper1-rgb commented 3 years ago

Sorry for late answer.

How many LaTeX packages have you installed by now

In the figure below, these are the LaTex packages all I have . image

This is just a guesstimate from me but what if the packages can't be identified by the LaTeX compiler so the svg doesn't come out right

BTW, I run the code python -m manim example_scenes.py UpdatersExample -pl. It generated a lot of .svg files in .\media\Tex and I opened one of them at random. It looks like it has <defs>.

<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.8.2 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='11.623024pt' height='1.051612pt' viewBox='166.044022 -1.051612 11.623024 1.051612'>
<defs>
<path id='g0-58' d='M1.912827-.52802C1.912827-.816936 1.673724-1.05604 1.384807-1.05604S.856787-.816936 .856787-.52802S1.09589 0 1.384807 0S1.912827-.239103 1.912827-.52802Z'/>
</defs>
<g id='page1'>
<use x='166.044022' y='0' xlink:href='#g0-58'/>
<use x='170.47183' y='0' xlink:href='#g0-58'/>
<use x='174.899638' y='0' xlink:href='#g0-58'/>
</g>
</svg>
NeoPlato commented 3 years ago

Hey I have a theory. Just to be sure.

Do the same three instructions from before, but using this shorter one. I think I have something.

\documentclass[preview]{standalone}

\usepackage[english]{babel}
\usepackage{amsmath}

\begin{document}

\centering This is some text

\end{document}
srandres-git commented 3 years ago

Hey I have a theory. Just to be sure.

Do the same three instructions from before, but using this shorter one. I think I have something.

\documentclass[preview]{standalone}

\usepackage[english]{babel}
\usepackage{amsmath}

\begin{document}

\centering This is some text

\end{document}

This worked for me. What did you have in mind?