Talmsmen
Talmsmen

Reputation: 193

Long Text with Manim

While rendering long pieces of text using the community edition of the Manim library, I have noticed that information renders outside of the visible window for a rather unsatisfactory effect. I suspect that the root of the problem is the failure of Latex to ensure that text remains within the pdf boundaries. Is there a method to automatically wrap text? I do not want to manually specify line breaks as the text will no longer appear justified.

Here is a minimal example:

enter image description here

from manim import *


class Edge_Wise(Scene):
    def construct(self):
        text=Tex("\\text{First we conceptualize an undirected graph  ${G}$  as a union of a finite number of line segments residing in  ${\\mathbb{{{C}}}}$ . By taking our earlier parametrization, we can create an almost trivial extension to  ${\\mathbb{{{R}}}}^{{{3}}}$ . In the following notation, we write a bicomplex number of a 2-tuple of complex numbers, the latter of which is multiplied by the constant  ${j}$ .  ${z}_{{0}}\\in{\\mathbb{{{C}}}}_{{>={0}}}$  is an arbitrary point in the upper half plane from which the contour integral begins. The function  ${\\tan{{\\left(\\frac{{{\\theta}-{\\pi}}}{{z}}\\right)}}}:{\\left[{0},{2}{\\pi}\\right)}\\to{\\left[-\\infty,\\infty\\right)}$  ensures that the vertices at  $\\infty$  for the Schwarz-Christoffel transform correspond to points along the branch cut at  ${\\mathbb{{{R}}}}_{{+}}$ .}")
        text.scale(0.6)
        self.play(FadeIn(text))
        self.wait(1)
        self.play(FadeOut(text))

Upvotes: 6

Views: 7102

Answers (2)

H3llShadow
H3llShadow

Reputation: 21

You can use ragged2e's justifying to achieve this.

You must first create a TexTemplate, which adds the requirement for the package. Then, you will need to use the tex_template parameter to select this newly created template.

class TextWrap(Scene):
    def construct(self):
        myBaseTemplate = TexTemplate(
            documentclass="\documentclass[preview]{standalone}"
        )
        myBaseTemplate.add_to_preamble(r"\usepackage{ragged2e}")

        text = Tex(
            "\\justifying{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus in lacus tristique, interdum turpis sit amet, bibendum felis. Suspendisse mattis arcu quis leo tempus condimentum. Sed luctus turpis mauris, a tristique erat viverra non. Aliquam sed odio convallis, imperdiet mi ac, interdum neque. Donec volutpat quis velit in dictum. Quisque nec quam nec tellus placerat finibus ac nec sapien. Pellentesque maximus velit eu varius lacinia. Pellentesque at nibh nec dolor laoreet vestibulum.}",
            tex_template=myBaseTemplate,
        ).scale(0.6)
        self.play(FadeIn(text))
        self.wait()

Output: Justified Lorem Ipsum via Manim

Upvotes: 2

jf_
jf_

Reputation: 3479

The \text environment you used does not wrap. It is intended to format text as text within math mode, and you don't need it when you are outside $...$. The following example gives you justified text:

class SquareToCircle(Scene):
    def construct(self):
        text=Tex("\\justifying {First we conceptualize an undirected graph  ${G}$  as a union of a finite number of line segments residing in  ${\\mathbb{{{C}}}}$ . By taking our earlier parametrization, we can create an almost trivial extension to  ${\\mathbb{{{R}}}}^{{{3}}}$ . In the following notation, we write a bicomplex number of a 2-tuple of complex numbers, the latter of which is multiplied by the constant  ${j}$ .  ${z}_{{0}}\\in{\\mathbb{{{C}}}}_{{>={0}}}$  is an arbitrary point in the upper half plane from which the contour integral begins. The function  ${\\tan{{\\left(\\frac{{{\\theta}-{\\pi}}}{{z}}\\right)}}}:{\\left[{0},{2}{\\pi}\\right)}\\to{\\left[-\\infty,\\infty\\right)}$  ensures that the vertices at  $\\infty$  for the Schwarz-Christoffel transform correspond to points along the branch cut at  ${\\mathbb{{{R}}}}_{{+}}$ .}")
        text.scale(0.6)
        self.play(FadeIn(text))
        self.wait(1)
        self.play(FadeOut(text))

Result: result

Upvotes: 10

Related Questions