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):
|
if not os.path.exists(folder):
|
||||||
os.makedirs(folder)
|
os.makedirs(folder)
|
||||||
|
|
||||||
|
TEX_USE_CTEX = False
|
||||||
TEX_TEXT_TO_REPLACE = "YourTextHere"
|
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:
|
with open(TEMPLATE_TEX_FILE, "r") as infile:
|
||||||
TEMPLATE_TEXT_FILE_BODY = infile.read()
|
TEMPLATE_TEXT_FILE_BODY = infile.read()
|
||||||
TEMPLATE_TEX_FILE_BODY = TEMPLATE_TEXT_FILE_BODY.replace(
|
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 = [
|
possible_paths = [
|
||||||
os.path.join(SVG_IMAGE_DIR, self.file_name),
|
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 + ".svg"),
|
||||||
|
os.path.join(SVG_IMAGE_DIR, self.file_name + ".xdv"),
|
||||||
self.file_name,
|
self.file_name,
|
||||||
]
|
]
|
||||||
for path in possible_paths:
|
for path in possible_paths:
|
||||||
|
|
|
@ -4,6 +4,7 @@ import hashlib
|
||||||
|
|
||||||
from constants import TEX_DIR
|
from constants import TEX_DIR
|
||||||
from constants import TEX_TEXT_TO_REPLACE
|
from constants import TEX_TEXT_TO_REPLACE
|
||||||
|
from constants import TEX_USE_CTEX
|
||||||
|
|
||||||
|
|
||||||
def tex_hash(expression, template_tex_file_body):
|
def tex_hash(expression, template_tex_file_body):
|
||||||
|
@ -44,7 +45,7 @@ def get_null():
|
||||||
|
|
||||||
|
|
||||||
def tex_to_dvi(tex_file):
|
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):
|
if not os.path.exists(result):
|
||||||
commands = [
|
commands = [
|
||||||
"latex",
|
"latex",
|
||||||
|
@ -54,12 +55,22 @@ def tex_to_dvi(tex_file):
|
||||||
tex_file,
|
tex_file,
|
||||||
">",
|
">",
|
||||||
get_null()
|
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))
|
exit_code = os.system(" ".join(commands))
|
||||||
if exit_code != 0:
|
if exit_code != 0:
|
||||||
log_file = tex_file.replace(".tex", ".log")
|
log_file = tex_file.replace(".tex", ".log")
|
||||||
raise Exception(
|
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)
|
"See log output above or the log file: %s" % log_file)
|
||||||
return result
|
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
|
Returns a list of PIL Image objects for these images sorted as they
|
||||||
where in the dvi
|
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):
|
if not os.path.exists(result):
|
||||||
commands = [
|
commands = [
|
||||||
"dvisvgm",
|
"dvisvgm",
|
||||||
|
|
Loading…
Add table
Reference in a new issue