Repository: ManimCommunity/manim

Issue:
`t2s` and `t2w` in `Text` is broken in main branch
Looks like `t2s` and `t2w` is broken in `Text`, see https://docs.manim.community/en/latest/reference/manim.mobject.svg.text_mobject.Text.html#textitalicandboldexample

More like the words which have different weights or slants have black colour which is should be same as rest of the work (as in white).
For example,
```py
from manim import *
config.background_color = RED
class TextItalicAndBoldExample(Scene):
    def construct(self):
        text = Text("Hello world", t2s={'world':ITALIC})
        self.add(text)
```
creates a white `Hello` and black `world` in italics, while it should create both "Hello World" in white colour as in previously released versions.

![](https://media.discordapp.net/attachments/833763907516497950/939938358807892038/unknown.png)

_Originally posted by @naveen521kk in https://github.com/ManimCommunity/manim/issues/2332#issuecomment-1030876857_


Discussion:

Resolving patch:
diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.py
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@ -607,7 +607,10 @@ def _text2hash(self, color: Color):
         return hasher.hexdigest()[:16]
 
     def _merge_settings(
-        self, left_setting: TextSetting, right_setting: TextSetting, args: Sequence[str]
+        self,
+        left_setting: TextSetting,
+        right_setting: TextSetting,
+        default_args: dict[str, Iterable[str]],
     ) -> TextSetting:
         contained = right_setting.end < left_setting.end
         new_setting = copy.copy(left_setting) if contained else copy.copy(right_setting)
@@ -617,10 +620,10 @@ def _merge_settings(
         if not contained:
             right_setting.end = new_setting.start
 
-        for arg in args:
+        for arg in default_args:
             left = getattr(left_setting, arg)
             right = getattr(right_setting, arg)
-            default = getattr(self, arg)
+            default = default_args[arg]
             if left != default and getattr(right_setting, arg) != default:
                 raise ValueError(
                     f"Ambiguous style for text '{self.text[right_setting.start:right_setting.end]}':"
@@ -630,13 +633,15 @@ def _merge_settings(
         return new_setting
 
     def _get_settings_from_t2xs(
-        self, t2xs: Sequence[tuple[dict[str, str], str]]
+        self,
+        t2xs: Sequence[tuple[dict[str, str], str]],
+        default_args: dict[str, Iterable[str]],
     ) -> Sequence[TextSetting]:
         settings = []
         t2xwords = set(chain(*([*t2x.keys()] for t2x, _ in t2xs)))
         for word in t2xwords:
             setting_args = {
-                arg: t2x[word] if word in t2x else getattr(self, arg)
+                arg: t2x[word] if word in t2x else default_args[arg]
                 for t2x, arg in t2xs
             }
 
@@ -645,10 +650,10 @@ def _get_settings_from_t2xs(
         return settings
 
     def _get_settings_from_gradient(
-        self, setting_args: dict[str, Iterable[str]]
+        self, default_args: dict[str, Iterable[str]]
     ) -> Sequence[TextSetting]:
         settings = []
-        args = copy.copy(setting_args)
+        args = copy.copy(default_args)
         if self.gradient:
             colors = color_gradient(self.gradient, len(self.text))
             for i in range(len(self.text)):
@@ -678,12 +683,12 @@ def _text2settings(self, color: Color):
             (self.t2w, "weight"),
             (self.t2c, "color"),
         ]
-        setting_args = {
+        default_args = {
             arg: getattr(self, arg) if arg != "color" else color for _, arg in t2xs
         }
 
-        settings = self._get_settings_from_t2xs(t2xs)
-        settings.extend(self._get_settings_from_gradient(setting_args))
+        settings = self._get_settings_from_t2xs(t2xs, default_args)
+        settings.extend(self._get_settings_from_gradient(default_args))
 
         # Handle overlaps
 
@@ -694,7 +699,7 @@ def _text2settings(self, color: Color):
 
             next_setting = settings[index + 1]
             if setting.end > next_setting.start:
-                new_setting = self._merge_settings(setting, next_setting, setting_args)
+                new_setting = self._merge_settings(setting, next_setting, default_args)
                 new_index = index + 1
                 while (
                     new_index < len(settings)
@@ -708,10 +713,10 @@ def _text2settings(self, color: Color):
         start = 0
         for setting in settings:
             if setting.start != start:
-                temp_settings.append(TextSetting(start, setting.start, **setting_args))
+                temp_settings.append(TextSetting(start, setting.start, **default_args))
             start = setting.end
         if start != len(self.text):
-            temp_settings.append(TextSetting(start, len(self.text), **setting_args))
+            temp_settings.append(TextSetting(start, len(self.text), **default_args))
         settings = sorted(temp_settings, key=lambda setting: setting.start)
 
         if re.search(r"\n", self.text):


Test patch: