def __init__(self, tex_string, **kwargs): super().__init__(**kwargs) self.tex_string = MTex.modify_tex_string(tex_string) tex_parser = _TexParser(self) self.tex_spans_dict = tex_parser.tex_spans_dict new_tex = tex_parser.get_labelled_expression() full_tex = self.get_tex_file_body(new_tex) hash_val = hash(full_tex) if hash_val not in tex_hash_to_mob_map: with display_during_execution(f"Writing \"{tex_string}\""): filename = tex_to_svg_file(full_tex) svg_mob = _LabelledTex(filename) tex_hash_to_mob_map[hash_val] = svg_mob self.add(*[ submob.copy() for submob in tex_hash_to_mob_map[hash_val] ]) self.build_submobjects() self.init_colors() self.set_color_by_tex_to_color_map(self.tex_to_color_map) if self.height is None: self.scale(SCALE_FACTOR_PER_FONT_POINT * self.font_size) if self.organize_left_to_right: self.organize_submobjects_left_to_right()
def __init__(self, tex_string, **kwargs): super().__init__(**kwargs) assert (isinstance(tex_string, str)) self.tex_string = tex_string if tex_string not in tex_string_with_color_to_mob_map: with display_during_execution(f" Writing \"{tex_string}\""): full_tex = self.get_tex_file_body(tex_string) filename = tex_to_svg_file(full_tex) svg_mob = SVGMobject(filename, height=None, color=self.color, stroke_width=self.stroke_width, path_string_config={ "should_subdivide_sharp_curves": True, "should_remove_null_curves": True, }) tex_string_with_color_to_mob_map[(self.color, tex_string)] = svg_mob self.add(*(sm.copy() for sm in tex_string_with_color_to_mob_map[(self.color, tex_string)])) self.init_colors(override=False) if self.height is None: self.scale(SCALE_FACTOR_PER_FONT_POINT * self.font_size) if self.organize_left_to_right: self.organize_submobjects_left_to_right()
def get_file_path_by_content(self, content: str) -> str: tex_config = get_tex_config() full_tex = tex_config["tex_body"].replace( tex_config["text_to_replace"], content) with display_during_execution(f"Writing \"{self.tex_string}\""): file_path = tex_to_svg_file(full_tex) return file_path
def _get_file_path(self, use_plain_tex: bool) -> str: if use_plain_tex: tex_string = self.tex_string else: tex_string = self.parser.get_labelled_tex_string() full_tex = self.get_tex_file_body(tex_string) with display_during_execution(f"Writing \"{self.tex_string}\""): file_path = self.tex_to_svg_file_path(full_tex) return file_path
def generate_mobject(self): tex_string = self.tex_string tex_parser = self.get_parser() self.tex_spans_dict = tex_parser.tex_spans_dict self.specified_substrings = tex_parser.specified_substrings plain_full_tex = self.get_tex_file_body(tex_string) plain_hash_val = hash(plain_full_tex) if plain_hash_val in TEX_HASH_TO_MOB_MAP: self.add(*TEX_HASH_TO_MOB_MAP[plain_hash_val].copy()) return self labelled_expression = tex_parser.get_labelled_expression() full_tex = self.get_tex_file_body(labelled_expression) hash_val = hash(full_tex) if hash_val in TEX_HASH_TO_MOB_MAP and not self.generate_plain_tex_file: self.add(*TEX_HASH_TO_MOB_MAP[hash_val].copy()) return self with display_during_execution(f"Writing \"{tex_string}\""): filename = tex_to_svg_file(full_tex) svg_mob = _LabelledTex(filename) self.add(*svg_mob.copy()) self.build_submobjects() TEX_HASH_TO_MOB_MAP[hash_val] = self if not self.generate_plain_tex_file: return self with display_during_execution(f"Writing \"{tex_string}\""): filename = tex_to_svg_file(plain_full_tex) plain_svg_mob = _PlainTex(filename) svg_mob = TEX_HASH_TO_MOB_MAP[hash_val] for plain_submob, submob in zip(plain_svg_mob, svg_mob): plain_submob.glyph_label = submob.glyph_label self.add(*plain_svg_mob.copy()) self.build_submobjects() TEX_HASH_TO_MOB_MAP[plain_hash_val] = self return self
def get_file_path(self) -> str: full_tex = self.get_tex_file_body(self.tex_string) with display_during_execution(f"Writing \"{self.tex_string}\""): file_path = tex_to_svg_file(full_tex) return file_path