123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #!/usr/bin/env python
- # __author__ = "Ronie Martinez"
- # __copyright__ = "Copyright 2016-2019, Ronie Martinez"
- # __credits__ = ["Ronie Martinez"]
- # __license__ = "MIT"
- # __maintainer__ = "Ronie Martinez"
- # __email__ = "ronmarti18@gmail.com"
- import codecs
- import os
- import re
- symbols_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'unimathsymbols.txt')
- symbols = None
- def convert_symbol(symbol):
- #单字母标号
- global symbols
- if not symbols:
- symbols = parse_symbols()
- # tjt修改
- symbol_parse = symbols.get(symbol, symbol)
- if symbol_parse == symbol and symbol[0] == "\\":
- symbol_parse = ""
- return symbol_parse
- # return symbols.get(symbol, symbol)
- def parse_symbols():
- _symbols = {}
- with codecs.open(symbols_file, encoding='utf-8') as f:
- for line in f:
- if not line.startswith('#'):
- columns = line.strip().split('^')
- _unicode = columns[1]
- latex = columns[2]
- unicode_math = columns[3]
- if latex and latex not in _symbols:
- _symbols[latex] = _unicode
- if unicode_math and unicode_math not in _symbols:
- _symbols[unicode_math] = _unicode
- for equivalent in re.findall(r'=\s+(\\[^,^ ]+),?', columns[-1]):
- if equivalent not in _symbols:
- _symbols[equivalent] = _unicode
- return _symbols
|