A community-maintained Python framework for creating mathematical animations.
Make sure that altering the tex template files will change tex_hash
Grant Sandersonfe9216997018
diff --git a/constants.py b/constants.pyindex 0ef138cd9..eaa276bb7 100644--- a/constants.py+++ b/constants.py@@ -137,6 +137,10 @@ for folder in [FILE_DIR, RASTER_IMAGE_DIR, SVG_IMAGE_DIR, ANIMATIONS_DIR, TEX_DITEX_TEXT_TO_REPLACE = "YourTextHere"TEMPLATE_TEX_FILE = os.path.join(THIS_DIR, "template.tex")TEMPLATE_TEXT_FILE = os.path.join(THIS_DIR, "text_template.tex")+with open(TEMPLATE_TEX_FILE, "r") as infile:+ TEMPLATE_TEX_FILE_BODY = infile.read()+with open(TEMPLATE_TEXT_FILE, "r") as infile:+ TEMPLATE_TEXT_FILE_BODY = infile.read()FFMPEG_BIN = "ffmpeg"diff --git a/mobject/svg/brace.py b/mobject/svg/brace.pyindex e5c42cb75..02ac89470 100644--- a/mobject/svg/brace.py+++ b/mobject/svg/brace.py@@ -19,6 +19,7 @@ class Brace(TexMobject):"width_multiplier": 2,"max_num_quads": 15,"min_num_quads": 0,+ "background_stroke_width": 0,}def __init__(self, mobject, direction=DOWN, **kwargs):diff --git a/mobject/svg/tex_mobject.py b/mobject/svg/tex_mobject.pyindex 6db0726fe..63cd30d23 100644--- a/mobject/svg/tex_mobject.py+++ b/mobject/svg/tex_mobject.py@@ -36,7 +36,7 @@ class TexSymbol(VMobjectFromSVGPathstring):class SingleStringTexMobject(SVGMobject):CONFIG = {- "template_tex_file": TEMPLATE_TEX_FILE,+ "template_tex_file_body": TEMPLATE_TEX_FILE_BODY,"stroke_width": 0,"fill_opacity": 1.0,"background_stroke_width": 5,@@ -54,7 +54,7 @@ class SingleStringTexMobject(SVGMobject):self.tex_string = tex_stringfile_name = tex_to_svg_file(self.get_modified_expression(tex_string),- self.template_tex_file+ self.template_tex_file_body)SVGMobject.__init__(self, file_name=file_name, **kwargs)if self.height is None:@@ -251,7 +251,7 @@ class TexMobject(SingleStringTexMobject):class TextMobject(TexMobject):CONFIG = {- "template_tex_file": TEMPLATE_TEXT_FILE,+ "template_tex_file_body": TEMPLATE_TEXT_FILE_BODY,"alignment": "\\centering",}@@ -261,7 +261,7 @@ class BulletedList(TextMobject):"buff": MED_LARGE_BUFF,"dot_scale_factor": 2,# Have to include because of handle_multiple_args implementation- "template_tex_file": TEMPLATE_TEXT_FILE,+ "template_tex_file_body": TEMPLATE_TEXT_FILE_BODY,"alignment": "",}diff --git a/utils/tex_file_writing.py b/utils/tex_file_writing.pyindex f41ff1adb..0d18ffec9 100644--- a/utils/tex_file_writing.py+++ b/utils/tex_file_writing.py@@ -6,34 +6,34 @@ from constants import TEX_DIRfrom constants import TEX_TEXT_TO_REPLACE-def tex_hash(expression, template_tex_file):- id_str = str(expression + template_tex_file)+def tex_hash(expression, template_tex_file_body):+ id_str = str(expression + template_tex_file_body)hasher = hashlib.sha256()hasher.update(id_str.encode())# Truncating at 16 bytes for cleanlinessreturn hasher.hexdigest()[:16]-def tex_to_svg_file(expression, template_tex_file):- tex_file = generate_tex_file(expression, template_tex_file)+def tex_to_svg_file(expression, template_tex_file_body):+ tex_file = generate_tex_file(expression, template_tex_file_body)dvi_file = tex_to_dvi(tex_file)return dvi_to_svg(dvi_file)-def generate_tex_file(expression, template_tex_file):+def generate_tex_file(expression, template_tex_file_body):result = os.path.join(TEX_DIR,- tex_hash(expression, template_tex_file)+ tex_hash(expression, template_tex_file_body)) + ".tex"if not os.path.exists(result):print("Writing \"%s\" to %s" % ("".join(expression), result))- with open(template_tex_file, "r") as infile:- body = infile.read()- body = body.replace(TEX_TEXT_TO_REPLACE, expression)+ new_body = template_tex_file_body.replace(+ TEX_TEXT_TO_REPLACE, expression+ )with open(result, "w") as outfile:- outfile.write(body)+ outfile.write(new_body)return result