Allow MTex to accept multiple strings as an argument

This commit is contained in:
Grant Sanderson 2022-12-20 14:09:53 -08:00
parent 6176bcd45a
commit e0725c111e

View file

@ -22,26 +22,41 @@ class MTex(StringMobject):
def __init__( def __init__(
self, self,
tex_string: str, *tex_strings: str,
font_size: int = 48, font_size: int = 48,
alignment: str = R"\centering", alignment: str = R"\centering",
template: str = "", template: str = "",
additional_preamble: str = "", additional_preamble: str = "",
tex_to_color_map: dict = dict(), tex_to_color_map: dict = dict(),
t2c: dict = dict(), t2c: dict = dict(),
isolate: Selector = [],
use_labelled_svg: bool = True, use_labelled_svg: bool = True,
**kwargs **kwargs
): ):
# Combine multi-string arg, but mark them to isolate
if len(tex_strings) > 1:
if isinstance(isolate, (str, re.Pattern, tuple)):
isolate = [isolate]
isolate = [*isolate, *tex_strings]
tex_string = " ".join(tex_strings)
# Prevent from passing an empty string. # Prevent from passing an empty string.
if not tex_string.strip(): if not tex_string.strip():
tex_string = R"\\" tex_string = R"\\"
self.tex_string = tex_string self.tex_string = tex_string
self.alignment = alignment self.alignment = alignment
self.template = template self.template = template
self.additional_preamble = additional_preamble self.additional_preamble = additional_preamble
self.tex_to_color_map = dict(**t2c, **tex_to_color_map) self.tex_to_color_map = dict(**t2c, **tex_to_color_map)
super().__init__(tex_string, use_labelled_svg=use_labelled_svg, **kwargs) super().__init__(
tex_string,
use_labelled_svg=use_labelled_svg,
isolate=isolate,
**kwargs
)
self.set_color_by_tex_to_color_map(self.tex_to_color_map) self.set_color_by_tex_to_color_map(self.tex_to_color_map)
self.scale(SCALE_FACTOR_PER_FONT_POINT * font_size) self.scale(SCALE_FACTOR_PER_FONT_POINT * font_size)