在 Colaboratory 的输出单元格中渲染 LaTeX [英] Rendering LaTeX in output cells in Colaboratory

查看:25
本文介绍了在 Colaboratory 的输出单元格中渲染 LaTeX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个像这样的单元格

I expect a cell like

from IPython.display import display, Math
display(Math(r"e^alpha"))

使用 MathJax 进行渲染,就像在普通 jupyter 中一样,但它只是显示乳胶代码,如:

to render with MathJax as it does in normal jupyter, but instead it just displays latex code like:

$$e^alpha$$

有没有办法让 Colaboratory 正确渲染它?(它可以很好地处理文本单元格).

Is there a way to get Colaboratory to render it correctly? (It manages it fine for text cells).

推荐答案

稍微简化一下scraaappy的回答.

Simplify scraaappy's answer a bit.

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

它只包含 MathJax 库,因此可以显示以下等式.

It just includes MathJax library so the following equations can be displayed.

或使用内置 output._publish(2018 年 8 月)

Or use the built-in output._publish (Aug 2018)

from IPython.display import Math
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"

javascript(url=url)
Math(r"e^alpha")

除了 CDN,您还可以使用 Colab 附带的 MathJax.https://colab.research.google.com/static/mathjax/MathJax.js?config=default

Instead of CDN, you can also use MathJax that comes with Colab. https://colab.research.google.com/static/mathjax/MathJax.js?config=default

这篇关于在 Colaboratory 的输出单元格中渲染 LaTeX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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