2018-12-29 19:14:41 +00:00
|
|
|
#! /usr/bin/python3
|
2016-06-05 14:38:57 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# file generate_symbols_images.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2012-12-15 12:02:40 +00:00
|
|
|
import sys,string,re,os,os.path
|
2016-06-05 14:38:57 +00:00
|
|
|
import io
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
def get_code(code, font):
|
2016-06-05 14:53:55 +00:00
|
|
|
# computer modern fonts use a strange encoding
|
|
|
|
cmfonts = ["cmex", "cmr", "cmm", "cmsy"]
|
|
|
|
if font not in cmfonts:
|
2012-12-15 12:02:40 +00:00
|
|
|
return code
|
2001-08-30 22:42:26 +00:00
|
|
|
if code < 10:
|
2013-11-19 20:36:35 +00:00
|
|
|
return code+161
|
2016-06-05 14:53:55 +00:00
|
|
|
if code < 11:
|
|
|
|
return code+162
|
|
|
|
elif code <= 32:
|
2013-11-19 20:36:35 +00:00
|
|
|
return code+163
|
2001-08-30 22:42:26 +00:00
|
|
|
else:
|
2013-11-19 20:36:35 +00:00
|
|
|
return code
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
font_names = {}
|
|
|
|
symbols = {}
|
|
|
|
xsymbols = {}
|
|
|
|
|
|
|
|
ignore_list = ["not", "braceld", "bracerd", "bracelu", "braceru",
|
2013-11-19 20:36:35 +00:00
|
|
|
"lmoustache", "rmoustache", "lgroup", "rgroup", "bracevert"]
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
def process(file):
|
2016-06-05 14:38:57 +00:00
|
|
|
fh = io.open(file, 'r', encoding='ascii')
|
2001-08-30 22:42:26 +00:00
|
|
|
lines = fh.readlines()
|
|
|
|
fh.close()
|
2012-12-15 12:02:40 +00:00
|
|
|
package, ext = os.path.splitext(os.path.basename(file))
|
|
|
|
if ext != ".sty":
|
|
|
|
package = ''
|
2013-12-11 20:07:59 +00:00
|
|
|
mdsymbolcode = 0
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
n = len(lines)
|
2016-06-05 14:38:57 +00:00
|
|
|
for i in range(n):
|
2013-11-19 20:36:35 +00:00
|
|
|
line = lines[i]
|
2022-11-21 01:13:39 +00:00
|
|
|
mo = re.match(r'\s*%.*', line)
|
2012-12-15 12:02:40 +00:00
|
|
|
if mo != None:
|
|
|
|
continue
|
2013-11-19 20:36:35 +00:00
|
|
|
next_line = ""
|
|
|
|
if i+1 < n:
|
|
|
|
next_line = lines[i+1]
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2013-11-19 20:36:35 +00:00
|
|
|
# some entries are spread over two lines so we join the next line
|
|
|
|
# to the current one, (if current line contains a comment, we remove it)
|
2016-06-05 14:38:57 +00:00
|
|
|
line = line.split('%')[0]+next_line
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2013-11-19 20:36:35 +00:00
|
|
|
mo = re.match(r'.*\\DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
|
|
|
|
if mo != None:
|
|
|
|
font_names[mo.group(1)] = mo.group(3)
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2013-12-11 20:07:59 +00:00
|
|
|
mo = re.match(r'^\s*\\mdsy\@DeclareSymbolFont\s*\{(.*?)\}\s*\{(.*?)\}\s*\{(.*?)\}.*', line)
|
|
|
|
if mo != None:
|
|
|
|
font_names[mo.group(1)] = mo.group(3)
|
|
|
|
|
|
|
|
# \mdsy@setslot resets the counter for \mdsy@DeclareSymbol
|
|
|
|
mo = re.match(r'^\s*\\mdsy\@setslot\s*\{(.*?)\}.*', line)
|
|
|
|
if mo != None:
|
|
|
|
mdsymbolcode = int(mo.group(1))
|
|
|
|
|
|
|
|
# \mdsy@nextslot increments the counter for \mdsy@DeclareSymbol
|
|
|
|
mo = re.match(r'^\s*\\mdsy\@nextslot.*', line)
|
|
|
|
if mo != None:
|
|
|
|
mdsymbolcode = mdsymbolcode + 1
|
|
|
|
|
|
|
|
mo = re.match(r'.*\\(\\mdsy\@)?DeclareMath(Symbol|Delimiter)\s*\{?\\(\w*?)\}?\s*\{?\\(.*?)\}?\s*\{(.*?)\}\s*\{([\'"]?)(.*?)\}.*', line)
|
2012-12-15 12:02:40 +00:00
|
|
|
code = -1
|
|
|
|
try:
|
|
|
|
if mo != None:
|
2013-12-11 20:07:59 +00:00
|
|
|
symbol = mo.group(3)
|
|
|
|
type = mo.group(4)
|
|
|
|
font = mo.group(5)
|
|
|
|
if mo.group(6) == '':
|
|
|
|
code = int(mo.group(7))
|
|
|
|
elif mo.group(6) == '"':
|
|
|
|
code = int(mo.group(7), 16)
|
2012-12-15 12:02:40 +00:00
|
|
|
else:
|
2013-12-11 20:07:59 +00:00
|
|
|
code = int(mo.group(7), 8)
|
2012-12-15 12:02:40 +00:00
|
|
|
else:
|
|
|
|
mo = re.match(r'.*\\edef\\(\w*?)\{.*?\{\\hexnumber@\\sym(.*?)\}(.*?)\}', line)
|
|
|
|
if mo != None:
|
|
|
|
symbol = mo.group(1)
|
|
|
|
type = "mathord"
|
|
|
|
font = mo.group(2)
|
|
|
|
code = int(mo.group(3), 16)
|
|
|
|
except ValueError:
|
|
|
|
code = -1
|
2004-10-28 14:35:53 +00:00
|
|
|
|
2013-12-11 20:07:59 +00:00
|
|
|
if mo == None:
|
|
|
|
mo = re.match(r'^\s*\\mdsy\@DeclareSymbol\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
|
|
|
|
if mo != None:
|
|
|
|
symbol = mo.group(1)
|
|
|
|
type = mo.group(3)
|
|
|
|
font = mo.group(2)
|
|
|
|
code = mdsymbolcode
|
|
|
|
mdsymbolcode = mdsymbolcode + 1
|
|
|
|
|
|
|
|
if mo == None:
|
|
|
|
mo = re.match(r'^\s*\\mdsy\@DeclareAlias\s*\{(.*?)\}\s*\{(.*?)\}\s*\{\\(.*?)\}.*', line)
|
|
|
|
if mo != None:
|
|
|
|
symbol = mo.group(1)
|
|
|
|
type = mo.group(3)
|
|
|
|
font = mo.group(2)
|
|
|
|
code = mdsymbolcode - 1
|
|
|
|
|
2013-11-19 20:36:35 +00:00
|
|
|
if mo != None and symbol not in ignore_list:
|
|
|
|
mo2 = re.match(r'\s*\\def\\(.*?)\{', next_line)
|
|
|
|
if mo2 != None and symbol == mo2.group(1)+"op":
|
|
|
|
sys.stderr.write("%s -> %s\n" % (symbol, mo2.group(1)))
|
|
|
|
symbol = mo2.group(1)
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2016-06-05 14:38:57 +00:00
|
|
|
if font in font_names:
|
2013-11-19 20:36:35 +00:00
|
|
|
font = font_names[font]
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2013-11-19 20:36:35 +00:00
|
|
|
code = get_code(code, font)
|
|
|
|
if code < 0:
|
|
|
|
continue
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2013-11-19 20:36:35 +00:00
|
|
|
xcode = 0
|
2016-06-05 14:38:57 +00:00
|
|
|
if symbol in xsymbols:
|
2013-11-19 20:36:35 +00:00
|
|
|
xcode = xsymbols[symbol]
|
|
|
|
del xsymbols[symbol]
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2016-06-05 14:38:57 +00:00
|
|
|
if symbol in symbols:
|
2013-11-19 20:36:35 +00:00
|
|
|
sys.stderr.write(symbol+ " exists\n")
|
|
|
|
if code != symbols[symbol]:
|
|
|
|
sys.stderr.write("code is not equal!!!\n")
|
|
|
|
else:
|
|
|
|
symbols[symbol] = code
|
|
|
|
if package == '':
|
2016-06-05 14:38:57 +00:00
|
|
|
print("%-18s %-4s %3d %3d %-6s" % (symbol,font,code,xcode,type))
|
2013-11-19 20:36:35 +00:00
|
|
|
else:
|
2016-06-05 14:38:57 +00:00
|
|
|
print("%-18s %-4s %3d %3d %-9s x %s" % (symbol,font,code,xcode,type,package))
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
path = os.path.split(sys.argv[0])[0]
|
2016-06-05 14:38:57 +00:00
|
|
|
fh = io.open(os.path.join(path, "x-font"), 'r', encoding='ascii')
|
2001-08-30 22:42:26 +00:00
|
|
|
lines = fh.readlines()
|
|
|
|
fh.close()
|
|
|
|
for line in lines:
|
2016-06-05 14:38:57 +00:00
|
|
|
x = line.split()
|
2001-08-30 22:42:26 +00:00
|
|
|
symbol = x[0]
|
2016-06-05 14:38:57 +00:00
|
|
|
code = int(x[1], 16)
|
2001-08-30 22:42:26 +00:00
|
|
|
xsymbols[symbol] = code
|
|
|
|
|
|
|
|
for file in sys.argv[1:]:
|
2016-06-05 14:38:57 +00:00
|
|
|
print("# Generated from " + os.path.basename(file) + "\n")
|
2001-08-30 22:42:26 +00:00
|
|
|
process(file)
|
2016-06-05 14:38:57 +00:00
|
|
|
print()
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
exceptions = [
|
2001-09-04 13:15:31 +00:00
|
|
|
("neq", "x", 0, 185, "mathrel"),
|
|
|
|
("textdegree", "x", 0, 176, "mathord"),
|
|
|
|
("cong", "x", 0, 64, "mathrel"),
|
|
|
|
("surd", "x", 0, 214, "mathord")
|
2001-08-30 22:42:26 +00:00
|
|
|
]
|
|
|
|
|
2016-06-05 14:38:57 +00:00
|
|
|
if "leq" in xsymbols:
|
2001-08-30 22:42:26 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
for x in exceptions:
|
2016-06-05 14:38:57 +00:00
|
|
|
print("%-18s %-4s %3d %3d %-6s" % x)
|
|
|
|
if x[0] in xsymbols:
|
2013-11-19 20:36:35 +00:00
|
|
|
del xsymbols[x[0]]
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2016-06-05 14:38:57 +00:00
|
|
|
print ("""
|
2001-09-21 18:23:02 +00:00
|
|
|
lyxbar cmsy 161 0 mathord
|
2004-10-28 14:35:53 +00:00
|
|
|
lyxeq cmr 61 0 mathord
|
2001-09-21 18:23:02 +00:00
|
|
|
lyxdabar msa 57 0 mathord
|
|
|
|
lyxright msa 75 0 mathord
|
|
|
|
lyxleft msa 76 0 mathord
|
2016-06-05 14:38:57 +00:00
|
|
|
""")
|
2001-09-21 18:23:02 +00:00
|
|
|
|
2001-08-30 22:42:26 +00:00
|
|
|
for symbol in xsymbols.keys():
|
|
|
|
sys.stderr.write(symbol+"\n")
|