Skip to content

tex_to_color_map colors wrong substring when using subscript then superscript #4427

@ccalauzenes

Description

@ccalauzenes

Description of bug / unexpected behavior

In MathTex the option tex_to_color_map does not color the right substring when using subscript then superscript. See example in code (very short).

Expected behavior

If I use MathTex(r"x_i^k", tex_to_color_map={"x_i": RED}), I expect the x and the i to be RED, and the k to stay WHITE. However, instead the i is WHITE and the k is RED.

How to reproduce the issue

Code for reproducing the problem
from manim import *

class TestScene(Scene):
    def construct(self):
        text = MathTex(r"x_i^k", tex_to_color_map={"x_i": RED})

        self.play(Write(text))
        self.wait()

Additional media files

Images/GIFs Image

System specifications

System Details
  • OS: macOS 15.6.1 (Sequoia)
  • Python version (python/py/python3 --version): 3.11.11
  • Installed modules (provide output from pip list):
Package                       Version        Editable project location
----------------------------- -------------- ----------------------------------
alabaster                     1.0.0
anyio                         4.8.0
argon2-cffi                   23.1.0
argon2-cffi-bindings          21.2.0
arrow                         1.3.0
asttokens                     3.0.0
async-lru                     2.0.4
attrs                         25.1.0
av                            13.1.0
babel                         2.17.0
beautifulsoup4                4.13.1
bleach                        6.2.0
certifi                       2025.1.31
cffi                          1.17.1
charset-normalizer            3.4.1
click                         8.1.8
cloup                         3.0.5
comm                          0.2.2
contourpy                     1.3.3
cycler                        0.12.1
debugpy                       1.8.12
decorator                     5.1.1
defusedxml                    0.7.1
docutils                      0.21.2
evdev                         1.9.1
executing                     2.2.0
fastjsonschema                2.21.1
fonttools                     4.59.1
fqdn                          1.5.1
furo                          2024.8.6
glcontext                     3.0.0
gTTS                          2.5.4
h11                           0.14.0
httpcore                      1.0.7
httpx                         0.28.1
idna                          3.10
imagesize                     1.4.1
ipykernel                     6.29.5
ipython                       8.32.0
ipywidgets                    8.1.7
isoduration                   20.11.0
isosurfaces                   0.1.2
jedi                          0.19.2
Jinja2                        3.1.5
joblib                        1.5.1
json5                         0.10.0
jsonpointer                   3.0.0
jsonschema                    4.23.0
jsonschema-specifications     2024.10.1
jupyter                       1.1.1
jupyter_client                8.6.3
jupyter-console               6.6.3
jupyter_core                  5.7.2
jupyter-events                0.12.0
jupyter-lsp                   2.2.5
jupyter_server                2.15.0
jupyter_server_terminals      0.5.3
jupyterlab                    4.3.5
jupyterlab_pygments           0.3.0
jupyterlab_server             2.27.3
jupyterlab_widgets            3.0.15
kiwisolver                    1.4.9
manim                         0.19.0
manim-voiceover               0.3.7
ManimPango                    0.6.0
mapbox_earcut                 1.0.3
markdown-it-py                3.0.0
MarkupSafe                    3.0.2
matplotlib                    3.10.5
matplotlib-inline             0.1.7
mdit-py-plugins               0.4.2
mdurl                         0.1.2
mistune                       3.1.1
moderngl                      5.12.0
moderngl-window               3.1.1
mutagen                       1.47.0
myst-parser                   4.0.0
nbclient                      0.10.2
nbconvert                     7.16.6
nbformat                      5.10.4
nest-asyncio                  1.6.0
networkx                      3.4.2
notebook                      7.3.2
notebook_shim                 0.2.4
numpy                         2.2.2
overrides                     7.7.0
packaging                     24.2
pandocfilters                 1.5.1
parso                         0.8.4
pexpect                       4.9.0
pillow                        11.1.0
pip                           24.0
platformdirs                  4.3.6
prometheus_client             0.21.1
prompt_toolkit                3.0.50
psutil                        6.1.1
ptyprocess                    0.7.0
pure_eval                     0.2.3
PyAudio                       0.2.14
pycairo                       1.27.0
pycparser                     2.22
pydub                         0.25.1
pyglet                        2.1.2
PyGLM                         2.7.3
Pygments                      2.19.1
pynput                        1.8.0
pyparsing                     3.2.3
python-dateutil               2.9.0.post0
python-dotenv                 0.21.1
python-json-logger            3.2.1
python-slugify                8.0.4
python-xlib                   0.33
PyYAML                        6.0.2
pyzmq                         26.2.1
referencing                   0.36.2
requests                      2.32.3
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
rich                          13.9.4
rpds-py                       0.22.3
scikit-learn                  1.7.1
scipy                         1.15.1
screeninfo                    0.8.1
Send2Trash                    1.8.3
setuptools                    65.5.1
six                           1.17.0
skia-pathops                  0.8.0.post2
sniffio                       1.3.1
snowballstemmer               2.2.0
soupsieve                     2.6
sox                           1.5.0
Sphinx                        8.1.3
sphinx-basic-ng               1.0.0b2
sphinx-copybutton             0.5.2
sphinx_design                 0.6.1
sphinx_reredirects            0.1.5
sphinxcontrib-applehelp       2.0.0
sphinxcontrib-devhelp         2.0.0
sphinxcontrib-htmlhelp        2.1.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          2.0.0
sphinxcontrib-serializinghtml 2.0.0
sphinxext-opengraph           0.9.1
srt                           3.5.3
stack-data                    0.6.3
svgelements                   1.9.6
terminado                     0.18.1
text-unidecode                1.3
threadpoolctl                 3.6.0
tinycss2                      1.4.0
tornado                       6.4.2
tqdm                          4.67.1
traitlets                     5.14.3
types-python-dateutil         2.9.0.20241206
typing_extensions             4.12.2
uri-template                  1.3.0
urllib3                       2.3.0
watchdog                      6.0.0
wcwidth                       0.2.13
webcolors                     24.11.1
webencodings                  0.5.1
websocket-client              1.8.0
wheel                         0.45.1
widgetsnbextension            4.0.14
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:

