Jupyter Notebook iPython 中的 Latex

问题描述 投票:0回答:2

我在jupyter笔记本中有一个python项目,我想用latex显示最终输出。

x = 5
print("The number you have inputted is ", complex(x, y), " ^ 1/", n, sep = '')

我希望使用乳胶对其进行格式化:


我读了很多论坛,但分数不适用于 2 位数字

n=10
from IPython.display import display, Markdown
display(Markdown(rf"""$ { complex(x, y) } ^ \frac{1}{n} $"""))

我能得到的最好的:


任何建议都会非常有帮助:)

python jupyter-notebook latex
2个回答
1
投票

您可以使用

Latex
直接将其显示为 Latex。要将大括号保留为 Latex 的文字,您需要使用双
{{
}}
。否则
\frac
无法获得完整的操作数。

from IPython.display import display, Latex

x=1
y=0
n=10

display(Latex(rf'$ { complex(x, y) } ^\frac{{1}}{{{n}}}$'))

Jupyterlab 中的输出:


0
投票

这可以使用 jupyprint 包来完成:https://pypi.org/project/jupyprint/

您可以使用以下代码:

import jupyprint as jp

x=1
y=0
n=10

jp.jupyprint(f"$ {complex(x, y)}" + " ^ \\frac{" + f"{1}" + "}{" + f"{n}" + "} $")

Here is how the output looks.

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