manim icon indicating copy to clipboard operation
manim copied to clipboard

support tikz,tikz-cd,includegraphics

Open zhuanvi opened this issue 1 year ago • 1 comments

Motivation

Manim is not correctly drawing tikzpictures

Proposed changes

  • svg_mobject.py
  • tex_file_writing.py

Test

Code:

from manimlib import *


class Video(Scene):
    
    def construct(self):
        
        txt = r"""
\begin{tikzcd}
    {\mathcal{C}}
    \arrow["K"', from=1-1, to=2-1]
    \arrow[bend left=37, "F" name=U, from=1-1, to=2-2] 
    \arrow[Rightarrow, "\eta" description, 
    shorten <=4pt, pos=0.58, from=U, to=2-1] \\
    {\mathcal{D}}
    \arrow["\mathrm{Lan}_K F"', ""{name=UU, below},
    from=2-1, to=2-2] & {\mathcal{E}}  \\
    {\quad } & {\quad }
    \arrow[phantom, ""{coordinate,name=Z}, 
    from=3-1, to=3-2]
    \arrow["L"', ""{name=DD}, 
     from=2-1, to= 2-2, 
     rounded corners,
    to path={ -- ([yshift=-3ex] \tikztostart.south)
              |- (Z) [pos=1] \tikztonodes
              -| ([yshift=-3ex] \tikztotarget.south)
              -- (\tikztotarget)}] 
    \arrow ["\chi", Rightarrow,  shorten <=1.5pt,
    from=UU, to= DD, yshift=-1ex]
\end{tikzcd}
        """
        
        tex = TexText(txt, template="ctex",additional_preamble=r"\usepackage{tikz-cd}").set_stroke(RED,width=4)
        self.play(ShowCreation(tex),run_time=10)

Result:

https://github.com/3b1b/manim/assets/15604323/20dadf47-97b2-4d0d-8af0-276e479af55a

zhuanvi avatar Aug 27 '23 16:08 zhuanvi