-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Coloring Fractions in LaTeX produces invalid LaTeX #3650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I was able to solve that problem for me using \over instead of \frac. |
Great that you were able to solve this on your own. Yes, its a well known but perhaps well-hidden fact: the individual parts after splitting need to still be correct LaTeX syntax, which is not the case when you split a |
Do you think it is worth noting these problems in the documentation, in order to stop beginners to stumble into the same pitfall? |
It's open source - you are welcome to collaborate! |
Closing essentially as a duplicate of #2884 |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
when trying to colorize an equation wrapped in a
MathTex
I ran into an issue regarding splitting the string at a\frac{}{}
resulting in manim to produce invalid latex eventually causing the rendering to fail.System information
python -m venv
Steps to reproduce
The problematic codes looks a follows
sin = MathTex( r"\frac{GK_{\alpha}}{H}", substrings_to_isolate=[r"GK_{\alpha}"] )
my goal was to visuallize sin a at a rectangular triangle and for visualization to color the strings GK_{\alpha} and H in some specific colors as described in https://docs.manim.community/en/stable/guides/using_text.html#correctlatexsubstringcoloring
unfortunately manim generates flawed latex, specifically this code
which latex rejects causing the rendering to fail.
Likely cause of the problem
in
__init()__
ofMathTex
inmanim/mobject/text/tex_mobject.py
at line 270 the given tex string is split up into multiple substrings based on the value ofsubstrings_to_isolate
with the function_break_up_tex_strings()
. According to my debugger in this case this yields['\\sin(\\alpha) = \\frac{', 'GK_{\\alpha}', '}{H}']
(I ran the debugger using a little bit different snippet of latex but it es essentially th same. The flawed latex will then look like this:\sin(\alpha) = \frac{}
This value is stored in self.tex_strings which is later used in the function called in line 278 in the same file
_break_up_by_substrings()
As far as I understand that function it basically creates one
SingleStringMathTex()
per substring resulting in the constructor ofSingleStringMathTex()
to write that flawed latex to a file and to try to compiel it.(Possible solutions)
First of all. I'm really new to manim, so I really don't know how fix that, but when debugging my way to the error I also saw the function
_get_modified_expressions
on line 128 being called to prepare the latex forSingleLineMathTex
. It itself calls a function named_modify_special_strings()
which is as far as I understand that responsible for checking certain special strings , e.g. \sqrt{}. Without knowing much about manim structure I think this could be a place to address this problem.I hope I could provide a helpful description of my problem. For further questions I'm available.
The text was updated successfully, but these errors were encountered: