-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor StringMobject and relevant classes #1795
Conversation
I notice that after refactoring Code kw = {
"isolate": [
"=",
"\\int_{0}^{\\infty} \\mathrm{e}^{- t}",
"\\mathrm{d} t"
],
"tex_to_color_map": {
"{z}": YELLOW,
"\\mathrm{e}": MAROON_A,
"c_{0}": BLUE,
"c_{1}": BLUE,
"c_{2}": BLUE,
"c_{n}": BLUE,
"{p}": BLUE_B,
"P \\left( t \\right)": BLUE
}
}
explicit_formula = MTex(
"= \\int_{0}^{\\infty} \\mathrm{e}^{- t}"
" \\left( c_{0} + c_{1} t + c_{2} t^{2} + \\cdots + c_{n} t^{n} \\right) \\mathrm{d} t",
**kw
)
expanded_formula = MTex(
"= \\int_{0}^{\\infty} \\mathrm{e}^{- t} c_{0} \\mathrm{d} t"
" + \\int_{0}^{\\infty} \\mathrm{e}^{- t} c_{1} t \\mathrm{d} t"
" + \\int_{0}^{\\infty} \\mathrm{e}^{- t} c_{2} t^{2} \\mathrm{d} t"
" + \\cdots"
" + \\int_{0}^{\\infty} \\mathrm{e}^{- t} c_{n} t^{n} \\mathrm{d} t",
**kw
).shift(DOWN)
self.add(explicit_formula)
self.wait()
self.play(TransformMatchingStrings(explicit_formula, expanded_formula))
self.wait() |
I'll fix up Mobject.copy to avoid the recursive explosion there—apologies for a hasty push there. |
I noticed some weird behavior of pango as ligatures kick in. I guess it's something deeply rooted in pango that currently I cannot fix. This shall require a deeper look into pango in the future... text = MarkupText("fast", t2c={"f": TEAL}, font="Source Han Sans Light") # works
text = MarkupText("fire", t2c={"f": TEAL}, font="Source Han Sans Light") # fails
text = MarkupText("<span font_features='liga=0'>fire</span>", t2c={"f": TEAL}, font="Source Han Sans Light") # works |
The original svg is used instead of the labelled one, so whitespaces around operators won't be eliminated if isolated. That means, |
Thank you, this is definitely an improved structure and syntax. |
Motivation
Refactor
StringMobject
(renamed fromLabelledString
),MarkupText
,MTex
classes.Proposed changes
manimlib/mobject/svg/labelled_string.py
: Unify logic fromMarkupText
,MTex
; removeuse_plain_tex
attributes; support a much more flexibleSelector
type; allow passing in substrings whose braces or tags aren't paired; rename some methods.manimlib/mobject/svg/mtex_mobject.py
: Allow passing in a 2-tuple totex_environment
, regarded as a prefix and a suffix respectively; removeuse_plain_tex
attributes.manimlib/mobject/svg/text_mobject.py
: Parse entities to prevent from cutting halfway; removeuse_plain_tex
attributes.manimlib/animation/creation.py
manimlib/animation/transform_matching_parts.py
manimlib/scene/interactive_scene.py
: Addfrom __future__ import annotations
.The method renaming in
StringMobject
class includes:The names of aliases remain unchanged (e.g.
MTex.get_parts_by_tex
)The type definition of
Selector
is given below:The
StringMobject.select_parts
method takes in aselector
as an input. Theisolate
parameter, keys oftex_to_color_map
, keys oft2c
, etc. are also of typeselector
.StringMobject.select_parts
no longer supportscase_sensitive
,substring
andregex
parameters --- only substrings inside spans specified by selectors will be selected.This PR handles imbalanced strings and entity strings, so the following will work:
This PR fixes #1792 by removing
line_height
from the global attribute dictionary if Pango doesn't support.