tufte layout files:
[lyx.git] / development / tools / generate_symbols_list.py
bloba18dd690c93be628e191c9ca3bbb153749f72c51
1 #!/usr/bin/python
2 import sys,string,re,os
4 def get_code(code, font):
5 if code < 10:
6 return code+161
7 elif code < 32:
8 return code+163
9 else:
10 return code
12 font_names = {}
13 symbols = {}
14 xsymbols = {}
16 ignore_list = ["not", "braceld", "bracerd", "bracelu", "braceru",
17 "lmoustache", "rmoustache", "lgroup", "rgroup", "bracevert"]
19 def process(file):
20 fh = open(file)
21 lines = fh.readlines()
22 fh.close()
24 n = len(lines)
25 for i in xrange(n):
26 line = lines[i]
27 next_line = ""
28 if i+1 < n:
29 next_line = lines[i+1]
31 # some entries are spread over two lines so we join the next line
32 # to the current one, (if current line contains a comment, we remove it)
33 line = string.split(line,'%')[0]+next_line
35 mo = re.match(r'.*\\DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
36 if mo != None:
37 font_names[mo.group(1)] = mo.group(3)
39 mo = re.match(r'.*\\DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{"(.*?)\}.*', line)
40 if mo != None:
41 symbol = mo.group(2)
42 type = mo.group(3)
43 font = mo.group(4)
44 code = mo.group(5)
45 else:
46 mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
47 if mo != None:
48 symbol = mo.group(1)
49 type = "mathord"
50 font = mo.group(2)
51 code = mo.group(3)
53 if mo != None and symbol not in ignore_list:
54 mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
55 if mo2 != None and symbol == mo2.group(1)+"op":
56 sys.stderr.write("%s -> %s\n" % (symbol, mo2.group(1)))
57 symbol = mo2.group(1)
59 if font_names.has_key(font):
60 font = font_names[font]
62 code = get_code(string.atoi(code, 16), font)
63 if code == 0:
64 continue
66 xcode = 0
67 if xsymbols.has_key(symbol):
68 xcode = xsymbols[symbol]
69 del xsymbols[symbol]
71 if symbols.has_key(symbol):
72 sys.stderr.write(symbol+ " exists\n")
73 if code != symbols[symbol]:
74 sys.stderr.write("code is not equal!!!\n")
75 else:
76 symbols[symbol] = code
77 print "%-18s %-4s %3d %3d %-6s" % (symbol,font,code,xcode,type)
80 path = os.path.split(sys.argv[0])[0]
81 fh = open(os.path.join(path, "x-font"))
82 lines = fh.readlines()
83 fh.close()
84 for line in lines:
85 x = string.split(line)
86 symbol = x[0]
87 code = string.atoi(x[1],16)
88 xsymbols[symbol] = code
90 for file in sys.argv[1:]:
91 print "# Generated from " + os.path.basename(file) + "\n"
92 process(file)
93 print
95 exceptions = [
96 ("neq", "x", 0, 185, "mathrel"),
97 ("textdegree", "x", 0, 176, "mathord"),
98 ("cong", "x", 0, 64, "mathrel"),
99 ("surd", "x", 0, 214, "mathord")
102 if xsymbols.has_key("leq"):
103 sys.exit(0)
105 for x in exceptions:
106 print "%-18s %-4s %3d %3d %-6s" % x
107 if xsymbols.has_key(x[0]):
108 del xsymbols[x[0]]
110 print """
111 lyxbar cmsy 161 0 mathord
112 lyxeq cmr 61 0 mathord
113 lyxdabar msa 57 0 mathord
114 lyxright msa 75 0 mathord
115 lyxleft msa 76 0 mathord
118 for symbol in xsymbols.keys():
119 sys.stderr.write(symbol+"\n")