3b1b / manim

Animation engine for explanatory math videos
MIT License
60.27k stars 5.69k forks source link

Manim is not correctly drawing tikzpictures #1209

Open rdownieMath opened 3 years ago

rdownieMath commented 3 years ago

I'm very very new to coding and am mostly trying to learn on my own. I'm starting to pick up the basics of manim, but am still having difficulties with troubleshooting. I've been trying to get manim to draw tikz diagrams and I've spent hours digging through what seemed like similar issues. I finally got it to draw the diagram, but it's all messed up and I can't find any solutions online.

I'm trying to do a tree diagram. It should look like this (from LaTeX):

Screen Shot 2020-08-19 at 9 44 20 PM

Here's the code I used in manim:

from manimlib.imports import * 

class TikzMobject(TextMobject):
    CONFIG = {
    "stroke_width": 3,
    "fill_opacity": 0,
    "stroke_opacity": 1,
    }

class Tree(Scene):
    def construct(self):

        TreeDiagram = TikzMobject(r"""
        \begin{tikzpicture}[level distance=5em,level 1/.style={sibling distance=5cm},level 2/.style={sibling distance=2.5cm},level 3/.style={sibling distance=1cm},every node/.style={shape=rectangle,rounded corners,draw,align=center}]]
        \node {Start}
        child { node {$s_1$} 
        child { node {$p_1$}
        child { node{$f_1$}}
        child { node{$f_2$}}}
        child { node {$p_2$}
        child { node{$f_1$}}
        child { node{$f_2$}}}}
        child { node {$s_2$} 
        child { node {$p_1$}
        child { node {$f_1$}}
        child { node {$f_2$}}}
        child { node {$p_2$}
        child { node {$f_1$}}
        child { node {$f_2$}}}}
        child { node {$s_3$}
        child { node {$p_1$}
        child { node {$f_1$}}
        child { node {$f_2$}}}
        child { node {$p_2$}
        child { node {$f_1$}}
        child { node {$f_2$}}}};
        \end{tikzpicture}
        """)
        TreeDiagram.scale(0.3)
        TreeDiagram.rotate(TAU/2)

        self.play(FadeIn(TreeDiagram))

But what it produces is this:

Screen Shot 2020-08-19 at 9 48 02 PM

I would greatly appreciate any help!

Elteoremadebeethoven commented 3 years ago

That's because Manim removes styles from SVGs (manim compiles the .tex file into dvi, then transforms the dvi to svg), so you can't depend on LaTeX styles for Manim, you'll have to do it by hand or create a class on your own.

shailvaidya commented 3 years ago

I encountered a similar issue once. Did you add dvisvgm to the document class of the tex_template.tex file? If yes then just remove it. It should be

\documentclass[preview]{standalone}

nosarthur commented 2 years ago

Is there any update on this case? I want to generate tikzcd diagrams, but all the arrows collapse to the corner

Functor_ManimCE_v0 14 0

timtro commented 2 years ago

I have the same issue of wanting to use manim to display lots of commutative diagrams (generated by tikzcd) and other TikZ drawn diagrams.

I'm completely naïve to manim's internals, but I am a capable programmer. I'm willing to put in some time to help if someone has time give me direction.