使用IPython.display.Latex时,LaTeX方程不会在Google合作实验室中呈现 [英] LaTeX equations do not render in google Colaboratory when using IPython.display.Latex

查看:348
本文介绍了使用IPython.display.Latex时,LaTeX方程不会在Google合作实验室中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在常规的jupyter笔记本中,例如,运行以下命令:

In a regular jupyter notebook, running, for example, the following:

from IPython.display import display, Math, Latex
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))

生成通过LaTeX渲染的方程式(通过Mathjax).

produces an equation rendered in LaTeX (via Mathjax).

即使LaTeX在markdown单元中工作正常,但如上所述生成的LaTeX方程似乎无法在Google Colaboratory中呈现. 例如,来自qutip的函数输出也会发生同样的情况,通常会在乳胶中渲染(例如,qutip.basis(2, 0)通常会在乳胶中渲染,但不在Colaboratory中呈现).

Even though LaTeX works fine in markdown cells, LaTeX equations produced as above do not seem to render in Google Colaboratory. The same happens to the output of functions for example from qutip, which would normally render in latex (for example, qutip.basis(2, 0) would normally render in latex, but doesn't in Colaboratory).

为什么会这样?有办法进行这项工作吗?

Why does this happen? Is there a way to have this work?

推荐答案

您可以通过包含MathJax库来获取要渲染的Latex.

You can get the Latex to render by including the MathJax library.

from IPython.display import Math, HTML
display(HTML("<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/"
               "latest.js?config=default'></script>"))

Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')

在这里提出了类似的问题: 在协作实验室的输出单元中渲染LaTeX

A similar questions was asked here: Rendering LaTeX in output cells in Colaboratory

这篇关于使用IPython.display.Latex时,LaTeX方程不会在Google合作实验室中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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