Closed JonasFovea closed 4 months ago
Once LaTeX has rendered your Tex()
objects no letters or words will ever be able to move around anymore. If you want to typeset text with a certain running length of the text lines, you will have to do this within your Tex()
object, for example by using the minipage
environment of LaTeX.
from manim import *
class textex(Scene):
def construct(self):
t1 = Tex(r"This is plain text mode\\ in two centered lines.").to_edge(UP, buff=0)
self.add(t1)
t2 = Tex(
r"This is a longer text block in a so-called minipage environment allowing for justified margins. And just because I can I also throw in some math $E=mc^2$.",
tex_environment="{minipage}{7cm}"
).set_color(YELLOW).scale_to_fit_width(8).next_to(t1,DOWN)
t3 = Tex(
r"\raggedright This is a longer text block in a so-called minipage environment allowing for justified margins. And just because I can I also throw in some math $E=mc^2$.",
tex_environment="{minipage}{7cm}"
).set_color(YELLOW).scale(0.5).next_to(t2,DOWN)
t4 = Tex(
r"\raggedleft This is a longer text block in a so-called minipage environment allowing for justified margins. And just because I can I also throw in some math $E=mc^2$.",
tex_environment="{minipage}{7cm}"
).set_color(YELLOW).scale(0.5).next_to(t3,DOWN)
t5 = Tex(
r"\centering This is a longer text block in a so-called minipage environment allowing for justified margins. And just because I can I also throw in some math $E=mc^2$.",
tex_environment="{minipage}{7cm}"
).set_color(YELLOW).scale(0.5).next_to(t4,DOWN)
self.add(t2,t3,t4,t5)
t6 = MathTex(
r"Q = \sum\limits_{i=1}^{n}i = \frac{n\left(n-1\right)}{2} \quad\text{C.\ F.\ Gauss}"
).set_color(RED).next_to(t5,DOWN)
self.add(t6)
class jonasfovea(Scene):
def construct(self):
text = Tex(r"""
{20em}The \emph{same} point $\mathbf{p}$ can be expressed
in two coordinate systems
by a linear combination of the respective base vectors.""",
font_size=60,
tex_environment='minipage')
self.add(text)
just a note of caution: in Manim 0.18.1 it is not possible to use tex_environment="{minipage}{7cm}"
because of a bug which hopefully will be gone in the upcoming 0.19. Instead you need to use the syntax from my second example, which would also work in future versions of Manim...
Ah okay, that makes sense!
Thanks a lot!
Description of bug / unexpected behavior
I would like to have a Tex-Mobject with a specific width and font size, so that the lines fill the full width.
So I specified both the width and the font size. But the text is either scaled to fit the width, or the font size is correct, but the text is wider, than specified.
Expected behavior
Text of the specified width with the specified font size and added linebreaks if necessary.
How to reproduce the issue
Code for reproducing the problem
```py Tex(r"The \emph{same} point $\mathbf{p}$ can be expressed in two coordinate systems " r"by a linear combination of the respective base vectors.", width=120, font_size=60, tex_environment='flushleft') ```Additional media files
Part of what is redered with the width set to 120 and fontsize of 60 (text is too wide and font is too small): Removing the font size, but keeping the width (text is too small):
Images/GIFs
Logs
Terminal output
``` PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR ```System specifications
System Details
- OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): - RAM: - Python version (`python/py/python3 --version`): - Installed modules (provide output from `pip list`): ``` PASTE HERE ```LaTeX details
+ LaTeX distribution (e.g. TeX Live 2020): + Installed LaTeX packages:Additional comments