2 import sys,string,re,os,os.path
4 def get_code(code, font):
5 if font != "dontknowwhichfontusesthisstrangeencoding":
18 ignore_list = ["not", "braceld", "bracerd", "bracelu", "braceru",
19 "lmoustache", "rmoustache", "lgroup", "rgroup", "bracevert"]
23 lines = fh.readlines()
25 package, ext = os.path.splitext(os.path.basename(file))
32 mo = re.match(r'\s*%.*', line)
37 next_line = lines[i+1]
39 # some entries are spread over two lines so we join the next line
40 # to the current one, (if current line contains a comment, we remove it)
41 line = string.split(line,'%')[0]+next_line
43 mo = re.match(r'.*\\DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
45 font_names[mo.group(1)] = mo.group(3)
47 mo = re.match(r'.*\\DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line)
55 code = int(mo.group(6))
56 elif mo.group(5) == '"':
57 code = int(mo.group(6), 16)
59 code = int(mo.group(6), 8)
61 mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
66 code = int(mo.group(3), 16)
70 if mo != None and symbol not in ignore_list:
71 mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
72 if mo2 != None and symbol == mo2.group(1)+"op":
73 sys.stderr.write("%s -> %s\n" % (symbol, mo2.group(1)))
76 if font_names.has_key(font):
77 font = font_names[font]
79 code = get_code(code, font)
84 if xsymbols.has_key(symbol):
85 xcode = xsymbols[symbol]
88 if symbols.has_key(symbol):
89 sys.stderr.write(symbol+ " exists\n")
90 if code != symbols[symbol]:
91 sys.stderr.write("code is not equal!!!\n")
93 symbols[symbol] = code
95 print "%-18s %-4s %3d %3d %-6s" % (symbol,font,code,xcode,type)
97 print "%-18s %-4s %3d %3d %-9s x %s" % (symbol,font,code,xcode,type,package)
100 path = os.path.split(sys.argv[0])[0]
101 fh = open(os.path.join(path, "x-font"))
102 lines = fh.readlines()
105 x = string.split(line)
107 code = string.atoi(x[1],16)
108 xsymbols[symbol] = code
110 for file in sys.argv[1:]:
111 print "# Generated from " + os.path.basename(file) + "\n"
116 ("neq", "x", 0, 185, "mathrel"),
117 ("textdegree", "x", 0, 176, "mathord"),
118 ("cong", "x", 0, 64, "mathrel"),
119 ("surd", "x", 0, 214, "mathord")
122 if xsymbols.has_key("leq"):
126 print "%-18s %-4s %3d %3d %-6s" % x
127 if xsymbols.has_key(x[0]):
131 lyxbar cmsy 161 0 mathord
132 lyxeq cmr 61 0 mathord
133 lyxdabar msa 57 0 mathord
134 lyxright msa 75 0 mathord
135 lyxleft msa 76 0 mathord
138 for symbol in xsymbols.keys():
139 sys.stderr.write(symbol+"\n")