Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX equations do not render in google Colaboratory when using IPython.display.Latex

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'))

produces an equation rendered in LaTeX (via Mathjax).

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?

like image 844
glS Avatar asked Feb 18 '18 21:02

glS


People also ask

Can you use LaTeX in Google Colab?

As an easier alternative, Latex can be rendered directly using the text cells feature of Google-colab notebooks. Show activity on this post.

How do I display LaTeX in Jupyter?

The Jupyter Notebook uses MathJax to render LaTeX inside HTML / Markdown. Just put your LaTeX math inside $ $ . Or enter in display math mode by writing between $$ $$ . The [n] is optional.

How do I use LaTeX in Jupyter notebook markdown?

One of the most popular is Jupyter Notebook that uses MathJax to render the Latex syntax inside the markdown/HTML. To use LaTeX in the Jupyter notebook, put the Latex math content inside the '$ … $' double '$$ … $$' symbols.


2 Answers

Update (April / 2021):

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^{2\pi i k} dx$

Old answer

As an alternative, the following description should work on text cell on Colab.

\begin{equation}

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

\end{equation}
like image 52
酒井 敦 Avatar answered Sep 20 '22 22:09

酒井 敦


An alternative is to use it as markdown with githubusercontent (source) instead a codeline on Colab, add a text (markdown text) and then to use the next line. e.g.

<img src="https://render.githubusercontent.com/render/math?math=e^{i \pi} = -1">

enter image description here

like image 36
mikesneider Avatar answered Sep 17 '22 22:09

mikesneider