33"""
44
55from collections import namedtuple
6+ import enum
67import functools
78from io import StringIO
89import logging
@@ -1944,8 +1945,11 @@ class Parser:
19441945 The grammar is based directly on that in TeX, though it cuts a few corners.
19451946 """
19461947
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 ()
19491953
19501954 _binary_operators = set ('''
19511955 + * -
@@ -2798,8 +2802,7 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den):
27982802
27992803 rule = float (rule )
28002804
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 :
28032806 num .shrink ()
28042807 den .shrink ()
28052808 cnum = HCentered ([num ])
@@ -2848,8 +2851,8 @@ def frac(self, s, loc, toks):
28482851 state .font , state .fontsize , state .dpi )
28492852 num , den = toks [0 ]
28502853
2851- return self ._genfrac ('' , '' , thickness ,
2852- self . _math_style_dict [ 'textstyle' ], num , den )
2854+ return self ._genfrac ('' , '' , thickness , self . _MathStyle . TEXTSTYLE ,
2855+ num , den )
28532856
28542857 def dfrac (self , s , loc , toks ):
28552858 assert len (toks ) == 1
@@ -2860,16 +2863,16 @@ def dfrac(self, s, loc, toks):
28602863 state .font , state .fontsize , state .dpi )
28612864 num , den = toks [0 ]
28622865
2863- return self ._genfrac ('' , '' , thickness ,
2864- self . _math_style_dict [ 'displaystyle' ], num , den )
2866+ return self ._genfrac ('' , '' , thickness , self . _MathStyle . DISPLAYSTYLE ,
2867+ num , den )
28652868
28662869 def binom (self , s , loc , toks ):
28672870 assert len (toks ) == 1
28682871 assert len (toks [0 ]) == 2
28692872 num , den = toks [0 ]
28702873
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 )
28732876
28742877 def sqrt (self , s , loc , toks ):
28752878 root , body = toks [0 ]
0 commit comments