强制 Sympy 在 MathJax Jupyter 中打印数学 [英] Force Sympy to print math in MathJax Jupyter

查看:45
本文介绍了强制 Sympy 在 MathJax Jupyter 中打印数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VSCode 和 Jupyter 来处理 Sympy.通常,它以 MathJax 格式打印数学方程.sympy 文档说:

I am using VSCode and Jupyter to work on Sympy. Normally, it prints the math equations in MathJax format. sympy documentation says:

在 IPython notebook 中,它将使用 MathJax 来渲染 LATEX.

In the IPython notebook, it will use MathJax to render LATEX.

MathJax 输出:

MathJax output:

但是,当我安装 matplotlib 时,它会使用 matplotlib 自动打印为图像.

But, when I install matplotlib, it automatically prints as image using matplotlib.

Matplotlib 输出:

Matplotlib output:

我必须安装 matplotlib 来绘制我的结果.有没有办法强制 sympy 以 MathJax 格式打印数学?我用过

I have to install matplotlib to plot my results. Is there any way to force sympy to print math in MathJax format? I used

init_printing(use_latex=True)

没有用.有什么想法吗?

which didn't work. Any ideas?

推荐答案

试试这个代码:

from IPython.display import Math, display
import sympy as sy

x = sy.symbols('x')
expression = sy.sin(x)

display(Math('f(x) = ' + sy.latex(expression)))

或者,对于您的情况,使用 LaTeX 格式:

or, for the case you have, use LaTeX format:

display(Math('\\left[ \\frac{3\\mu_2^2+2\\sigma_2^2\\log(2)}{2\\mu_2} \\right]'))

结果如下:

这篇关于强制 Sympy 在 MathJax Jupyter 中打印数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