field_eq2latex.py 970 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env/python
  2. # -*- coding:utf-8 -*-
  3. """
  4. 域公式转latex
  5. """
  6. import re
  7. SUB = {"A":"Ⓐ",
  8. "V":"Ⓥ",
  9. "W":"Ⓦ",
  10. "X":"Ⓧ",
  11. "G":"Ⓖ",
  12. }
  13. def get_latex(item):
  14. if "$eq \\\\f(" in item:
  15. item = re.sub(r"\$eq \\\\f\((.+?),(.+?)\)", r"$\\frac{\1}{\2}", item)
  16. if "$eq \\\\r(" in item:
  17. item = re.sub(r"\$eq \\\\r\((.+?)\)", r"$\sqrt{\1}", item)
  18. if "$eq \\\\o\\\\" in item:
  19. item = re.sub(r"\$eq \\\\o\\\\al\((.+?),.+?\)", r"$\1", item)
  20. ac_info = re.search("\$eq \\\\o\\\\ac\(○,([A-Z])\)", item)
  21. if ac_info:
  22. if ac_info.group(1) in SUB.keys():
  23. item = item.replace(ac_info.group(0), SUB.get(ac_info.group(1)))
  24. return item
  25. if __name__ == '__main__':
  26. f = "t=【域公式】$eq \\\\f(v<sub>0</sub>,a)$=【域公式】$eq \\\\f(6,1)$ s=6s, $eq \\\\r(6)$ "
  27. # print(re.sub(r"\\\\o\\\\al\((.+?),.+?\)", r"\1",f))
  28. print(get_latex(f))