Skip to main content

Converts Tikz markup code into an SVGMobject for use in manim.

Project description

Manim Tikz

Converts Tikz markup code into an SVGMobject for use in manim.

Installation

manim-tikz requires manim version 0.17.0 and above, which uses the svgelements library for SVG rendering, as this changes how SVG images are rendered. manim-tikz be installed from PyPI using pip:

pip install manim-tikz

Usage

manim-tikz adds the subclass Tikz to the manim class SVGMobject, as well as the subclass TikzTemplate to the manim class TexTemplate behind the scenes for Tikz to use.

To convert Tikz markup code into an SVGMobject, import Tikz from the manim-tikz library:

from manim import *
from manim-tikz import Tikz

Then when constructing a Scene in manim, define a Tikz object like so:

tikz_image = Tikz(code, [packages], [libaries], [tikzset], preamble, use_pdf)
  • code: The Tikz code to render, as a string.
  • [packages] (optional): A list of string for additional LaTeX packages to include in the preamble, added using the \usepackage command. For example, if you include any special fonts or symbols in your Tikz picture, like marvosym.
  • [libraries] (optional): A list of string for any Tikz libraries you require to render your Tikz picture, such as positioning, arrows.meta or calc. These will be added to the preamble using the \usetikzlibrary command.
  • [tikzset] (optional): A list of string for any style definitions and similar you want to define before the Tikz picture (see the Tikz/PGF package manual for further details). Added to the preamble using the \tikzset command.
  • preamble (optional): A string for any other commands you wish to add to the preamble, such as setting up package options. Be careful, making a mistake here can easily result in errors!
  • use_pdf (optional, False by default): By default, manim-tikz will render the Tikz markup to a DVI file, which is then imported into manim. However, some drawing commands generated by Tikz do not render properly in DVI and require postscript (PDF). Setting this option to True will render to a PDF file instead, so use this option if there are problems with the output.

Example

from manim import *
from manim_tikz import Tikz

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

        test_tex = Tikz(r"\draw[magenta, line width=10mm, fill=blue] (0,0) rectangle(1,1);", use_pdf=False)

        self.add(test_tex)

manim-tikz

Animation

Like any other SVGMobject, manim can animate these images using the same animation functions. You might get some rather bizarre results depending on how the drawing order has been interpreted, but they generally look nice.

Future implementations of this plugin may try to include animated Tikz images using the animate library in Tikz, I'll have to look further into how manim handles animated SVG images.

Issues

Line Thickness

At the moment it seems that the default line thickness for TikZ is almost imperceptibly thin when rendered in manim. Not sure why this happens, but you may want to consider increasing line width in your Tikz images.

Fadings, Gradients, Shadows etc.

I haven't yet tested the library using any of these Tikz features, so I don't know how well they will work in manim. I'll look at making some tests in the future.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manim_tikz-0.0.1a1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manim_tikz-0.0.1a1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file manim_tikz-0.0.1a1.tar.gz.

File metadata

  • Download URL: manim_tikz-0.0.1a1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.13 Windows/10

File hashes

Hashes for manim_tikz-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 5f6d7a40009f05becd3c0a0afbf9a76efc3df5262bb08fec79d9426841745699
MD5 3f06cc5e7ae2c38ca7aa905882dda2b0
BLAKE2b-256 7453c4d6c867124395027c4e0dc8fe2e2132eb9a0fca93f0dd3c371bf00db075

See more details on using hashes here.

File details

Details for the file manim_tikz-0.0.1a1-py3-none-any.whl.

File metadata

  • Download URL: manim_tikz-0.0.1a1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.13 Windows/10

File hashes

Hashes for manim_tikz-0.0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1c10ede6265574af18a24e21eeffc0454735dae9ce1a9b7c61a8363abc89f79
MD5 b2fde991a43c6498a7f081aca79f90c2
BLAKE2b-256 c556c184ab313ee907283ae8d9627d0e95f65ac2adaf0bb8ae5470e73c570e98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page