I wrote a class object to access mathematical alphanumeric symbols from the unicode block as described on https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
# San-serif
LATIN_SANSERIF_NORMAL_UPPER = (120224, 120250)
LATIN_SANSERIF_NORMAL_LOWER = (120250, 120276)
LATIN_SANSERIF_BOLD_UPPER = (120276, 120302)
LATIN_SANSERIF_BOLD_LOWER = (120302, 120328)
LATIN_SANSERIF_ITALIC_UPPER = (120328, 120354)
LATIN_SANSERIF_ITALIC_LOWER = (120354, 120380)
LATIN_SANSERIF_BOLDITALIC_UPPER = (120380, 120406)
LATIN_SANSERIF_BOLDITALIC_LOWER = (120406, 120432)
class MathAlphanumeric:
    def __init__(self, script, font, style, case):
        self.script = script
        self.font = font
        self.style = style
        self.case = case
        
    def charset(self):
        start, end = eval('_'.join([self.script, self.font, self.style, self.case]).upper())
        for c in range(start, end):
            yield chr(c)
    
    @staticmethod
    def supported_scripts():
        return {'latin', 'greek', 'digits'}
    
    @staticmethod
    def supported_fonts():
        return {'serif', 'sanserif', 'calligraphy', 'fraktor', 'monospace', 'doublestruck'}
    
    @staticmethod
    def supported_style():
        return {'normal', 'bold', 'italic', 'bold-italic'}
    
    @staticmethod
    def supported_case():
        return {'upper', 'lower'}
         
And to use it, I'll do:
ma = MathAlphanumeric('latin', 'sanserif', 'bold', 'lower')
print(list(ma.charset()))
[out]:
['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
The code works as expected but to cover all the mathematical alphanum symbols, I'll have to to enumerate through all the start and end symbols from the script * fonts * style * case no. of constants.
My questions are:
- Is there a better way to create the desired MathAlphanumericobject?
- Is there a way to avoid the initialisation of script * fonts * style * caseno. of constants, in order forMathAlphanumeric.charset()to work as expected?
- Has an object or function like this been available in some unicode.org related library?
 
     
    