1010import sys
1111import re
1212
13- # Selection of features following "Writing mathematical expressions" tutorial
14- mathtext_titles = {
15- 0 : "Header demo" ,
16- 1 : "Subscripts and superscripts" ,
17- 2 : "Fractions, binomials and stacked numbers" ,
18- 3 : "Radicals" ,
19- 4 : "Fonts" ,
20- 5 : "Accents" ,
21- 6 : "Greek, Hebrew" ,
22- 7 : "Delimiters, functions and Symbols" }
23- n_lines = len (mathtext_titles )
24-
25- # Randomly picked examples
26- mathext_demos = {
27- 0 : r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = "
28- r"U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} "
29- r"\int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ "
30- r"U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_"
31- r"{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$" ,
32-
33- 1 : r"$\alpha_i > \beta_i,\ "
34- r"\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau},\ "
35- r"\ldots$" ,
36-
37- 2 : r"$\frac{3}{4},\ \binom{3}{4},\ \genfrac{}{}{0}{}{3}{4},\ "
38- r"\left(\frac{5 - \frac{1}{x}}{4}\right),\ \ldots$" ,
39-
40- 3 : r"$\sqrt{2},\ \sqrt[3]{x},\ \ldots$" ,
41-
42- 4 : r"$\mathrm{Roman}\ , \ \mathit{Italic}\ , \ \mathtt{Typewriter} \ "
43- r"\mathrm{or}\ \mathcal{CALLIGRAPHY}$" ,
44-
45- 5 : r"$\acute a,\ \bar a,\ \breve a,\ \dot a,\ \ddot a, \ \grave a, \ "
46- r"\hat a,\ \tilde a,\ \vec a,\ \widehat{xyz},\ \widetilde{xyz},\ "
47- r"\ldots$" ,
48-
49- 6 : r"$\alpha,\ \beta,\ \chi,\ \delta,\ \lambda,\ \mu,\ "
50- r"\Delta,\ \Gamma,\ \Omega,\ \Phi,\ \Pi,\ \Upsilon,\ \nabla,\ "
51- r"\aleph,\ \beth,\ \daleth,\ \gimel,\ \ldots$" ,
52-
53- 7 : r"$\coprod,\ \int,\ \oint,\ \prod,\ \sum,\ "
54- r"\log,\ \sin,\ \approx,\ \oplus,\ \star,\ \varpropto,\ "
55- r"\infty,\ \partial,\ \Re,\ \leftrightsquigarrow, \ \ldots$" }
13+ # Selection of features following "Writing mathematical expressions" tutorial,
14+ # with randomly picked examples.
15+ mathtext_demos = {
16+ "Header demo" :
17+ r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = "
18+ r"U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} "
19+ r"\int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ "
20+ r"U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_"
21+ r"{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$" ,
22+
23+ "Subscripts and superscripts" :
24+ r"$\alpha_i > \beta_i,\ "
25+ r"\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau},\ "
26+ r"\ldots$" ,
27+
28+ "Fractions, binomials and stacked numbers" :
29+ r"$\frac{3}{4},\ \binom{3}{4},\ \genfrac{}{}{0}{}{3}{4},\ "
30+ r"\left(\frac{5 - \frac{1}{x}}{4}\right),\ \ldots$" ,
31+
32+ "Radicals" :
33+ r"$\sqrt{2},\ \sqrt[3]{x},\ \ldots$" ,
34+
35+ "Fonts" :
36+ r"$\mathrm{Roman}\ , \ \mathit{Italic}\ , \ \mathtt{Typewriter} \ "
37+ r"\mathrm{or}\ \mathcal{CALLIGRAPHY}$" ,
38+
39+ "Accents" :
40+ r"$\acute a,\ \bar a,\ \breve a,\ \dot a,\ \ddot a, \ \grave a, \ "
41+ r"\hat a,\ \tilde a,\ \vec a,\ \widehat{xyz},\ \widetilde{xyz},\ "
42+ r"\ldots$" ,
43+
44+ "Greek, Hebrew" :
45+ r"$\alpha,\ \beta,\ \chi,\ \delta,\ \lambda,\ \mu,\ "
46+ r"\Delta,\ \Gamma,\ \Omega,\ \Phi,\ \Pi,\ \Upsilon,\ \nabla,\ "
47+ r"\aleph,\ \beth,\ \daleth,\ \gimel,\ \ldots$" ,
48+
49+ "Delimiters, functions and Symbols" :
50+ r"$\coprod,\ \int,\ \oint,\ \prod,\ \sum,\ "
51+ r"\log,\ \sin,\ \approx,\ \oplus,\ \star,\ \varpropto,\ "
52+ r"\infty,\ \partial,\ \Re,\ \leftrightsquigarrow, \ \ldots$" ,
53+ }
54+ n_lines = len (mathtext_demos )
5655
5756
5857def doall ():
@@ -73,32 +72,31 @@ def doall():
7372 # Gap between lines in axes coords
7473 line_axesfrac = 1 / n_lines
7574
76- # Plotting header demonstration formula
77- full_demo = mathext_demos [ 0 ]
75+ # Plot header demonstration formula.
76+ full_demo = mathtext_demos [ 'Header demo' ]
7877 ax .annotate (full_demo ,
7978 xy = (0.5 , 1. - 0.59 * line_axesfrac ),
8079 color = 'tab:orange' , ha = 'center' , fontsize = 20 )
8180
82- # Plotting features demonstration formulae
83- for i_line in range (1 , n_lines ):
81+ # Plot feature demonstration formulae.
82+ for i_line , (title , demo ) in enumerate (mathtext_demos .items ()):
83+ print (i_line , demo )
84+ if i_line == 0 :
85+ continue
86+
8487 baseline = 1 - i_line * line_axesfrac
8588 baseline_next = baseline - line_axesfrac
86- title = mathtext_titles [i_line ] + ":"
8789 fill_color = ['white' , 'tab:blue' ][i_line % 2 ]
8890 ax .fill_between ([0 , 1 ], [baseline , baseline ],
8991 [baseline_next , baseline_next ],
9092 color = fill_color , alpha = 0.2 )
91- ax .annotate (title ,
93+ ax .annotate (f' { title } :' ,
9294 xy = (0.07 , baseline - 0.3 * line_axesfrac ),
9395 color = mpl_grey_rgb , weight = 'bold' )
94- demo = mathext_demos [i_line ]
9596 ax .annotate (demo ,
9697 xy = (0.05 , baseline - 0.75 * line_axesfrac ),
9798 color = mpl_grey_rgb , fontsize = 16 )
9899
99- for i in range (n_lines ):
100- s = mathext_demos [i ]
101- print (i , s )
102100 plt .show ()
103101
104102
@@ -111,8 +109,7 @@ def doall():
111109 fd .write ("\\ begin{document}\n " )
112110 fd .write ("\\ begin{enumerate}\n " )
113111
114- for i in range (n_lines ):
115- s = mathext_demos [i ]
112+ for s in mathtext_demos .values ():
116113 s = re .sub (r"(?<!\\)\$" , "$$" , s )
117114 fd .write ("\\ item %s\n " % s )
118115
0 commit comments