1234567891011121314151617181920212223242526272829303132333435363738 |
- #!/usr/bin/env/python
- # -*- coding:utf-8 -*-
- """
- 域公式转latex
- """
- import re
- SUB = {"A":"Ⓐ",
- "V":"Ⓥ",
- "W":"Ⓦ",
- "X":"Ⓧ",
- "G":"Ⓖ",
- }
- def get_latex(item):
- if "$eq \\\\f(" in item:
- item = re.sub(r"\$eq \\\\f\((.+?),(.+?)\)", r"$\\frac{\1}{\2}", item)
- if "$eq \\\\r(" in item:
- item = re.sub(r"\$eq \\\\r\((.+?)\)", r"$\sqrt{\1}", item)
- if "$eq \\\\o\\\\" in item:
- item = re.sub(r"\$eq \\\\o\\\\al\((.+?),.+?\)", r"$\1", item)
- ac_info = re.search("\$eq \\\\o\\\\ac\(○,([A-Z])\)", item)
- if ac_info:
- if ac_info.group(1) in SUB.keys():
- item = item.replace(ac_info.group(0), SUB.get(ac_info.group(1)))
- return item
- if __name__ == '__main__':
- f = "t=【域公式】$eq \\\\f(v<sub>0</sub>,a)$=【域公式】$eq \\\\f(6,1)$ s=6s, $eq \\\\r(6)$ "
- # print(re.sub(r"\\\\o\\\\al\((.+?),.+?\)", r"\1",f))
- print(get_latex(f))
|