在协作的输出单元格中渲染LaTeX [英] Rendering LaTeX in output cells in Colaboratory
问题描述
我希望像这样的单元格
from IPython.display import display, Math
display(Math(r"e^\alpha"))
像使用普通jupyter一样使用MathJax进行渲染, 但相反,它只显示乳胶代码,如:
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
这篇关于在协作的输出单元格中渲染LaTeX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!