Skip to content

Commit 71050b7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into newExamples
2 parents 1e32a0b + d09f593 commit 71050b7

File tree

6 files changed

+159
-59
lines changed

6 files changed

+159
-59
lines changed

.github/manimdependency.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
{
2-
"windows": {
3-
"ffmpeg": "https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-2020-09-21-full_build.zip",
4-
"pango": "v0.1.0"
5-
}
2+
"windows": {
3+
"ffmpeg": "https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.3.1-2020-09-21-full_build.zip",
4+
"pango": "v0.1.0",
5+
"tinytex": [
6+
"standalone",
7+
"preview",
8+
"doublestroke",
9+
"ms",
10+
"setspace",
11+
"rsfs",
12+
"relsize",
13+
"ragged2e",
14+
"fundus-calligra",
15+
"microtype",
16+
"wasysym",
17+
"physics",
18+
"dvisvgm",
19+
"jknapltx",
20+
"wasy",
21+
"cm-super",
22+
"babel-english"
23+
]
24+
}
625
}

.github/workflows/ci.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
name: CI
22
on:
33
push:
4-
branches:
5-
- master
4+
branches:
5+
- master
66
pull_request:
7-
branches:
8-
- master
7+
branches:
8+
- master
99

1010
jobs:
1111
test:
1212
runs-on: ${{ matrix.os }}
1313
env:
14-
POETRY_VIRTUALENVS_CREATE: false
14+
POETRY_VIRTUALENVS_CREATE: false
1515
strategy:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu-latest, macos-latest, windows-latest]
19-
python: [3.6,3.7, 3.8]
19+
python: [3.6, 3.7, 3.8]
2020

2121
steps:
2222
- name: Checkout the repository
@@ -36,8 +36,8 @@ jobs:
3636
shell: bash
3737
id: pip-cache-and-time
3838
run: |
39-
echo "::set-output name=dir::$(pip cache dir)"
40-
echo "::set-output name=date::$(/bin/date -u "+%m%Y")"
39+
echo "::set-output name=dir::$(pip cache dir)"
40+
echo "::set-output name=date::$(/bin/date -u "+%m%Y")"
4141
4242
- name: pip cache
4343
uses: actions/cache@v2
@@ -73,27 +73,31 @@ jobs:
7373
if: runner.os == 'Windows'
7474
uses: actions/cache@v2
7575
with:
76-
path: ${{ github.workspace }}\ManimCache
77-
key: ${{ runner.os }}-dependencies-ffmpeg-tinytex-${{ hashFiles('.github/manimdependency.json') }}-${{ steps.pip-cache-and-time.outputs.date }}
76+
path: ${{ github.workspace }}\ManimCache
77+
key: ${{ runner.os }}-dependencies-ffmpeg-tinytex-${{ hashFiles('.github/manimdependency.json') }}-${{ steps.pip-cache-and-time.outputs.date }}
7878

7979
- name: Download system dependencies (Windows)
8080
if: runner.os == 'Windows' && steps.cache-windows.outputs.cache-hit != 'true'
8181
run: |
8282
$ffmpegUrl = python -c "import json;print(json.load(open('.github/manimdependency.json'))['windows']['ffmpeg'])"
8383
$pangoVersion = python -c "import json;print(json.load(open('.github/manimdependency.json'))['windows']['pango'])"
84+
$tinyTexPackages = $(python -c "import json;print(' '.join(json.load(open('.github/manimdependency.json'))['windows']['tinytex']))") -Split ' '
8485
$OriPath = $env:PATH
8586
echo "Install Tinytex"
8687
Invoke-WebRequest "https://ci.appveyor.com/api/projects/yihui/tinytex/artifacts/TinyTeX.zip?job=image:%20Visual%20Studio%202019" -O "$($env:TMP)\TinyTex.zip"
8788
Expand-Archive -LiteralPath "$($env:TMP)\TinyTex.zip" -DestinationPath "$($PWD)\ManimCache\LatexWindows"
8889
$env:Path = "$($PWD)\ManimCache\LatexWindows\TinyTeX\bin\win32;$($env:PATH)"
8990
tlmgr update --self
90-
tlmgr install standalone preview doublestroke ms setspace rsfs relsize ragged2e fundus-calligra microtype wasysym physics dvisvgm jknapltx wasy cm-super babel-english
91+
foreach ($c in $tinyTexPackages){
92+
$c=$c.Trim()
93+
tlmgr install $c
94+
}
9195
$env:PATH=$OriPath
9296
echo "Completed Latex"
9397
Invoke-WebRequest "$ffmpegUrl" -O "$($env:TMP)\ffmpeg.zip"
9498
7z x "$($env:TMP)\ffmpeg.zip" -o"$($PWD)\ManimCache"
9599
Move-Item "ManimCache\ffmpeg-*" "ManimCache\FFmpeg"
96-
Invoke-WebRequest "https://github.com/ManimCommunity/manim-windows/releases/download/$($pangoVersion)/pango-windows-binaires-x64.zip" -O "$($env:TMP)\Pango.zip"
100+
Invoke-WebRequest "https://github.com/ManimCommunity/pango-windows-binaries/releases/download/$($pangoVersion)/pango-windows-binaires-x64.zip" -O "$($env:TMP)\Pango.zip"
97101
mkdir "$($PWD)\ManimCache\Pango"
98102
7z x "$($env:TMP)\Pango.zip" -o"$($PWD)\ManimCache\Pango"
99103

