发布于 2021-01-07 14:50:34
这里的问题是如何像latex编辑器/编译器系统那样将unicode字符串转换为latex输出。最好的包是pylatexenc
回答你的问题:
from pylatexenc.latex2text import LatexNodes2Text
from pylatexenc.latexencode import UnicodeToLatexEncoder
# To convert some latex unicode input to actual latex output
in_expr_unicode = r"""5\div2\times(68+87)-10\div4"""
out_latex = LatexNodes2Text().latex_to_text(in_expr_unicode)
print(' The math formula: ', out_latex)
# To convert the latex string back to unicode printable string (for use in some latex editor)
u = UnicodeToLatexEncoder(unknown_char_policy='replace')
print('The latex editor input was: ', u.unicode_to_latex(out_latex))
输出将为:
The math formula: 5÷2×(68+87)-10÷4
The latex editor input was: 5{\textdiv}2{\texttimes}(68+87)-10{\textdiv}4
发布于 2021-01-07 14:20:08
对于去掉括号,您可以如下描述初始表达式:
py2tex('5/2*(68+87)-10/4')
我在这个包中看不到任何显示乘号或除号的帮助。
https://stackoverflow.com/questions/65607397
复制相似问题