简体   繁体   中英

latex jupyter notebook it does not work

I started using python with the jupyter notebook and the problem is that the printing is not like the standard LaTeX My cell:

%%latex
\begin{center}
$(a+b)^{2} = a^{2}+2ab+b^{2}$
\end{center}

The result in the notebook looks like in the following picture: 在此处输入图片说明

from jupyter docs :

The subset of latex which is supported depends on the implementation in the client. In the Jupyter Notebook, this magic only renders the subset of latex defined by MathJax here .

You could use markdown to display your formula: use single $ to indicate latex, or double $$ to center it. You need to format your cell as markdown instead of code

Your cell becomes one of these two lines:

$$(a+b)^{2} = a^{2}+2ab+b^{2}$$
$(a+b)^{2} = a^{2}+2ab+b^{2}$

You must run the cell to display markdown.

I had a similar problem. A certain set of latex equations in my ipython notebook just stopped rendering properly. It turned out that my latex interpreter had gotten into a weird state because I executed a cell with the code \\def in it, by accident.

To fix the problem, I just saved my notebook, stopped the python kernel, closed the notebook in the browser, then re-opened it again and re-executed all the cells. This fixed the problem, and the equations rendered correctly again.

If you are going to use an environment like this:

\begin{equation}
(a+b)^{2} = a^{2}+2ab+b^{2}
\end{equation}

Notice I do not use the $$ env which is better used as inline math. Another thing to notice is that there are no spaces between the lines, if you add spaces between the lines, the notebook will display the latex code instead of rendering it when you run the cell.

In my case (winpython), it looks like my firewall prevent Mathjax to be succesfully installed. I had to install Mathjax from a local file to get I to work :

  • download the latest Mathjax.zip
  • python -m IPython.external.mathjax C:\\path\\to\\your\\file\\Mathjax.zip

I am now able to render latex in code cells and in markdown cells either

I discovered from https://stackoverflow.com/a/32166264/4347428 that the MathJax will not render unless you go into your jupyter config and ensure mathjax is enabled:

## Whether to enable MathJax for typesetting math/TeX
#
#  MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
#  very large, so you may want to disable it if you have a slow internet
#  connection, or for offline use of the notebook.
#
#  When disabled, equations etc. will appear as their untransformed TeX source.
c.NotebookApp.enable_mathjax = True

Unfortunately, this didn't get me all the way there, and neither did making sure the notebook was Trusted in the upper right, but perhaps it'll help someone else.

使用 jupyterlab 安装这个包: jupyterlab-mathjax3为我解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM