问题描述
在常规的 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^{2pi 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?
推荐答案
更新(2021 年 4 月):
可以在 Colab 中编写公式,只需将它们放在 $
符号之间,无需导入库:
It's possible to write formulas in Colab just putting them between $
symbols, with no need to import libraries:
$F(k) = int_{-infty}^{infty} f(x) e^{2pi i k} dx$
旧答案
作为替代方案,以下描述应适用于 Colab 上的文本单元格.
As an alternative, the following description should work on text cell on Colab.
egin{equation}
F(k) = int_{-infty}^{infty} f(x) e^{2pi i k} dx
end{equation}
这篇关于使用 IPython.display.Latex 时,LaTeX 方程不会在谷歌 Colaboratory 中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!