如何在Python 3中以漂亮的方式显示数学方程式

问题描述 投票:-3回答:3

我试图在Jupyter笔记本中以漂亮的方式显示矢量方程。我想要实现这样的事情:

使用IPython.display模块,我能够以一种漂亮的方式打印矩阵。问题是显示“(2 *矩阵) - (1 *另一个子矩阵)......”内联。

这可能吗?

python python-3.x
3个回答
2
投票
from IPython.display import display, Math, Latex
display(Math(r'2 \cdot  \begin{bmatrix} 1 \\ -2 \\ \end{bmatrix} -1 \cdot \begin{bmatrix} 2 \\ -3 \\ \end{bmatrix} +1 \cdot \begin{bmatrix} -3 \\ 1 \\ \end{bmatrix} -1 \cdot \begin{bmatrix} 1 \\ -1 \\ \end{bmatrix}= \begin{bmatrix} -4 \\ 1 \\ \end{bmatrix}'))

enter image description here

更粗。你可以使用\ bullet而不是\ cdot



0
投票

可以在Jupyter笔记本代码单元格中使用%%latex魔术函数。这将在Latex中呈现整个单元格输出:

%%latex
\begin{align} 2 \cdot \begin{bmatrix} 1 \\ -2 \\ \end{bmatrix} -1 \cdot \begin{bmatrix} 2 \\ -3 \\ \end{bmatrix} +1 \cdot \begin{bmatrix} -3 \\ 1 \\ \end{bmatrix} -1 \cdot \begin{bmatrix} 1 \\ -1 \\ \end{bmatrix}= \begin{bmatrix} -4 \\ 1 \\ \end{bmatrix} \end{align}

enter image description here

here描述了在Jupyter中渲染LaTeX的所有不同方法。

© www.soinside.com 2019 - 2024. All rights reserved.