我已经制作了一个函数来计算LaTeX表达式: 以下是代码
from sympy import latex, sympify
from sympy.parsing.latex import parse_latex
from sympy import latex, parse_expr
# ------->> Example LaTeX string
latex_string = r'\frac{30}{2}'
# ------->> Convert LaTeX string to a sympy expression
expr = parse_latex(latex_string)
# ------->> Evaluate the expression
result = expr.evalf()
# ------->> Print the result
print(result)
但是当我向该函数发送\sin(30)
时,它返回-0.988031624092862
而不是0.5
.我已经在Stackoverflow和聊天GPT中搜索了很多,并得到了这个来生成罪恶的价值
import sympy as sp
# Calculate the sine of 30 degrees
result = sp.sin(sp.rad(30))
# Print the result
print(result)
但我想以\sin(30)
(LaTeX)格式发送输入.有人能告诉我怎样才能做到这一点吗?