This module implements some utility functions to search some shapes (formulas, symbols) inside a Tex (or MathTex) mobject.
The approach is to compare the shapes (bezier curves) of the symbols, instead of the particular strings that produced them.
This approach is generic and avoids the use of other manim mechanisms that would break under some circunstances, such as
the presence of \frac{}{}
in a formula.
The function you would probably want to use is group_shapes_in_tex()
. Despite the confusing name, the goal is to
find all the occurences of a given symbol (or group of symbols, or list of symbols) inside a Tex mobject, and return a VGroup containing them
all. This way you can apply whatever operations you wan to the resulting group, such as changing the color, iterate
on its members to highligth them, etc.
The remaining functions in this module are auxiliary or utility functions such as the following (for detais about parameters and usage, see the docstrings in the code)
-
search_shape_in_text()
which searches a single shape in the given text, and returns a list ofslice()
objects containing the start and end indexes of the submobjects that matched (it is a list because it can be several matches, as for example if you search for the "x" shape in an equation in which "x" appears several times) -
search_shapes_in_tex()
which receives a list of shapes instead a single one, and returns the list of all matches of any of the given shapes. For example you can pass a list containing the shape of an "a" and the shape of an "A", and will return a list with all the slices in which either "a" or "A" appear -
group_shapes_in_text()
receives either a single shape or a list of shapes, and uses the above functions to locate the required indexes. Then build and returns aVGroup
containing the selected submobjects. -
all_sizes_symbol()
generates all the shapes of a given symbol, in different sizes. This is useful if you want to locate for example all "x" shapes in a formula, no matter if they appear in subindices, exponents, sum limits, etc. LaTeX uses a slightly different font for each case, so in order to find all of them you have to use this function to generate the list of all those slightly different shapes -
colorize_similar_tex()
this receives a "config" dict with strings as keys and colors and values. It usesMathTex()
convert each key (string) in a shape, searches the shape in the given mobject, and changes its color to the value given in the dict.