【问题标题】:Latex in Jupyter Notebook iPythonJupyter Notebook iPython中的乳胶
【发布时间】:2021-04-21 08:38:16
【问题描述】:

我在 jupyter notebook 中有一个 python 项目,我想用乳胶显示最终输出。

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


    【解决方案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 中的输出:

    【讨论】:

    • OP 想要打印格式化的字符串......上面的代码注释给出了 2 位数字(n)的所需输出
    • 谢谢。更新了答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 2021-06-20
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 2017-07-18
    相关资源
    最近更新 更多