-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add template and additional_preamble parameters to Tex
#1818
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
Conversation
font and additional_preamble parameters to Tex
font and additional_preamble parameters to Textemplate and additional_preamble parameters to Tex
TonyCrane
left a comment
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, parameterstemplateandadditional_preambleare 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 totemplateattribute. By default,templateis an empty string, in which case manim will use the default template specified atstyle.tex_templatein the configuration file. Currently this key replaces all 4 attributes undertexkey. The original template files (tex_template.texandctex_template.tex) are now removed, and are now included asdefaultandctexfor backward compatibility.Users may add preambles specifically to a
TexorMTexinstance viaadditional_preambleattribute, 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 specificTexinstances. Manim Community is also concerned about such an issue (ManimCommunity/manim#2889). That's whybasic,emptytemplates show up in thetex_templates.yml. I also collected all 52 templates from the Community Edition and sorted them alphabetically.New
protectattribute forStringMobjectUsers may use
protectattribute to specify some substrings that are not expected to be broken up.Demo
Result
In the demonstration above, without specifying
protect="{bmatrix}", all of letterbs (including ones in the wordbmatrix) will be isolated. In fact,MTexcan 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).protectattribute should be of typeSelector, the same asisolate.Add back
disable_ligaturesattribute inMarkupTextandTextFor backward compatibility. Default to be
True.Features removed
Removes
is_markupattribute forMarkupTextandTextThis 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_templateattribute inMTexThis 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 ofprotectattribute to overcome this problem in an elegant way.No longer adjusts spans in
StringMobjectIn 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
svgelementscannot parseuseelements whose referred elements are defined afterwards. This is fixed by expanding alluseelements in svg before parsing.#1792 Cannot show text in Ubuntu20.04
Textuses theline_heightattribute 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_sizeattribute in a markup tag can only be integers. This issue is fixed by inserting aroundfunction.Other bugs
MTex.get_part_by_texandText.get_part_by_textmiss**kwargswhen passing attributes.manimlib/animation/indication.pyfile 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_templateattribute; removetexitems.manimlib/mobject/svg/mtex_mobject.py: Addtemplate,additional_preambleattributes; refactorMTexaccording toStringMobject.manimlib/mobject/svg/string_mobject.py: RefactorStringMobject.manimlib/mobject/svg/svg_mobject.py: Expanduseelements beforehand; usehash_stringfunction.manimlib/mobject/svg/tex_mobject.py: Addtemplate,additional_preambleattributes.manimlib/mobject/svg/text_mobject.py: Removeis_markupattribute; refactorTextaccording 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_stringfunction.manimlib/utils/tex_file_writing.py: Make manim able to generate tex files based on specific preamble; removetex_hashfunction.