mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 18:37:45 +00:00
Add String.get_symbol_substrings and Tex.get_symbol_substrings
This commit is contained in:
parent
4335e85659
commit
3aa9eb6372
2 changed files with 14 additions and 2 deletions
|
|
@ -561,7 +561,10 @@ class StringMobject(SVGMobject, ABC):
|
|||
return self.select_parts(selector)[index]
|
||||
|
||||
def substr_to_path_count(self, substr: str) -> int:
|
||||
return len(re.sub(R"\s", "", substr))
|
||||
return len(re.sub(r"\s", "", substr))
|
||||
|
||||
def get_symbol_substrings(self):
|
||||
return list(re.sub(r"\s", "", self.string))
|
||||
|
||||
def select_unisolated_substring(self, pattern: str | re.Pattern) -> VGroup:
|
||||
if isinstance(pattern, str):
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Tex(StringMobject):
|
|||
isolate = [isolate]
|
||||
isolate = [*isolate, *tex_strings]
|
||||
|
||||
tex_string = " ".join(tex_strings)
|
||||
tex_string = (" ".join(tex_strings)).strip()
|
||||
|
||||
# Prevent from passing an empty string.
|
||||
if not tex_string.strip():
|
||||
|
|
@ -222,6 +222,15 @@ class Tex(StringMobject):
|
|||
log.warning(f"Estimated size of {tex} does not match true size")
|
||||
return num_tex_symbols(substr)
|
||||
|
||||
def get_symbol_substrings(self):
|
||||
pattern = "|".join((
|
||||
# Tex commands
|
||||
r"\\[a-zA-Z]+",
|
||||
# And most single characters, with these exceptions
|
||||
r"[^\^\{\}\s\_\$\\\&]",
|
||||
))
|
||||
return re.findall(pattern, self.string)
|
||||
|
||||
def make_number_changable(
|
||||
self,
|
||||
value: float | int | str,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue