mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Add support for ctex
This commit is contained in:
parent
6964db2bd5
commit
f33ed570f5
4 changed files with 45 additions and 4 deletions
|
@ -134,8 +134,10 @@ for folder in [FILE_DIR, RASTER_IMAGE_DIR, SVG_IMAGE_DIR, ANIMATIONS_DIR, TEX_DI
|
|||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
TEX_USE_CTEX = False
|
||||
TEX_TEXT_TO_REPLACE = "YourTextHere"
|
||||
TEMPLATE_TEX_FILE = os.path.join(THIS_DIR, "tex_template.tex")
|
||||
TEMPLATE_TEX_FILE = os.path.join(THIS_DIR, "tex_template.tex" if not TEX_USE_CTEX
|
||||
else "ctex_template.tex")
|
||||
with open(TEMPLATE_TEX_FILE, "r") as infile:
|
||||
TEMPLATE_TEXT_FILE_BODY = infile.read()
|
||||
TEMPLATE_TEX_FILE_BODY = TEMPLATE_TEXT_FILE_BODY.replace(
|
||||
|
|
27
ctex_template.tex
Normal file
27
ctex_template.tex
Normal file
|
@ -0,0 +1,27 @@
|
|||
\documentclass[preview]{standalone}
|
||||
|
||||
\usepackage[english]{babel}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{dsfont}
|
||||
\usepackage{setspace}
|
||||
\usepackage{tipa}
|
||||
\usepackage{relsize}
|
||||
\usepackage{textcomp}
|
||||
\usepackage{mathrsfs}
|
||||
\usepackage{calligra}
|
||||
\usepackage{wasysym}
|
||||
\usepackage{ragged2e}
|
||||
\usepackage{physics}
|
||||
\usepackage{xcolor}
|
||||
\usepackage{textcomp}
|
||||
\usepackage{microtype}
|
||||
%\DisableLigatures{encoding = *, family = * }
|
||||
\usepackage[UTF8]{ctex}
|
||||
\linespread{1}
|
||||
|
||||
\begin{document}
|
||||
|
||||
YourTextHere
|
||||
|
||||
\end{document}
|
|
@ -53,6 +53,7 @@ class SVGMobject(VMobject):
|
|||
possible_paths = [
|
||||
os.path.join(SVG_IMAGE_DIR, self.file_name),
|
||||
os.path.join(SVG_IMAGE_DIR, self.file_name + ".svg"),
|
||||
os.path.join(SVG_IMAGE_DIR, self.file_name + ".xdv"),
|
||||
self.file_name,
|
||||
]
|
||||
for path in possible_paths:
|
||||
|
|
|
@ -4,6 +4,7 @@ import hashlib
|
|||
|
||||
from constants import TEX_DIR
|
||||
from constants import TEX_TEXT_TO_REPLACE
|
||||
from constants import TEX_USE_CTEX
|
||||
|
||||
|
||||
def tex_hash(expression, template_tex_file_body):
|
||||
|
@ -44,7 +45,7 @@ def get_null():
|
|||
|
||||
|
||||
def tex_to_dvi(tex_file):
|
||||
result = tex_file.replace(".tex", ".dvi")
|
||||
result = tex_file.replace(".tex", ".dvi" if not TEX_USE_CTEX else ".xdv")
|
||||
if not os.path.exists(result):
|
||||
commands = [
|
||||
"latex",
|
||||
|
@ -54,12 +55,22 @@ def tex_to_dvi(tex_file):
|
|||
tex_file,
|
||||
">",
|
||||
get_null()
|
||||
] if not TEX_USE_CTEX else [
|
||||
"xelatex",
|
||||
"-no-pdf",
|
||||
"-interaction=batchmode",
|
||||
"-halt-on-error",
|
||||
"-output-directory=" + TEX_DIR,
|
||||
tex_file,
|
||||
">",
|
||||
get_null()
|
||||
]
|
||||
exit_code = os.system(" ".join(commands))
|
||||
if exit_code != 0:
|
||||
log_file = tex_file.replace(".tex", ".log")
|
||||
raise Exception(
|
||||
"Latex error converting to dvi. "
|
||||
("Latex error converting to dvi. " if not TEX_USE_CTEX
|
||||
else "Xelatex error converting to xdv. ") +
|
||||
"See log output above or the log file: %s" % log_file)
|
||||
return result
|
||||
|
||||
|
@ -71,7 +82,7 @@ def dvi_to_svg(dvi_file, regen_if_exists=False):
|
|||
Returns a list of PIL Image objects for these images sorted as they
|
||||
where in the dvi
|
||||
"""
|
||||
result = dvi_file.replace(".dvi", ".svg")
|
||||
result = dvi_file.replace(".dvi" if not TEX_USE_CTEX else ".xdv", ".svg")
|
||||
if not os.path.exists(result):
|
||||
commands = [
|
||||
"dvisvgm",
|
||||
|
|
Loading…
Add table
Reference in a new issue