带有Manim的长文本

问题描述 投票:0回答:2

在使用 Manim 库的社区版呈现长文本时,我注意到信息呈现在可见窗口之外,效果相当不尽如人意。我怀疑问题的根源是 Latex 未能确保文本保留在 pdf 边界内。有没有自动换行的方法?我不想手动指定换行符,因为文本将不再对齐。

这是一个最小的例子:

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))

python latex manim
2个回答
9
投票

你用的

\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))

结果:


0
投票

您可以使用ragged2ejustifying来实现这一点。 您必须首先创建一个 TexTemplate,它添加了包的要求。

随后,您需要使用 tex_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][1]


  [1]: https://i.stack.imgur.com/vv37v.png
© www.soinside.com 2019 - 2024. All rights reserved.