Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

python - How do I display the multiplication and division symbol using pytexit?

enter image description here

For example, I want a multiplication sign between 5/2 and the brackets. Also a division sign between 10 and 4.

I also have another question, how do I remove the brackets around 68 and 87? thank you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The question here is how to convert a unicode string into a latex output as a latex editor/compiler system would do. The best package for that is pylatexenc

To answer your question:

from pylatexenc.latex2text import LatexNodes2Text
from pylatexenc.latexencode import UnicodeToLatexEncoder

# To convert some latex unicode input to actual latex output
in_expr_unicode = r"""5div2imes(68+87)-10div4"""
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 output would be:

          The math formula:  5÷2×(68+87)-10÷4
The latex editor input was:  5{extdiv}2{exttimes}(68+87)-10{extdiv}4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...