Skip to content

Commit 56ab8b9

Browse files
Darylgoldenkolibril13kilacoda-oldbehackl
authored
Add documentation about set_color_by_tex (#1269)
* Add documentation about set_color_by_tex * Attempt to fix linting * Fix build error * Apply suggestions from code review Co-authored-by: kolibril13 <[email protected]> * Apply suggestions from code review Co-authored-by: Benjamin Hackl <[email protected]> * Fixes * Apply suggestions from code review Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: kolibril13 <[email protected]> Co-authored-by: kilacoda <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent b412bf9 commit 56ab8b9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

manim/mobject/svg/tex_mobject.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,37 @@ def construct(self):
113113
tex.set_color_by_tex('igsta', RED)
114114
self.add(tex)
115115
116+
Note that :func:`~.set_color_by_tex` colors the entire substring containing the Tex searched for,
117+
not just the specific symbol or Tex expression searched for. Consider the following example:
118+
119+
.. manim:: IncorrectLaTeXSubstringColoring
120+
:save_last_frame:
121+
122+
class IncorrectLaTeXSubstringColoring(Scene):
123+
def construct(self):
124+
equation = MathTex(
125+
r"e^x = x^0 + x^1 + \frac{1}{2} x^2 + \frac{1}{6} x^3 + \cdots + \frac{1}{n!} x^n + \cdots"
126+
)
127+
equation.set_color_by_tex("x", YELLOW)
128+
self.add(equation)
129+
130+
As you can see, this colors the entire equation yellow, contrary to what may be expected. To color only ``x`` yellow, we have to do the following:
131+
132+
.. manim:: CorrectLaTeXSubstringColoring
133+
:save_last_frame:
134+
135+
class CorrectLaTeXSubstringColoring(Scene):
136+
def construct(self):
137+
equation = MathTex(
138+
r"e^x = x^0 + x^1 + \frac{1}{2} x^2 + \frac{1}{6} x^3 + \cdots + \frac{1}{n!} x^n + \cdots",
139+
substrings_to_isolate="x"
140+
)
141+
equation.set_color_by_tex("x", YELLOW)
142+
self.add(equation)
143+
144+
By setting ``substring_to_isolate`` to ``x``, we split up the :class:`~.MathTex` into substrings
145+
automatically and isolate ``x`` components into individual substrings. Only then can :meth:`~.set_color_by_tex` be used to achieve the desired result.
146+
116147
LaTeX Maths Fonts - The Template Library
117148
++++++++++++++++++++++++++++++++++++++++
118149
Changing fonts in LaTeX when typesetting mathematical formulae is a little bit more tricky than

0 commit comments

Comments
 (0)