Skip to content
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

Code Mobject incorrect color string parsing #4104

Closed
marcel-goldschen-ohm opened this issue Jan 13, 2025 · 5 comments · Fixed by #4115
Closed

Code Mobject incorrect color string parsing #4104

marcel-goldschen-ohm opened this issue Jan 13, 2025 · 5 comments · Fixed by #4115
Labels
issue:bug Something isn't working... For use in issues
Milestone

Comments

@marcel-goldschen-ohm
Copy link

marcel-goldschen-ohm commented Jan 13, 2025

Description of bug / unexpected behavior

Code Mobject does not work for me at all in fresh install of mania v0.18.1. Throws ValueError due to attempt to parse an invalid color string. I tracked the issue down to the HTML/JSON for the code text which appears to be specifying at least some colors using shorthand notation (e.g., "#C93" instead of "#CC9933"). In the case of the shorthand, the color string still includes the next three characters which results in an invalid color string.

Fix

A quick fix is to see if the next character is a '"' as the HTML would be something like color="#C93", and if so convert from shorthand to the full correct color string. In code_mobject.py just after the color is parsed on lines 477-479:

color = words[word_index][
    color_index + starti : color_index + starti + 7
]

, the following insert after the above code fixes this aberrant behavior:

if color[0] == '#' and color[4] == '"':
    color = '#' + color[1]*2 + color[2]*2 + color[3]*2

I'm a bit weirded out that this problem seems to have suddenly arose for me, so although the above fix does fix the issue, I'm wondering if there is something else going on? Also seems like a better solution would be to check for this in the color utils and handle it there so it is not just fixed for the Code Mobject.

Expected behavior

No errors.

How to reproduce the issue

Just attempt to instantiate a Code mobject. e.g.,

from manim import *

class Test(Scene):
    def construct(self):
        code = Code(code="x = 3", language='python')
        self.play(Write(code))

Logs

Terminal output
ValueError: Color #CCC">x not found

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): macOS 15.2 (Sequoia)
  • RAM: 32 GB
  • Python version (python/py/python3 --version): 3.12.8
  • Installed modules (provide output from pip list):
Package                Version
---------------------- -----------
annotated-types        0.7.0
appnope                0.1.4
asttokens              3.0.0
av                     13.1.0
beautifulsoup4         4.12.3
certifi                2024.12.14
charset-normalizer     3.4.1
click                  8.1.8
click-default-group    1.2.4
cloup                  3.0.5
comm                   0.2.2
Cython                 3.0.11
debugpy                1.8.11
decorator              5.1.1
executing              2.1.0
glcontext              3.0.0
idna                   3.10
ipykernel              6.29.5
ipython                8.31.0
isosurfaces            0.1.2
jedi                   0.19.2
Jinja2                 3.1.5
jupyter_client         8.6.3
jupyter_core           5.7.2
lxml                   5.3.0
manim                  0.18.1
manim-slides           5.3.0
ManimPango             0.6.0
mapbox_earcut          1.0.3
markdown-it-py         3.0.0
MarkupSafe             3.0.2
matplotlib-inline      0.1.7
mdurl                  0.1.2
moderngl               5.12.0
moderngl-window        3.1.0
nest-asyncio           1.6.0
networkx               3.4.2
numpy                  2.2.1
packaging              24.2
parso                  0.8.4
pexpect                4.9.0
pillow                 11.1.0
pip                    24.3.1
platformdirs           4.3.6
prompt_toolkit         3.0.48
psutil                 6.1.1
ptyprocess             0.7.0
pure_eval              0.2.3
pycairo                1.27.0
pydantic               2.10.5
pydantic_core          2.27.2
pydantic-extra-types   2.10.1
pydub                  0.25.1
pyglet                 2.1.0
PyGLM                  2.7.3
Pygments               2.19.1
pyobjc-core            10.3.2
pyobjc-framework-Cocoa 10.3.2
python-dateutil        2.9.0.post0
python-pptx            1.0.2
pyzmq                  26.2.0
QtPy                   2.4.2
requests               2.32.3
rich                   13.9.4
rtoml                  0.12.0
scipy                  1.15.1
screeninfo             0.8.1
setuptools             75.8.0
six                    1.17.0
skia-pathops           0.8.0.post2
soupsieve              2.6
srt                    3.5.3
stack-data             0.6.3
svgelements            1.9.6
tornado                6.4.2
tqdm                   4.67.1
traitlets              5.14.3
typing_extensions      4.12.2
urllib3                2.3.0
watchdog               6.0.0
wcwidth                0.2.13
wheel                  0.45.1
XlsxWriter             3.2.0
@ericelbing
Copy link

ericelbing commented Jan 15, 2025

I'm having the same problem on my m1 mac with macos 15.1.1 with a fresh install of manim, which is why I'm still using the docker image on tag v0.18.0 (probably the same version the containers on mybinder.com are running, because the interactive example in the docs is still working)

jeertmans added a commit to jeertmans/manim-slides that referenced this issue Jan 15, 2025
jeertmans added a commit to jeertmans/manim-slides that referenced this issue Jan 15, 2025
@jeertmans
Copy link
Contributor

jeertmans commented Jan 15, 2025

I also faced this issue, and it was caused by this commit (pygments/pygments@0853028), release with Pygment 2.19. Pinning pygments<2.19 avoids this issue (e.g., see: jeertmans/manim-slides#518), but I think this could be easily fixed on Manim's side.

@marcel-goldschen-ohm
Copy link
Author

Thanks @jeertmans , pinning pygments solved it!

@jeertmans
Copy link
Contributor

@marcel-goldschen-ohm I don’t think you should close this issue, as it is still a bug (to me) that must be fixed on Manim’s side :)

@marcel-goldschen-ohm
Copy link
Author

Sounds good, reopened.

@behackl behackl added this to the v0.19.0 milestone Jan 15, 2025
@behackl behackl added the issue:bug Something isn't working... For use in issues label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue:bug Something isn't working... For use in issues
Projects
None yet
4 participants