i adjustbox: Graphics package-alike macros for "general" boxes
i adobemapping: Adobe cmap and pdfmapping files
i amscls: AMS document classes for LaTeX
i amsfonts: TeX fonts from the American Mathematical Society
i amsmath: AMS mathematical facilities for LaTeX
i arphic: Arphic (Chinese) font packages
i atbegshi: Execute stuff at \shipout time
i atveryend: Hooks at the very end of a document
i auxhook: Hooks for auxiliary files
i babel: Multilingual support for LaTeX, LuaLaTeX, XeLaTeX, and Plain TeX
i babel-english: Babel support for English
i beamer: A LaTeX class for producing presentations and slides
i bibtex: Process bibliographies (bib files) for LaTeX or other formats
i bibtex.aarch64-linux: aarch64-linux files of bibtex
i bigintcalc: Integer calculations on very large numbers
i bitset: Handle bit-vector datatype
i cbfonts-fd: LaTeX font description files for the CB Greek fonts
i cjk: CJK language support
i cjkpunct: Adjust locations and kerning of CJK punctuation marks
i cm: Computer Modern fonts
i cm-super: CM-Super family of fonts
i cns: Chinese/Japanese/Korean bitmap fonts
i collectbox: Collect and process macro arguments as boxes
i collection-basic: Essential programs and files
i colorprofiles: Collection of free ICC profiles
i count1to: Make use of count1 to count9
i ctablestack: Catcode table stable support
i ctex: LaTeX classes and packages for Chinese typesetting
i currfile: Provide file name and path of input files
i dehyph: German hyphenation patterns for traditional orthography
i doublestroke: Typeset mathematical double stroke symbols
i dvipdfmx: An extended version of dvipdfm
i dvipdfmx.aarch64-linux: aarch64-linux files of dvipdfmx
i dvips: A DVI to PostScript driver
i dvips.aarch64-linux: aarch64-linux files of dvips
i dvisvgm: Convert DVI, EPS, and PDF files to Scalable Vector Graphics format (SVG)
i dvisvgm.aarch64-linux: aarch64-linux files of dvisvgm
i ec: Computer modern fonts in T1 and TS1 encodings
i enctex: A TeX extension that translates input on its way into TeX
i epstopdf: Convert EPS to PDF using Ghostscript
i epstopdf-pkg: Call epstopdf "on the fly"
i epstopdf.aarch64-linux: aarch64-linux files of epstopdf
i etex: An extended version of TeX, from the NTS project
i etex-pkg: E-TeX support package
i etexcmds: Avoid name clashes with e-TeX commands
i etoolbox: e-TeX tools for LaTeX
i euenc: Unicode font encoding definitions for XeTeX
i everyhook: Hooks for standard TeX token lists
i everysel: Provides hooks into \selectfont
i extractbb: A reimplementation of extractbb, written in Lua
i extractbb.aarch64-linux: aarch64-linux files of extractbb
i fandol: Four basic fonts for Chinese typesetting
i filemod: Provide file modification times, and compare them
i firstaid: First aid for external LaTeX files and packages that need updating
i fonts-tlwg: Thai fonts for LaTeX from TLWG
i fontspec: Advanced font selection in XeLaTeX and LuaLaTeX
i fp: Fixed point arithmetic
i frcursive: French cursive hand fonts
i fundus-calligra: Support for the calligra font in LaTeX documents
i garuda-c90: TeX support (from CJK) for the garuda font
i geometry: Flexible and complete interface to document dimensions
i gettitlestring: Clean up title references
i gincltex: Include TeX files as graphics (.tex support for \includegraphics)
i glyphlist: Adobe Glyph List and TeX extensions
i gnu-freefont: A Unicode font, with rather wide coverage
i graphics: The LaTeX standard graphics bundle
i graphics-cfg: Sample configuration files for LaTeX color and graphics
i graphics-def: Colour and graphics option files
i hycolor: Implements colour for packages hyperref and bookmark
i hyperref: Extensive support for hypertext in LaTeX
i hyph-utf8: Hyphenation patterns expressed in UTF-8
i hyphen-base: core hyphenation support files
i hyphen-english: English hyphenation patterns.
i hyphenex: US English hyphenation exceptions file
i ifplatform: Conditionals to test which platform is being used
i iftex: Am I running under pdfTeX, XeTeX or LuaTeX?
i infwarerr: Complete set of information/warning/error message macros
i intcalc: Expandable arithmetic operations with integers
i jknapltx: Miscellaneous packages by Joerg Knappen
i knuth-lib: Core TeX and Metafont sources from Knuth
i knuth-local: Knuth's local information
i kpathsea: Path searching library for TeX-related files
i kpathsea.aarch64-linux: aarch64-linux files of kpathsea
i kvdefinekeys: Define keys for use in the kvsetkeys package
i kvoptions: Key value format for package options
i kvsetkeys: Key value parser with default handler support
i l3backend: LaTeX3 backend drivers
i l3backend-dev: LaTeX3 backend drivers (dev)
i l3kernel: LaTeX3 programming conventions
i l3kernel-dev: Development pre-release of l3kernel
i l3packages: High-level LaTeX3 concepts
i latex: A TeX macro package that defines LaTeX
i latex-base-dev: Development pre-release of the LaTeX kernel
i latex-bin: LaTeX executables and man pages
i latex-bin.aarch64-linux: aarch64-linux files of latex-bin
i latex-firstaid-dev: Development pre-release of the LaTeX firstaid package
i latex-fonts: A collection of fonts used in LaTeX distributions
i latexconfig: configuration files for LaTeX-related formats
i letltxmacro: Let assignment for LaTeX macros
i lm: Latin modern fonts in outline formats
i ltxcmds: Some LaTeX kernel commands for general use
i lua-alt-getopt: Process application arguments the same way as getopt_long
i lua-uni-algos: Unicode algorithms for LuaTeX
i luahbtex: LuaTeX with HarfBuzz library for glyph shaping
i luahbtex.aarch64-linux: aarch64-linux files of luahbtex
i lualibs: Additional Lua functions for LuaTeX macro programmers
i luaotfload: OpenType 'loader' for Plain TeX and LaTeX
i luaotfload.aarch64-linux: aarch64-linux files of luaotfload
i luatex: The LuaTeX engine
i luatex.aarch64-linux: aarch64-linux files of luatex
i luatexbase: Basic resource management for LuaTeX code
i luatexja: Typeset Japanese with Lua(La)TeX
i makeindex: Makeindex development sources
i makeindex.aarch64-linux: aarch64-linux files of makeindex
i mathastext: Use the text font in maths mode
i metafont: A system for specifying fonts
i metafont.aarch64-linux: aarch64-linux files of metafont
i mflogo: LaTeX support for Metafont logo fonts
i mfware: Supporting tools for use with Metafont
i mfware.aarch64-linux: aarch64-linux files of mfware
i microtype: Subliminal refinements towards typographical perfection
i modes: A collection of Metafont mode_def's
i mptopdf: mpost to PDF, native MetaPost graphics inclusion
i mptopdf.aarch64-linux: aarch64-linux files of mptopdf
i multitoc: Set table of contents in multiple columns
i norasi-c90: TeX support (from CJK) for the norasi font
i pdfescape: Implements pdfTeX's escape features using TeX or e-TeX
i pdftex: A TeX extension for direct creation of PDF
i pdftex.aarch64-linux: aarch64-linux files of pdftex
i pdftexcmds: LuaTeX support for pdfTeX utility functions
i pgf: Create PostScript and PDF graphics in TeX
i physics: Macros supporting the Mathematics of Physics
i plain: The Plain TeX format
i platex: pLaTeX2e and miscellaneous macros for pTeX
i platex-tools: pLaTeX standard tools bundle
i platex.aarch64-linux: aarch64-linux files of platex
i prelim2e: Allows the marking of preliminary versions of a document
i preview: Extract bits of a LaTeX source for output
i ptex: A TeX system for publishing in Japanese
i ptex-base: Plain TeX format for pTeX and e-pTeX
i ptex-fonts: Fonts for use with pTeX
i ptex.aarch64-linux: aarch64-linux files of ptex
i ragged2e: Alternative versions of "ragged"-type commands
i refcount: Counter operations with label references
i relsize: Set the font size relative to the current font size
i rerunfilecheck: Checksum based rerun checks on auxiliary files
i rsfs: Ralph Smith's Formal Script font
i scheme-infraonly: infrastructure-only scheme (no TeX at all)
i scheme-minimal: minimal scheme (plain only)
i setspace: Set space between lines
i standalone: Compile TeX pictures stand-alone or as part of a document
i stringenc: Converting a string between different encodings
i svn-prov: Subversion variants of \Provides... macros
i tex: A sophisticated typesetting engine
i tex-ini-files: Model TeX format creation files
i tex.aarch64-linux: aarch64-linux files of tex
i texlive-common: TeX Live documentation (common elements)
i texlive-en: TeX Live manual (English)
i texlive-msg-translations: translations of the TeX Live installer and TeX Live Manager
i texlive-scripts: TeX Live infrastructure programs
i texlive-scripts-extra: TeX Live scripts
i texlive-scripts-extra.aarch64-linux: aarch64-linux files of texlive-scripts-extra
i texlive-scripts.aarch64-linux: aarch64-linux files of texlive-scripts
i texlive.infra: basic TeX Live infrastructure
i texlive.infra.aarch64-linux: aarch64-linux files of texlive.infra
i tipa: Fonts and macros for IPA phonetics characters
i tlshell: GUI frontend (tcl/tk-based) for tlmgr
i tlshell.aarch64-linux: aarch64-linux files of tlshell
i tools: The LaTeX standard tools bundle
i translator: Easy translation of strings in LaTeX
i ttfutils: convert TrueType to TFM and PK fonts
i ttfutils.aarch64-linux: aarch64-linux files of ttfutils
i uhc: Fonts for the Korean language
i ulem: Package for underlining
i unicode-data: Unicode data and loaders for TeX
i uniquecounter: Provides unlimited unique counter
i uplatex: pLaTeX2e and miscellaneous macros for upTeX
i uplatex.aarch64-linux: aarch64-linux files of uplatex
i uptex: Unicode version of pTeX
i uptex-base: Plain TeX formats and documents for upTeX
i uptex-fonts: Fonts for use with upTeX
i uptex.aarch64-linux: aarch64-linux files of uptex
i url: Verbatim with URL-sensitive line breaks
i wadalab: Wadalab (Japanese) font packages
i wasy: The wasy fonts (Waldi symbol fonts)
i wasysym: LaTeX support for the wasy fonts
i xcjk2uni: Convert CJK characters to Unicode, in pdfTeX
i xcolor: Driver-independent color extensions for LaTeX and pdfLaTeX
i xdvi: A DVI previewer for the X Window System
i xdvi.aarch64-linux: aarch64-linux files of xdvi
i xecjk: Support for CJK documents in XeLaTeX
i xetex: An extended variant of TeX for use with Unicode sources
i xetex.aarch64-linux: aarch64-linux files of xetex
i xetexconfig: crop.cfg for XeLaTeX
i xkeyval: Extension of the keyval package
i xpinyin: Automatically add pinyin to Chinese characters
i xunicode: Generate Unicode characters from accented glyphs
i zapfding: URW 'Base 35' font pack for LaTeX
i zhmetrics: TFM subfont files for using Chinese fonts in 8-bit TeX
i zhmetrics-uptex: Chinese font metrics for upTeX
i zhnumber: Typeset Chinese representations of numbers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions