Skip to content

Commit 4166f46

Browse files
committed
Revert "Merge pull request #48 from PhilippImhof/customtex"
This reverts commit 9c8913f, reversing changes made to a29eabd.
1 parent 165acd5 commit 4166f46

File tree

8 files changed

+43
-450
lines changed

8 files changed

+43
-450
lines changed

example_scenes/customtex.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

manim/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,3 @@
6868
from .utils.sounds import *
6969
from .utils.space_ops import *
7070
from .utils.strings import *
71-
from .utils.tex import *

manim/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def main():
77
args = config.parse_cli()
88
cfg = config.get_configuration(args)
99
config.initialize_directories(cfg)
10-
config.initialize_tex(cfg)
1110
extract_scene.main(cfg)
1211

1312

manim/config.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import os
44
import sys
55
import types
6-
import manim.constants as consts
76

8-
from .utils.tex import *
97
from . import constants
108
from . import dirs
119
from .logger import logger
1210

13-
__all__ = ["parse_cli", "get_configuration", "initialize_directories","register_tex_template","initialize_tex"]
11+
__all__ = ["parse_cli", "get_configuration", "initialize_directories"]
1412

1513

1614
def parse_cli():
@@ -142,12 +140,7 @@ def parse_cli():
142140
"--text_dir",
143141
help="Directory to write text",
144142
)
145-
parser.add_argument(
146-
"--tex_template",
147-
help="Specify a custom TeX template file",
148-
)
149143
return parser.parse_args()
150-
151144
except argparse.ArgumentError as err:
152145
logger.error(str(err))
153146
sys.exit(2)
@@ -183,7 +176,6 @@ def get_configuration(args):
183176
"video_dir": args.video_dir,
184177
"tex_dir": args.tex_dir,
185178
"text_dir": args.text_dir,
186-
"tex_template": args.tex_template,
187179
}
188180

189181
# Camera configuration
@@ -289,39 +281,3 @@ def initialize_directories(config):
289281
dirs.VIDEO_DIR = dir_config["video_dir"]
290282
dirs.TEX_DIR = dir_config["tex_dir"]
291283
dirs.TEXT_DIR = dir_config["text_dir"]
292-
293-
def register_tex_template(tpl):
294-
"""Register the given LaTeX template for later use.
295-
296-
Parameters
297-
----------
298-
tpl : :class:`~.TexTemplate`
299-
The LaTeX template to register.
300-
"""
301-
consts.TEX_TEMPLATE = tpl
302-
303-
def initialize_tex(config):
304-
"""Safely create a LaTeX template object from a file.
305-
If file is not readable, the default template file is used.
306-
307-
Parameters
308-
----------
309-
filename : :class:`str`
310-
The name of the file with the LaTeX template.
311-
"""
312-
filename=""
313-
if config["tex_template"]:
314-
filename = os.path.expanduser(config["tex_template"])
315-
if filename and not os.access(filename, os.R_OK):
316-
# custom template not available, fallback to default
317-
logger.warning(
318-
f"Custom TeX template {filename} not found or not readable. "
319-
"Falling back to the default template."
320-
)
321-
filename = ""
322-
if filename:
323-
# still having a filename -> use the file
324-
consts.TEX_TEMPLATE = TexTemplateFromFile(filename=filename)
325-
else:
326-
# use the default template
327-
consts.TEX_TEMPLATE = TexTemplate()

manim/constants.py

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,6 @@
22
import os
33
from .logger import logger
44

5-
MEDIA_DIR = ""
6-
VIDEO_DIR = ""
7-
VIDEO_OUTPUT_DIR = ""
8-
TEX_DIR = ""
9-
TEXT_DIR = ""
10-
TEX_TEMPLATE = None
11-
12-
def initialize_directories(config):
13-
global MEDIA_DIR
14-
global VIDEO_DIR
15-
global VIDEO_OUTPUT_DIR
16-
global TEX_DIR
17-
global TEXT_DIR
18-
19-
video_path_specified = config["video_dir"] or config["video_output_dir"]
20-
21-
if not (video_path_specified and config["tex_dir"]):
22-
if config["media_dir"]:
23-
MEDIA_DIR = config["media_dir"]
24-
else:
25-
MEDIA_DIR = os.path.join(
26-
os.path.expanduser('~'),
27-
"Dropbox (3Blue1Brown)/3Blue1Brown Team Folder"
28-
)
29-
if not os.path.isdir(MEDIA_DIR):
30-
MEDIA_DIR = "./media"
31-
print(
32-
f"Media will be written to {MEDIA_DIR + os.sep}. You can change "
33-
"this behavior with the --media_dir flag."
34-
)
35-
else:
36-
if config["media_dir"]:
37-
print(
38-
"Ignoring --media_dir, since both --tex_dir and a video "
39-
"directory were both passed"
40-
)
41-
42-
TEX_DIR = config["tex_dir"] or os.path.join(MEDIA_DIR, "Tex")
43-
TEXT_DIR = os.path.join(MEDIA_DIR, "texts")
44-
if not video_path_specified:
45-
VIDEO_DIR = os.path.join(MEDIA_DIR, "videos")
46-
VIDEO_OUTPUT_DIR = os.path.join(MEDIA_DIR, "videos")
47-
elif config["video_output_dir"]:
48-
VIDEO_OUTPUT_DIR = config["video_output_dir"]
49-
else:
50-
VIDEO_DIR = config["video_dir"]
51-
52-
for folder in [VIDEO_DIR, VIDEO_OUTPUT_DIR, TEX_DIR, TEXT_DIR]:
53-
if folder != "" and not os.path.exists(folder):
54-
os.makedirs(folder)
55-
56-
575
NOT_SETTING_FONT_MSG='''
586
You haven't set font.
597
If you are not using English, this may cause text rendering problem.
@@ -72,23 +20,19 @@ class MyText(Text):
7220
OBLIQUE = 'OBLIQUE'
7321
BOLD = 'BOLD'
7422

75-
HELP_MESSAGE = """
76-
Usage:
77-
python extract_scene.py <module> [<scene name>]
78-
-p preview in low quality
79-
-s show and save picture of last frame
80-
-w write result to file [this is default if nothing else is stated]
81-
-o <file_name> write to a different file_name
82-
-l use low quality
83-
-m use medium quality
84-
-a run and save every scene in the script, or all args for the given scene
85-
-q don't print progress
86-
-f when writing to a movie file, export the frames in png sequence
87-
-t use transperency when exporting images
88-
-n specify the number of the animation to start from
89-
-r specify a resolution
90-
-c specify a background color
91-
"""
23+
TEX_USE_CTEX = False
24+
TEX_TEXT_TO_REPLACE = "YourTextHere"
25+
TEMPLATE_TEX_FILE = os.path.join(
26+
os.path.dirname(os.path.realpath(__file__)),
27+
"tex_template.tex" if not TEX_USE_CTEX else "ctex_template.tex"
28+
)
29+
with open(TEMPLATE_TEX_FILE, "r") as infile:
30+
TEMPLATE_TEXT_FILE_BODY = infile.read()
31+
TEMPLATE_TEX_FILE_BODY = TEMPLATE_TEXT_FILE_BODY.replace(
32+
TEX_TEXT_TO_REPLACE,
33+
"\\begin{align*}\n" + TEX_TEXT_TO_REPLACE + "\n\\end{align*}",
34+
)
35+
9236
SCENE_NOT_FOUND_MESSAGE = """
9337
{} is not in the script
9438
"""

manim/mobject/svg/tex_mobject.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ...utils.strings import split_string_list_to_isolate_substrings
1212
from ...utils.tex_file_writing import tex_to_svg_file
1313

14+
1415
TEX_MOB_SCALE_FACTOR = 0.05
1516

1617

@@ -20,8 +21,10 @@ class TexSymbol(VMobjectFromSVGPathstring):
2021
"""
2122
pass
2223

24+
2325
class SingleStringTexMobject(SVGMobject):
2426
CONFIG = {
27+
"template_tex_file_body": TEMPLATE_TEX_FILE_BODY,
2528
"stroke_width": 0,
2629
"fill_opacity": 1.0,
2730
"background_stroke_width": 1,
@@ -30,7 +33,6 @@ class SingleStringTexMobject(SVGMobject):
3033
"height": None,
3134
"organize_left_to_right": False,
3235
"alignment": "",
33-
"type": "tex",
3436
}
3537

3638
def __init__(self, tex_string, **kwargs):
@@ -39,7 +41,7 @@ def __init__(self, tex_string, **kwargs):
3941
self.tex_string = tex_string
4042
file_name = tex_to_svg_file(
4143
self.get_modified_expression(tex_string),
42-
self.type
44+
self.template_tex_file_body
4345
)
4446
SVGMobject.__init__(self, file_name=file_name, **kwargs)
4547
if self.height is None:
@@ -245,9 +247,9 @@ def sort_alphabetically(self):
245247

246248
class TextMobject(TexMobject):
247249
CONFIG = {
250+
"template_tex_file_body": TEMPLATE_TEXT_FILE_BODY,
248251
"alignment": "\\centering",
249252
"arg_separator": "",
250-
"type": "text",
251253
}
252254

253255

@@ -256,6 +258,7 @@ class BulletedList(TextMobject):
256258
"buff": MED_LARGE_BUFF,
257259
"dot_scale_factor": 2,
258260
# Have to include because of handle_multiple_args implementation
261+
"template_tex_file_body": TEMPLATE_TEXT_FILE_BODY,
259262
"alignment": "",
260263
}
261264

@@ -322,4 +325,4 @@ def __init__(self, *text_parts, **kwargs):
322325
else:
323326
underline.set_width(self.underline_width)
324327
self.add(underline)
325-
self.underline = underline
328+
self.underline = underline

0 commit comments

Comments
 (0)