Update how tex configuration default is passed in

This commit is contained in:
Grant Sanderson 2024-12-11 07:18:30 -06:00
parent 37a05094ea
commit 4d7f6093b4
2 changed files with 18 additions and 25 deletions

View file

@ -56,15 +56,19 @@ file_writer:
pixel_format: "yuv420p"
saturation: 1.0
gamma: 1.0
# Most of the scene configuration will come from CLI arguments,
# but defaults can be set here
scene:
# Most of the scene configuration will come from CLI arguments,
# but defaults can be set here
show_animation_progress: False
leave_progress_bars: False
# How long does a scene pause on Scene.wait calls
default_wait_time: 1.0
style:
tex_template: "default"
vmobject:
default_stroke_width: 4.0
tex:
# See tex_templates.yml
template: "default"
style: # TODO, change to `text`
font: "Consolas"
text_alignment: "LEFT"
embed:
@ -89,9 +93,6 @@ sizes:
# Default buffers used in Mobject.next_to or Mobject.to_edge
default_mobject_to_edge_buff: 0.5
default_mobject_to_mobject_buff: 0.25
vmobject:
# Default stroke width for VMobject
default_stroke_width: 4.0
colors:
blue_e: "#1C758A"
blue_d: "#29ABCA"

View file

@ -16,9 +16,6 @@ from manimlib.logger import log
from manimlib.utils.simple_functions import hash_string
SAVED_TEX_CONFIG = {}
def get_tex_template_config(template_name: str) -> dict[str, str]:
name = template_name.replace(" ", "_").lower()
template_path = os.path.join(get_manim_dir(), "manimlib", "tex_templates.yml")
@ -33,7 +30,8 @@ def get_tex_template_config(template_name: str) -> dict[str, str]:
return templates_dict[name]
def get_tex_config() -> dict[str, str]:
@lru_cache
def get_tex_config(template: str = "") -> dict[str, str]:
"""
Returns a dict which should look something like this:
{
@ -42,16 +40,13 @@ def get_tex_config() -> dict[str, str]:
"preamble": "..."
}
"""
# Only load once, then save thereafter
if not SAVED_TEX_CONFIG:
template_name = get_global_config()["style"]["tex_template"]
template_config = get_tex_template_config(template_name)
SAVED_TEX_CONFIG.update({
"template": template_name,
"compiler": template_config["compiler"],
"preamble": template_config["preamble"]
})
return SAVED_TEX_CONFIG
template = template or get_global_config()["tex"]["template"]
template_config = get_tex_template_config(template)
return {
"template": template,
"compiler": template_config["compiler"],
"preamble": template_config["preamble"]
}
def get_full_tex(content: str, preamble: str = ""):
@ -94,10 +89,7 @@ def latex_to_svg(
message = message[:max_message_len - 3] + "..."
print(message, end="\r")
tex_config = get_tex_config()
if template and template != tex_config["template"]:
tex_config = get_tex_template_config(template)
tex_config = get_tex_config(template)
compiler = tex_config["compiler"]
if compiler == "latex":