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))
33 mo = re.match(r'\s*%.*', line)
38 next_line = lines[i+1]
40 # some entries are spread over two lines so we join the next line
41 # to the current one, (if current line contains a comment, we remove it)
42 line = string.split(line,'%')[0]+next_line
44 mo = re.match(r'.*\\DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
46 font_names[mo.group(1)] = mo.group(3)
48 mo = re.match(r'^\s*\\mdsy\@DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
50 font_names[mo.group(1)] = mo.group(3)
52 # \mdsy@setslot resets the counter for \mdsy@DeclareSymbol
53 mo = re.match(r'^\s*\\mdsy\@setslot\s*\{(.*?)\}.*', line)
55 mdsymbolcode = int(mo.group(1))
57 # \mdsy@nextslot increments the counter for \mdsy@DeclareSymbol
58 mo = re.match(r'^\s*\\mdsy\@nextslot.*', line)
60 mdsymbolcode = mdsymbolcode + 1
62 mo = re.match(r'.*\\(\\mdsy\@)?DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line)
70 code = int(mo.group(7))
71 elif mo.group(6) == '"':
72 code = int(mo.group(7), 16)
74 code = int(mo.group(7), 8)
76 mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
81 code = int(mo.group(3), 16)
86 mo = re.match(r'^\s*\\mdsy\@DeclareSymbol\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
92 mdsymbolcode = mdsymbolcode + 1
95 mo = re.match(r'^\s*\\mdsy\@DeclareAlias\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
100 code = mdsymbolcode - 1
102 if mo != None and symbol not in ignore_list:
103 mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
104 if mo2 != None and symbol == mo2.group(1)+"op":
105 sys.stderr.write("%s -> %s\n" % (symbol, mo2.group(1)))
106 symbol = mo2.group(1)
108 if font_names.has_key(font):
109 font = font_names[font]
111 code = get_code(code, font)
116 if xsymbols.has_key(symbol):
117 xcode = xsymbols[symbol]
120 if symbols.has_key(symbol):
121 sys.stderr.write(symbol+ " exists\n")
122 if code != symbols[symbol]:
123 sys.stderr.write("code is not equal!!!\n")
125 symbols[symbol] = code
127 print "%-18s %-4s %3d %3d %-6s" % (symbol,font,code,xcode,type)
129 print "%-18s %-4s %3d %3d %-9s x %s" % (symbol,font,code,xcode,type,package)
132 path = os.path.split(sys.argv[0])[0]
133 fh = open(os.path.join(path, "x-font"))
134 lines = fh.readlines()
137 x = string.split(line)
139 code = string.atoi(x[1],16)
140 xsymbols[symbol] = code
142 for file in sys.argv[1:]:
143 print "# Generated from " + os.path.basename(file) + "\n"
148 ("neq", "x", 0, 185, "mathrel"),
149 ("textdegree", "x", 0, 176, "mathord"),
150 ("cong", "x", 0, 64, "mathrel"),
151 ("surd", "x", 0, 214, "mathord")
154 if xsymbols.has_key("leq"):
158 print "%-18s %-4s %3d %3d %-6s" % x
159 if xsymbols.has_key(x[0]):
163 lyxbar cmsy 161 0 mathord
164 lyxeq cmr 61 0 mathord
165 lyxdabar msa 57 0 mathord
166 lyxright msa 75 0 mathord
167 lyxleft msa 76 0 mathord
170 for symbol in xsymbols.keys():
171 sys.stderr.write(symbol+"\n")