MarkupText¶
Qualified name: algan.mobs.manim\_compat.MarkupText
- class MarkupText(text, fill_opacity=1, stroke_width=0, color=None, font_size=48, line_spacing=-1, font='', slant='NORMAL', weight='NORMAL', justify=False, gradient=None, tab_width=4, height=None, width=None, should_center=True, disable_ligatures=False, warn_missing_font=True, **kwargs)¶
Bases:
ManimCompatMobDisplay (non-LaTeX) text rendered using Pango.
Text objects behave like a
VGroup-like iterable of all characters in the given text. In particular, slicing is possible.What is PangoMarkup?
PangoMarkup is a small markup language like html and it helps you avoid using “range of characters” while coloring or styling a piece a Text. You can use this language with
MarkupText.A simple example of a marked-up string might be:
<span foreground="blue" size="x-large">Blue text</span> is <i>cool</i>!"
and it can be used with
MarkupTextasA more elaborate example would be:
PangoMarkup can also contain XML features such as numeric character entities such as
©for © can be used too.The most general markup tag is
<span>, then there are some convenience tags.Here is a list of supported tags:
<b>bold</b>,<i>italic</i>and<b><i>bold+italic</i></b><u>underline</u>and<s>strike through</s><tt>typewriter font</tt><big>bigger font</big>and<small>smaller font</small><sup>superscript</sup>and<sub>subscript</sub><span underline="double" underline_color="green">double underline</span><span underline="error">error underline</span><span overline="single" overline_color="green">overline</span><span strikethrough="true" strikethrough_color="red">strikethrough</span><span font_family="sans">temporary change of font</span><span foreground="red">temporary change of color</span><span fgcolor="red">temporary change of color</span><gradient from="YELLOW" to="RED">temporary gradient</gradient>
For
<span>markup, colors can be specified either as hex triples like#aabbccor as named CSS colors likeAliceBlue. The<gradient>tag is handled by Manim rather than Pango, and supports hex triplets or Manim constants likeREDorRED_A. If you want to use Manim constants likeRED_Atogether with<span>, you will need to use Python’s f-String syntax as follows:MarkupText(f'<span foreground="{RED_A}">here you go</span>')
If your text contains ligatures, the
MarkupTextclass may incorrectly determine the first and last letter when creating the gradient. This is due to the fact thatflare two separate characters, but might be set as one single glyph - a ligature. If your language does not depend on ligatures, consider settingdisable_ligaturestoTrue. If you must use ligatures, thegradienttag supports an optional attributeoffsetwhich can be used to compensate for that error.For example:
<gradient from="RED" to="YELLOW" offset="1">example</gradient>to start the gradient one letter earlier<gradient from="RED" to="YELLOW" offset=",1">example</gradient>to end the gradient one letter earlier<gradient from="RED" to="YELLOW" offset="2,1">example</gradient>to start the gradient two letters earlier and end it one letter earlier
Specifying a second offset may be necessary if the text to be colored does itself contain ligatures. The same can happen when using HTML entities for special chars.
When using
underline,overlineorstrikethroughtogether with<gradient>tags, you will also need to use the offset, because underlines are additional paths in the finalSVGMobject. Check out the following example.Escaping of special characters:
>should be written as>whereas<and&must be written as<and&.You can find more information about Pango markup formatting at the corresponding documentation page: Pango Markup. Please be aware that not all features are supported by this class and that the
<gradient>tag mentioned above is not supported by Pango.- Parameters:
text (str) – The text that needs to be created as mobject.
fill_opacity (float) – The fill opacity, with 1 meaning opaque and 0 meaning transparent.
stroke_width (float) – Stroke width.
font_size (float) – Font size.
line_spacing (float) – Line spacing.
font (str) – Global font setting for the entire text. Local overrides are possible.
slant (str) – Global slant setting, e.g. NORMAL or ITALIC. Local overrides are possible.
weight (str) – Global weight setting, e.g. NORMAL or BOLD. Local overrides are possible.
gradient (Iterable[ParsableManimColor] | None) – Global gradient setting. Local overrides are possible.
warn_missing_font (bool) – If True (default), Manim will issue a warning if the font does not exist in the (case-sensitive) list of fonts returned from manimpango.list_fonts().
color (ParsableManimColor | None)
justify (bool)
tab_width (int)
height (int | None)
width (int | None)
should_center (bool)
disable_ligatures (bool)
kwargs (Any)
- Returns:
The text displayed in form of a
VGroup-like mobject.- Return type:
Tests
Check that the creation of
MarkupTextworks:>>> MarkupText('The horse does not eat cucumber salad.') MarkupText('The horse does not eat cucumber salad.')
Methods
Attributes
animation_managerThis mob's scene-owned animation manager.
basisThe Mob's orientation and scale, as a flattened 3x3 matrix of shape
(*, 9).casts_shadowsWhether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.
childrenThe Mobs attached below this one, in attachment order.
closed_shellWhether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.
draws_descendantsWhether
get_render_primitivesreturns geometry belonging to this Mob's DESCENDANTS as well as its own.forwardGet the direction the Mob is facing.
lifespanThis mob's [spawn, despawn) interval on its Scene timeline (a
Lifespan).locationThe Mob's position in world space, shape
(*, 3).normalized_basisThe Mob's orientation with scale divided out, shape
(*, 9).parentsThe Mobs this one is attached to, in attachment order.
receives_shadowsWhether this Mob's surfaces are darkened by shadows cast onto them.
rightGet the Mob's own rightward direction.
scale_coefficientThe Mob's scale along its own right, up and forward axes, shape
(*, 3).stroke_colorThe color of the circuit's border stroke.
two_sidedWhether this Mob's geometry should be lit from whichever side the ray arrives on.
upGet the Mob's own upward direction.
xThe Mob's x coordinate in world units, shape
(*, 1).xyThe Mob's x and y coordinates in world units, shape
(*, 2).yThe Mob's y coordinate in world units, shape
(*, 1).zThe Mob's z coordinate in world units, shape
(*, 1).z_indexWhich of two exactly coplanar circuits draws in front (higher wins).