-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Add template
and additional_preamble
parameters to Tex
#1818
Conversation
font
and additional_preamble
parameters to Tex
font
and additional_preamble
parameters to Tex
template
and additional_preamble
parameters to Tex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But we'd better add a new example about Tex
and TexText
in example_scenes.py
. And it's better to add a new page to the docs to introduce these full features of them.
Recently the issue concerned with |
Looks good to me. If possible in the future (and I fully recognize the hypocrisy in this), it's better to split up conceptually distinct changes into multiple different PRs, e.g. the introduction of templates vs. the various issues fixed. |
Features added
Supports self-defined tex templates and temporary addition of preambles
Sometimes users may want to temporarily use tex commands from tex packages not included in tex template files by default. So I add support for it. This is inspired from Manim Community. For classes
Tex
,MTex
, parameterstemplate
andadditional_preamble
are added. Example usages are shown below.Demo
Result
Demo
Result
Demo
Result
58 tex templates in total are provided in
manimlib/tex_templates.yml
. Users may feel free to add whatever template they want to this file for own usage. These templates can simply be accessed by passing their names totemplate
attribute. By default,template
is an empty string, in which case manim will use the default template specified atstyle.tex_template
in the configuration file. Currently this key replaces all 4 attributes undertex
key. The original template files (tex_template.tex
andctex_template.tex
) are now removed, and are now included asdefault
andctex
for backward compatibility.Users may add preambles specifically to a
Tex
orMTex
instance viaadditional_preamble
attribute, which is also an empty string by default.Frankly speaking, I'm a bit worried if having so much packages imported in a tex file could cause side effects. For instance, the
"\vdots"
command doesn't show up in the final svg (not caused by questionable parsing ofsvgelements
; even the path is not defined). This issue may be caused by the line"\usepackage[T1]{fontenc}"
(which I'm not sure). The point is, I would suggest using a template with only a few elementary packages imported, and add packages for specificTex
instances. Manim Community is also concerned about such an issue (ManimCommunity/manim#2889). That's whybasic
,empty
templates show up in thetex_templates.yml
. I also collected all 52 templates from the Community Edition and sorted them alphabetically.New
protect
attribute forStringMobject
Users may use
protect
attribute to specify some substrings that are not expected to be broken up.Demo
Result
In the demonstration above, without specifying
protect="{bmatrix}"
, all of letterb
s (including ones in the wordbmatrix
) will be isolated. In fact,MTex
can automatically handle most cases --- it protects all substrings matched by the regex expression\\([a-zA-Z]+|.)
. The case above is tricky so that we shall tackle it manually. Sidenote, this attribute only prevents from cutting halfway at protected spans, so isolating"\\begin{bmatrix}"
in the example above is still allowed (but nobody will do so, unless on purpose).protect
attribute should be of typeSelector
, the same asisolate
.Add back
disable_ligatures
attribute inMarkupText
andText
For backward compatibility. Default to be
True
.Features removed
Removes
is_markup
attribute forMarkupText
andText
This attribute is not expected to be altered up to the class --- so why not remove it?
No longer allows passing in a 2-tuple to
tex_template
attribute inMTex
This feature was originally added in #1795 in order to escape isolating substrings in, e.g.,
\begin{table}{ccc}
,\end{table}
(which cannot be solved by passingtex_environment="table"
). Now we can make use ofprotect
attribute to overcome this problem in an elegant way.No longer adjusts spans in
StringMobject
In the previous implementation, I designed an algorithm to handle spans pointing to crazy substrings, like
"a{b"
. From now on, such spans will receive warnings and will no longer be adjusted. Similarly, partly overlapping substrings now lead to warnings instead of exceptions.Issues fixed
#1760 After using math font package in tex_template of ManimGL, the TexText cannot displayed correctly
This issue is caused since
svgelements
cannot parseuse
elements whose referred elements are defined afterwards. This is fixed by expanding alluse
elements in svg before parsing.#1792 Cannot show text in Ubuntu20.04
Text
uses theline_height
attribute to control the line spacing, which requires pango with version >=1.50. The version of pango is now checked to decide whether to insert this attribute.#1848 Fix: can't parse
<u>Boolean Operation</u>
Fixed passingly in the refactory.
#1850 ValueError: Invalid markup string - when entering characters in Interactive mode
The
font_size
attribute in a markup tag can only be integers. This issue is fixed by inserting around
function.Other bugs
MTex.get_part_by_tex
andText.get_part_by_text
miss**kwargs
when passing attributes.manimlib/animation/indication.py
file misses imports frommanimlib.constants
.Proposed changes
manimlib/animation/indication.py
: Add missed imports.manimlib/animation/transform_matching_parts.py
: RefactorTransformMatchingStrings
.manimlib/default_config.yml
: Addtex_template
attribute; removetex
items.manimlib/mobject/svg/mtex_mobject.py
: Addtemplate
,additional_preamble
attributes; refactorMTex
according toStringMobject
.manimlib/mobject/svg/string_mobject.py
: RefactorStringMobject
.manimlib/mobject/svg/svg_mobject.py
: Expanduse
elements beforehand; usehash_string
function.manimlib/mobject/svg/tex_mobject.py
: Addtemplate
,additional_preamble
attributes.manimlib/mobject/svg/text_mobject.py
: Removeis_markup
attribute; refactorText
according toStringMobject
.manimlib/tex_templates.yml
: Add preambles of tex templates.manimlib/tex_templates/.
: Remove tex template files.manimlib/utils/init_config.py
: Alter according todefault_config.yml
.manimlib/utils/simple_functions.py
: Addhash_string
function.manimlib/utils/tex_file_writing.py
: Make manim able to generate tex files based on specific preamble; removetex_hash
function.