Basics#
[1]:
from manim_presenter import *
config.media_embed = True
config.media_width = "100%"
_RV = "-v WARNING -qm --progress_bar None --disable_caching Example"
_RI = "-v WARNING -s --progress_bar None --disable_caching Example"
config.disable_caching = True
Manim Community v0.17.3
Create slides#
The first thing we must do is create a folder called slides
, where the texts must be saved.
[2]:
%ls scripts/
_01.txt _03.txt slides01.txt
_02.txt itemize.txt slides02.txt
The files must be in this format:
<== label01
Text content 01
==>
<== label02
Text content 02
==>
The labels are to differentiate the content of each one, there can be as many as you want.
[3]:
%cat ./scripts/_01.txt
<== text01
This is a plain text with "Text"
==>
<== paragraph01
This is a plain text with
multiple lines
==>
<== tex01
\underline{This} is {\bf text} with \LaTeX
==>
<== math01
\frac{d}{dx} \int_0^x f(t)dt = f(x)
==>
The slides go inside an arrangement with the same name:
slides = [
{}, # <- Slide 1
{}, # <- Slide 2
# ...
]
Each slide must have a name so that it can be differentiated, it also supports an element called arrange
that is used to indicate the methods you want to use to order the elements.
Since there can be many slides you have to specify the slide in the preview_slide
variable.
[4]:
class Example(Presentation):
file = "_01.txt"
folder = "scripts" # <- By default
default_type_text = Tex # <- By default
slides = [
{
"slide": "s01",
"arrange": [
lambda mob: mob.arrange(DOWN, buff=1),
lambda mob: mob[0].set_color(RED)
],
"elements" : [
{
"name": "text01",
"type": Text,
},{
"name": "paragraph01",
"type": Paragraph,
},{
"name": "tex01",
# "type": Tex, # <- Value by default
},{
"name": "math01",
"type": MathTex,
},
],
},
]
preview_slide = "s01"
%manim $_RI

You can change the default type using the default_type_text
variable.
[5]:
class Example(Presentation):
file = "_01.txt"
default_type_text = Text # <- Change "type" default
slides = [
{
"slide": "s01",
"arrange": [lambda mob: mob.arrange(UP, buff=1)],
"elements" : [
{ "name": "text01" },
{ "name": "paragraph01"},
{ "name": "tex01" }
],
},
]
preview_slide = "s01"
%manim $_RI

Not only can you include normal text, you can use any text that can be passed as a parameter to some class.
[6]:
%cat ./scripts/_02.txt
<== image01
./images/image01.jpg
==>
<== svg01
./images/svg01.svg
==>
<== code01
print("Hello world!")
# This a comment
class SomeClass:
def some_method(self):
pass
==>
[7]:
class Example(Presentation):
file = "_02.txt" # <-
slides = [
{
"slide": "s01",
"arrange": [lambda mob: mob.arrange(RIGHT, buff=0.2)],
"elements" : [
{
"name": "image01",
"type": ImageMobject,
},{
"name": "svg01",
"type": SVGMobject,
},{
"name": "code01",
"type": lambda mob: Code(code=mob, language="python"),
},
],
},
]
preview_slide = "s01"
%manim $_RI

Groups#
[8]:
%cat ./scripts/_03.txt
<== image
./images/image02.jpg
==>
<== svg
./images/svg02.svg
==>
<== code
print("Hello world!")
# This a comment
class SomeClass:
def some_method(self):
pass
==>
[9]:
ELEMENTS = [
{
"name": "image",
"type": lambda mob: ImageMobject(mob).set(height=3),
},{
"name": "svg",
"type": SVGMobject,
},{
"name": "code",
"type": lambda mob: Code(code=mob, language="python"),
},
]
class Example(Presentation):
file = "_03.txt"
slides = [
{
"slide": "s01",
"arrange": [lambda mob: mob.arrange(DOWN, buff=1)],
"elements": ELEMENTS,
},
]
preview_slide = "s01"
%manim $_RI

[10]:
class Example(Presentation):
file = "_03.txt"
slides = [
{
"slide": "s01",
# "arrange": [lambda mob: mob.arrange(DOWN, buff=1)], # <--- Not use arrange
"elements" : [
*ELEMENTS,
# GROUPS
{
"group": SGroup(Group, "image", "svg"),
"name": "grp01", # <--- NAME
"methods": [lambda grp: grp.arrange(RIGHT, buff=2)]
}, { # -------------------vvvvv NAME
"group": SGroup(Group, "grp01", "code"),
"methods": [
lambda grp: grp.arrange(DOWN),
lambda grp: grp[-1].to_edge(RIGHT),
]
}
],
},
]
preview_slide = "s01"
%manim $_RI

Custom LaTeX classes#
Created by @Abulafia.
[11]:
class LatexItems(Tex):
def __init__(self, *args, page_width="15em", itemize="itemize", ragged="", **kwargs):
"""
*args is a sequence of strings to be typeset by latex. The expected usage is that
each of these strings starts by r"\item "
page_width is the width of the minipage in which the environment will be typeset
it is recommended to use "em" as unit (being 1em the width of letter m)
itemize is the environment to use. It can be "itemize", "enumerate" or "description"
The last one requires each item to be followed by the term to be defined in
square brackets, eg: r"\item[Foo] this is a foo"
ragged is an optional command that will be inserted at the beginning of the minipage
environment. Its intended usage is to provide r"\raggedright" to avoid the hyphenation
and full-justification of the paragraphs
EXAMPLE:
items = LatexItems(r"\item Foo", r"\item Bar", r"\item Foobar")
for item in items:
self.play(Write(item))
"""
template = TexTemplate()
template.body = (
r"\documentclass[preview]{standalone}\usepackage[english]{babel}"
r"\usepackage{amsmath}\usepackage{amssymb}\begin{document}"
rf"\begin{{minipage}}{{{page_width}}}{ragged}"
rf"\begin{{{itemize}}}YourTextHere\end{{{itemize}}}"
r"\end{minipage}\end{document}"
)
super().__init__(*args, tex_template=template, tex_environment=None, **kwargs)
[12]:
%cat ./scripts/itemize.txt
<== list01
\item[Orbits:] All planets move in elliptical orbits, with the sun at one focus.
\item[Areas:] A line connecting planet to sun will sweep out equal area in equal time.
\item[Periods:] $T^2 \propto a^3$ -- The period squared is proportional to the orbit's semi-major axis cubed.
==>
[13]:
class Example(Presentation):
file = "itemize.txt"
slides = [
{
"slide": "s01",
"elements" : [
{
"name": "list01",
"type": LatexItems,
}
],
},
]
preview_slide = "s01"
%manim $_RI

[14]:
class Example(Presentation):
file = "itemize.txt"
slides = [
{
"slide": "s01",
"elements" : [
{
"name": "list01",
"type": lambda mob: LatexItems(mob, page_width="22em"),
}
],
},
]
preview_slide = "s01"
%manim $_RI
