(symb_name)
return ''.join([name, sups_result, subs_result])
return pretty representation of a symbol
return pretty representation of a symbol
return pretty representation of a symbol
def pretty_symbol(symb_name):
    """return pretty representation of a symbol"""
    # let's split symb_name into symbol + index
    # UC: beta1
    # UC: f_beta

    if not _use_unicode:
        return symb_name

    name, sups, subs = split_super_sub(symb_name)

    def translate(s) :
        gG = greek_unicode.get(s)
        if gG is not None:
            return gG
        for key in sorted(modifier_dict.keys(), key=lambda k:len(k), reverse=True) :
            if s.lower().endswith(key) and len(s)>len(key):
                return modifier_dict[key](translate(s[:-len(key)]))
        return s

    name = translate(name)

    # Let's prettify sups/subs. If it fails at one of them, pretty sups/subs are
    # not used at all.
    def pretty_list(l, mapping):
        result = []
        for s in l:
            pretty = mapping.get(s)
            if pretty is None:
                try:  # match by separate characters
                    pretty = ''.join([mapping[c] for c in s])
                except KeyError:
                    return None
            result.append(pretty)
        return result

    pretty_sups = pretty_list(sups, sup)
    if pretty_sups is not None:
        pretty_subs = pretty_list(subs, sub)
    else:
        pretty_subs = None

    # glue the results into one string
    if pretty_subs is None:  # nice formatting of sups/subs did not work
        if subs:
            name += '_'+'_'.join([translate(s) for s in subs])
        if sups:
            name += '__'+'__'.join([translate(s) for s in sups])
        return name
    else:
        sups_result = ' '.join(pretty_sups)
        subs_result = ' '.join(pretty_subs)

    return ''.join([name, sups_result, subs_result])
def pretty_symbol ( symb_name ) : # let's split symb_name into symbol + index # UC: beta1 # UC: f_beta if not _use_unicode : return symb_name name , sups , subs = split_super_sub ( symb_name ) def translate ( s ) : gG = greek_unicode . get ( s ) if gG is not None : return gG for key in sorted ( modifier_dict . keys ( ) , key = lambda k : len ( k ) , reverse = True ) : if s . lower ( ) . endswith ( key ) and len ( s ) > len ( key ) : return modifier_dict [ key ] ( translate ( s [ : - len ( key ) ] ) ) return s name = translate ( name ) # Let's prettify sups/subs. If it fails at one of them, pretty sups/subs are # not used at all. def pretty_list ( l , mapping ) : result = [ ] for s in l : pretty = mapping . get ( s ) if pretty is None : try : # match by separate characters pretty = '' . join ( [ mapping [ c ] for c in s ] ) except KeyError : return None result . append ( pretty ) return result pretty_sups = pretty_list ( sups , sup ) if pretty_sups is not None : pretty_subs = pretty_list ( subs , sub ) else : pretty_subs = None # glue the results into one string if pretty_subs is None : # nice formatting of sups/subs did not work if subs : name += '_' + '_' . join ( [ translate ( s ) for s in subs ] ) if sups : name += '__' + '__' . join ( [ translate ( s ) for s in sups ] ) return name else : sups_result = ' ' . join ( pretty_sups ) subs_result = ' ' . join ( pretty_subs ) return '' . join ( [ name , sups_result , subs_result ] )