3
3
"""
4
4
5
5
from collections import namedtuple
6
+ import enum
6
7
import functools
7
8
from io import StringIO
8
9
import logging
@@ -1944,8 +1945,11 @@ class Parser:
1944
1945
The grammar is based directly on that in TeX, though it cuts a few corners.
1945
1946
"""
1946
1947
1947
- _math_style_dict = dict (displaystyle = 0 , textstyle = 1 ,
1948
- scriptstyle = 2 , scriptscriptstyle = 3 )
1948
+ class _MathStyle (enum .Enum ):
1949
+ DISPLAYSTYLE = enum .auto ()
1950
+ TEXTSTYLE = enum .auto ()
1951
+ SCRIPTSTYLE = enum .auto ()
1952
+ SCRIPTSCRIPTSTYLE = enum .auto ()
1949
1953
1950
1954
_binary_operators = set ('''
1951
1955
+ * -
@@ -2798,8 +2802,7 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den):
2798
2802
2799
2803
rule = float (rule )
2800
2804
2801
- # If style != displaystyle == 0, shrink the num and den
2802
- if style != self ._math_style_dict ['displaystyle' ]:
2805
+ if style is not self ._MathStyle .DISPLAYSTYLE :
2803
2806
num .shrink ()
2804
2807
den .shrink ()
2805
2808
cnum = HCentered ([num ])
@@ -2848,8 +2851,8 @@ def frac(self, s, loc, toks):
2848
2851
state .font , state .fontsize , state .dpi )
2849
2852
num , den = toks [0 ]
2850
2853
2851
- return self ._genfrac ('' , '' , thickness ,
2852
- self . _math_style_dict [ 'textstyle' ], num , den )
2854
+ return self ._genfrac ('' , '' , thickness , self . _MathStyle . TEXTSTYLE ,
2855
+ num , den )
2853
2856
2854
2857
def dfrac (self , s , loc , toks ):
2855
2858
assert len (toks ) == 1
@@ -2860,16 +2863,16 @@ def dfrac(self, s, loc, toks):
2860
2863
state .font , state .fontsize , state .dpi )
2861
2864
num , den = toks [0 ]
2862
2865
2863
- return self ._genfrac ('' , '' , thickness ,
2864
- self . _math_style_dict [ 'displaystyle' ], num , den )
2866
+ return self ._genfrac ('' , '' , thickness , self . _MathStyle . DISPLAYSTYLE ,
2867
+ num , den )
2865
2868
2866
2869
def binom (self , s , loc , toks ):
2867
2870
assert len (toks ) == 1
2868
2871
assert len (toks [0 ]) == 2
2869
2872
num , den = toks [0 ]
2870
2873
2871
- return self ._genfrac ('(' , ')' , 0.0 ,
2872
- self . _math_style_dict [ 'textstyle' ], num , den )
2874
+ return self ._genfrac ('(' , ')' , 0.0 , self . _MathStyle . TEXTSTYLE ,
2875
+ num , den )
2873
2876
2874
2877
def sqrt (self , s , loc , toks ):
2875
2878
root , body = toks [0 ]
0 commit comments