Skip to content

set_color_by_tex selects wrong substring in certain contexts #3492

@benatouba

Description

@benatouba

Description of bug / unexpected behavior

In a certain context, the wrong symbol is highlighted, namely the symbol after the wanted/correct one.

Expected behavior

Set color to the isolated substring.

How to reproduce the issue

from manim import Scene, MathTex, ORANGE

class ExampleScene(Scene):
    def construct(self):  # noqa: PLR0915
        formula = MathTex(
            r"P(X=k) = ",
            "\\binom{12}{k} ",
            r"0.5^k",
            r"(1-0.5)^{12-k}",
            substrings_to_isolate=["k"],
        ).scale(1.3)
        self.play(formula.animate.set_color_by_tex("k", ORANGE))

Wrong display:
image

Additional context

I am using the latest version of manim v0.18.0

Additional media files

System specifications

System Details
  • OS : Linux 6.6.3-zen1-1-zen x86_64 (Arch)
  • RAM:
  • Python version : 3.11.6
  • Installed modules (provide output from pip list):
Package                           Version      Editable project location
--------------------------------- ------------ -------------------------
affine                            2.4.0
anyio                             4.1.0
argon2-cffi                       23.1.0
argon2-cffi-bindings              21.2.0
arrow                             1.3.0
astroid                           3.0.1
asttokens                         2.4.1
async-lru                         2.0.4
attrs                             23.1.0
Babel                             2.13.1
beautifulsoup4                    4.12.2
black                             23.11.0
bleach                            6.1.0
cdo                               1.6.0
certifi                           2023.11.17
cf-xarray                         0.8.6
cffi                              1.16.0
cftime                            1.6.3
charset-normalizer                3.3.2
click                             8.1.7
click-default-group               1.2.4
click-plugins                     1.1.1
cligj                             0.7.2
cloudpickle                       3.0.0
cloup                             2.1.2
cmake                             3.27.9
colorama                          0.4.6
comm                              0.2.0
contourpy                         1.2.0
csscompressor                     0.9.5
cycler                            0.12.1
daiquiri                          3.2.3
dask                              2023.12.0
debugpy                           1.8.0
decorator                         5.1.1
defusedxml                        0.7.1
descartes                         1.1.0
dill                              0.3.7
evdev                             1.6.1
executing                         2.0.1
fastjsonschema                    2.19.0
ffmpeg-python                     0.2.0
filelock                          3.13.1
fiona                             1.9.5
flake8                            6.1.0
fonttools                         4.46.0
fqdn                              1.5.1
fsspec                            2023.12.0
future                            0.18.3
geopandas                         0.14.1
glcontext                         2.5.0
huggingface-hub                   0.19.4
icecream                          2.1.3
idna                              3.6
imageio                           2.33.0
importlib-metadata                7.0.0
iniconfig                         2.0.0
ipykernel                         6.27.1
ipython                           8.18.1
ipython-genutils                  0.2.0
ipywidgets                        8.1.1
isoduration                       20.11.0
isort                             5.12.0
isosurfaces                       0.1.0
jedi                              0.19.1
Jinja2                            3.1.2
joblib                            1.3.2
json5                             0.9.14
jsonpointer                       2.4
jsonschema                        4.20.0
jsonschema-specifications         2023.11.2
jupyter                           1.0.0
jupyter_client                    8.6.0
jupyter-console                   6.6.3
jupyter-contrib-core              0.4.2
jupyter-contrib-nbextensions      0.7.0
jupyter_core                      5.5.0
jupyter-events                    0.9.0
jupyter-highlight-selected-word   0.2.0
jupyter-lsp                       2.2.1
jupyter-nbextensions-configurator 0.6.3
jupyter-nbutils                   0.1.3
jupyter-require                   0.6.1
jupyter_server                    2.11.2
jupyter_server_terminals          0.4.4
jupyterlab                        4.0.9
jupyterlab_pygments               0.3.0
jupyterlab_server                 2.25.2
jupyterlab-widgets                3.0.9
kiwisolver                        1.4.5
lazy_loader                       0.3
lit                               17.0.6
llvmlite                          0.41.1
locket                            1.0.0
lxml                              4.9.3
manim                             0.18.0
manim-fontawesome                 6.4.2
manim-voiceover                   0.3.4.post1
ManimPango                        0.5.0
mapbox-earcut                     1.0.1
markdown-it-py                    3.0.0
MarkupSafe                        2.1.3
matplotlib                        3.8.2
matplotlib-inline                 0.1.6
mccabe                            0.7.0
mdurl                             0.1.2
MetPy                             1.5.1
mistune                           3.0.2
moderngl                          5.9.0
moderngl-window                   2.4.4
more-itertools                    10.1.0
mpmath                            1.3.0
multipledispatch                  1.0.0
mutagen                           1.47.0
mypy-extensions                   1.0.0
nbclient                          0.9.0
nbconvert                         7.12.0
nbformat                          5.9.2
nc-time-axis                      1.4.1
nest-asyncio                      1.5.8
netCDF4                           1.6.5
networkx                          3.2.1
notebook                          7.0.6
notebook_shim                     0.2.3
numba                             0.58.1
numpy                             1.26.2
nvidia-cublas-cu11                11.10.3.66
nvidia-cuda-cupti-cu11            11.7.101
nvidia-cuda-nvrtc-cu11            11.7.99
nvidia-cuda-runtime-cu11          11.7.99
nvidia-cudnn-cu11                 8.5.0.96
nvidia-cufft-cu11                 10.9.0.58
nvidia-curand-cu11                10.2.10.91
nvidia-cusolver-cu11              11.4.0.1
nvidia-cusparse-cu11              11.7.4.91
nvidia-nccl-cu11                  2.14.3
nvidia-nvtx-cu11                  11.7.91
openai-whisper                    20230314
overrides                         7.4.0
packaging                         23.2
pandas                            2.1.3
pandocfilters                     1.5.0
parso                             0.8.3
partd                             1.4.1
pathspec                          0.11.2
pexpect                           4.9.0
Pillow                            9.5.0
Pint                              0.22
pint-xarray                       0.3
pip                               23.3.1
platformdirs                      4.1.0
pluggy                            1.3.0
pooch                             1.8.0
prettyprint                       0.1.5
prometheus-client                 0.19.0
prompt-toolkit                    3.0.41
psutil                            5.9.6
ptyprocess                        0.7.0
pure-eval                         0.2.2
pyarrow                           14.0.1
PyAudio                           0.2.14
pycairo                           1.25.1
pycodestyle                       2.11.1
pycparser                         2.21
pydub                             0.25.1
pyflakes                          3.1.0
pyglet                            2.0.10
Pygments                          2.17.2
pylint                            3.0.2
pynput                            1.7.6
pyparsing                         3.1.1
pyproj                            3.6.1
pyrr                              0.10.3
pytest                            7.4.3
pytest-mock                       3.12.0
python-dateutil                   2.8.2
python-dotenv                     0.21.1
python-json-logger                2.0.7
python-slugify                    8.0.1
python-xlib                       0.33
pytz                              2023.3.post1
PyYAML                            6.0.1
pyzmq                             25.1.2
qtconsole                         5.5.1
QtPy                              2.4.1
rasterio                          1.3.9
referencing                       0.31.1
regex                             2023.10.3
requests                          2.31.0
rfc3339-validator                 0.1.4
rfc3986-validator                 0.1.1
rich                              13.7.0
rpds-py                           0.13.2
ruff                              0.1.7
safetensors                       0.4.1
salem                             0.3.9
scikit-image                      0.22.0
scikit-learn                      1.3.2
scipy                             1.11.4
screeninfo                        0.8.1
Send2Trash                        1.8.2
setuptools                        69.0.2
shapely                           2.0.2
six                               1.16.0
skia-pathops                      0.7.4
sniffio                           1.3.0
snuggs                            1.4.7
soupsieve                         2.5
sox                               1.4.1
srt                               3.5.3
stable-ts                         2.11.1
stack-data                        0.6.3
svgelements                       1.9.6
sympy                             1.12
terminado                         0.18.0
text-unidecode                    1.3
threadpoolctl                     3.2.0
tifffile                          2023.9.26
tiktoken                          0.3.1
tinycss2                          1.2.1
tokenizers                        0.15.0
tomli                             2.0.1
tomlkit                           0.12.3
toolz                             0.12.0
torch                             2.1.0
torchaudio                        2.1.0
tornado                           6.4
tqdm                              4.66.1
traitlets                         5.14.0
transformers                      4.35.2
triton                            2.0.0
types-python-dateutil             2.8.19.14
typing_extensions                 4.8.0
tzdata                            2023.3
uri-template                      1.3.0
urllib3                           2.1.0
watchdog                          3.0.0
wcwidth                           0.2.12
webcolors                         1.13
webencodings                      0.5.1
websocket-client                  1.7.0
wheel                             0.41.3
widgetsnbextension                4.0.9
windrose                          1.9.0
xarray                            2023.11.0
zipp                              3.17.0

LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
    texlive-basic 2023.66594-19
    texlive-bin 2023.66984-16
    texlive-binextra 2023.66594-19
    texlive-fontsrecommended 2023.66594-19
    texlive-latex 2023.66594-19
    texlive-latexextra 2023.66594-19
    texlive-latexrecommended 2023.66594-19
    texlive-mathscience 2023.66594-19
    texlive-pictures 2023.66594-19
    texlive-plaingeneric 2023.66594-19
FFMPEG

Output of ffmpeg -version:

ffmpeg version n6.1 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 13.2.1 (GCC) 20230801
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cud
a-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-li
bass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-
libgsm --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmodplug --enable-libmp3lame --enable-libopencore_amr
nb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librav1e -
-enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --en
able-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc -
-enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
libavutil      58. 29.100 / 58. 29.100
libavcodec     60. 31.102 / 60. 31.102
libavformat    60. 16.100 / 60. 16.100
libavdevice    60.  3.100 / 60.  3.100
libavfilter     9. 12.100 /  9. 12.100
libswscale      7.  5.100 /  7.  5.100
libswresample   4. 12.100 /  4. 12.100
libpostproc    57.  3.100 / 57.  3.100

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue:bugSomething isn't working... For use in issues

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions