A community-maintained Python framework for creating mathematical animations.
Simplifying the TexTemplate() system.
Aron Fischer700d3fa3745e
diff --git a/example_scenes/advanced_tex_fonts.py b/example_scenes/advanced_tex_fonts.pynew file mode 100644index 000000000..eb675af0a--- /dev/null+++ b/example_scenes/advanced_tex_fonts.py@@ -0,0 +1,47 @@+from manim import *+++class TexTemplateFrenchCursive(TexTemplate):+ def prepare_template_body(self):+ # For more LaTeX font examples from http://jf.burnol.free.fr/showcase.html+ self.body = r"""+\documentclass[preview]{standalone}+\usepackage[english]{babel}+\usepackage{amsmath}+\usepackage{amssymb}+\usepackage[T1]{fontenc}+\usepackage[default]{frcursive}+\usepackage[eulergreek,noplusnominus,noequal,nohbar,%+nolessnomore,noasterisk]{mathastext}++\begin{document}++YourTextHere++\end{document}+"""+++class FrenchCursive(Tex):+ def __init__(self, *tex_strings, **kwargs):+ super().__init__(+ *tex_strings, tex_template=TexTemplateFrenchCursive(), **kwargs+ )+++class AdvancedTexFontExample(Scene):+ def construct(self):+ self.add(Tex("Tex Font Example").to_edge(UL))+ self.play(ShowCreation(FrenchCursive("$f: A \\longrightarrow B$").shift(UP)))+ self.play(+ ShowCreation(FrenchCursive("Behold! We can write math in French Cursive"))+ )+ self.wait(1)+ self.play(+ ShowCreation(+ Tex(+ "See more font templates at \\\\ http://jf.burnol.free.fr/showcase.html"+ ).shift(2 * DOWN)+ )+ )+ self.wait(2)diff --git a/example_scenes/customtex.py b/example_scenes/customtex.pyindex bb50bb455..24c1188ac 100644--- a/example_scenes/customtex.py+++ b/example_scenes/customtex.py@@ -22,10 +22,29 @@ class InCodeTexTemplate(Scene):"""def construct(self):- tpl = TexTemplate()- tpl.append_package(["esvect", ["f"]])- config["tex_template"] = tpl+ # Create a template+ template = TexTemplate()+ # Other options include+ # BasicTexTemplate()+ # ThreeBlueOneBrownTexTemplate()+ # ThreeBlueOneBrownCTEXTemplate()++ # Add packages to the template+ template.add_to_preamble(r"\usepackage{esvect}")++ # Set the compiler and output format (default: latex and .dvi)+ template.tex_compiler = "pdflatex"+ # Alternatives are "latex", "pdflatex", "xelatex", "lualatex", "luatex"+ template.output_format = ".pdf"+ # alternatives are ".dvi", ".pdf", and ".xdv"++ # To use this as the default template for all Tex:+ config["tex_template"] = template- # text=Tex(r"$\vv{vb}$")text = MathTex(r"\vv{vb}")self.play(Write(text))++ # To use this template for a single Tex() or MathTex() object only+ text2 = MathTex(r"f:A\rightarrow B", tex_template=template)+ text2.shift(DOWN)+ self.play(Write(text2))diff --git a/manim/__init__.py b/manim/__init__.pyindex 0f6b70bfd..51cec02d0 100644--- a/manim/__init__.py+++ b/manim/__init__.py@@ -79,3 +79,4 @@ from .utils.sounds import *from .utils.space_ops import *from .utils.strings import *from .utils.tex import *+from .utils.tex_templates import *diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.pyindex 3a0efafd4..fdfc4cc58 100644--- a/manim/mobject/svg/tex_mobject.py+++ b/manim/mobject/svg/tex_mobject.py@@ -27,6 +27,7 @@ from ...utils.config_ops import digest_configfrom ...utils.strings import split_string_list_to_isolate_substringsfrom ...utils.tex_file_writing import tex_to_svg_filefrom ...utils.color import BLACK+from ...utils.tex import TexTemplateTEX_MOB_SCALE_FACTOR = 0.05@@ -47,7 +48,7 @@ class SingleStringMathTex(SVGMobject):"height": None,"organize_left_to_right": False,"alignment": "",- "type": "tex",+ "tex_environment": "align*","template": None,}@@ -59,7 +60,7 @@ class SingleStringMathTex(SVGMobject):self.tex_string = tex_stringfile_name = tex_to_svg_file(self.get_modified_expression(tex_string),- self.type,+ environment=self.tex_environment,tex_template=self.template,)SVGMobject.__init__(self, file_name=file_name, **kwargs)@@ -156,6 +157,7 @@ class MathTex(SingleStringMathTex):"arg_separator": " ","substrings_to_isolate": [],"tex_to_color_map": {},+ "tex_environment": "align*",}def __init__(self, *tex_strings, **kwargs):@@ -264,7 +266,7 @@ class Tex(MathTex):CONFIG = {"alignment": "\\centering","arg_separator": "",- "type": "text",+ "tex_environment": None,}diff --git a/manim/utils/tex.py b/manim/utils/tex.pyindex 14d596b32..42c44b2b5 100644--- a/manim/utils/tex.py+++ b/manim/utils/tex.py@@ -1,298 +1,137 @@-"""Utilities for processing custom LaTeX templates."""+"""Utilities for processing LaTeX templates."""-__all__ = ["TexTemplateFromFile", "TexTemplate"]+__all__ = [+ "TexTemplate",+ "TexTemplateFromFile",+ "BasicTexTemplate",+ "ThreeBlueOneBrownTexTemplate",+ "ThreeBlueOneBrownCTEXTemplate",+]import os-from ..utils.config_ops import digest_config--class TexTemplateFromFile:+threeblueonebrown_tex_template_body = r"""+\documentclass[preview]{standalone}++\usepackage[english]{babel}+\usepackage[utf8]{inputenc}+\usepackage[T1]{fontenc}+\usepackage{amsmath}+\usepackage{amssymb}+\usepackage{dsfont}+\usepackage{setspace}+\usepackage{tipa}+\usepackage{relsize}+\usepackage{textcomp}+\usepackage{mathrsfs}+\usepackage{calligra}+\usepackage{wasysym}+\usepackage{ragged2e}+\usepackage{physics}+\usepackage{xcolor}+\usepackage{microtype}+\DisableLigatures{encoding = *, family = * }+\linespread{1}++\begin{document}++YourTextHere++\end{document}+"""+++class TexTemplate:+ """+ Class representing a TeX template to be used for creating Tex() and MathTex() objects."""- Class representing a TeX template file- """ # TODO: attributes, dataclasses stuff-- CONFIG = {- "use_ctex": False,- "filename": "tex_template.tex",- "text_to_replace": "YourTextHere",- "tex_compiler": {- "command": "latex",- "output_format": ".dvi",- },- }- body = ""++ tex_compiler = None+ output_format = None+ body = None+ has_environment = Falsedef __init__(self, **kwargs):- digest_config(self, kwargs)- self.rebuild_cache()-- def rebuild_cache(self):- """For faster access, the LaTeX template's code is cached.- If the base file is modified, the cache needs to be rebuilt.- """- with open(self.filename, "r") as infile:- self.body = infile.read()+ if self.tex_compiler is None:+ self.tex_compiler = kwargs.pop("tex_compiler", "latex")+ if self.output_format is None:+ self.output_format = kwargs.pop("output_format", ".dvi")+ self.prepare_template_body()++ def prepare_template_body(self):+ self.body = threeblueonebrown_tex_template_body++ def add_to_preamble(self, txt):+ # Adds txt to the TeX template preamble just before \begin{document}+ self.body = self.body.replace("\\begin{document}", txt + "\n\\begin{document}")++ def add_to_document(self, txt):+ # Adds txt to the TeX template just after \begin{document}+ self.body = self.body.replace(+ "\\begin{document}", "\\begin{document}\n" + txt + "\n"+ )++ def get_texcode_for_expression(self, expression):+ # Inserts expression verbatim into TeX template.+ return self.body.replace("YourTextHere", expression)- def get_text_for_text_mode(self, expression):- """Inserting expression verbatim into TeX template.-- Parameters- ----------- expression : :class:`str`- String containing the expression to be typeset, e.g. ``"foo"``-- Returns- -------- :class:`str`- LaTeX code based on the template containing the given expression and ready for typesetting.- """- return self.body.replace(self.text_to_replace, expression)-- def get_text_for_env(self, environment, expression):- """Inserts an expression wrapped in a given environment into the TeX template.-- Parameters- ----------- environment : :class:`str`- The environment in which we should wrap the expression.- expression : :class:`str`- The string containing the expression to be typeset, e.g. ``$\\sqrt{2}$``-- Returns- -------- :class:`str`- LaTeX code based on template, containing the given expression and ready for typesetting- """+ def get_texcode_for_expression_in_env(self, expression, 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(- self.text_to_replace, "{0}\n{1}\n{2}".format(begin, expression, end)+ "YourTextHere", "{0}\n{1}\n{2}".format(begin, expression, end))- def get_text_for_tex_mode(self, expression):- """Inserts an expression within an ``align*`` environment into the TeX template.- Parameters- ----------- expression : :class:`str`- The string containing the (math) expression to be typeset,- e.g. ``$\\sqrt{2}$``+class BasicTexTemplate(TexTemplate):+ def prepare_template_body(self):+ self.body = r"""+\documentclass[preview]{standalone}++\usepackage[english]{babel}+\usepackage{amsmath}+\usepackage{amssymb}++\begin{document}++YourTextHere++\end{document}+"""+++class ThreeBlueOneBrownTexTemplate(TexTemplate):+ """+ The default TeX template from the 3b1b version of manim+ """- Returns- -------- :class:`str`- LaTeX code based on template, containing the given expression and ready for typesetting- """- return self.get_text_for_env("align*", expression)+ def prepare_template_body(self):+ self.body = threeblueonebrown_tex_template_body-class TexTemplate(TexTemplateFromFile):+class ThreeBlueOneBrownCTEXTemplate(ThreeBlueOneBrownTexTemplate):+ """+ The default TeX template from the 3b1b version of manim with the use_ctex option"""- Class for dynamically managing a TeX template- """ # TODO: Add attributes (when dataclasses are implemented)-- CONFIG = {- "documentclass": ["standalone", ["preview"]],- "common_packages": [- ["babel", ["english"]],- "amsmath",- "amssymb",- "dsfont",- "setspace",- "tipa",- "relsize",- "textcomp",- "mathrsfs",- "calligra",- "wasysym",- "ragged2e",- "physics",- "xcolor",- "microtype",- ],- "tex_packages": [["inputenc", ["utf8"]], ["fontenc", ["T1"]]],- "ctex_packages": [["ctex", ["UTF8"]]],- "common_preamble_text": r"\linespread{1}" "\n",- "tex_preamble_text": r"\DisableLigatures{encoding = *, family = *}" "\n",- "ctex_preamble_text": "",- "document_prefix": "",- "document_suffix": "",- }def __init__(self, **kwargs):- digest_config(self, kwargs)- self.rebuild_cache()-- def rebuild_cache(self):- """For faster access, the LaTeX template's code is cached.- If the base file is modified, the cache needs to be rebuilt."""- tpl = self.generate_tex_command(- "documentclass",- required_params=[self.documentclass[0]],- optional_params=self.documentclass[1],- )- for pkg in self.common_packages:- tpl += self.generate_usepackage(pkg)-- if self.use_ctex:- for pkg in self.ctex_packages:- tpl += self.generate_usepackage(pkg)- else:- for pkg in self.tex_packages:- tpl += self.generate_usepackage(pkg)-- tpl += self.common_preamble_text- if self.use_ctex:- tpl += self.ctex_preamble_text- else:- tpl += self.tex_preamble_text-- tpl += "\n" r"\begin{document}" "\n"- tpl += f"\n{self.text_to_replace}\n"- tpl += "\n" r"\end{document}"-- self.body = tpl-- def prepend_package(self, pkg):- """Adds a new package (or several new packages)- before all other packages. Sometimes, the order of- the ``\\usepackage`` directives is relevant.-- Parameters- ----------- pkg : :class:`str`- The package name, e.g. ``"siunitx"``- """- self.common_packages.insert(0, pkg)- self.rebuild_cache()-- def append_package(self, pkg):- """Adds a new package (or several new packages)- after all other packages. Sometimes, the order of- the ``\\usepackage`` directives is relevant.-- Parameters- ----------- pkg : :class:`str`- The package name, e.g. ``"siunitx"``- """- self.common_packages.append(pkg)- self.rebuild_cache()-- def append_to_preamble(self, text):- """Adds commands (e.g. macro definitions) at the end of the preamble.-- Parameters- ----------- text : :class:`str`- The text to be included, e.g. ``"\\newcommand{\\R}{\\mathbb{Q}}"``.- """- if self.use_ctex:- self.ctex_preamble_text += text- else:- self.tex_preamble_text += text- self.rebuild_cache()- pass-- def clear_preamble(self):- """Removes custom definitions from the LaTeX preamble.- This does not affect the imported packages or documentclass."""- self.common_preamble_text = ""- self.ctex_preamble_text = ""- self.tex_preamble_text = ""- self.rebuild_cache()- pass-- def generate_tex_command(self, command, *, required_params, optional_params=[]):- """- Function for creating LaTeX command strings with or without options.- Internally used to generate ``\\usepackage`` commands.-- Parameters- ----------- command : :class:`str`- The command, e.g. ``"usepackage"``.- required_params : Iterable[:class:`str`]- The required parameters of this command, each wrapped in ``{}``.- optional_params : Iterable[:class:`str`]- The optional parameters of this command, each separated by a comma inside one ``[]``.-- Examples- --------- ::-- generate_tex_command("usepackage", required_params=["packagename"], optional_params=["option1", "option2"])-- Returns- -------- :class:`str`- The generated command.- """- optional_params = list(optional_params) # so we can measure its length- return r"\{0}{1}{2}".format(- command,- f"[{','.join(optional_params)}]" if optional_params else "",- "".join("{" + param + "}" for param in required_params),- )+ self.tex_compiler = kwargs.pop("tex_compiler", "xelatex")+ self.output_format = kwargs.pop("output_format", ".xdv")+ super().__init__(**kwargs)- def generate_usepackage(self, pkg):- if isinstance(pkg, list):- return self.generate_tex_command(- "usepackage", required_params=[pkg[0]], optional_params=pkg[1]- )- else:- return self.generate_tex_command("usepackage", required_params=[pkg])-- def get_text_for_text_mode(self, expression):- """Inserts an expression verbatim into the TeX template.-- Parameters- ----------- expression : :class:`str`- The expression to be typeset, e.g. ``"foo"``.-- Returns- -------- :class:`str`- LaTeX code based on the template, containing the given expression and ready for typesetting- """- return self.body.replace(self.text_to_replace, expression)-- def get_text_for_env(self, environment, expression):- """Inserts an expression wrapped in a given environment into the TeX template.-- Parameters- ----------- environment : :class:`str`- The environment in which we should wrap the expression.- expression : :class:`str`- The string containing the expression to be typeset, e.g. ``"$\\sqrt{2}$"``-- Returns- -------- :class:`str`- LaTeX code based on template, containing the given expression and ready for typesetting- """- begin = r"\begin{" + environment + "}"- end = r"\end{" + environment + "}"- return self.body.replace(- self.text_to_replace, "{0}\n{1}\n{2}".format(begin, expression, end)+ def prepare_template_body(self):+ self.body = threeblueonebrown_tex_template_body.replace(+ r"\DisableLigatures{encoding = *, family = * }", r"\usepackage[UTF8]{ctex}")- def get_text_for_tex_mode(self, expression):- """Inserts an expression within an ``align*`` environment into- the TeX template.-- Parameters- ----------- expression : :class:`str`- The string containing the (math) expression to be typeset,- e.g. ``"$\\sqrt{2}$"``-- Returns- -------- :class:`str`- LaTeX code based on template, containing the given expression and ready for typesetting- """- return self.get_text_for_env("align*", expression)++class TexTemplateFromFile(TexTemplate):+ def __init__(self, **kwargs):+ self.template_file = kwargs.pop("filename", "tex_template.tex")+ super().__init__(**kwargs)++ def prepare_template_body(self):+ with open(self.template_file, "r") as infile:+ self.body = infile.read()diff --git a/manim/utils/tex_templates.py b/manim/utils/tex_templates.pynew file mode 100644index 000000000..abb0a0a65--- /dev/null+++ b/manim/utils/tex_templates.py@@ -0,0 +1,902 @@+# -*- coding: utf-8 -*-+"""A library of LaTeX templates."""+__all__ = [+ "TexFontTemplates",+]++from .tex import *++#+# This file makes TexFontTemplates available for use in manim Tex and MathTex objects.+#+# TexFontTemplates takes a font_id and returns the appropriate TexTemplate()+# Usage:+# my_tex_template = TexFontTemplates.font_id+#+# Note: not all of these will work out-of-the-box.+# They may require specific fonts to be installed on the local system.+# For example TexFontTemplates.comic_sans will only work if the Microsoft font 'Comic Sans'+# is installed on the local system.+#+# More information on these templates, along with example output can be found at+# http://jf.burnol.free.fr/showcase.html"+#+#+# Choices for font_id are:+#+# american_typewriter : "American Typewriter"+# antykwa : "Antykwa Półtawskiego (TX Fonts for Greek and math symbols)"+# apple_chancery : "Apple Chancery"+# auriocus_kalligraphicus : "Auriocus Kalligraphicus (Symbol Greek)"+# baskervald_adf_fourier : "Baskervald ADF with Fourier"+# baskerville_it : "Baskerville (Italic)"+# biolinum : "Biolinum"+# brushscriptx : "BrushScriptX-Italic (PX math and Greek)"+# chalkboard_se : "Chalkboard SE"+# chalkduster : "Chalkduster"+# comfortaa : "Comfortaa"+# comic_sans : "Comic Sans MS"+# droid_sans : "Droid Sans"+# droid_sans_it : "Droid Sans (Italic)"+# droid_serif : "Droid Serif"+# droid_serif_px_it : "Droid Serif (PX math symbols) (Italic)"+# ecf_augie : "ECF Augie (Euler Greek)"+# ecf_jd : "ECF JD (with TX fonts)"+# ecf_skeetch : "ECF Skeetch (CM Greek)"+# ecf_tall_paul : "ECF Tall Paul (with Symbol font)"+# ecf_webster : "ECF Webster (with TX fonts)"+# electrum_adf : "Electrum ADF (CM Greek)"+# epigrafica : Epigrafica+# fourier_utopia : "Fourier Utopia (Fourier upright Greek)"+# french_cursive : "French Cursive (Euler Greek)"+# gfs_bodoni : "GFS Bodoni"+# gfs_didot : "GFS Didot (Italic)"+# gfs_neoHellenic : "GFS NeoHellenic"+# gnu_freesans_tx : "GNU FreeSerif (and TX fonts symbols)"+# gnu_freeserif_freesans : "GNU FreeSerif and FreeSans"+# helvetica_fourier_it : "Helvetica with Fourier (Italic)"+# latin_modern_tw_it : "Latin Modern Typewriter Proportional (CM Greek) (Italic)"+# latin_modern_tw : "Latin Modern Typewriter Proportional"+# libertine : "Libertine"+# libris_adf_fourier : "Libris ADF with Fourier"+# minion_pro_myriad_pro : "Minion Pro and Myriad Pro (and TX fonts symbols)"+# minion_pro_tx : "Minion Pro (and TX fonts symbols)"+# new_century_schoolbook : "New Century Schoolbook (Symbol Greek)"+# new_century_schoolbook_px : "New Century Schoolbook (Symbol Greek, PX math symbols)"+# noteworthy_light : "Noteworthy Light"+# palatino : "Palatino (Symbol Greek)"+# papyrus : "Papyrus"+# romande_adf_fourier_it : "Romande ADF with Fourier (Italic)"+# slitex : "SliTeX (Euler Greek)"+# times_fourier_it : "Times with Fourier (Italic)"+# urw_avant_garde : "URW Avant Garde (Symbol Greek)"+# urw_zapf_chancery : "URW Zapf Chancery (CM Greek)"+# venturis_adf_fourier_it : "Venturis ADF with Fourier (Italic)"+# verdana_it : "Verdana (Italic)"+# vollkorn_fourier_it : "Vollkorn with Fourier (Italic)"+# vollkorn : "Vollkorn (TX fonts for Greek and math symbols)"+# zapf_chancery : "Zapf Chancery"+# -----------------------------------------------------------------------------------------+#+#+#+#+#+#+#+#+#+#++# Latin Modern Typewriter Proportional+lmtp = BasicTexTemplate()+lmtp.description = "Latin Modern Typewriter Proportional"+lmtp.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[variablett]{lmodern}+\renewcommand{\rmdefault}{\ttdefault}+\usepackage[LGRgreek]{mathastext}+\MTgreekfont{lmtt} % no lgr lmvtt, so use lgr lmtt+\Mathastext+\let\varepsilon\epsilon % only \varsigma in LGR+"""+)+++# Fourier Utopia (Fourier upright Greek)+fufug = BasicTexTemplate()+fufug.description = "Fourier Utopia (Fourier upright Greek)"+fufug.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[upright]{fourier}+\usepackage{mathastext}+"""+)+++# Droid Serif+droidserif = BasicTexTemplate()+droidserif.description = "Droid Serif"+droidserif.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[default]{droidserif}+\usepackage[LGRgreek]{mathastext}+\let\varepsilon\epsilon+"""+)+++# Droid Sans+droidsans = BasicTexTemplate()+droidsans.description = "Droid Sans"+droidsans.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[default]{droidsans}+\usepackage[LGRgreek]{mathastext}+\let\varepsilon\epsilon+"""+)+++# New Century Schoolbook (Symbol Greek)+ncssg = BasicTexTemplate()+ncssg.description = "New Century Schoolbook (Symbol Greek)"+ncssg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{newcent}+\usepackage[symbolgreek]{mathastext}+\linespread{1.1}+"""+)+++# French Cursive (Euler Greek)+fceg = BasicTexTemplate()+fceg.description = "French Cursive (Euler Greek)"+fceg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[default]{frcursive}+\usepackage[eulergreek,noplusnominus,noequal,nohbar,%+nolessnomore,noasterisk]{mathastext}+"""+)+++# Auriocus Kalligraphicus (Symbol Greek)+aksg = BasicTexTemplate()+aksg.description = "Auriocus Kalligraphicus (Symbol Greek)"+aksg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{aurical}+\renewcommand{\rmdefault}{AuriocusKalligraphicus}+\usepackage[symbolgreek]{mathastext}+"""+)+++# Palatino (Symbol Greek)+palatinosg = BasicTexTemplate()+palatinosg.description = "Palatino (Symbol Greek)"+palatinosg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{palatino}+\usepackage[symbolmax,defaultmathsizes]{mathastext}+"""+)+++# Comfortaa+comfortaa = BasicTexTemplate()+comfortaa.description = "Comfortaa"+comfortaa.add_to_preamble(+ r"""+\usepackage[default]{comfortaa}+\usepackage[LGRgreek,defaultmathsizes,noasterisk]{mathastext}+\let\varphi\phi+\linespread{1.06}+"""+)+++# ECF Augie (Euler Greek)+ecfaugieeg = BasicTexTemplate()+ecfaugieeg.description = "ECF Augie (Euler Greek)"+ecfaugieeg.add_to_preamble(+ r"""+\renewcommand\familydefault{fau} % emerald package+\usepackage[defaultmathsizes,eulergreek]{mathastext}+"""+)+++# Electrum ADF (CM Greek)+electrumadfcm = BasicTexTemplate()+electrumadfcm.description = "Electrum ADF (CM Greek)"+electrumadfcm.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[LGRgreek,basic,defaultmathsizes]{mathastext}+\usepackage[lf]{electrum}+\Mathastext+\let\varphi\phi+"""+)+++# American Typewriter+americantypewriter = BasicTexTemplate()+americantypewriter.description = "American Typewriter"+americantypewriter.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{American Typewriter}+\usepackage[defaultmathsizes]{mathastext}+"""+)+americantypewriter.tex_compiler = "xelatex"+++# Minion Pro and Myriad Pro (and TX fonts symbols)+mpmptx = BasicTexTemplate()+mpmptx.description = "Minion Pro and Myriad Pro (and TX fonts symbols)"+mpmptx.add_to_preamble(+ r"""+\usepackage{txfonts}+\usepackage[upright]{txgreeks}+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Minion Pro}+\setsansfont[Mapping=tex-text,Scale=MatchUppercase]{Myriad Pro}+\renewcommand\familydefault\sfdefault+\usepackage[defaultmathsizes]{mathastext}+\renewcommand\familydefault\rmdefault+"""+)+mpmptx.tex_compiler = "xelatex"+++# New Century Schoolbook (Symbol Greek, PX math symbols)+ncssgpxm = BasicTexTemplate()+ncssgpxm.description = "New Century Schoolbook (Symbol Greek, PX math symbols)"+ncssgpxm.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{pxfonts}+\usepackage{newcent}+\usepackage[symbolgreek,defaultmathsizes]{mathastext}+\linespread{1.06}+"""+)+++# Vollkorn (TX fonts for Greek and math symbols)+vollkorntx = BasicTexTemplate()+vollkorntx.description = "Vollkorn (TX fonts for Greek and math symbols)"+vollkorntx.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{txfonts}+\usepackage[upright]{txgreeks}+\usepackage{vollkorn}+\usepackage[defaultmathsizes]{mathastext}+"""+)+++# Libertine+libertine = BasicTexTemplate()+libertine.description = "Libertine"+libertine.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{libertine}+\usepackage[greek=n]{libgreek}+\usepackage[noasterisk,defaultmathsizes]{mathastext}+"""+)+++# SliTeX (Euler Greek)+slitexeg = BasicTexTemplate()+slitexeg.description = "SliTeX (Euler Greek)"+slitexeg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{tpslifonts}+\usepackage[eulergreek,defaultmathsizes]{mathastext}+\MTEulerScale{1.06}+\linespread{1.2}+"""+)+++# ECF Webster (with TX fonts)+ecfwebstertx = BasicTexTemplate()+ecfwebstertx.description = "ECF Webster (with TX fonts)"+ecfwebstertx.add_to_preamble(+ r"""+\usepackage{txfonts}+\usepackage[upright]{txgreeks}+\renewcommand\familydefault{fwb} % emerald package+\usepackage{mathastext}+\renewcommand{\int}{\intop\limits}+\linespread{1.5}+"""+)+ecfwebstertx.add_to_document(+ r"""+\mathversion{bold}+"""+)+++# Romande ADF with Fourier (Italic)+italicromandeadff = BasicTexTemplate()+italicromandeadff.description = "Romande ADF with Fourier (Italic)"+italicromandeadff.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{fourier}+\usepackage{romande}+\usepackage[italic,defaultmathsizes,noasterisk]{mathastext}+\renewcommand{\itshape}{\swashstyle}+"""+)+++# Apple Chancery+applechancery = BasicTexTemplate()+applechancery.description = "Apple Chancery"+applechancery.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Apple Chancery}+\usepackage[defaultmathsizes]{mathastext}+"""+)+applechancery.tex_compiler = "xelatex"+++# Zapf Chancery+zapfchancery = BasicTexTemplate()+zapfchancery.description = "Zapf Chancery"+zapfchancery.add_to_preamble(+ r"""+\DeclareFontFamily{T1}{pzc}{}+\DeclareFontShape{T1}{pzc}{mb}{it}{<->s*[1.2] pzcmi8t}{}+\DeclareFontShape{T1}{pzc}{m}{it}{<->ssub * pzc/mb/it}{}+\usepackage{chancery} % = \renewcommand{\rmdefault}{pzc}+\renewcommand\shapedefault\itdefault+\renewcommand\bfdefault\mddefault+\usepackage[defaultmathsizes]{mathastext}+\linespread{1.05}+"""+)+++# Verdana (Italic)+italicverdana = BasicTexTemplate()+italicverdana.description = "Verdana (Italic)"+italicverdana.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Verdana}+\usepackage[defaultmathsizes,italic]{mathastext}+"""+)+italicverdana.tex_compiler = "xelatex"+++# URW Zapf Chancery (CM Greek)+urwzccmg = BasicTexTemplate()+urwzccmg.description = "URW Zapf Chancery (CM Greek)"+urwzccmg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\DeclareFontFamily{T1}{pzc}{}+\DeclareFontShape{T1}{pzc}{mb}{it}{<->s*[1.2] pzcmi8t}{}+\DeclareFontShape{T1}{pzc}{m}{it}{<->ssub * pzc/mb/it}{}+\DeclareFontShape{T1}{pzc}{mb}{sl}{<->ssub * pzc/mb/it}{}+\DeclareFontShape{T1}{pzc}{m}{sl}{<->ssub * pzc/mb/sl}{}+\DeclareFontShape{T1}{pzc}{m}{n}{<->ssub * pzc/mb/it}{}+\usepackage{chancery}+\usepackage{mathastext}+\linespread{1.05}"""+)+urwzccmg.add_to_document(+ r"""+\boldmath+"""+)+++# Comic Sans MS+comicsansms = BasicTexTemplate()+comicsansms.description = "Comic Sans MS"+comicsansms.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Comic Sans MS}+\usepackage[defaultmathsizes]{mathastext}+"""+)+comicsansms.tex_compiler = "xelatex"+++# GFS Didot (Italic)+italicgfsdidot = BasicTexTemplate()+italicgfsdidot.description = "GFS Didot (Italic)"+italicgfsdidot.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\renewcommand\rmdefault{udidot}+\usepackage[LGRgreek,defaultmathsizes,italic]{mathastext}+\let\varphi\phi+"""+)+++# Chalkduster+chalkduster = BasicTexTemplate()+chalkduster.description = "Chalkduster"+chalkduster.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Chalkduster}+\usepackage[defaultmathsizes]{mathastext}+"""+)+chalkduster.tex_compiler = "lualatex"+chalkduster.output_format = ".pdf"+++# Minion Pro (and TX fonts symbols)+mptx = BasicTexTemplate()+mptx.description = "Minion Pro (and TX fonts symbols)"+mptx.add_to_preamble(+ r"""+\usepackage{txfonts}+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Minion Pro}+\usepackage[defaultmathsizes]{mathastext}+"""+)+mptx.tex_compiler = "xelatex"+++# GNU FreeSerif and FreeSans+gnufsfs = BasicTexTemplate()+gnufsfs.description = "GNU FreeSerif and FreeSans"+gnufsfs.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[ExternalLocation,+ Mapping=tex-text,+ BoldFont=FreeSerifBold,+ ItalicFont=FreeSerifItalic,+ BoldItalicFont=FreeSerifBoldItalic]{FreeSerif}+\setsansfont[ExternalLocation,+ Mapping=tex-text,+ BoldFont=FreeSansBold,+ ItalicFont=FreeSansOblique,+ BoldItalicFont=FreeSansBoldOblique,+ Scale=MatchLowercase]{FreeSans}+\renewcommand{\familydefault}{lmss}+\usepackage[LGRgreek,defaultmathsizes,noasterisk]{mathastext}+\renewcommand{\familydefault}{\sfdefault}+\Mathastext+\let\varphi\phi % no `var' phi in LGR encoding+\renewcommand{\familydefault}{\rmdefault}+"""+)+gnufsfs.tex_compiler = "xelatex"+gnufsfs.output_format = ".pdf"++# GFS NeoHellenic+gfsneohellenic = BasicTexTemplate()+gfsneohellenic.description = "GFS NeoHellenic"+gfsneohellenic.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\renewcommand{\rmdefault}{neohellenic}+\usepackage[LGRgreek]{mathastext}+\let\varphi\phi+\linespread{1.06}+"""+)+++# ECF Tall Paul (with Symbol font)+ecftallpaul = BasicTexTemplate()+ecftallpaul.description = "ECF Tall Paul (with Symbol font)"+ecftallpaul.add_to_preamble(+ r"""+\DeclareFontFamily{T1}{ftp}{}+\DeclareFontShape{T1}{ftp}{m}{n}{+ <->s*[1.4] ftpmw8t+}{} % increase size by factor 1.4+\renewcommand\familydefault{ftp} % emerald package+\usepackage[symbol]{mathastext}+\let\infty\inftypsy+"""+)+++# Droid Sans (Italic)+italicdroidsans = BasicTexTemplate()+italicdroidsans.description = "Droid Sans (Italic)"+italicdroidsans.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[default]{droidsans}+\usepackage[LGRgreek,defaultmathsizes,italic]{mathastext}+\let\varphi\phi+"""+)+++# Baskerville (Italic)+italicbaskerville = BasicTexTemplate()+italicbaskerville.description = "Baskerville (Italic)"+italicbaskerville.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Baskerville}+\usepackage[defaultmathsizes,italic]{mathastext}+"""+)+italicbaskerville.tex_compiler = "xelatex"+++# ECF JD (with TX fonts)+ecfjdtx = BasicTexTemplate()+ecfjdtx.description = "ECF JD (with TX fonts)"+ecfjdtx.add_to_preamble(+ r"""+\usepackage{txfonts}+\usepackage[upright]{txgreeks}+\renewcommand\familydefault{fjd} % emerald package+\usepackage{mathastext}+"""+)+ecfjdtx.add_to_document(+ r"""\mathversion{bold}+"""+)+++# Antykwa Półtawskiego (TX Fonts for Greek and math symbols)+aptxgm = BasicTexTemplate()+aptxgm.description = "Antykwa Półtawskiego (TX Fonts for Greek and math symbols)"+aptxgm.add_to_preamble(+ r"""+\usepackage[OT4,OT1]{fontenc}+\usepackage{txfonts}+\usepackage[upright]{txgreeks}+\usepackage{antpolt}+\usepackage[defaultmathsizes,nolessnomore]{mathastext}+"""+)+++# Papyrus+papyrus = BasicTexTemplate()+papyrus.description = "Papyrus"+papyrus.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Papyrus}+\usepackage[defaultmathsizes]{mathastext}+"""+)+papyrus.tex_compiler = "xelatex"+++# GNU FreeSerif (and TX fonts symbols)+gnufstx = BasicTexTemplate()+gnufstx.description = "GNU FreeSerif (and TX fonts symbols)"+gnufstx.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\usepackage{txfonts} %\let\mathbb=\varmathbb+\setmainfont[ExternalLocation,+ Mapping=tex-text,+ BoldFont=FreeSerifBold,+ ItalicFont=FreeSerifItalic,+ BoldItalicFont=FreeSerifBoldItalic]{FreeSerif}+\usepackage[defaultmathsizes]{mathastext}+"""+)+gnufstx.tex_compiler = "xelatex"+gnufstx.output_format = ".pdf"+++# ECF Skeetch (CM Greek)+ecfscmg = BasicTexTemplate()+ecfscmg.description = "ECF Skeetch (CM Greek)"+ecfscmg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[T1]{fontenc}+\DeclareFontFamily{T1}{fsk}{}+\DeclareFontShape{T1}{fsk}{m}{n}{<->s*[1.315] fskmw8t}{}+\renewcommand\rmdefault{fsk}+\usepackage[noendash,defaultmathsizes,nohbar,defaultimath]{mathastext}+"""+)+++# Latin Modern Typewriter Proportional (CM Greek) (Italic)+italiclmtpcm = BasicTexTemplate()+italiclmtpcm.description = "Latin Modern Typewriter Proportional (CM Greek) (Italic)"+italiclmtpcm.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[variablett,nomath]{lmodern}+\renewcommand{\familydefault}{\ttdefault}+\usepackage[frenchmath]{mathastext}+\linespread{1.08}+"""+)+++# Baskervald ADF with Fourier+baskervaldadff = BasicTexTemplate()+baskervaldadff.description = "Baskervald ADF with Fourier"+baskervaldadff.add_to_preamble(+ r"""+\usepackage[upright]{fourier}+\usepackage{baskervald}+\usepackage[defaultmathsizes,noasterisk]{mathastext}+"""+)+++# Droid Serif (PX math symbols) (Italic)+italicdroidserifpx = BasicTexTemplate()+italicdroidserifpx.description = "Droid Serif (PX math symbols) (Italic)"+italicdroidserifpx.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{pxfonts}+\usepackage[default]{droidserif}+\usepackage[LGRgreek,defaultmathsizes,italic,basic]{mathastext}+\let\varphi\phi+"""+)+++# Biolinum+biolinum = BasicTexTemplate()+biolinum.description = "Biolinum"+biolinum.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{libertine}+\renewcommand{\familydefault}{\sfdefault}+\usepackage[greek=n,biolinum]{libgreek}+\usepackage[noasterisk,defaultmathsizes]{mathastext}+"""+)+++# Vollkorn with Fourier (Italic)+italicvollkornf = BasicTexTemplate()+italicvollkornf.description = "Vollkorn with Fourier (Italic)"+italicvollkornf.add_to_preamble(+ r"""+\usepackage{fourier}+\usepackage{vollkorn}+\usepackage[italic,nohbar]{mathastext}+"""+)+++# Chalkboard SE+chalkboardse = BasicTexTemplate()+chalkboardse.description = "Chalkboard SE"+chalkboardse.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Chalkboard SE}+\usepackage[defaultmathsizes]{mathastext}+"""+)+chalkboardse.tex_compiler = "xelatex"+++# Noteworthy Light+noteworthylight = BasicTexTemplate()+noteworthylight.description = "Noteworthy Light"+noteworthylight.add_to_preamble(+ r"""+\usepackage[no-math]{fontspec}+\setmainfont[Mapping=tex-text]{Noteworthy Light}+\usepackage[defaultmathsizes]{mathastext}+"""+)+++# Epigrafica+epigrafica = BasicTexTemplate()+epigrafica.description = "Epigrafica"+epigrafica.add_to_preamble(+ r"""+\usepackage[LGR,OT1]{fontenc}+\usepackage{epigrafica}+\usepackage[basic,LGRgreek,defaultmathsizes]{mathastext}+\let\varphi\phi+\linespread{1.2}+"""+)+++# Libris ADF with Fourier+librisadff = BasicTexTemplate()+librisadff.description = "Libris ADF with Fourier"+librisadff.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[upright]{fourier}+\usepackage{libris}+\renewcommand{\familydefault}{\sfdefault}+\usepackage[noasterisk]{mathastext}+"""+)+++# Venturis ADF with Fourier (Italic)+italicvanturisadff = BasicTexTemplate()+italicvanturisadff.description = "Venturis ADF with Fourier (Italic)"+italicvanturisadff.add_to_preamble(+ r"""+\usepackage{fourier}+\usepackage[lf]{venturis}+\usepackage[italic,defaultmathsizes,noasterisk]{mathastext}+"""+)+++# GFS Bodoni+gfsbodoni = BasicTexTemplate()+gfsbodoni.description = "GFS Bodoni"+gfsbodoni.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\renewcommand{\rmdefault}{bodoni}+\usepackage[LGRgreek]{mathastext}+\let\varphi\phi+\linespread{1.06}+"""+)+++# BrushScriptX-Italic (PX math and Greek)+brushscriptxpx = BasicTexTemplate()+brushscriptxpx.description = "BrushScriptX-Italic (PX math and Greek)"+brushscriptxpx.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{pxfonts}+%\usepackage{pbsi}+\renewcommand{\rmdefault}{pbsi}+\renewcommand{\mddefault}{xl}+\renewcommand{\bfdefault}{xl}+\usepackage[defaultmathsizes,noasterisk]{mathastext}+"""+)+brushscriptxpx.add_to_document(+ r"""\boldmath+"""+)+brushscriptxpx.tex_compiler = "xelatex"+++# URW Avant Garde (Symbol Greek)+urwagsg = BasicTexTemplate()+urwagsg.description = "URW Avant Garde (Symbol Greek)"+urwagsg.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage{avant}+\renewcommand{\familydefault}{\sfdefault}+\usepackage[symbolgreek,defaultmathsizes]{mathastext}+"""+)+++# Times with Fourier (Italic)+italictimesf = BasicTexTemplate()+italictimesf.description = "Times with Fourier (Italic)"+italictimesf.add_to_preamble(+ r"""+\usepackage{fourier}+\renewcommand{\rmdefault}{ptm}+\usepackage[italic,defaultmathsizes,noasterisk]{mathastext}+"""+)+++# Helvetica with Fourier (Italic)+italichelveticaf = BasicTexTemplate()+italichelveticaf.description = "Helvetica with Fourier (Italic)"+italichelveticaf.add_to_preamble(+ r"""+\usepackage[T1]{fontenc}+\usepackage[scaled]{helvet}+\usepackage{fourier}+\renewcommand{\rmdefault}{phv}+\usepackage[italic,defaultmathsizes,noasterisk]{mathastext}+"""+)+++class TexFontTemplateCollection(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"+++TexFontTemplates = TexFontTemplateCollection()