问题描述
我已经观看了有关如何使用tikz进行manim的视频,并遵循了多个线程来解决问题,但是似乎无济于事。
我已经修改了tex_template.tex以包含必需的软件包,并将文档类更改为“ preview,dvisvgm”。
我还修改了tex_file_writing.py使其包含
"--libgs='/usr/local/Cellar/ghostscript/9.26_1/lib/libgs.dylib'"
在dvi_to_svg部分。
尽管我不断得到所有这些信息:异常:乳胶错误转换为dvi。尝试运行时
from manimlib.imports import *
class OutFit(Scene):
def construct(self):
TreeDiagram = TexMobject(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,top color=white,bottom color=blue!20}]]
\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}""")
self.play(Write(TreeDiagram))
非常感谢您的帮助。
解决方法
您为什么使用TexMobject
而不是TextMobject
?提出问题之前,请多加注意。另外,您还需要manimlib / tex_template.tex文件中包含的tikz软件包。
无论如何,不建议这样做,因为您正在滥用LaTeX函数,最佳和最佳选择是创建一个类,该类生成所需的树,但是由于该类不存在,因此您将必须自己编程Manim中包含这样的课程,并不难。
class OutFit(Scene):
def construct(self):
tree_diagram = TextMobject(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}]
\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}""",stroke_width=1,fill_opacity=0)
tree_diagram.set_width(FRAME_WIDTH-1)
self.play(Write(tree_diagram))