Skip to content

MLR127: Literal by-tex key cannot occur in the MathTex literal

qual reports MLR127 when a literal key passed to get_part_by_tex / set_color_by_tex does not occur — not even as a substring — in the literal arguments of the MathTex / Tex the receiver is provably bound to. get_part_by_tex then returns None and set_color_by_tex silently changes nothing.

  • Default severity: warning
  • Minimum confidence: high
  • Implementation phase: 2
  • Fix: none (the message suggests passing a real substring and isolating it with double braces or substrings_to_isolate=[...])

Soundness: MathTex splits its arguments into parts (double-brace groups, substrings_to_isolate, tex_to_color_map keys), and every part is a contiguous substring of exactly one constructor argument. A key absent from all literal arguments can therefore never match any part, regardless of isolation kwargs. A key that does occur in the literal but is not currently split out stays silent, because isolation could make it match.

The receiver binding is proven conservatively: a plain name bound exactly once in its file, directly to a knowledge-resolved MathTex(...) / Tex(...) call whose positional arguments are all plain string literals. Rebound names, non-literal arguments, and fluent chains stay silent.

Wrong:

eq = MathTex("a^2", "+", "b^2")
eq.set_color_by_tex("c^2", RED)  # "c^2" occurs nowhere: no-op

Right:

eq = MathTex("a^2", "+", "b^2")
eq.set_color_by_tex("a^2", RED)
# or isolate the piece you want to address:
eq = MathTex("{{ a^2 }} + b^2")
eq.set_color_by_tex(" a^2 ", RED)