A community-maintained Python framework for creating mathematical animations.
Better docstrings. Move all but three templates to TexTemplateLibrary
Aron Fischerf9859d0eb0bc
diff --git a/docs/source/examples/tex.rst b/docs/source/examples/tex.rstindex c70d302e5..7a1c0f00f 100644--- a/docs/source/examples/tex.rst+++ b/docs/source/examples/tex.rst@@ -51,7 +51,7 @@ LaTeXclass Example5bLaTeX(Scene):def construct(self):- TemplateForFrenchCursive = TexTemplate(+ templateForFrenchCursive = TexTemplate(preamble=r"""\usepackage[english]{babel}\usepackage{amsmath}@@ -60,7 +60,7 @@ LaTeX\usepackage[default]{frcursive}\usepackage[eulergreek,noplusnominus,noequal,nohbar,nolessnomore,noasterisk]{mathastext}""")- tex = Tex('Hello \LaTeX', tex_template=TemplateForFrenchCursive).scale(3)+ tex = Tex('Hello \LaTeX', tex_template=templateForFrenchCursive).scale(3)self.add(tex).. manim:: Example6LaTeX@@ -68,7 +68,7 @@ LaTeXclass Example6LaTeX(Scene):def construct(self):- tex = Tex('Hello 你好 \LaTeX', tex_template=CTEXTemplate()).scale(3)+ tex = Tex('Hello 你好 \LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3)self.add(tex)diff --git a/docs/source/reference.rst b/docs/source/reference.rstindex 804869f38..88d275c26 100644--- a/docs/source/reference.rst+++ b/docs/source/reference.rst@@ -118,6 +118,7 @@ Utilities~utils.space_ops~utils.strings~utils.tex+ ~utils.tex_templates~utils.tex_file_writingdiff --git a/example_scenes/advanced_tex_fonts.py b/example_scenes/advanced_tex_fonts.pyindex 1b6d460dd..4d26992dd 100644--- a/example_scenes/advanced_tex_fonts.py+++ b/example_scenes/advanced_tex_fonts.py@@ -113,7 +113,9 @@ class TexFontTemplateLibrary(Scene):self.add(Tex("Tex Font Template Example").to_edge(UL))for font in examples:- print("Compiling tex for: ", font.description)+ print(+ "Compiling tex for: ", font.description+ ) # To help you figure out which examples to comment out.write_one_line(font)self.play(diff --git a/manim/__init__.py b/manim/__init__.pyindex 7b6b67cde..51cec02d0 100644--- a/manim/__init__.py+++ b/manim/__init__.py@@ -79,4 +79,4 @@ from .utils.sounds import *from .utils.space_ops import *from .utils.strings import *from .utils.tex import *-from .utils.tex_templates import TexFontTemplates+from .utils.tex_templates import *diff --git a/manim/utils/tex.py b/manim/utils/tex.pyindex b4e1e488e..2ada64589 100644--- a/manim/utils/tex.py+++ b/manim/utils/tex.py@@ -4,8 +4,6 @@ __all__ = ["TexTemplate","TexTemplateFromFile","BasicTexTemplate",- "ThreeBlueOneBrownTexTemplate",- "CTEXTemplate",]@@ -101,26 +99,26 @@ class TexTemplate:)def prepend_to_preamble(self, txt):- # Adds txt to the TeX template preamble just after the \documentclass+ """Adds txt to the TeX template preamble just after the \documentclass"""self.preamble = txt + "\n" + self.preambleself.rebuild()def add_to_preamble(self, txt):- # Adds txt to the TeX template preamble just before \begin{document}+ """Adds txt to the TeX template preamble just before \begin{document}"""self.preamble += "\n" + txtself.rebuild()def add_to_document(self, txt):- # Adds txt to the TeX template just after \begin{document}+ """Adds txt to the TeX template just after \begin{document}"""self.post_doc_commands += "\n" + txt + "\n"self.rebuild()def get_texcode_for_expression(self, expression):- # Inserts expression verbatim into TeX template.+ """Inserts expression verbatim into TeX template."""return self.body.replace(self.placeholder_text, expression)def get_texcode_for_expression_in_env(self, expression, environment):- # Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}+ """Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}"""begin = r"\begin{" + environment + "}"end = r"\end{" + environment + "}"return self.body.replace(@@ -129,6 +127,8 @@ class TexTemplate:class BasicTexTemplate(TexTemplate):+ """A simple Tex Template with only basic AMS packages"""+def __init__(self, *args, **kwargs):basic_headers = r"""\usepackage[english]{babel}@@ -139,33 +139,6 @@ class BasicTexTemplate(TexTemplate):super().__init__(*args, preamble=preamble, **kwargs)-class ThreeBlueOneBrownTexTemplate(TexTemplate):- """- The default TeX template from the 3b1b version of manim- """-- pass---class CTEXTemplate(TexTemplate):- """- The default TeX template from the 3b1b version of manim with the use_ctex option- """-- def __init__(self, **kwargs):- tex_compiler = kwargs.pop("tex_compiler", "xelatex")- output_format = kwargs.pop("output_format", ".xdv")- ctexpreamble = TexTemplate.default_preamble.replace(- r"\DisableLigatures{encoding = *, family = * }", r"\usepackage[UTF8]{ctex}"- )- super().__init__(- tex_compiler=tex_compiler,- output_format=output_format,- preamble=ctexpreamble,- **kwargs- )--class TexTemplateFromFile(TexTemplate):"""A TexTemplate object created from a template file (default: tex_template.tex)diff --git a/manim/utils/tex_templates.py b/manim/utils/tex_templates.pyindex 222424cb1..924a35859 100644--- a/manim/utils/tex_templates.py+++ b/manim/utils/tex_templates.py@@ -1,13 +1,48 @@# -*- coding: utf-8 -*-"""A library of LaTeX templates."""__all__ = [+ "TexTemplateLibrary","TexFontTemplates",]from .tex import *+# This file makes TexTemplateLibrary and TexFontTemplates available for use in manim Tex and MathTex objects.+++# TexTemplateLibrary#-# This file makes TexFontTemplates available for use in manim Tex and MathTex objects.+class TexTemplateLibrary(object):+ """+ A collection of basic TeX templates++ Usage+ -----+ As a value for the keyword argument tex_template of Tex() and MathTex() mobjects+ Tex("My TeX code", tex_template=TexTemplateLibrary.ctex)++ """++ default = TexTemplate()+ """ The default TeX template in manim """++ threeb1b = TexTemplate()+ """ The default TeX template in manim as used by 3b1b """++ ctex = TexTemplate(+ tex_compiler="xelatex",+ output_format=".xdv",+ preamble=TexTemplate.default_preamble.replace(+ r"\DisableLigatures{encoding = *, family = * }", r"\usepackage[UTF8]{ctex}"+ ),+ )+ """ The TeX template in manim as used by 3b1b when using the use_ctex flag """++ simple = BasicTexTemplate()+ """ A simple TeX template with only basic AMS packages loaded """+++# TexFontTemplates## TexFontTemplates takes a font_id and returns the appropriate TexTemplate()# Usage:@@ -848,61 +883,117 @@ italichelveticaf.add_to_preamble(class TexFontTemplates(object):- """A list of Tex templates for the fonts described at http://jf.burnol.free.fr/showcase.html"""-- american_typewriter = americantypewriter # "American Typewriter"- antykwa = aptxgm # "Antykwa Półtawskiego (TX Fonts for Greek and math symbols)"- apple_chancery = applechancery # "Apple Chancery"- auriocus_kalligraphicus = aksg # "Auriocus Kalligraphicus (Symbol Greek)"- baskervald_adf_fourier = baskervaldadff # "Baskervald ADF with Fourier"- baskerville_it = italicbaskerville # "Baskerville (Italic)"- biolinum = biolinum # "Biolinum"- brushscriptx = brushscriptxpx # "BrushScriptX-Italic (PX math and Greek)"- chalkboard_se = chalkboardse # "Chalkboard SE"- chalkduster = chalkduster # "Chalkduster"- comfortaa = comfortaa # "Comfortaa"- comic_sans = comicsansms # "Comic Sans MS"- droid_sans = droidsans # "Droid Sans"- droid_sans_it = italicdroidsans # "Droid Sans (Italic)"- droid_serif = droidserif # "Droid Serif"- droid_serif_px_it = italicdroidserifpx # "Droid Serif (PX math symbols) (Italic)"- ecf_augie = ecfaugieeg # "ECF Augie (Euler Greek)"- ecf_jd = ecfjdtx # "ECF JD (with TX fonts)"- ecf_skeetch = ecfscmg # "ECF Skeetch (CM Greek)"- ecf_tall_paul = ecftallpaul # "ECF Tall Paul (with Symbol font)"- ecf_webster = ecfwebstertx # "ECF Webster (with TX fonts)"- electrum_adf = electrumadfcm # "Electrum ADF (CM Greek)"- epigrafica = epigrafica # Epigrafica- fourier_utopia = fufug # "Fourier Utopia (Fourier upright Greek)"- french_cursive = fceg # "French Cursive (Euler Greek)"- gfs_bodoni = gfsbodoni # "GFS Bodoni"- gfs_didot = italicgfsdidot # "GFS Didot (Italic)"- gfs_neoHellenic = gfsneohellenic # "GFS NeoHellenic"- gnu_freesans_tx = gnufstx # "GNU FreeSerif (and TX fonts symbols)"- gnu_freeserif_freesans = gnufsfs # "GNU FreeSerif and FreeSans"- helvetica_fourier_it = italichelveticaf # "Helvetica with Fourier (Italic)"- latin_modern_tw_it = (- italiclmtpcm # "Latin Modern Typewriter Proportional (CM Greek) (Italic)"- )- latin_modern_tw = lmtp # "Latin Modern Typewriter Proportional"- libertine = libertine # "Libertine"- libris_adf_fourier = librisadff # "Libris ADF with Fourier"- minion_pro_myriad_pro = mpmptx # "Minion Pro and Myriad Pro (and TX fonts symbols)"- minion_pro_tx = mptx # "Minion Pro (and TX fonts symbols)"- new_century_schoolbook = ncssg # "New Century Schoolbook (Symbol Greek)"- new_century_schoolbook_px = (- ncssgpxm # "New Century Schoolbook (Symbol Greek, PX math symbols)"- )- noteworthy_light = noteworthylight # "Noteworthy Light"- palatino = palatinosg # "Palatino (Symbol Greek)"- papyrus = papyrus # "Papyrus"- romande_adf_fourier_it = italicromandeadff # "Romande ADF with Fourier (Italic)"- slitex = slitexeg # "SliTeX (Euler Greek)"- times_fourier_it = italictimesf # "Times with Fourier (Italic)"- urw_avant_garde = urwagsg # "URW Avant Garde (Symbol Greek)"- urw_zapf_chancery = urwzccmg # "URW Zapf Chancery (CM Greek)"- venturis_adf_fourier_it = italicvanturisadff # "Venturis ADF with Fourier (Italic)"- verdana_it = italicverdana # "Verdana (Italic)"- vollkorn_fourier_it = italicvollkornf # "Vollkorn with Fourier (Italic)"- vollkorn = vollkorntx # "Vollkorn (TX fonts for Greek and math symbols)"- zapf_chancery = zapfchancery # "Zapf Chancery"+ """+ A collection of TeX templates for the fonts described at http://jf.burnol.free.fr/showcase.html++ Usage+ -----+ As a value for the keyword argument tex_template of Tex() and MathTex() mobjects+ Tex("My TeX code", tex_template=TexFontTemplates.comic_sans)++ """++ american_typewriter = americantypewriter+ """American Typewriter"""+ antykwa = aptxgm+ """Antykwa Półtawskiego (TX Fonts for Greek and math symbols)"""+ apple_chancery = applechancery+ """Apple Chancery"""+ auriocus_kalligraphicus = aksg+ """Auriocus Kalligraphicus (Symbol Greek)"""+ baskervald_adf_fourier = baskervaldadff+ """Baskervald ADF with Fourier"""+ baskerville_it = italicbaskerville+ """Baskerville (Italic)"""+ biolinum = biolinum+ """Biolinum"""+ brushscriptx = brushscriptxpx+ """BrushScriptX-Italic (PX math and Greek)"""+ chalkboard_se = chalkboardse+ """Chalkboard SE"""+ chalkduster = chalkduster+ """Chalkduster"""+ comfortaa = comfortaa+ """Comfortaa"""+ comic_sans = comicsansms+ """Comic Sans MS"""+ droid_sans = droidsans+ """Droid Sans"""+ droid_sans_it = italicdroidsans+ """Droid Sans (Italic)"""+ droid_serif = droidserif+ """Droid Serif"""+ droid_serif_px_it = italicdroidserifpx+ """Droid Serif (PX math symbols) (Italic)"""+ ecf_augie = ecfaugieeg+ """ECF Augie (Euler Greek)"""+ ecf_jd = ecfjdtx+ """ECF JD (with TX fonts)"""+ ecf_skeetch = ecfscmg+ """ECF Skeetch (CM Greek)"""+ ecf_tall_paul = ecftallpaul+ """ECF Tall Paul (with Symbol font)"""+ ecf_webster = ecfwebstertx+ """ECF Webster (with TX fonts)"""+ electrum_adf = electrumadfcm+ """Electrum ADF (CM Greek)"""+ epigrafica = epigrafica+ """ Epigrafica """+ fourier_utopia = fufug+ """Fourier Utopia (Fourier upright Greek)"""+ french_cursive = fceg+ """French Cursive (Euler Greek)"""+ gfs_bodoni = gfsbodoni+ """GFS Bodoni"""+ gfs_didot = italicgfsdidot+ """GFS Didot (Italic)"""+ gfs_neoHellenic = gfsneohellenic+ """GFS NeoHellenic"""+ gnu_freesans_tx = gnufstx+ """GNU FreeSerif (and TX fonts symbols)"""+ gnu_freeserif_freesans = gnufsfs+ """GNU FreeSerif and FreeSans"""+ helvetica_fourier_it = italichelveticaf+ """Helvetica with Fourier (Italic)"""+ latin_modern_tw_it = italiclmtpcm+ """Latin Modern Typewriter Proportional (CM Greek) (Italic)"""+ latin_modern_tw = lmtp+ """Latin Modern Typewriter Proportional"""+ libertine = libertine+ """Libertine"""+ libris_adf_fourier = librisadff+ """Libris ADF with Fourier"""+ minion_pro_myriad_pro = mpmptx+ """Minion Pro and Myriad Pro (and TX fonts symbols)"""+ minion_pro_tx = mptx+ """Minion Pro (and TX fonts symbols)"""+ new_century_schoolbook = ncssg+ """New Century Schoolbook (Symbol Greek)"""+ new_century_schoolbook_px = ncssgpxm+ """New Century Schoolbook (Symbol Greek, PX math symbols)"""+ noteworthy_light = noteworthylight+ """Noteworthy Light"""+ palatino = palatinosg+ """Palatino (Symbol Greek)"""+ papyrus = papyrus+ """Papyrus"""+ romande_adf_fourier_it = italicromandeadff+ """Romande ADF with Fourier (Italic)"""+ slitex = slitexeg+ """SliTeX (Euler Greek)"""+ times_fourier_it = italictimesf+ """Times with Fourier (Italic)"""+ urw_avant_garde = urwagsg+ """URW Avant Garde (Symbol Greek)"""+ urw_zapf_chancery = urwzccmg+ """URW Zapf Chancery (CM Greek)"""+ venturis_adf_fourier_it = italicvanturisadff+ """Venturis ADF with Fourier (Italic)"""+ verdana_it = italicverdana+ """Verdana (Italic)"""+ vollkorn_fourier_it = italicvollkornf+ """Vollkorn with Fourier (Italic)"""+ vollkorn = vollkorntx+ """Vollkorn (TX fonts for Greek and math symbols)"""+ zapf_chancery = zapfchancery+ """Zapf Chancery"""