manim icon indicating copy to clipboard operation
manim copied to clipboard

Not able to generate mobject based on circuitikz

Open xandhiller opened this issue 4 years ago • 0 comments

Describe the bug

I have tried to generate a very simple circuitikz circuit, but it seems that after processing the mobject fails an assertion.

Code:

Here is the code I am attempting to run:

class TestResistor(Scene):
    def construct(self):
        res = Tex(r"\begin{circuitikz} \draw (0,0) to[R] (2,0); \end{circuitikz}")
        self.play(Write(res), run_time=3)

I have added the packages to tex_template.tex:

\usepackage{tikz}
\usepackage{circuitikz}

I have also edited the dvi_to_svg() function in manimlib/utils/tex_file_writing.py to have access to the ghostscript path:

def dvi_to_svg(dvi_file, regen_if_exists=False):
    """
    Converts a dvi, which potentially has multiple slides, into a
    directory full of enumerated pngs corresponding with these slides.
    Returns a list of PIL Image objects for these images sorted as they
    where in the dvi
    """
    file_type = get_tex_config()["intermediate_filetype"]
    result = dvi_file.replace("." + file_type, ".svg")
    if not os.path.exists(result):
        commands = [
            "dvisvgm",
            "\"{}\"".format(dvi_file),
            "-n",
            "-v",
            "0",
            "-o",
            "\"{}\"".format(result),
            "--libgs='/opt/homebrew/Cellar/ghostscript/9.54.0/lib/libgs.dylib'",  # this line edited
            ">",
            os.devnull
        ]
        os.system(" ".join(commands))
    return result

Wrong display or Error traceback:

Here is the traceback:

Traceback (most recent call last):                                     
  File "/opt/homebrew/anaconda3/bin/manimgl", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/__main__.py", line 17, in main
    scene.run()
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/scene/scene.py", line 75, in run
    self.construct()
  File "presentation.py", line 88, in construct
    res = Tex(r"\begin{circuitikz} \draw (0,0) to[R] (2,0); \end{circuitikz}")
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/tex_mobject.py", line 167, in __init__
    super().__init__(full_string, **kwargs)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/tex_mobject.py", line 43, in __init__
    svg_mob = SVGMobject(
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 57, in __init__
    super().__init__(**kwargs)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/types/vectorized_mobject.py", line 77, in __init__
    super().__init__(**kwargs)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/mobject.py", line 76, in __init__
    self.init_points()
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 73, in init_points
    mobjects = self.get_mobjects_from(svg)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 89, in get_mobjects_from
    result += it.chain(*[
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 90, in <listcomp>
    self.get_mobjects_from(child)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 89, in get_mobjects_from
    result += it.chain(*[
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 90, in <listcomp>
    self.get_mobjects_from(child)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 89, in get_mobjects_from
    result += it.chain(*[
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 90, in <listcomp>
    self.get_mobjects_from(child)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 89, in get_mobjects_from
    result += it.chain(*[
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 90, in <listcomp>
    self.get_mobjects_from(child)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 89, in get_mobjects_from
    result += it.chain(*[
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 90, in <listcomp>
    self.get_mobjects_from(child)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 94, in get_mobjects_from
    result.append(self.path_string_to_mobject(
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 123, in path_string_to_mobject
    return VMobjectFromSVGPathstring(
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 325, in __init__
    super().__init__(**kwargs)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/types/vectorized_mobject.py", line 77, in __init__
    super().__init__(**kwargs)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/mobject.py", line 76, in __init__
    self.init_points()
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 342, in init_points
    self.handle_command(command, new_points)
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/svg/svg_mobject.py", line 369, in handle_command
    func(*new_points[:n_points])
  File "/opt/homebrew/anaconda3/lib/python3.8/site-packages/manimlib/mobject/types/vectorized_mobject.py", line 292, in start_new_path
    assert(self.get_num_points() % self.n_points_per_curve == 0)
AssertionError

Additional context

xandhiller avatar Jul 13 '21 09:07 xandhiller