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 if font != "dontknowwhichfontusesthisstrangeencoding":
28 ignore_list = ["not", "braceld", "bracerd", "bracelu", "braceru",
29 "lmoustache", "rmoustache", "lgroup", "rgroup", "bracevert"]
32 fh = io.open(file, 'r', encoding='ascii')
33 lines = fh.readlines()
35 package, ext = os.path.splitext(os.path.basename(file))
43 mo = re.match(r'\s*%.*', line)
48 next_line = lines[i+1]
50 # some entries are spread over two lines so we join the next line
51 # to the current one, (if current line contains a comment, we remove it)
52 line = line.split('%')[0]+next_line
54 mo = re.match(r'.*\\DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
56 font_names[mo.group(1)] = mo.group(3)
58 mo = re.match(r'^\s*\\mdsy\@DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
60 font_names[mo.group(1)] = mo.group(3)
62 # \mdsy@setslot resets the counter for \mdsy@DeclareSymbol
63 mo = re.match(r'^\s*\\mdsy\@setslot\s*\{(.*?)\}.*', line)
65 mdsymbolcode = int(mo.group(1))
67 # \mdsy@nextslot increments the counter for \mdsy@DeclareSymbol
68 mo = re.match(r'^\s*\\mdsy\@nextslot.*', line)
70 mdsymbolcode = mdsymbolcode + 1
72 mo = re.match(r'.*\\(\\mdsy\@)?DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line)
80 code = int(mo.group(7))
81 elif mo.group(6) == '"':
82 code = int(mo.group(7), 16)
84 code = int(mo.group(7), 8)
86 mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
91 code = int(mo.group(3), 16)
96 mo = re.match(r'^\s*\\mdsy\@DeclareSymbol\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
102 mdsymbolcode = mdsymbolcode + 1
105 mo = re.match(r'^\s*\\mdsy\@DeclareAlias\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
110 code = mdsymbolcode - 1
112 if mo != None and symbol not in ignore_list:
113 mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
114 if mo2 != None and symbol == mo2.group(1)+"op":
115 sys.stderr.write("%s -> %s\n" % (symbol, mo2.group(1)))
116 symbol = mo2.group(1)
118 if font in font_names:
119 font = font_names[font]
121 code = get_code(code, font)
126 if symbol in xsymbols:
127 xcode = xsymbols[symbol]
130 if symbol in symbols:
131 sys.stderr.write(symbol+ " exists\n")
132 if code != symbols[symbol]:
133 sys.stderr.write("code is not equal!!!\n")
135 symbols[symbol] = code
137 print("%-18s %-4s %3d %3d %-6s" % (symbol,font,code,xcode,type))
139 print("%-18s %-4s %3d %3d %-9s x %s" % (symbol,font,code,xcode,type,package))
142 path = os.path.split(sys.argv[0])[0]
143 fh = io.open(os.path.join(path, "x-font"), 'r', encoding='ascii')
144 lines = fh.readlines()
150 xsymbols[symbol] = code
152 for file in sys.argv[1:]:
153 print("# Generated from " + os.path.basename(file) + "\n")
158 ("neq", "x", 0, 185, "mathrel"),
159 ("textdegree", "x", 0, 176, "mathord"),
160 ("cong", "x", 0, 64, "mathrel"),
161 ("surd", "x", 0, 214, "mathord")
164 if "leq" in xsymbols:
168 print("%-18s %-4s %3d %3d %-6s" % x)
173 lyxbar cmsy 161 0 mathord
174 lyxeq cmr 61 0 mathord
175 lyxdabar msa 57 0 mathord
176 lyxright msa 75 0 mathord
177 lyxleft msa 76 0 mathord
180 for symbol in xsymbols.keys():
181 sys.stderr.write(symbol+"\n")