Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Improve/extend reference manual (#438)

Benjamin Hackl54679781101c
diff --git a/docs/source/_templates/autosummary/class.rst b/docs/source/_templates/autosummary/class.rst
index 1874ef9cf..96ea78b59 100644
--- a/docs/source/_templates/autosummary/class.rst
+++ b/docs/source/_templates/autosummary/class.rst
@@ -3,6 +3,7 @@
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
+ :members:
{% block methods %}
{%- if methods %}
@@ -10,7 +11,6 @@
.. autosummary::
:nosignatures:
- :toctree: .
{% for item in methods if item != '__init__' and item not in inherited_members %}
~{{ name }}.{{ item }}
{%- endfor %}
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index a329230de..804869f38 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -8,46 +8,85 @@ the :doc:`changelog`.
.. warning:: The pages linked to here are currently a work in progress.
-
-List of Modules
-***************
-
.. currentmodule:: manim
-**Mathematical Objects**
+********************
+Mathematical Objects
+********************
.. autosummary::
:toctree: reference
- ~mobject.mobject
- ~mobject.types.vectorized_mobject
+ ~mobject.changing
+ ~mobject.coordinate_systems
+ ~mobject.frame
+ ~mobject.functions
~mobject.geometry
+ ~mobject.matrix
+ ~mobject.mobject
+ ~mobject.mobject_update_utils
~mobject.number_line
+ ~mobject.numbers
+ ~mobject.probability
+ ~mobject.shape_matchers
+ ~mobject.three_d_shading_utils
+ ~mobject.three_d_utils
+ ~mobject.three_dimensions
+ ~mobject.value_tracker
+ ~mobject.vector_field
+ ~mobject.svg.brace
+ ~mobject.svg.code_mobject
+ ~mobject.svg.drawings
~mobject.svg.svg_mobject
+ ~mobject.svg.tex_mobject
+ ~mobject.svg.text_mobject
+ ~mobject.types.image_mobject
+ ~mobject.types.point_cloud_mobject
+ ~mobject.types.vectorized_mobject
-**Scenes**
+******
+Scenes
+******
.. autosummary::
:toctree: reference
+ ~scene.graph_scene
+ ~scene.moving_camera_scene
+ ~scene.reconfigurable_scene
+ ~scene.sample_space_scene
~scene.scene
+ ~scene.scene_file_writer
+ ~scene.three_d_scene
+ ~scene.vector_space_scene
~scene.zoomed_scene
- ~scene.moving_camera_scene
-**Animations**
+**********
+Animations
+**********
.. autosummary::
:toctree: reference
~animation.animation
+ ~animation.composition
~animation.creation
~animation.fading
- ~animation.composition
+ ~animation.growing
+ ~animation.indication
+ ~animation.movement
+ ~animation.numbers
+ ~animation.rotation
+ ~animation.specialized
+ ~animation.transform
+ ~animation.update
-**Cameras**
+*******
+Cameras
+*******
.. autosummary::
:toctree: reference
@@ -59,7 +98,32 @@ List of Modules
~camera.three_d_camera
-**Other modules**
+*********
+Utilities
+*********
+
+.. autosummary::
+ :toctree: reference
+
+ ~utils.bezier
+ ~utils.color
+ ~utils.config_ops
+ ~utils.hashing
+ ~utils.images
+ ~utils.iterables
+ ~utils.paths
+ ~utils.rate_functions
+ ~utils.simple_functions
+ ~utils.sounds
+ ~utils.space_ops
+ ~utils.strings
+ ~utils.tex
+ ~utils.tex_file_writing
+
+
+*************
+Other modules
+*************
.. autosummary::
:toctree: reference
diff --git a/manim/animation/growing.py b/manim/animation/growing.py
index 8b7919019..62fbee89e 100644
--- a/manim/animation/growing.py
+++ b/manim/animation/growing.py
@@ -1,3 +1,5 @@
+"""Animations that grow mobjects."""
+
__all__ = [
"GrowFromPoint",
"GrowFromCenter",
diff --git a/manim/animation/indication.py b/manim/animation/indication.py
index 6e9b9763c..4711b72d3 100644
--- a/manim/animation/indication.py
+++ b/manim/animation/indication.py
@@ -1,3 +1,5 @@
+"""Animations drawing attention to particular mobjects."""
+
__all__ = [
"FocusOn",
"Indicate",
diff --git a/manim/animation/movement.py b/manim/animation/movement.py
index 571e6e29f..34268237c 100644
--- a/manim/animation/movement.py
+++ b/manim/animation/movement.py
@@ -1,3 +1,5 @@
+"""Animations related to movement."""
+
__all__ = [
"Homotopy",
"SmoothedVectorizedHomotopy",
diff --git a/manim/animation/numbers.py b/manim/animation/numbers.py
index 54466232c..1af261eb1 100644
--- a/manim/animation/numbers.py
+++ b/manim/animation/numbers.py
@@ -1,3 +1,5 @@
+"""Animations for changing numbers."""
+
__all__ = ["ChangingDecimal", "ChangeDecimalToValue"]
diff --git a/manim/animation/rotation.py b/manim/animation/rotation.py
index 39053e17f..38704f903 100644
--- a/manim/animation/rotation.py
+++ b/manim/animation/rotation.py
@@ -1,3 +1,5 @@
+"""Animations related to rotation."""
+
__all__ = ["Rotating", "Rotate"]
diff --git a/manim/animation/specialized.py b/manim/animation/specialized.py
index bcceecdb6..5cda1068e 100644
--- a/manim/animation/specialized.py
+++ b/manim/animation/specialized.py
@@ -1,3 +1,5 @@
+"""Animations for highly specialiced applications."""
+
__all__ = ["MoveCar", "Broadcast"]
diff --git a/manim/animation/transform.py b/manim/animation/transform.py
index 563b43b5c..43cd7ac9f 100644
--- a/manim/animation/transform.py
+++ b/manim/animation/transform.py
@@ -1,3 +1,5 @@
+"""Animations transforming one mobject into another."""
+
__all__ = [
"Transform",
"ReplacementTransform",
diff --git a/manim/animation/update.py b/manim/animation/update.py
index 7d55c2ea2..11934a6db 100644
--- a/manim/animation/update.py
+++ b/manim/animation/update.py
@@ -1,3 +1,5 @@
+"""Animations that update mobjects."""
+
__all__ = ["UpdateFromFunc", "UpdateFromAlphaFunc", "MaintainPositionRelativeTo"]
diff --git a/manim/camera/camera.py b/manim/camera/camera.py
index 3fea6091c..81c8db9f5 100644
--- a/manim/camera/camera.py
+++ b/manim/camera/camera.py
@@ -1,4 +1,4 @@
-"A Camera converts the mobjects contained in a Scene into an array of pixels"
+"A camera converts the mobjects contained in a Scene into an array of pixels."
__all__ = ["Camera", "BackgroundColoredVMobjectDisplayer"]
@@ -31,18 +31,20 @@ from ..utils.space_ops import get_norm
class Camera(object):
- """
- Base Camera class.
+ """Base camera class.
+
This is the object which takes care of what exactly is displayed
on screen at any given moment.
Some important CONFIG values and local variables to note are:
- self.background_image : str, optional
+ background_image : :class:`str`, optional
The path to an image that should be the background image.
If not set, the background is filled with `self.background_color`
- self.pixel_height
+ pixel_height : :class:`int`, optional
+ The height of the scene in pixels.
+
"""
CONFIG = {
diff --git a/manim/camera/mapping_camera.py b/manim/camera/mapping_camera.py
index 460d4c6cc..124ed8b74 100644
--- a/manim/camera/mapping_camera.py
+++ b/manim/camera/mapping_camera.py
@@ -1,3 +1,5 @@
+"""A camera that allows mapping between objects."""
+
__all__ = ["MappingCamera", "OldMultiCamera", "SplitScreenCamera"]
diff --git a/manim/camera/moving_camera.py b/manim/camera/moving_camera.py
index 342bb44ce..e5d02e444 100644
--- a/manim/camera/moving_camera.py
+++ b/manim/camera/moving_camera.py
@@ -1,3 +1,11 @@
+"""A camera able to move through a scene.
+
+.. SEEALSO::
+
+ :mod:`.moving_camera_scene`
+
+"""
+
__all__ = ["CameraFrame", "MovingCamera"]
@@ -24,6 +32,11 @@ class CameraFrame(VGroup):
class MovingCamera(Camera):
"""
Stays in line with the height, width and position of it's 'frame', which is a Rectangle
+
+ .. SEEALSO::
+
+ :class:`.MovingCameraScene`
+
"""
CONFIG = {
diff --git a/manim/camera/multi_camera.py b/manim/camera/multi_camera.py
index bc5dc2e71..a503a849a 100644
--- a/manim/camera/multi_camera.py
+++ b/manim/camera/multi_camera.py
@@ -1,3 +1,5 @@
+"""A camera supporting multiple perspectives."""
+
__all__ = ["MultiCamera"]
diff --git a/manim/camera/three_d_camera.py b/manim/camera/three_d_camera.py
index 3fe133d70..55271aeeb 100644
--- a/manim/camera/three_d_camera.py
+++ b/manim/camera/three_d_camera.py
@@ -1,3 +1,5 @@
+"""A camera that can be positioned and oriented in three-dimensional space."""
+
__all__ = ["ThreeDCamera"]
@@ -32,7 +34,7 @@ class ThreeDCamera(Camera):
}
def __init__(self, *args, **kwargs):
- """Initialises the ThreeDCamera
+ """Initializes the ThreeDCamera
Parameters
----------
diff --git a/manim/mobject/changing.py b/manim/mobject/changing.py
index 4dc5a484a..58c3b0625 100644
--- a/manim/mobject/changing.py
+++ b/manim/mobject/changing.py
@@ -1,3 +1,5 @@
+"""Animation of a mobject boundary and tracing of points."""
+
__all__ = ["AnimatedBoundary", "TracedPath"]
@@ -9,6 +11,24 @@ from ..utils.space_ops import get_norm
class AnimatedBoundary(VGroup):
+ """Boundary of a :class:`.VMobject` with animated color change.
+
+ Examples
+ --------
+ .. manim:: AnimatedBoundaryExample
+ :display_source:
+ :quality: low
+
+ class AnimatedBoundaryExample(Scene):
+ def construct(self):
+ text = Text("So shiny!")
+ boundary = AnimatedBoundary(text, colors=[RED, GREEN, BLUE],
+ cycle_rate=3)
+ self.add(text, boundary)
+ self.wait(2)
+
+ """
+
CONFIG = {
"colors": [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
"max_stroke_width": 3,
@@ -65,6 +85,26 @@ class AnimatedBoundary(VGroup):
class TracedPath(VMobject):
+ """Traces the path of a point returned by a function call.
+
+ Examples
+ --------
+ .. manim:: TracedPathExample
+ :display_source:
+ :quality: low
+
+ class TracedPathExample(Scene):
+ def construct(self):
+ circ = Circle(Color=RED).shift(4*LEFT)
+ dot = Dot(color=RED).move_to(circ.get_start())
+ rolling_circle = VGroup(circ, dot)
+ trace = TracedPath(circ.get_start)
+ rolling_circle.add_updater(lambda m: m.rotate(-0.3))
+ self.add(trace, rolling_circle)
+ self.play(rolling_circle.shift, 8*RIGHT, run_time=4, rate_func=linear)
+
+ """
+
CONFIG = {
"stroke_width": 2,
"stroke_color": WHITE,
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py
index 1f32a676a..6fd8fcbd2 100644
--- a/manim/mobject/coordinate_systems.py
+++ b/manim/mobject/coordinate_systems.py
@@ -1,3 +1,5 @@
+"""Mobjects that represent coordinate systems."""
+
__all__ = ["CoordinateSystem", "Axes", "ThreeDAxes", "NumberPlane", "ComplexPlane"]
diff --git a/manim/mobject/frame.py b/manim/mobject/frame.py
index a1e7695e7..cf975efb8 100644
--- a/manim/mobject/frame.py
+++ b/manim/mobject/frame.py
@@ -1,3 +1,5 @@
+"""Special rectangles."""
+
__all__ = [
"ScreenRectangle",
"FullScreenRectangle",
diff --git a/manim/mobject/functions.py b/manim/mobject/functions.py
index 8776eaf74..42ab87d61 100644
--- a/manim/mobject/functions.py
+++ b/manim/mobject/functions.py
@@ -1,3 +1,5 @@
+"""Mobjects representing function graphs."""
+
__all__ = ["ParametricFunction", "FunctionGraph"]
diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py
index 80f258cde..4da05dab4 100644
--- a/manim/mobject/matrix.py
+++ b/manim/mobject/matrix.py
@@ -1,3 +1,5 @@
+"""Mobjects representing matrices."""
+
__all__ = [
"Matrix",
"DecimalMatrix",
diff --git a/manim/mobject/mobject_update_utils.py b/manim/mobject/mobject_update_utils.py
index f43e69d94..5d6692fc8 100644
--- a/manim/mobject/mobject_update_utils.py
+++ b/manim/mobject/mobject_update_utils.py
@@ -1,3 +1,5 @@
+"""Utility functions for continuous animation of mobjects."""
+
__all__ = [
"assert_is_mobject_method",
"always",
diff --git a/manim/mobject/numbers.py b/manim/mobject/numbers.py
index ee2d51b2a..f4f4a308c 100644
--- a/manim/mobject/numbers.py
+++ b/manim/mobject/numbers.py
@@ -1,3 +1,5 @@
+"""Mobjects representing numbers."""
+
__all__ = ["DecimalNumber", "Integer", "Variable"]
diff --git a/manim/mobject/probability.py b/manim/mobject/probability.py
index 670d38112..2c6132f05 100644
--- a/manim/mobject/probability.py
+++ b/manim/mobject/probability.py
@@ -1,3 +1,5 @@
+"""Mobjects representing objects from probability theory and statistics."""
+
__all__ = ["SampleSpace", "BarChart"]
diff --git a/manim/mobject/shape_matchers.py b/manim/mobject/shape_matchers.py
index 96eefd1fd..a3cc7ad92 100644
--- a/manim/mobject/shape_matchers.py
+++ b/manim/mobject/shape_matchers.py
@@ -1,3 +1,5 @@
+"""Mobjects used to mark and annotate other mobjects."""
+
__all__ = ["SurroundingRectangle", "BackgroundRectangle", "Cross", "Underline"]
diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py
index 27c2a1427..379d878a2 100644
--- a/manim/mobject/svg/brace.py
+++ b/manim/mobject/svg/brace.py
@@ -1,3 +1,5 @@
+"""Mobject representing curly braces."""
+
__all__ = ["Brace", "BraceLabel", "BraceText"]
diff --git a/manim/mobject/svg/code_mobject.py b/manim/mobject/svg/code_mobject.py
index 16a73b086..00732fed9 100644
--- a/manim/mobject/svg/code_mobject.py
+++ b/manim/mobject/svg/code_mobject.py
@@ -1,3 +1,5 @@
+"""Mobject representing highlighted source code listings."""
+
__all__ = [
"Code",
"hilite_me",
@@ -7,7 +9,7 @@ __all__ = [
import html
import os
from ...constants import *
-from ...mobject.geometry import RoundedRectangle, Dot
+from ...mobject.geometry import Dot, RoundedRectangle
from ...mobject.shape_matchers import SurroundingRectangle
from ...mobject.svg.text_mobject import Paragraph
from ...mobject.types.vectorized_mobject import VGroup
@@ -19,26 +21,30 @@ from pygments.lexers import get_lexer_by_name
from pygments.formatters.html import HtmlFormatter
from pygments.styles import get_all_styles
+
class Code(VGroup):
- """Class Code is used to display code with color highlighted.
-
- Code.styles_list static variable is containing list of names of all styles
- Code is VGroup() with three things
- Code[0] is Code.background_mobject is a VGroup()
- VGroup() of SurroundingRectangle() if background == "rectangle"
- VGroup() of RoundedRectangle() and Dot() for three buttons if background == "window"
- Code[1] is Code.line_numbers Which is a Paragraph() object, this mean you can use
- Code.line_numbers[0] or Code.line_numbers.chars[0] or Code[1].chars[0] to access first line number
- Code[2] is Code.code
- Which is a Paragraph() with color highlighted, this mean you can use
- Code.code[1] or Code.code.chars[1] or Code[2].chars[1]
- line number 1
- Code.code[1][0] or Code.code.chars[1][0] or Code[2].chars[1][0]
- first character of line number 1
- Code.code[1][0:5] Code.code.chars[1][0:5] or Code[2].chars[1][0:5]
- first five characters of line number 1
- Code.code[][] Code.code.chars[][] or Code[2].chars[][] will create problems when using Transform() because of invisible characters
- so, before using Transform() remove invisible characters by using remove_invisible_chars()
+ """A highlighted source code listing.
+
+ An object ``listing`` of :class:`.Code` is a :class:`.VGroup` consisting
+ of three objects:
+
+ - The background, ``listing.background_mobject``. This is either
+ a :class:`.Rectangle` (if the listing has been initialized with
+ ``background="rectangle"``, the default option) or a :class:`.VGroup`
+ resembling a window (if ``background="window"`` has been passed).
+
+ - The line numbers, ``listing.line_numbers`` (a :class:`.Paragraph`
+ object).
+
+ - The highlighted code itself, ``listing.code`` (a :class:`.Paragraph`
+ object).
+
+ .. WARNING::
+
+ Using a :class:`.Transform` on text with leading whitespace (and in
+ this particular case: code) can look
+ `weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
+ :meth:`remove_invisible_chars` to resolve this issue.
Parameters
----------
@@ -51,49 +57,52 @@ class Code(VGroup):
scale_factor : class:`float`, optional
A number which scales displayed code. Defaults to 0.5.
font : :class:`str`, optional
- The name of the text font to be used. Defaults to `"Monospac821 BT"`.
+ The name of the text font to be used. Defaults to ``"Monospac821 BT"``.
stroke_width : class:`float`, optional
Stroke width for text. 0 is recommended, and the default.
margin: class :`float`, optional
Inner margin of text from the background. Defaults to 0.3.
indentation_chars : :class:`str`, optional
- "Indentation chars" refers to the spaces/tabs at the beginning of a given code line. Defaults to `" "`.
+ "Indentation chars" refers to the spaces/tabs at the beginning of a given code line. Defaults to ``" "`` (spaces).
background : :class:`str`, optional
- Defines the background's type. Currently supports only `"rectangle"` (default) and `"window"`.
+ Defines the background's type. Currently supports only ``"rectangle"`` (default) and ``"window"``.
background_stroke_width : class:`float`, optional
Defines the stroke width of the background. Defaults to 1.
background_stroke_color : class:`str`, optional
- Defines the stroke color for the background. Defaults to `WHITE`.
+ Defines the stroke color for the background. Defaults to ``WHITE``.
corner_radius : :class:`float`, optional
Defines the corner radius for the background. Defaults to 0.2.
insert_line_no : :class:`bool`, optional
- Defines whether line numbers should be inserted in displayed code. Defaults to `True`.
+ Defines whether line numbers should be inserted in displayed code. Defaults to ``True``.
line_no_from : :class:`int`, optional
Defines the first line's number in the line count. Defaults to 1.
line_no_buff : :class:`float`, optional
Defines the spacing between line numbers and displayed code. Defaults to 0.4.
style : :class:`str`, optional
- Defines the style type of displayed code. You can see possible names of styles in with :attr:`styles_list`. Defaults to `"vim"`.
+ Defines the style type of displayed code. You can see possible names of styles in with :attr:`styles_list`. Defaults to ``"vim"``.
language : Optional[:class:`str`], optional
- Specifies the programming language the given code was written in. If `None` (the default), the language will be automatically detected. For the list of possible options, visit https://pygments.org/docs/lexers/ and look for 'aliases or short names'.
+ Specifies the programming language the given code was written in. If ``None``
+ (the default), the language will be automatically detected. For the list of
+ possible options, visit https://pygments.org/docs/lexers/ and look for
+ 'aliases or short names'.
generate_html_file : :class:`bool`, optional
Defines whether to generate highlighted html code to the folder `assets/codes/generated_html_files`. Defaults to `False`.
Attributes
----------
background_mobject : :class:`~.VGroup`
- To display background according to background type specified by background in Parameters.
- VGroup with SurroundingRectangle() if background == "rectangle"
- VGroup with RoundedRectangle() and Dot() for three buttons if background == "window"
+ The background of the code listing.
line_numbers : :class:`~.Paragraph`
- To display line numbers of displayed code if insert_line_no == True.
+ The line numbers for the code listing. Empty, if
+ ``insert_line_no=False`` has been specified.
code : :class:`~.Paragraph`
- To display highlighted code.
+ The highlighted code.
Examples
--------
Normal usage::
- helloworldcpp = Code(
+
+ listing = Code(
"helloworldcpp.cpp",
tab_width=4,
background_stroke_width=1,
@@ -103,9 +112,15 @@ class Code(VGroup):
background="window",
language="cpp",
)
+
Remove unwanted invisible characters::
- self.play(Transform(remove_invisible_chars(Code.code.chars[0:2]), remove_invisible_chars(Code.code.chars[3][0:3])))
- remove_invisible_chars(Code.code) or remove_invisible_chars(Code)
+
+ self.play(Transform(remove_invisible_chars(listing.code.chars[0:2]),
+ remove_invisible_chars(listing.code.chars[3][0:3])))
+
+ remove_invisible_chars(listing.code)
+ remove_invisible_chars(listing)
+
"""
# tuples in the form (name, aliases, filetypes, mimetypes)
@@ -294,7 +309,7 @@ class Code(VGroup):
self.insert_line_no,
"border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;",
self.file_path,
- self.line_no_from
+ self.line_no_from,
)
if self.generate_html_file:
@@ -457,7 +472,9 @@ class Code(VGroup):
return line_str
-def hilite_me(code, language, style, insert_line_no, divstyles, file_path, line_no_from):
+def hilite_me(
+ code, language, style, insert_line_no, divstyles, file_path, line_no_from
+):
"""Function to highlight code from string to html.
Parameters
diff --git a/manim/mobject/svg/drawings.py b/manim/mobject/svg/drawings.py
index dd945363f..070186fd7 100644
--- a/manim/mobject/svg/drawings.py
+++ b/manim/mobject/svg/drawings.py
@@ -1,3 +1,5 @@
+"""Mobjects representing predefined SVG drawings."""
+
__all__ = [
"Lightbulb",
"BitcoinLogo",
diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.py
index 1c9b7fed4..dd6db48f4 100644
--- a/manim/mobject/svg/tex_mobject.py
+++ b/manim/mobject/svg/tex_mobject.py
@@ -1,3 +1,5 @@
+"""Mobjects representing text rendered using LaTeX."""
+
__all__ = [
"TexSymbol",
"SingleStringMathTex",
diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.py
index c36a3464b..6116fe3e9 100644
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@ -1,5 +1,8 @@
+"""Mobjects used for displaying (non-LaTeX) text."""
+
__all__ = ["TextSetting", "Text", "Paragraph"]
+
import re
import os
import copy
@@ -19,17 +22,17 @@ TEXT_MOB_SCALE_FACTOR = 0.05
def remove_invisible_chars(mobject):
- """Fuction to remove unwanted invisble characters from some mobject
+ """Function to remove unwanted invisible characters from some mobject
Parameters
- ---------
+ ----------
mobject : :class:`~.SVGMobject`
- Any SVGMobject from which we want to remove unwanted invisble characters.
+ Any SVGMobject from which we want to remove unwanted invisible characters.
Returns
-------
:class:`~.SVGMobject`
- The SVGMobject without unwanted invisble characters.
+ The SVGMobject without unwanted invisible characters.
"""
iscode = False
@@ -63,14 +66,19 @@ class TextSetting(object):
class Text(SVGMobject):
- """ Text is used for displaying Text.
- Text is VGroup() of each characters
- that mean you can use it like
- Text[0:5] or Text.chars[0:5] to access first five characters
- Text[0:5] or Text or Text.chars[0:5] will create problems when using Transform() because of invisible characters
- so, before using Transform() remove invisible characters by using remove_invisible_chars()
- for example self.play(Transform(remove_invisible_chars(text.chars[0:4]), remove_invisible_chars(text2.chars[0:2])))
+ """Display (non-LaTeX) text.
+
+ Text objects behave like a :class:`.VGroup`-like iterable of all characters
+ in the given text. In particular, slicing is possible.
+
+ .. WARNING::
+
+ Using a :class:`.Transform` on text with leading whitespace can look
+ `weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
+ :meth:`remove_invisible_chars` to resolve this issue.
+
"""
+
CONFIG = {
# Mobject
"color": WHITE,
@@ -382,20 +390,20 @@ class TextWithBackground(Text):
class Paragraph(VGroup):
- """Paragraph is used to display paragraphs with more efficiency or having some extra features.
+ r"""Display a paragraph of text.
- paragraph paragraph.chars is VGroup() of each lines and each line is VGroup() of that line's characters
- that mean you can use it like
- paragraph[0:5] or paragraph.chars[0:5] to access first five lines
- paragraph[0][0:5] or paragraph.chars[0][0:5] to access first line's first five characters
- paragraph or paragraph[] or paragraph.chars[][] will create problems when using Transform() because of invisible characters
- so, before using Transform() remove invisible characters by using remove_invisible_chars()
+ For a given :class:`.Paragraph` ``par``, the attribute ``par.chars`` is a
+ :class:`.VGroup` containing all the lines. In this context, every line is
+ constructed as a :class:`.VGroup` of characters contained in the line.
- paragraph(" a b", " bcd\nefg") is same as paragraph(" a b", " bcd", "efg")
- that means paragraph[2] is "efg"
+ .. WARNING::
+
+ Using a :class:`.Transform` on text with leading whitespace can look
+ `weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
+ :meth:`remove_invisible_chars` to resolve this issue.
Parameters
- ---------
+ ----------
line_spacing : :class:`int`, optional
Represents the spaning betweeb lines. Default to -1, which means auto.
alignment : :class:`str`, optional
@@ -404,11 +412,17 @@ class Paragraph(VGroup):
Examples
--------
Normal usage::
- paragraph = Paragraph('this is a awesome', 'paragraph', 'With \nNewlines', '\tWith Tabs', ' With Spaces',
- 'With Alignments',
- 'center', "left", "right")
+
+ paragraph = Paragraph('this is a awesome', 'paragraph',
+ 'With \nNewlines', '\tWith Tabs',
+ ' With Spaces', 'With Alignments',
+ 'center', 'left', 'right')
+
Remove unwanted invisible characters::
- self.play(Transform(remove_invisible_chars(paragraph.chars[0:2]), remove_invisible_chars(paragraph.chars[3][0:3]))
+
+ self.play(Transform(remove_invisible_chars(paragraph.chars[0:2]),
+ remove_invisible_chars(paragraph.chars[3][0:3]))
+
"""
CONFIG = {
@@ -457,7 +471,7 @@ class Paragraph(VGroup):
"""Function to convert plain string to 2d-VGroup of chars. 2d-VGroup mean "VGroup of VGroup".
Parameters
- ---------
+ ----------
lines_str_list : :class:`str`
Plain text string.
@@ -484,7 +498,7 @@ class Paragraph(VGroup):
"""Function to set all line's aligment to a specific value.
Parameters
- ---------
+ ----------
alignment : :class:`str`
Defines the alignment of paragraph. Possible values are "left", "right", "center".
"""
@@ -496,7 +510,7 @@ class Paragraph(VGroup):
"""Function to set one line's aligment to a specific value.
Parameters
- ---------
+ ----------
alignment : :class:`str`
Defines the alignment of paragraph. Possible values are "left", "right", "center".
line_no : :class:`int`
@@ -506,8 +520,7 @@ class Paragraph(VGroup):
return self
def set_all_lines_to_initial_positions(self):
- """Function to set one all lines to initial positions.
- """
+ """Set all lines to their initial positions."""
self.lines[1] = [None for _ in range(self.lines[0].__len__())]
for line_no in range(0, self.lines[0].__len__()):
self[line_no].move_to(
@@ -519,7 +532,7 @@ class Paragraph(VGroup):
"""Function to set one line to initial positions.
Parameters
- ---------
+ ----------
line_no : :class:`int`
Defines the line number for which we want to set given alignment.
"""
@@ -531,7 +544,7 @@ class Paragraph(VGroup):
"""Function to change one line's aligment to a specific value.
Parameters
- ---------
+ ----------
alignment : :class:`str`
Defines the alignment of paragraph. Possible values are "left", "right", "center".
line_no : :class:`int`
diff --git a/manim/mobject/three_d_shading_utils.py b/manim/mobject/three_d_shading_utils.py
index 110e2e577..25dc41f32 100644
--- a/manim/mobject/three_d_shading_utils.py
+++ b/manim/mobject/three_d_shading_utils.py
@@ -1,3 +1,5 @@
+"""Utility functions for shading of three-dimensional mobjects."""
+
import numpy as np
from ..constants import ORIGIN
diff --git a/manim/mobject/three_d_utils.py b/manim/mobject/three_d_utils.py
index 1ec6b8f74..ec2ee4d24 100644
--- a/manim/mobject/three_d_utils.py
+++ b/manim/mobject/three_d_utils.py
@@ -1,3 +1,5 @@
+"""Utility functions for three-dimensional mobjects."""
+
__all__ = [
"get_3d_vmob_gradient_start_and_end_points",
"get_3d_vmob_start_corner_index",
diff --git a/manim/mobject/three_dimensions.py b/manim/mobject/three_dimensions.py
index f113bfa81..ffb65f7a5 100644
--- a/manim/mobject/three_dimensions.py
+++ b/manim/mobject/three_dimensions.py
@@ -1,3 +1,5 @@
+"""Three-dimensional mobjects."""
+
__all__ = ["ThreeDVMobject", "ParametricSurface", "Sphere", "Cube", "Prism"]
diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py
index 952476772..b1e32357b 100644
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -1,3 +1,5 @@
+"""Mobjects representing raster images."""
+
__all__ = ["AbstractImageMobject", "ImageMobject", "ImageMobjectFromCamera"]
diff --git a/manim/mobject/types/point_cloud_mobject.py b/manim/mobject/types/point_cloud_mobject.py
index ffe523081..d94c53dd3 100644
--- a/manim/mobject/types/point_cloud_mobject.py
+++ b/manim/mobject/types/point_cloud_mobject.py
@@ -1,3 +1,5 @@
+"""Mobjects representing point clouds."""
+
__all__ = ["PMobject", "Mobject1D", "Mobject2D", "PGroup", "PointCloudDot", "Point"]
diff --git a/manim/mobject/value_tracker.py b/manim/mobject/value_tracker.py
index f680657a4..3955b0d0f 100644
--- a/manim/mobject/value_tracker.py
+++ b/manim/mobject/value_tracker.py
@@ -1,3 +1,5 @@
+"""Mobjects that dynamically show the change of a variable."""
+
__all__ = ["ValueTracker", "ExponentialValueTracker", "ComplexValueTracker"]
@@ -8,11 +10,38 @@ from ..mobject.mobject import Mobject
class ValueTracker(Mobject):
- """
+ """A mobject that can be used for tracking (real-valued) parameters.
+ Useful for animating parameter changes.
+
Not meant to be displayed. Instead the position encodes some
number, often one which another animation or continual_animation
uses for its update function, and by treating it as a mobject it can
still be animated and manipulated just like anything else.
+
+ Examples
+ --------
+ .. manim:: ValueTrackerExample
+ :display_source:
+ :quality: low
+
+ class ValueTrackerExample(Scene):
+ def construct(self):
+ number_line = NumberLine()
+ pointer = Vector(DOWN)
+ label = MathTex("x").add_updater(lambda m: m.next_to(pointer, UP))
+
+ pointer_value = ValueTracker(0)
+ pointer.add_updater(
+ lambda m: m.next_to(
+ number_line.n2p(pointer_value.get_value()),
+ UP
+ )
+ )
+ self.add(number_line, pointer,label)
+ self.play(pointer_value.set_value, 5)
+ self.wait()
+ self.play(pointer_value.set_value, 3)
+
"""
def __init__(self, value=0, **kwargs):
diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.py
index 89ab1ca37..0a41e7478 100644
--- a/manim/mobject/vector_field.py
+++ b/manim/mobject/vector_field.py
@@ -1,3 +1,5 @@
+"""Mobjects representing vector fields."""
+
__all__ = [
"VectorField",
"StreamLines",
diff --git a/manim/scene/graph_scene.py b/manim/scene/graph_scene.py
index 2865bde45..7abf24c87 100644
--- a/manim/scene/graph_scene.py
+++ b/manim/scene/graph_scene.py
@@ -1,3 +1,5 @@
+"""A scene for plotting / graphing functions."""
+
__all__ = ["GraphScene"]
@@ -787,17 +789,13 @@ class GraphScene(Scene):
secant_line_length : int, float, optional
How long the secant line should be.
- Returns:
- --------
- VGroup
- Resulting group is of the form VGroup(
- dx_line,
- df_line,
- dx_label, (if applicable)
- df_label, (if applicable)
- secant_line, (if applicable)
- )
- with attributes of those names.
+
+ Returns
+ -------
+ :class:`.VGroup`
+ A group containing the elements ``dx_line``, ``df_line``, and
+ if applicable also ``dx_label``, ``df_label``, ``secant_line``.
+
"""
kwargs = locals()
kwargs.pop("self")
@@ -859,12 +857,18 @@ class GraphScene(Scene):
def add_T_label(
self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs
):
- """
+ """Create a triangle marker with a vertical line from the x-axis
+ to ``self.v_graph`` at the given x coordinate ``x_val``.
+
This method adds to the Scene:
- -- a Vertical line from the x-axis to the corresponding point on the graph/curve.
- -- a small vertical Triangle whose top point lies on the base of the vertical line
- -- a MathTex to be a label for the Line and Triangle, at the bottom of the Triangle.
- The scene needs to have the graph have the identifier/variable name self.v_graph.
+
+ - a Vertical line from the x-axis to the corresponding point on the graph/curve.
+ - a small vertical Triangle whose top point lies on the base of the vertical line
+ - a MathTex to be a label for the Line and Triangle, at the bottom of
+ the Triangle.
+
+ The scene needs to have the graph have the identifier/variable
+ name ``self.v_graph``.
Parameters
----------
@@ -872,7 +876,7 @@ class GraphScene(Scene):
The x value at which the secant enters, and intersects
the graph for the first time.
- side np.array(), optional
+ side : np.array(), optional
label : str, optional
The label to give the vertline and triangle
diff --git a/manim/scene/moving_camera_scene.py b/manim/scene/moving_camera_scene.py
index 05adc5ae8..31dc76a09 100644
--- a/manim/scene/moving_camera_scene.py
+++ b/manim/scene/moving_camera_scene.py
@@ -1,3 +1,11 @@
+"""A scene whose camera can be moved around.
+
+.. SEEALSO::
+
+ :mod:`.moving_camera`
+
+"""
+
__all__ = ["MovingCameraScene"]
from ..camera.moving_camera import MovingCamera
@@ -9,6 +17,10 @@ class MovingCameraScene(Scene):
"""
This is a Scene, with special configurations and properties that
make it suitable for cases where the camera must be moved around.
+
+ .. SEEALSO::
+
+ :class:`.MovingCamera`
"""
CONFIG = {"camera_class": MovingCamera}
diff --git a/manim/scene/sample_space_scene.py b/manim/scene/sample_space_scene.py
index f2c5e61bc..030c0e460 100644
--- a/manim/scene/sample_space_scene.py
+++ b/manim/scene/sample_space_scene.py
@@ -1,3 +1,5 @@
+"""A scene suitable for usage with :class:`.SampleSpace`."""
+
__all__ = ["SampleSpaceScene"]
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index c5781637c..e3f992551 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -1,4 +1,4 @@
-"""A Scene is the canvas of the animation."""
+"""Basic canvas for animations."""
__all__ = ["Scene", "EndSceneEarlyException"]
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index fcad34229..e510c351d 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -1,3 +1,5 @@
+"""The interface between scenes and ffmpeg."""
+
__all__ = ["SceneFileWriter"]
@@ -141,14 +143,16 @@ class SceneFileWriter(object):
return fn if fn else self.scene.__class__.__name__
def get_resolution_directory(self):
- """
+ """Get the name of the resolution directory directly containing
+ the video file.
+
This method gets the name of the directory that immediately contains the
- video file. This name is <height_in_pixels_of_video>p<frame_rate>
- E.G:
- If you are rendering an 854x480 px animation at 15fps, the name of the directory
- that immediately contains the video file will be
- 480p15.
- The file structure should look something like:
+ video file. This name is ``<height_in_pixels_of_video>p<frame_rate>``.
+ For example, if you are rendering an 854x480 px animation at 15fps,
+ the name of the directory that immediately contains the video file
+ will be ``480p15``.
+
+ The file structure should look something like::
MEDIA_DIR
|--Tex
@@ -157,9 +161,10 @@ class SceneFileWriter(object):
|--<name_of_file_containing_scene>
|--<height_in_pixels_of_video>p<frame_rate>
|--<scene_name>.mp4
+
Returns
-------
- str
+ :class:`str`
The name of the directory.
"""
pixel_height = self.scene.camera.pixel_height
diff --git a/manim/scene/three_d_scene.py b/manim/scene/three_d_scene.py
index a1b9be811..26dbf5ed2 100644
--- a/manim/scene/three_d_scene.py
+++ b/manim/scene/three_d_scene.py
@@ -1,3 +1,5 @@
+"""A scene suitable for rendering three-dimensional objects and animations."""
+
__all__ = ["ThreeDScene", "SpecialThreeDScene"]
@@ -263,15 +265,16 @@ class ThreeDScene(Scene):
class SpecialThreeDScene(ThreeDScene):
- """
- This is basically ThreeDScene++ .
- It has some extra configuration for
- axes, spheres, lower quality etc.
-
- Some key differences are:
- The camera shades applicable 3DMobjects by default,
- except if rendering in low quality.
- Some default params for Spheres and Axes have been added.
+ """An extension of :class:`ThreeDScene` with more settings.
+
+ It has some extra configuration for axes, spheres,
+ and an override for low quality rendering. Further key differences
+ are:
+
+ * The camera shades applicable 3DMobjects by default,
+ except if rendering in low quality.
+ * Some default params for Spheres and Axes have been added.
+
"""
CONFIG = {
@@ -310,12 +313,12 @@ class SpecialThreeDScene(ThreeDScene):
ThreeDScene.__init__(self, **config)
def get_axes(self):
- """
- Returns a set of 3D Axes.
+ """Return a set of 3D axes.
Returns
-------
- ThreeDAxes
+ :class:`.ThreeDAxes`
+ A set of 3D axes.
"""
axes = ThreeDAxes(**self.three_d_axes_config)
for axis in axes:
@@ -335,18 +338,16 @@ class SpecialThreeDScene(ThreeDScene):
def get_sphere(self, **kwargs):
"""
- Returns a sphere with the passed **kwargs
- as properties.
+ Returns a sphere with the passed keyword arguments as properties.
Parameters
----------
**kwargs
- Some valid kwargs are:
- Any param of a Sphere or ParametricSurface.
+ Any valid parameter of :class:`.Sphere` or :class:`.ParametricSurface`.
Returns
-------
- Sphere
+ :class:`.Sphere`
The sphere object.
"""
config = merge_dicts_recursively(self.sphere_config, kwargs)
diff --git a/manim/scene/vector_space_scene.py b/manim/scene/vector_space_scene.py
index 7536c5555..8214f9d1c 100644
--- a/manim/scene/vector_space_scene.py
+++ b/manim/scene/vector_space_scene.py
@@ -1,3 +1,5 @@
+"""A scene suitable for vector spaces."""
+
__all__ = ["VectorScene", "LinearTransformationScene"]
@@ -174,20 +176,22 @@ class VectorScene(Scene):
Parameters
----------
- vector : Arrow
+ vector : :class:`.Arrow`
The arrow representing the vector.
**kwargs
- Any valid keyword arguments of matrix.vector_coordinate_label
+ Any valid keyword arguments of :meth:`~.matrix.vector_coordinate_label`:
- integer_labels (True) : Whether or not to round the coordinates
- to integers.
- n_dim (2) : The number of dimensions of the vector.
- color (WHITE) : The color of the label.
+ integer_labels : :class:`bool`
+ Whether or not to round the coordinates to integers. Default: ``True``.
+ n_dim : :class:`int`
+ The number of dimensions of the vector. Default: ``2``.
+ color
+ The color of the label. Default: ``WHITE``.
Returns
-------
- Matrix
+ :class:`.Matrix`
The column matrix representing the vector.
"""
coords = vector_coordinate_label(vector, **kwargs)
diff --git a/manim/scene/zoomed_scene.py b/manim/scene/zoomed_scene.py
index 72217cfd6..acbf1997f 100644
--- a/manim/scene/zoomed_scene.py
+++ b/manim/scene/zoomed_scene.py
@@ -1,3 +1,5 @@
+"""A scene supporting zooming in on a specified section."""
+
__all__ = ["ZoomedScene"]
diff --git a/manim/utils/bezier.py b/manim/utils/bezier.py
index d9944f783..3c9157b6d 100644
--- a/manim/utils/bezier.py
+++ b/manim/utils/bezier.py
@@ -1,3 +1,5 @@
+"""Utility functions related to Bézier curves."""
+
__all__ = [
"bezier",
"partial_bezier_points",
diff --git a/manim/utils/color.py b/manim/utils/color.py
index 271d48372..cd0726a68 100644
--- a/manim/utils/color.py
+++ b/manim/utils/color.py
@@ -1,3 +1,5 @@
+"""Utility functions for conversion between color models."""
+
__all__ = [
"color_to_rgb",
"color_to_rgba",
diff --git a/manim/utils/config_ops.py b/manim/utils/config_ops.py
index 4ffb46ea4..cde690191 100644
--- a/manim/utils/config_ops.py
+++ b/manim/utils/config_ops.py
@@ -1,3 +1,5 @@
+"""Utilities required by manim's CONFIG attributes."""
+
__all__ = [
"get_all_descendent_classes",
"filtered_locals",
diff --git a/manim/utils/debug.py b/manim/utils/debug.py
index 3e615d597..f02f26e7b 100644
--- a/manim/utils/debug.py
+++ b/manim/utils/debug.py
@@ -1,3 +1,5 @@
+"""Debugging utilities."""
+
__all__ = ["print_family", "get_submobject_index_labels"]
diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py
index 44e359ed7..e62476ba0 100644
--- a/manim/utils/file_ops.py
+++ b/manim/utils/file_ops.py
@@ -1,3 +1,5 @@
+"""Utility functions for interacting with the file system."""
+
__all__ = [
"add_extension_if_not_present",
"guarantee_existence",
diff --git a/manim/utils/hashing.py b/manim/utils/hashing.py
index b753cb160..ee79effef 100644
--- a/manim/utils/hashing.py
+++ b/manim/utils/hashing.py
@@ -1,3 +1,5 @@
+"""Utilities for scene caching."""
+
import json
import zlib
import inspect
diff --git a/manim/utils/images.py b/manim/utils/images.py
index 0e60e1dbf..ad9a5dc63 100644
--- a/manim/utils/images.py
+++ b/manim/utils/images.py
@@ -1,3 +1,5 @@
+"""Image manipulation utilities."""
+
__all__ = ["get_full_raster_image_path", "drag_pixels", "invert_image"]
diff --git a/manim/utils/iterables.py b/manim/utils/iterables.py
index 08c81f0d5..5919479ff 100644
--- a/manim/utils/iterables.py
+++ b/manim/utils/iterables.py
@@ -1,3 +1,5 @@
+"""Operations on iterables."""
+
__all__ = [
"remove_list_redundancies",
"list_update",
diff --git a/manim/utils/paths.py b/manim/utils/paths.py
index d71daeb3d..addaa84b9 100644
--- a/manim/utils/paths.py
+++ b/manim/utils/paths.py
@@ -1,3 +1,5 @@
+"""Functions determining transformation paths between sets of points."""
+
__all__ = [
"straight_path",
"path_along_arc",
diff --git a/manim/utils/rate_functions.py b/manim/utils/rate_functions.py
index 5727f6d27..dfd1a0c4d 100644
--- a/manim/utils/rate_functions.py
+++ b/manim/utils/rate_functions.py
@@ -1,3 +1,5 @@
+"""A selection of rate functions, i.e., *speed curves* for animations."""
+
__all__ = [
"linear",
"smooth",
diff --git a/manim/utils/simple_functions.py b/manim/utils/simple_functions.py
index dfd5583b3..0e9c68874 100644
--- a/manim/utils/simple_functions.py
+++ b/manim/utils/simple_functions.py
@@ -1,3 +1,5 @@
+"""A collection of simple functions."""
+
__all__ = [
"sigmoid",
"choose_using_cache",
diff --git a/manim/utils/sounds.py b/manim/utils/sounds.py
index 38c173a76..dd46294d9 100644
--- a/manim/utils/sounds.py
+++ b/manim/utils/sounds.py
@@ -1,3 +1,5 @@
+"""Sound-related utility functions."""
+
__all__ = [
"play_chord",
"play_error_sound",
diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.py
index 6569de264..e3e6f17a6 100644
--- a/manim/utils/space_ops.py
+++ b/manim/utils/space_ops.py
@@ -1,3 +1,5 @@
+"""Utility functions for two- and three-dimensional vectors."""
+
__all__ = [
"get_norm",
"quaternion_mult",
diff --git a/manim/utils/strings.py b/manim/utils/strings.py
index 07a0cd79b..5ef6dfe05 100644
--- a/manim/utils/strings.py
+++ b/manim/utils/strings.py
@@ -1,3 +1,5 @@
+"""String manipulation utilities."""
+
__all__ = [
"to_camel_case",
"initials",
diff --git a/manim/utils/tex.py b/manim/utils/tex.py
index a4f72b32f..969481281 100644
--- a/manim/utils/tex.py
+++ b/manim/utils/tex.py
@@ -1,3 +1,5 @@
+"""Utilities for processing custom LaTeX templates."""
+
__all__ = ["TexTemplateFromFile", "TexTemplate"]
@@ -34,7 +36,7 @@ class TexTemplateFromFile:
Parameters
----------
expression : :class:`str`
- String containing the expression to be typeset, e.g. `"foo"`
+ String containing the expression to be typeset, e.g. ``"foo"``
Returns
-------
@@ -44,15 +46,14 @@ class TexTemplateFromFile:
return self.body.replace(self.text_to_replace, expression)
def get_text_for_env(self, environment, expression):
- """Inserts an expression into the TeX template, surrounded
- by `\\begin{<environment>} ... \\end{<environment>}` for a certain environment.
+ """Inserts an expression wrapped in a given environment into the TeX template.
Parameters
----------
environment : :class:`str`
The environment in which we should wrap the expression.
expression : :class:`str`
- The string containing the expression to be typeset, e.g. $\\sqrt{2}$
+ The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``
Returns
-------
@@ -66,13 +67,13 @@ class TexTemplateFromFile:
)
def get_text_for_tex_mode(self, expression):
- """Inserts an expression into the TeX template, surrounded
- by `\\begin{align*} ... \\end{align*}` for math mode.
+ """Inserts an expression within an ``align*`` environment into the TeX template.
Parameters
----------
expression : :class:`str`
- The string containing the (math) expression to be typeset, e.g. $\\sqrt{2}$
+ The string containing the (math) expression to be typeset,
+ e.g. ``$\\sqrt{2}$``
Returns
-------
@@ -152,12 +153,12 @@ class TexTemplate(TexTemplateFromFile):
def prepend_package(self, pkg):
"""Adds a new package (or several new packages)
before all other packages. Sometimes, the order of
- the `\\usepackage` directives is relevant.
+ the ``\\usepackage`` directives is relevant.
Parameters
----------
pkg : :class:`str`
- The package name, e.g. "siunitx"
+ The package name, e.g. ``"siunitx"``
"""
self.common_packages.insert(0, pkg)
self.rebuild_cache()
@@ -165,12 +166,12 @@ class TexTemplate(TexTemplateFromFile):
def append_package(self, pkg):
"""Adds a new package (or several new packages)
after all other packages. Sometimes, the order of
- the `\\usepackage` directives is relevant.
+ the ``\\usepackage`` directives is relevant.
Parameters
----------
pkg : :class:`str`
- The package name, e.g. "siunitx"
+ The package name, e.g. ``"siunitx"``
"""
self.common_packages.append(pkg)
self.rebuild_cache()
@@ -181,7 +182,7 @@ class TexTemplate(TexTemplateFromFile):
Parameters
----------
text : :class:`str`
- The text to be included, e.g. "\\newcommand{\\R}{\\mathbb{Q}}"
+ The text to be included, e.g. ``"\\newcommand{\\R}{\\mathbb{Q}}"``.
"""
if self.use_ctex:
self.ctex_preamble_text += text
@@ -202,20 +203,21 @@ class TexTemplate(TexTemplateFromFile):
def generate_tex_command(self, command, *, required_params, optional_params=[]):
"""
Function for creating LaTeX command strings with or without options.
- Internally used to generate `\\usepackage{...}`
+ Internally used to generate ``\\usepackage`` commands.
Parameters
----------
command : :class:`str`
- The command, e.g. `"usepackage"`
+ The command, e.g. ``"usepackage"``.
required_params : Iterable[:class:`str`]
- The required parameters of this command, each wrapped in `{}`s.
+ The required parameters of this command, each wrapped in ``{}``.
optional_params : Iterable[:class:`str`]
- The optional parameters of this command, each separated by a comma inside one `[]`.
+ The optional parameters of this command, each separated by a comma inside one ``[]``.
Examples
--------
::
+
generate_tex_command("usepackage", required_params=["packagename"], optional_params=["option1", "option2"])
Returns
@@ -242,9 +244,9 @@ class TexTemplate(TexTemplateFromFile):
"""Inserts an expression verbatim into the TeX template.
Parameters
- ----–-----
+ ----------
expression : :class:`str`
- The expression to be typeset, e.g. `"foo"`
+ The expression to be typeset, e.g. ``"foo"``.
Returns
-------
@@ -254,15 +256,14 @@ class TexTemplate(TexTemplateFromFile):
return self.body.replace(self.text_to_replace, expression)
def get_text_for_env(self, environment, expression):
- """Inserts an expression into the TeX template, surrounded
- by `\\begin{<environment>} ... \\end{<environment>}` for a certain environment.
+ """Inserts an expression wrapped in a given environment into the TeX template.
Parameters
----------
environment : :class:`str`
The environment in which we should wrap the expression.
expression : :class:`str`
- The string containing the expression to be typeset, e.g. $\\sqrt{2}$
+ The string containing the expression to be typeset, e.g. ``"$\\sqrt{2}$"``
Returns
-------
@@ -276,13 +277,14 @@ class TexTemplate(TexTemplateFromFile):
)
def get_text_for_tex_mode(self, expression):
- """Inserts an expression into the TeX template, surrounded
- by `\\begin{align*} ... \\end{align*}` for math mode.
+ """Inserts an expression within an ``align*`` environment into
+ the TeX template.
Parameters
----------
expression : :class:`str`
- The string containing the (math) expression to be typeset, e.g. $\\sqrt{2}$
+ The string containing the (math) expression to be typeset,
+ e.g. ``"$\\sqrt{2}$"``
Returns
-------
diff --git a/manim/utils/tex_file_writing.py b/manim/utils/tex_file_writing.py
index fefdd5821..e1b527eb6 100644
--- a/manim/utils/tex_file_writing.py
+++ b/manim/utils/tex_file_writing.py
@@ -1,3 +1,11 @@
+"""Interface for writing, compiling, and converting ``.tex`` files.
+
+.. SEEALSO::
+
+ :mod:`.mobject.svg.tex_mobject`
+
+"""
+
import os
import hashlib
from pathlib import Path