.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/text_labels_and_annotations/mathtext_examples.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_text_labels_and_annotations_mathtext_examples.py: ================= Mathtext Examples ================= Selected features of Matplotlib's math rendering engine. .. GENERATED FROM PYTHON SOURCE LINES 8-121 .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_mathtext_examples_001.png :alt: Matplotlib's math rendering engine :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_mathtext_examples_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_mathtext_examples_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0 $W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} \int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$ 1 $\alpha_i > \beta_i,\ \alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau},\ \ldots$ 2 $\frac{3}{4},\ \binom{3}{4},\ \genfrac{}{}{0}{}{3}{4},\ \left(\frac{5 - \frac{1}{x}}{4}\right),\ \ldots$ 3 $\sqrt{2},\ \sqrt[3]{x},\ \ldots$ 4 $\mathrm{Roman}\ , \ \mathit{Italic}\ , \ \mathtt{Typewriter} \ \mathrm{or}\ \mathcal{CALLIGRAPHY}$ 5 $\acute a,\ \bar a,\ \breve a,\ \dot a,\ \ddot a, \ \grave a, \ \hat a,\ \tilde a,\ \vec a,\ \widehat{xyz},\ \widetilde{xyz},\ \ldots$ 6 $\alpha,\ \beta,\ \chi,\ \delta,\ \lambda,\ \mu,\ \Delta,\ \Gamma,\ \Omega,\ \Phi,\ \Pi,\ \Upsilon,\ \nabla,\ \aleph,\ \beth,\ \daleth,\ \gimel,\ \ldots$ 7 $\coprod,\ \int,\ \oint,\ \prod,\ \sum,\ \log,\ \sin,\ \approx,\ \oplus,\ \star,\ \varpropto,\ \infty,\ \partial,\ \Re,\ \leftrightsquigarrow, \ \ldots$ | .. code-block:: Python import re import subprocess import sys import matplotlib.pyplot as plt # Selection of features following "Writing mathematical expressions" tutorial, # with randomly picked examples. mathtext_demos = { "Header demo": r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = " r"U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} " r"\int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ " r"U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_" r"{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$", "Subscripts and superscripts": r"$\alpha_i > \beta_i,\ " r"\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau},\ " r"\ldots$", "Fractions, binomials and stacked numbers": r"$\frac{3}{4},\ \binom{3}{4},\ \genfrac{}{}{0}{}{3}{4},\ " r"\left(\frac{5 - \frac{1}{x}}{4}\right),\ \ldots$", "Radicals": r"$\sqrt{2},\ \sqrt[3]{x},\ \ldots$", "Fonts": r"$\mathrm{Roman}\ , \ \mathit{Italic}\ , \ \mathtt{Typewriter} \ " r"\mathrm{or}\ \mathcal{CALLIGRAPHY}$", "Accents": r"$\acute a,\ \bar a,\ \breve a,\ \dot a,\ \ddot a, \ \grave a, \ " r"\hat a,\ \tilde a,\ \vec a,\ \widehat{xyz},\ \widetilde{xyz},\ " r"\ldots$", "Greek, Hebrew": r"$\alpha,\ \beta,\ \chi,\ \delta,\ \lambda,\ \mu,\ " r"\Delta,\ \Gamma,\ \Omega,\ \Phi,\ \Pi,\ \Upsilon,\ \nabla,\ " r"\aleph,\ \beth,\ \daleth,\ \gimel,\ \ldots$", "Delimiters, functions and Symbols": r"$\coprod,\ \int,\ \oint,\ \prod,\ \sum,\ " r"\log,\ \sin,\ \approx,\ \oplus,\ \star,\ \varpropto,\ " r"\infty,\ \partial,\ \Re,\ \leftrightsquigarrow, \ \ldots$", } n_lines = len(mathtext_demos) def doall(): # Colors used in Matplotlib online documentation. mpl_grey_rgb = (51 / 255, 51 / 255, 51 / 255) # Creating figure and axis. fig = plt.figure(figsize=(7, 7)) ax = fig.add_axes([0.01, 0.01, 0.98, 0.90], facecolor="white", frameon=True) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_title("Matplotlib's math rendering engine", color=mpl_grey_rgb, fontsize=14, weight='bold') ax.set_xticks([]) ax.set_yticks([]) # Gap between lines in axes coords line_axesfrac = 1 / n_lines # Plot header demonstration formula. full_demo = mathtext_demos['Header demo'] ax.annotate(full_demo, xy=(0.5, 1. - 0.59 * line_axesfrac), color='tab:orange', ha='center', fontsize=20) # Plot feature demonstration formulae. for i_line, (title, demo) in enumerate(mathtext_demos.items()): print(i_line, demo) if i_line == 0: continue baseline = 1 - i_line * line_axesfrac baseline_next = baseline - line_axesfrac fill_color = ['white', 'tab:blue'][i_line % 2] ax.axhspan(baseline, baseline_next, color=fill_color, alpha=0.2) ax.annotate(f'{title}:', xy=(0.06, baseline - 0.3 * line_axesfrac), color=mpl_grey_rgb, weight='bold') ax.annotate(demo, xy=(0.04, baseline - 0.75 * line_axesfrac), color=mpl_grey_rgb, fontsize=16) plt.show() if '--latex' in sys.argv: # Run: python mathtext_examples.py --latex # Need amsmath and amssymb packages. with open("mathtext_examples.ltx", "w") as fd: fd.write("\\documentclass{article}\n") fd.write("\\usepackage{amsmath, amssymb}\n") fd.write("\\begin{document}\n") fd.write("\\begin{enumerate}\n") for s in mathtext_demos.values(): s = re.sub(r"(?` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mathtext_examples.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_