Skip to content

Commit

Permalink
Address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chopan050 committed Nov 27, 2024
1 parent 6552eb5 commit 139a325
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
6 changes: 2 additions & 4 deletions manim/mobject/text/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ def _string_to_mob(
if mob_class is None:
mob_class = self.mob_class

_mob_class = self.mob_class if mob_class is None else mob_class

if string not in string_to_mob_map:
string_to_mob_map[string] = _mob_class(string, **kwargs)
string_to_mob_map[string] = mob_class(string, **kwargs)
mob = string_to_mob_map[string].copy()
mob.font_size = self._font_size
return mob
Expand Down Expand Up @@ -346,7 +344,7 @@ def construct(self):

def __init__(
self,
number: float | complex = 0,
number: float = 0,
num_decimal_places: int = 0,
**kwargs: Any,
) -> None:
Expand Down
40 changes: 19 additions & 21 deletions manim/mobject/text/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
self.initial_height: float = self.height

if height is None:
self.font_size: float = self._font_size
self.font_size = self._font_size

if self.organize_left_to_right:
self._organize_submobjects_left_to_right()
Expand Down Expand Up @@ -323,14 +323,11 @@ def _break_up_tex_strings(self, tex_strings: Sequence[str]) -> list[str]:
# Separate out any strings specified in the isolate
# or tex_to_color_map lists.
patterns: list[str] = self.substrings_to_isolate.copy()
for key in self.tex_to_color_map:
try:
# If the given key behaves like tex_strings
key + "" # type: ignore [operator]
patterns.append(key) # type: ignore [arg-type]
except TypeError:
# If the given key is a tuple
patterns.extend(key)
for tex_or_texes in self.tex_to_color_map:
if isinstance(tex_or_texes, str):
patterns.append(tex_or_texes)
else:
patterns += tex_or_texes

patterns = [f"({re.escape(pattern)})" for pattern in patterns]
pattern = "|".join(patterns)
Expand Down Expand Up @@ -374,7 +371,7 @@ def _break_up_by_substrings(self) -> Self:
def get_parts_by_tex(
self, tex_string: str, substring: bool = True, case_sensitive: bool = True
) -> VGroup:
def test(tex1: str, tex2: str) -> bool:
def compare_tex(tex1: str, tex2: str) -> bool:
if not case_sensitive:
tex1 = tex1.lower()
tex2 = tex2.lower()
Expand All @@ -384,7 +381,11 @@ def test(tex1: str, tex2: str) -> bool:
return tex1 == tex2

return VGroup(
*(m for m in self.submobjects if test(tex_string, m.get_tex_string()))
*(
m
for m in self.submobjects
if compare_tex(tex_string, m.get_tex_string())
)
)

def get_part_by_tex(
Expand Down Expand Up @@ -430,17 +431,14 @@ def set_opacity_by_tex(

def set_color_by_tex_to_color_map(
self,
texes_to_color_map: dict[str | Iterable[str], ParsableManimColor],
tex_to_color_map: dict[str | Iterable[str], ParsableManimColor],
**kwargs: Any,
) -> Self:
for texes, color in list(texes_to_color_map.items()):
try:
# If the given key behaves like tex_strings
texes + "" # type: ignore [operator]
self.set_color_by_tex(texes, color, **kwargs) # type: ignore [arg-type]
except TypeError:
# If the given key is a tuple
for tex in texes:
for tex_or_texes, color in tex_to_color_map.items():
if isinstance(tex_or_texes, str):
self.set_color_by_tex(tex_or_texes, color, **kwargs)
else:
for tex in tex_or_texes:
self.set_color_by_tex(tex, color, **kwargs)
return self

Expand Down Expand Up @@ -478,7 +476,7 @@ class Tex(MathTex):

def __init__(
self,
*tex_strings: Any,
*tex_strings: str,
arg_separator: str = "",
tex_environment: str = "center",
**kwargs: Any,
Expand Down

0 comments on commit 139a325

Please sign in to comment.