Is it possible to show `print` output as LaTeX in jupyter notebook?

后端 未结 2 670
慢半拍i
慢半拍i 2020-12-13 09:34

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(\'Dim         


        
2条回答
  •  猫巷女王i
    2020-12-13 10:07

    Here's another solution that let's you include text and math a little easier: Use Markdown with r (so backslashed don't become escape chars) and f string for value insertion.

    from IPython.display import display, Markdown
    
    a = 13.49
    b = 2.2544223
    P = 302.99
    V = 90.02
    
    display(Markdown(
       rf"""
    Dims: ${a}m \times{b:5.2}m$
    
    Area: ${P}m^2$
    
    Volume: ${V}m^3$
    """))
    

提交回复
热议问题