Unicode to Tex symbols, Type1 names, and vice versa

I finally solved the problem of automaticaly generating the dicts for
unicode <-> TeX conversion. This is the first step in enabling unicode
support in mathtext.

The STIX projects is usefull after all :wink: They keep a nice table of
Unicode symbols at:

Any comments about the script are appreciated :). Now I'll dig a bit
deeper into the font classes to fix them to suport unicode.

'''A script for seemlesly copying the data from the stix-tbl.ascii*
file to a set
of python dicts. Dicts are then pickled to coresponding files, for
later retrieval.
Currently used table file:

import pickle

table_filename = 'stix-tbl.ascii-2005-09-24'
dict_names = ['uni2type1', 'type12uni', 'uni2tex', 'tex2uni']
dicts = {}
# initialize the dicts
for name in dict_names:
    dicts[name] = {}

for line in file(table_filename):
    if line[:2]==' 0':
        uni_num = eval("u'\\u"+line[2:6].strip().lower()+"'")
        type1_name = line[12:37].strip()
        tex_name = line[83:110].strip()
        if type1_name:
            dicts['uni2type1'][uni_num] = type1_name
            dicts['type12uni'][type1_name] = uni_num
        if tex_name:
            dicts['uni2tex'][uni_num] = tex_name
            dicts['tex2uni'][tex_name] = uni_num
for name in dict_names:
    pickle.dump(dicts[name], open(name + '.pcl','w'))

# An example
uni_char = u'\u00d7'
print dicts['uni2tex'][uni_char]
print dicts['uni2type1'][uni_char]
# Testing of results, testing; feel free to unquote
# _mathtext_data.py can be found in the matplolib dir
#~ from _mathtext_data import latex_to_bakoma
#~ supported = 0
#~ unsupported = 0
#~ for tex_symbol in latex_to_bakoma:
    #~ try:
        #~ print tex_symbol, dicts['tex2uni'][tex_symbol]
        #~ supported += 1
    #~ except KeyError:
        #~ unsupported += 1
        #~ pass
#~ print supported, unsupported