如何在IPython Notebook中显示LaTeX代码?
当前回答
Since, I was not able to use all the latex commands in Code even after using the %%latex keyword or the $..$ limiter, I installed the nbextensions through which I could use the latex commands in Markdown. After following the instructions here: https://github.com/ipython-contrib/IPython-notebook-extensions/blob/master/README.md and then restarting the Jupyter and then localhost:8888/nbextensions and then activating "Latex Environment for Jupyter", I could run many Latex commands. Examples are here: https://rawgit.com/jfbercher/latex_envs/master/doc/latex_env_doc.html
\section{First section}
\textbf{Hello}
$
\begin{equation}
c = \sqrt{a^2 + b^2}
\end{equation}
$
\begin{itemize}
\item First item
\item Second item
\end{itemize}
\textbf{World}
如你所见,我仍然无法使用uspackage。但也许将来会有所改进。
其他回答
我开发了pretty typy,它提供了一种打印方程的好方法。不幸的是,它不是高性能的,需要测试。
例子:
当然,sympy是一个很好的替代方案,尽管prettyPy不允许计算表达式,变量初始化是不需要的。
IPython笔记本使用MathJax在html/markdown中渲染LaTeX。只要把你的LaTeX数学放在$$中。
$$c = \sqrt{a^2 + b^2}$$
或者你可以从Python中显示LaTeX / Math输出,就像在笔记本之旅结束时看到的那样:
from IPython.display import display, Math, Latex
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))
这是在我刚刚做的搜索中出现的,通过更多的搜索发现了一个更好的解决方案,IPython笔记本现在有一个%%乳胶魔法,使整个细胞乳胶没有$$包装每行。
关于富显示系统,请参考笔记本手册
您可以选择一个要降价的单元格,然后编写由mathjax解释的latex代码,就像上面提到的应答器之一一样。
另外,iPython笔记本教程的Latex部分很好地解释了这一点。
你可以这样做:
from IPython.display import Latex
Latex(r"""\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 \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{eqnarray}""")
或者这样做:
%%latex
\begin{align}
\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 \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{align}
更多信息在此链接
minrk给出的答案(包括完整性)很好,但还有另一种方式我更喜欢。
通过在文本单元格中键入%% LaTeX作为第一行,还可以将整个单元格呈现为LaTeX。这很有用,如果你
想要更多的控制, 想要的不仅仅是数学环境, 或者如果你要在一个格子里写很多数学。
minrk的回答是:
IPython笔记本使用MathJax进行渲染 html/markdown中的LaTeX。只要把你的LaTeX数学放在$$中。 $$c = \√{a^2 + b^2}$$ 或者你也可以从Python中显示LaTeX / Math输出,如图所示 笔记本的结尾 旅游: IPython。display导入display, Math, Latex 显示器(数学(r 'F (k) = \ int_ {- \ infty} ^ {\ infty} f (x) e ^{2 \πk} dx '))
推荐文章
- 折叠单元在jupyter笔记本
- 如何知道哪个Python在Jupyter笔记本上运行?
- 使用Python 3在Jupyter Notebook中使用相对导入从位于另一个目录中的模块导入本地函数
- 如何嵌入HTML到IPython输出?
- 如何在Latex中编写url ?
- 使用pandoc从Markdown转换为PDF时设置空白大小
- Python和IPython的区别是什么?
- 如何从终端运行。ipynb Jupyter Notebook ?
- 移除jupyter笔记本上的内核
- 如何使用列的格式字符串显示浮动的熊猫数据帧?
- 使用Python 2。3. Python。IPython Notebook中的x
- 如何加载/编辑/运行/保存文本文件(.py)到IPython笔记本细胞?
- 在R中制作乳胶表的工具
- 在安装pip后,“jupyter:命令未找到”
- 在IPython中自动重载模块