Skip to content

Commit

Permalink
docs: Document SingleStringMathTex parameters, and usage of color i…
Browse files Browse the repository at this point in the history
…n TeX
  • Loading branch information
microlith57 committed Mar 16, 2024
1 parent f46f087 commit 729bd63
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/source/guides/using_text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,49 @@ we have to add it manually.
)
self.add(tex)

You can use the ``xcolor`` package to apply colors within TeX, but to do this
you have to explicitly state that you want to preserve these colors (as the
default is to override them with whatever the default :class:`~.VMobject`
color is):

.. manim:: XColor
:save_last_frame:

class XColor(Scene):
def construct(self):
myTemplate = TexTemplate()
myTemplate.add_to_preamble(r"\usepackage{xcolor}")
tex = Tex(
r"\textcolor{white}{Hello} \textcolor{yellow}{\LaTeX}",
tex_template=myTemplate,
font_size=144,
preserve_colors=True,
)
self.add(tex)

You can use :func:`manim.mobject.mobject.Mobject.set_default` to make this the
default:

.. manim:: DefaultTexTemplate
:save_last_frame:

class DefaultTexTemplate(Scene):
def construct(self):
myTemplate = TexTemplate()
myTemplate.add_to_preamble(r"\usepackage{xcolor}")
myTemplate.add_to_document(r"\color{white}")

Tex.set_default(
tex_template=myTemplate,
preserve_colors=True
)

tex = Tex(
r"Hello \textcolor{yellow}{\LaTeX}",
font_size=144,
)
self.add(tex)

Substrings and parts
====================

Expand Down
30 changes: 30 additions & 0 deletions manim/mobject/text/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@
class SingleStringMathTex(SVGMobject):
"""Elementary building block for rendering text with LaTeX.
Parameters
----------
tex_string
The TeX source string to render.
stroke_width
The stroke width of the mobject. If ``None`` (the default),
the stroke width values set in the generated SVG file are used.
should_center
Whether or not the mobject should be centered after
being imported.
height
organize_left_to_right
tex_environment
The TeX environment to wrap the string in.
tex_template
The TeX template to use when rendering the string.
font_size
preserve_colors
If ``False`` (the default), the mobject is recolored based on
the default :class:`~.VMobject` color.
If ``True``, the colors in the TeX document are used.
.. warning::
By default, TeX strings are coloured black, meaning they
will be invisible against a black background.
If you want to use this option, it is recommended to set
a default color in TeX.
kwargs
Further arguments passed to the parent class.
Tests
-----
Check that creating a :class:`~.SingleStringMathTex` object works::
Expand Down

0 comments on commit 729bd63

Please sign in to comment.