docs/source/examples.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Examples
66
examples/shapes_images_positions
77
examples/annotations
88
examples/plots
9-
examples/text
109
examples/tex
1110
examples/formulas
1211
examples/3d

docs/source/examples/tex.rst

Lines changed: 114 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
1+
Text and LaTeX
2+
===============
3+
4+
5+
Text
6+
--------------
7+
The simplest way to add text to you animation is to use the :class:`~.Text` class. It uses the Cairo library to render text.
8+
A newer addition to manim is the :class:`~.PangoText` class, which uses the Pango library.
9+
10+
The Text() mobject
11+
+++++++++++++++++++
12+
13+
.. manim:: Example1Text
14+
:save_last_frame:
15+
16+
class Example1Text(Scene):
17+
def construct(self):
18+
text = Text('Hello world').scale(3)
19+
self.add(text)
20+
21+
For more examples, see: :class:`~.Text`.
22+
23+
The PangoText() mobject
24+
+++++++++++++++++++++++
25+
26+
The :class:`~.PangoText` mobject uses the Pango library to render text. Use this whenever you want to use non-English alphabets like `你好` or `こんにちは` or `안녕하세요` or `مرحبا بالعالم`.
27+
28+
129
LaTeX
2-
=================================
30+
-------------------
31+
32+
The Tex() mobject
33+
+++++++++++++++++++
34+
Just as you can use :class:`~.Text` to add text to your videos, you can use :class:`~.Tex` to insert LaTeX.
35+
36+
.. manim:: ExampleLaTeX
37+
:save_last_frame:
38+
39+
class ExampleLaTeX(Scene):
40+
def construct(self):
41+
tex = Tex(r'\LaTeX').scale(3)
42+
self.add(tex)
43+
44+
Note that we are using a raw string (``r'---'``) instead of a regular string (``'---'``).
45+
This is because TeX code uses a lot of special characters - like ``\`` for example -
46+
that have special meaning within a regular python string. An alternative would have
47+
been to write ``\\`` as in ``Tex('\\LaTeX')``.
48+
49+
The MathTex() mobject
50+
++++++++++++++++++++++
51+
Anything enclosed in ``$`` signs is interpreted as maths-mode:
352

453
.. manim:: Example1LaTeX
554
:save_last_frame:
@@ -9,14 +58,45 @@ LaTeX
958
tex = Tex(r'$\xrightarrow{Hello}$ \LaTeX').scale(3)
1059
self.add(tex)
1160

