2 # -*- coding: utf-8 -*-
4 # file generate_symbols_images.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # Full author contact details are available in file CREDITS
10 from __future__ import print_function
11 import sys,string,re,os,os.path
14 def get_code(code, font):
15 # computer modern fonts use a strange encoding
16 cmfonts = ["cmex", "cmr", "cmm", "cmsy"]
17 if font not in cmfonts:
32 ignore_list = ["not", "braceld", "bracerd", "bracelu", "braceru",
33 "lmoustache", "rmoustache", "lgroup", "rgroup", "bracevert"]
36 fh = io.open(file, 'r', encoding='ascii')
37 lines = fh.readlines()
39 package, ext = os.path.splitext(os.path.basename(file))
47 mo = re.match(r'\s*%.*', line)
52 next_line = lines[i+1]
54 # some entries are spread over two lines so we join the next line
55 # to the current one, (if current line contains a comment, we remove it)
56 line = line.split('%')[0]+next_line
58 mo = re.match(r'.*\\DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
60 font_names[mo.group(1)] = mo.group(3)
62 mo = re.match(r'^\s*\\mdsy\@DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
64 font_names[mo.group(1)] = mo.group(3)
66 # \mdsy@setslot resets the counter for \mdsy@DeclareSymbol
67 mo = re.match(r'^\s*\\mdsy\@setslot\s*\{(.*?)\}.*', line)
69 mdsymbolcode = int(mo.group(1))
71 # \mdsy@nextslot increments the counter for \mdsy@DeclareSymbol
72 mo = re.match(r'^\s*\\mdsy\@nextslot.*', line)
74 mdsymbolcode = mdsymbolcode + 1
76 mo = re.match(r'.*\\(\\mdsy\@)?DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line)
84 code = int(mo.group(7))
85 elif mo.group(6) == '"':
86 code = int(mo.group(7), 16)
88 code = int(mo.group(7), 8)
90 mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
95 code = int(mo.group(3), 16)
100 mo = re.match(r'^\s*\\mdsy\@DeclareSymbol\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
106 mdsymbolcode = mdsymbolcode + 1
109 mo = re.match(r'^\s*\\mdsy\@DeclareAlias\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
114 code = mdsymbolcode - 1
116 if mo != None and symbol not in ignore_list:
117 mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
118 if mo2 != None and symbol == mo2.group(1)+"op":
119 sys.stderr.write("%s -> %s\n" % (symbol, mo2.group(1)))
120 symbol = mo2.group(1)
122 if font in font_names:
123 font = font_names[font]
125 code = get_code(code, font)
130 if symbol in xsymbols:
131 xcode = xsymbols[symbol]
134 if symbol in symbols:
135 sys.stderr.write(symbol+ " exists\n")
136 if code != symbols[symbol]:
137 sys.stderr.write("code is not equal!!!\n")
139 symbols[symbol] = code
141 print("%-18s %-4s %3d %3d %-6s" % (symbol,font,code,xcode,type))
143 print("%-18s %-4s %3d %3d %-9s x %s" % (symbol,font,code,xcode,type,package))
146 path = os.path.split(sys.argv[0])[0]
147 fh = io.open(os.path.join(path, "x-font"), 'r', encoding='ascii')
148 lines = fh.readlines()
154 xsymbols[symbol] = code
156 for file in sys.argv[1:]:
157 print("# Generated from " + os.path.basename(file) + "\n")
162 ("neq", "x", 0, 185, "mathrel"),
163 ("textdegree", "x", 0, 176, "mathord"),
164 ("cong", "x", 0, 64, "mathrel"),
165 ("surd", "x", 0, 214, "mathord")
168 if "leq" in xsymbols:
172 print("%-18s %-4s %3d %3d %-6s" % x)
177 lyxbar cmsy 161 0 mathord
178 lyxeq cmr 61 0 mathord
179 lyxdabar msa 57 0 mathord
180 lyxright msa 75 0 mathord
181 lyxleft msa 76 0 mathord
184 for symbol in xsymbols.keys():
185 sys.stderr.write(symbol+"\n")