Skip to content

set_color_by_t2c in Text mobject doesn't account for white space #1674

@Sylk1-9

Description

@Sylk1-9

Description of bug / unexpected behavior

(using ManimCE_v0.7.0)

When using the internal function set_color_by_t2c(t2c={word:color}) on an mobject.svg.text_mobject (created with Text("mystring") ), the coloring of the string is sometimes shifted. When running some researches and tests, I am almost certain that it badly accounts for blanck spaces when calculating the index at which the word to color starts and end (done by the internal function self.find_indexes(word, self.original_text)). This results in a single positif shift of the index of the word to color for each previous blank spaces present in the string (see example and image below).

Expected behavior

The coloring should correspond to the word passed by in the dictionary {word:color}

How to reproduce the issue

Code for reproducing the problem
from manim import *

class Test(Scene):
    def construct(self):
        TxExample = Text("This example contains white spaces", color=WHITE).scale_in_place(0.8)
        TxExample.set_color_by_t2c({"This": GREEN})
        TxExample.set_color_by_t2c({"example": RED})
        TxExample.set_color_by_t2c({"contains": BLUE})
        TxExample.set_color_by_t2c({"white": GOLD})
        self.add(TxExample)

Additional media files

Images/GIFs

Test_ManimCE_v0 7 0

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:
FFMPEG

Output of ffmpeg -version:

PASTE HERE

Additional comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue:bugSomething isn't working... For use in issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions