Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display latex table/tabular in Jupyter with latex cell magic

According to this Rich Display System example the Jupyter notebook can display latex using the %%latex cell magic.

The example given using the align environment works fine on my system (Notebook Server 3.2.0-8b0eef4) but when I try and show a tabular or a table, the result is just nicely typesetting Latex code!

Latex not working

Is there some kind of preamble I need to add to make this work?

like image 422
LondonRob Avatar asked Feb 27 '17 17:02

LondonRob


People also ask

How do I show LaTeX in Jupyter Notebook?

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 $$ $$ .

What is %% Writefile in Jupyter Notebook?

%%writefile lets you output code developed in a Notebook to a Python module. The sys library connects a Python program to the system it is running on. The list sys. argv contains the command-line arguments that a program was run with.

Can you do LaTeX in Jupyter Notebook?

Jupyter Book uses MathJax for typesetting math in your HTML book build. This allows you to have LaTeX-style mathematics in your online content.


1 Answers

Answer

Jupyter builds on MathJax and cite "MathJax doesn't implement tabular". The link also shows the recommended array environment as tabular replacement.


Workaround:

Latex can also be used in Markdown cells (Celltype Markdown instead of Code). You can select the left area besides the cell and press "m" key or via Cell>Cell-Type in top menu. Then you could use html for the table.

<table>
    <tr>
        <td>
\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\end{eqnarray}
        </td>
        <td>
\begin{eqnarray}
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{eqnarray}
        </td>
    </tr>
</table>

Markdown table two cells Latex Html mixed

Markdown cells are rendered so you don't see the code that generates the rendered latex. Instead you just see the rendered version until you double click it. Plus you have the option of Markdown tables

like image 66
CodingYourLife Avatar answered Oct 25 '22 12:10

CodingYourLife