如何在IPython Notebook中显示LaTeX代码?
当前回答
我在这篇文章中写了如何在Jupyter Notebook中编写LaTeX。
你需要用美元($)符号把它们括起来。
要向左对齐,请使用单个美元($)符号。
$ P (A) = \压裂{n (A)} {n (U)} $
要对齐到中心,请使用双元($$)符号。
$ $ P (A) = \压裂{n (A)} {n (U)} $ $
使用\limit for \lim, \sum和\int在每个符号的顶部和底部添加限制。 使用反斜杠来转义LaTeX的特殊单词,如数学符号、拉丁单词、文本等。
试试这个。
$$\overline{x}=\frac{\sum \limits _{i=1} ^k f_i x_i}{n} \text{, where } n=\sum \limits _{i=1} ^k f_i $$
矩阵
分段函数
$$
\begin{align}
\text{Probability density function:}\\
\begin{cases}
\frac{1}{b-a}&\text{for $x\in[a,b]$}\\
0&\text{otherwise}\\
\end{cases}
\\
\text{Cumulative distribution function:}\\
\begin{cases}
0&\text{for $x<a$}\\
\frac{x-a}{b-a}&\text{for $x\in[a,b)$}\\
1&\text{for $x\ge b$}\\
\end{cases}
\end{align}
$$
上面的代码将创建这个。
如果你想知道如何为方程添加编号和对齐方程,请阅读这篇文章来了解详细信息。
其他回答
如果您的主要目标是做数学运算,那么SymPy提供了一种很好的方法来实现看起来很棒的函数乳胶表达式。
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。但也许将来会有所改进。
有一天我在使用colab时遇到了这个问题。我发现最省事的方法就是在打印之前运行这段代码。那么,一切都很有魅力。
from IPython.display import Math, HTML
def load_mathjax_in_cell_output():
display(HTML("<script src='https://www.gstatic.com/external_hosted/"
"mathjax/latest/MathJax.js?config=default'></script>"))
get_ipython().events.register('pre_run_cell', load_mathjax_in_cell_output)
import sympy as sp
sp.init_printing()
结果如下所示:
我开发了pretty typy,它提供了一种打印方程的好方法。不幸的是,它不是高性能的,需要测试。
例子:
当然,sympy是一个很好的替代方案,尽管prettyPy不允许计算表达式,变量初始化是不需要的。
我在这篇文章中写了如何在Jupyter Notebook中编写LaTeX。
你需要用美元($)符号把它们括起来。
要向左对齐,请使用单个美元($)符号。
$ P (A) = \压裂{n (A)} {n (U)} $
要对齐到中心,请使用双元($$)符号。
$ $ P (A) = \压裂{n (A)} {n (U)} $ $
使用\limit for \lim, \sum和\int在每个符号的顶部和底部添加限制。 使用反斜杠来转义LaTeX的特殊单词,如数学符号、拉丁单词、文本等。
试试这个。
$$\overline{x}=\frac{\sum \limits _{i=1} ^k f_i x_i}{n} \text{, where } n=\sum \limits _{i=1} ^k f_i $$
矩阵
分段函数
$$
\begin{align}
\text{Probability density function:}\\
\begin{cases}
\frac{1}{b-a}&\text{for $x\in[a,b]$}\\
0&\text{otherwise}\\
\end{cases}
\\
\text{Cumulative distribution function:}\\
\begin{cases}
0&\text{for $x<a$}\\
\frac{x-a}{b-a}&\text{for $x\in[a,b)$}\\
1&\text{for $x\ge b$}\\
\end{cases}
\end{align}
$$
上面的代码将创建这个。
如果你想知道如何为方程添加编号和对齐方程,请阅读这篇文章来了解详细信息。
推荐文章
- 我如何确定文件编码在OS X?
- 检查pandas数据框架索引中是否存在值
- 在LaTeX中突出显示源代码
- 如何将LaTeX与Markdown混合?
- Ipython笔记本清除单元格输出代码
- 在LaTeX中出现“Missing $ inserted”错误
- tqdm在Jupyter笔记本重复打印新的进度条
- 乳胶渲染在README。md在Github上
- 在LaTeX中引用一个表
- 折叠单元在jupyter笔记本
- 如何知道哪个Python在Jupyter笔记本上运行?
- 使用Python 3在Jupyter Notebook中使用相对导入从位于另一个目录中的模块导入本地函数
- 如何嵌入HTML到IPython输出?
- 如何在Latex中编写url ?
- 使用pandoc从Markdown转换为PDF时设置空白大小