Is it possible to show `print` output as LaTeX in jupyter notebook?(是否可以在 jupyter 笔记本中将“打印输出显示为 LaTeX?)
问题描述
我正在编写一个非常简单的脚本来计算椭圆体的面积和体积以及其他一些东西.我正在展示我的输出,如下所示:
I was writing a very simple script to count ellipsoid area and volume and some other things. I was presenting my output printing it out like this:
print('Dims: {}x{}m
Area: {}m^2
Volume: {}m^3'.format(a, round(b,2), P, V))
当然,是什么给出了这个输出(带有样本数据):
What, of course, gave this output (with sample data):
Dims: 13.49x2.25m
Area: 302.99m^2
Volume: 90.92m^3
正如我之前写的,我使用的是 jupyter notebook,所以我可以在 markdown 单元格中使用 $
运算符来创建 LaTeX 公式.
As I wrote earlier, I am using jupyter notebook, so I can use $
operators in markdown cells to create LaTeX formulas.
我的问题是,是否可以使用 Python 代码 生成输出,将其理解为 LaTeX 公式并以如下方式打印:
My question is, is it possible to generate output using Python code in a way that it will be understood as LaTeX formula and printed in such a way, that:
感谢所有回复.
推荐答案
使用 IPython.display
的 display
函数和 Math
对象:
Use IPython.display
's display
function with a Math
object:
from IPython.display import display, Math
display(Math(r'Dims: {}x{}m \ Area: {}m^2 \ Volume: {}m^3'.format(a, round(b,2), P, V)))
注意使用 Latex 样式的 \
换行符和 r''
字符串,它将反斜杠作为文字反斜杠,而不是将它们视为转义字符.
Note the use of Latex-style \
newlines, and the r''
string, which will take the backslashes as literal backslashes and not see them as escape characters.
在这里找到了解决方案.
这篇关于是否可以在 jupyter 笔记本中将“打印"输出显示为 LaTeX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 jupyter 笔记本中将“打印"输出显示为 LaTeX?


基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01