61+
Whereas in a :class:`~.MathTex` mobject everything is math-mode by default and you would use ``\text{}`` to
62+
insert regular text:
63+
64+
.. manim:: Example1bLaTeX
65+
:save_last_frame:
66+
67+
class Example1bLaTeX(Scene):
68+
def construct(self):
69+
tex = MathTex(r'\xrightarrow{Hello}\text{ \LaTeX}').scale(3)
70+
self.add(tex)
71+
72+
LaTeX commands and keyword arguments
73+
+++++++++++++++++++++++++++++++++++++
74+
We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` text type.
75+
1276
.. manim:: Example2LaTeX
1377
:save_last_frame:
1478

1579
class Example2LaTeX(Scene):
1680
def construct(self):
17-
tex = Tex(r'$\mathtt{Hello}$ \LaTeX', color=BLUE).scale(3)
81+
tex = Tex(r'$\mathtt{Hello}$ \LaTeX').scale(3)
82+
self.add(tex)
83+
84+
On the manim side, the :class:`~.Tex` class also accepts attributes to change the appearance of the output.
85+
This is very similar to the :class:`~.Text` class. For example, the ``color`` keyword changes the color of the TeX mobject:
86+
87+
.. manim:: Example2bLaTeX
88+
:save_last_frame:
89+
90+
class Example2bLaTeX(Scene):
91+
def construct(self):
92+
tex = Tex(r'Hello \LaTeX', color=BLUE).scale(3)
1893
self.add(tex)
1994

95+
Extra LaTeX Packages
96+
+++++++++++++++++++++
97+
Some commands require special packages to be loaded into the TeX template. For example,
98+
to use the ``mathscr`` script, we need to add the ``mathrsfs`` package. Since this package isn't loaded
99+
into manim's tex template by default, we add it manually:
20100

21101
.. manim:: Example3LaTeX
22102
:save_last_frame:
@@ -25,50 +105,62 @@ LaTeX
25105
def construct(self):
26106
myTemplate = TexTemplate()
27107
myTemplate.add_to_preamble(r"\usepackage{mathrsfs}")
28-
tex = Tex(r'$\mathscr{H}ello$ \LaTeX}', tex_template=myTemplate).scale(3)
108+
tex = Tex(r'$\mathscr{H} \rightarrow \mathbb{H}$}', tex_template=myTemplate).scale(3)
29109
self.add(tex)
30110

111+
Substrings and parts
112+
+++++++++++++++++++++
113+
The TeX mobject can accept multiple strings as arguments. Afterwards you can refer to the individual
114+
parts either by their index (like ``tex[1]``), or you can look them up by (parts of) the tex code like
115+
in this example where we set the color of the ``\bigstar`` using :func:`~.set_color_by_tex`:
31116

32117
.. manim:: Example4LaTeX
33118
:save_last_frame:
34119

35120
class Example4LaTeX(Scene):
36121
def construct(self):
37-
tex = Tex('Hello', '$\\bigstar$', '\LaTeX').scale(3)
122+
tex = Tex('Hello', r'$\bigstar$', r'\LaTeX').scale(3)
38123
tex.set_color_by_tex('igsta', RED)
39124
self.add(tex)
40125

126+
LaTeX Maths Fonts - The Template Library
127+
++++++++++++++++++++++++++++++++++++++++++++
128+
Changing fonts in LaTeX when typesetting mathematical formulae is a little bit more tricky than
129+
with regular text. It requires changing the template that is used to compile the tex code.
130+
Manim comes with a collection of :class:`~.TexFontTemplates` ready for you to use. These templates will all work
131+
in maths mode:
132+
41133
.. manim:: Example5LaTeX
42134
:save_last_frame:
43135

44136
class Example5LaTeX(Scene):
45137
def construct(self):
46-
tex = Tex('Hello \LaTeX', tex_template=TexFontTemplates.french_cursive).scale(3)
138+
tex = Tex(r'$f: A \rightarrow B$', tex_template=TexFontTemplates.french_cursive).scale(3)
47139
self.add(tex)
48140

49-
.. manim:: Example5bLaTeX
50-
:save_last_frame:
51-
52-
class Example5bLaTeX(Scene):
53-
def construct(self):
54-
templateForFrenchCursive = TexTemplate(
55-
preamble=r"""
56-
\usepackage[english]{babel}
57-
\usepackage{amsmath}
58-
\usepackage{amssymb}
59-
\usepackage[T1]{fontenc}
60-
\usepackage[default]{frcursive}
61-
\usepackage[eulergreek,noplusnominus,noequal,nohbar,nolessnomore,noasterisk]{mathastext}
62-
""")
63-
tex = Tex('Hello \LaTeX', tex_template=templateForFrenchCursive).scale(3)
64-
self.add(tex)
141+
Manim also has a :class:`~.TexTemplateLibrary` containing the TeX templates used by 3Blue1Brown. One example
142+
is the ctex template, used for typesetting Chinese. For this to work, the ctex LaTeX package
143+
must be installed on your system. Furthermore, if you are only typesetting Text, you probably do not
144+
need :class:`~.Tex` at all, and should use :class:`~.Text` or :class:`~.PangoText` instead.
65145

66146
.. manim:: Example6LaTeX
67147
:save_last_frame:
68148

69149
class Example6LaTeX(Scene):
70150
def construct(self):
71-
tex = Tex('Hello 你好 \LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3)
151+
tex = Tex('Hello 你好 \\LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3)
72152
self.add(tex)
73153

74154

155+
Aligning formulae
156+
++++++++++++++++++
157+
A :class:`~.MathTex` mobject is typeset in the LaTeX ``align*`` environment. This means you can use the ``&`` alignment
158+
character when typesetting multiline formulae:
159+
160+
.. manim:: Example7LaTeX
161+
:save_last_frame:
162+
163+
class Example7LaTeX(Scene):
164+
def construct(self):
165+
tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6').scale(2)
166+
self.add(tex)

docs/source/examples/text.rst

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/source/manim_directive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ def run(self):
173173
f'config["frame_rate"] = {frame_rate}',
174174
f'config["pixel_height"] = {pixel_height}',
175175
f'config["pixel_width"] = {pixel_width}',
176-
f'file_writer_config["media_dir"] = "{media_dir}"',
177-
f'file_writer_config["images_dir"] = "{images_dir}"',
178-
f'file_writer_config["tex_dir"] = "{tex_dir}"',
179-
f'file_writer_config["text_dir"] = "{text_dir}"',
180-
f'file_writer_config["video_dir"] = "{video_dir}"',
176+
f'file_writer_config["media_dir"] = r"{media_dir}"',
177+
f'file_writer_config["images_dir"] = r"{images_dir}"',
178+
f'file_writer_config["tex_dir"] = r"{tex_dir}"',
179+
f'file_writer_config["text_dir"] = r"{text_dir}"',
180+
f'file_writer_config["video_dir"] = r"{video_dir}"',
181181
f'file_writer_config["save_last_frame"] = {save_last_frame}',
182182
f'file_writer_config["write_to_movie"] = {write_to_movie}',
183183
f'file_writer_config["save_as_gif"] = {save_as_gif}',
184-
f'file_writer_config["output_file"] = "{output_file}"',
184+
f'file_writer_config["output_file"] = r"{output_file}"',
185185
]
186186

187187
user_code = self.content

0 commit comments

Comments
 (0)