如何让iPython使用latex输出结果?
例如,就像在此页面上一样:http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/master/examples/notebooks/SymPy%20Examples.ipynb
如果我执行代码:
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
我得到输出:
Out[13]: 3*pi/2 + exp(I*x)/(x**2 + y)
我希望看到乳胶中的输出,如上面的链接所示。
答案 0 :(得分:6)
针对那些google的更新答案:
from IPython.display import Math
Math('3 \cdot \\frac{\pi}{2} + e^{\\frac{I*x}{x^2 + y}}')
比SymPy更笨拙,但不需要额外的包。
答案 1 :(得分:2)
正如您在@tcaswell发布和提及的链接中所做的那样,您需要使用
“激活”乳胶打印from sympy.interactive import printing
printing.init_printing(use_latex=True)
use_latex = True语句需要使用sympy 0.7.2但不能使用0.7.3。