manim
manim copied to clipboard
Cannot type Chinese and Latex in one line
I'm a math teacher in China. I want to show some math questions which contains latex symbols and Chinese descriptions to my students by manim. However I meet the trouble to type these math questions.
English= TexText(""" This works good $\\displaystyle\\frac{x}{y}$, $$x^2+y^2=a^2$$ """)
The codes above work good, but when it comes to Chinese like the codes below manim failed.
Chinese = TexText(""" 无法运行 $\\displaystyle\\frac{x}{y}$, $$x^2+y^2=a^2$$ """)
Warning: Using the default configuration file, which you can modify in /Users/tech/Downloads/animation/manim-master/venv/lib/python3.9/site-packages/manimlib/default_config.yml If you want to create a local configuration file, you can create a file named custom_config.yml, or run manimgl --config
2021-05-18 11:06:55.416 Python[24219:386229] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/sy/pkxzmw0906q_9vfq7_1_yj040000gn/T/org.python.python.savedState ERROR:root:
LaTeX Error! Not a worry, it happens to the best of us.
Package inputenc Error: Unicode character 中 (U+4E2D)
I work on MACm11.3.1 and I git the latest manim(2021/5/18).
Try this #680
from manimlib.imports import *
class Demo(Scene):
def construct(self):
text = Text("你好", font='Source Han Sans')
self.play(Write(text))
#or use basic only text = Text("你好") #font used should be download in Mac/PC
text Unlike TextMobject, Text only receive one str.
When there is only one line, the space(' ') in front or back will be ignored.
'\t' is not supported.
then shift text to the position
老师,您可以分别创建两个文本,一个是Tex,用于编写数学公式,另一个使用Text,用于汉字,然后使用next_to将二者连接起来,最后使用VGroup将二者合并。希望有帮助!
你是否修改了config文件,包含中文的需要用xelatex编译。
tex:
executable: xelatex -no-pdf
intermediate_filetype: xdv
template_file: ctex_template.tex
text_to_replace: '[tex_expression]'
CONFIG的修改应该是没有的。老师的代码,那个TexText里出现了中文,所以无法识别,表现为编译出错。我几天前初学的时候也尝试过,结果一样,这个似乎是读取数据的问题。后来我找到了替代方案(因为我使用的最新版,里面已经把CTEX是否为True的选项删除,没法按照网上相关提示修改为True),这个替代方案是使用Text(有别于TexMobject和TextMobject)作为中文显示工具。
结果很好。
我的结论是TextMobject和TexMobject只能盛放英文和符号,不支持中文。
?完全是支持中文的啊,只要使用xelatex编译了 你这个只是另一种用法,而且它们背后的原理是完全不一样的 在使用的时候也会比较不方便,因为你需要把所有的中文和公式分开,再用VGroup合并
确实不方便。但是我没有找到网上所说的“修改TEX_USE_CTEX=True”的文件位置(尴尬.jpg)
你是否修改了config文件,包含中文的需要用xelatex编译。
tex: executable: xelatex -no-pdf intermediate_filetype: xdv template_file: ctex_template.tex text_to_replace: '[tex_expression]'
我不是说了吗,新版要修改config文件
直接运行manimgl --config,在第[6/8]个问题的时候输入xelatex也可以
还望大佬指教config文件的位置(是在1.manim的主程序文件夹manimlib文件夹下,还是2.Python库site-packages里manim文件夹下?(这个没有找到config文件))直接运行manimgl --config的话……No Module named 'manimlib' (CMD环境),不胜感激!
正在安装manimlib
你是怎么安装的manimgl,安装位置的manimlib文件夹里会有一个默认的default_config.yml 也可以在你运行的地方手动创建一个custom_config.yml,里面加上这几行
建议你加QQ群862671480,在里面方便点
可以尝试这个 , 如这里所显示 运用 manimgl 或 manim community 都有这个功能,主要是安装所需的 font
from manimlib import *
class TexAndText(Scene):
def construct(self):
ctext = Text("公式", font='KaiTi', font_size=50).shift(2*LEFT)
mtext = Tex("{{A^2}} + {{B^2}} = {{C^2}}").next_to(ctext)
VGroup(ctext, mtext).arrange( buff=1)
self.play(Write(ctext))
self.play(FadeIn(mtext, UP))
self.wait(3)
?完全是支持中文的啊,只要使用xelatex编译了 你这个只是另一种用法,而且它们背后的原理是完全不一样的 在使用的时候也会比较不方便,因为你需要把所有的中文和公式分开,再用VGroup合并
这个是可以的,但是它麻烦,这不是最好的解决办法
因为编程技术太菜,没法回答入群问题(若非此,我早就想要加进去的)
我找到了
请问你找到了啥,你用的是社区版吗?
请问你找到了啥,你用的是社区版吗?
为那个时候的我抱歉,那时候我完全不懂得社区内问题类规则:把自己的解决方式发出来,并且加SOLVED标签(如果可以),所以现在我也不清楚我说的找到了是什么😢。那个时候我应该确实是用的社区版,也是因为我没分清GL和社区版的区别,在这里(GL)体现为二者混为一谈🙏
I apologize for that time, when I was completely ignorant of the rules for problem/issue in the community: post your solution and add a SOLVED tag (if you can), so now I'm not sure what I'm talking about when I say I've found it(“我找到了”). I think I did use the community version at that time, also because I didn't distinguish the difference between GL and community version, which is reflected here (GL) as a conflation of the two