Skip to content

Can not use \textcolor , always render as white color #3783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhangsn opened this issue May 23, 2024 · 2 comments
Closed

Can not use \textcolor , always render as white color #3783

zhangsn opened this issue May 23, 2024 · 2 comments

Comments

@zhangsn
Copy link

zhangsn commented May 23, 2024

Description of bug / unexpected behavior

Same as title

Expected behavior

Should render the text in red color

How to reproduce the issue

Code for reproducing the problem
from manim import *

class Demo(Scene):
    def construct(self):
        myTemplate = TexTemplate()
        myTemplate.add_to_preamble(r"\usepackage{color}")
        mtex = MathTex(
            "\\textcolor{red}{red}",
            tex_template=myTemplate)
        self.add(mtex)

Logs

Terminal output
docker run --rm -it -v "/Users/zhangsn/Dev/manim:/manim" manimcommunity/manim manim -qm scenes.py Demo
Manim Community v0.18.1

[05/23/24 09:09:46] INFO                                                                                                                                                            scene_file_writer.py:737
                             File ready at '/manim/media/images/scenes/Demo_ManimCE_v0.18.1.png'                                                                                                            
                                                                                                                                                                                                            
                    INFO     Rendered Demo                                                                                                                                                      scene.py:247
                             Played 0 animations    

Demo_ManimCE_v0 18 1

System specifications

System Details
use docker manimcommunity/manim  Manim Community v0.18.1
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:

Additional comments

@uwezi
Copy link
Contributor

uwezi commented May 23, 2024

You cannot use color inside your LaTeX, that is a known limitation in Manim.
(Otherwise almost all text would always be invisible since the default color in LaTeX is black, while by default Manim uses a white background...)

You will have to color your LaTeX objects in Manim afterwards using .set_color(). Or the different additional commands for "automatic" coloring - which might fail though, because of their respective limitations.

class Demo(Scene):
    def construct(self):
        myTemplate = TexTemplate()
        mtex1 = MathTex(
            r"\text{red}\,\int_0^\infty x\,\text{d}x",
            tex_template=myTemplate
        )
        mtex2 = Tex(
            r"red blue yellow",
        ).next_to(mtex1,DOWN)
        mtex1.set_color(RED)
        mtex2[0][0:3].set_color(RED)
        mtex2[0][3:7].set_color(BLUE)
        mtex2[0][7:].set_color(YELLOW)
        self.add(mtex1,mtex2)

image

@zhangsn
Copy link
Author

zhangsn commented May 25, 2024

Thanks for the reply.😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants