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 astring.[packages](optional): A list ofstringfor additional LaTeX packages to include in the preamble, added using the\usepackagecommand. For example, if you include any special fonts or symbols in your Tikz picture, likemarvosym.[libraries](optional): A list ofstringfor any Tikz libraries you require to render your Tikz picture, such aspositioning,arrows.metaorcalc. These will be added to the preamble using the\usetikzlibrarycommand.[tikzset](optional): A list ofstringfor 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\tikzsetcommand.preamble(optional): Astringfor 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,Falseby default): By default,manim-tikzwill render the Tikz markup to a DVI file, which is then imported intomanim. However, some drawing commands generated by Tikz do not render properly in DVI and require postscript (PDF). Setting this option toTruewill 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)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f6d7a40009f05becd3c0a0afbf9a76efc3df5262bb08fec79d9426841745699
|
|
| MD5 |
3f06cc5e7ae2c38ca7aa905882dda2b0
|
|
| BLAKE2b-256 |
7453c4d6c867124395027c4e0dc8fe2e2132eb9a0fca93f0dd3c371bf00db075
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1c10ede6265574af18a24e21eeffc0454735dae9ce1a9b7c61a8363abc89f79
|
|
| MD5 |
b2fde991a43c6498a7f081aca79f90c2
|
|
| BLAKE2b-256 |
c556c184ab313ee907283ae8d9627d0e95f65ac2adaf0bb8ae5470e73c570e98
|