2

I have a python project in jupyter notebook, and I want to display the final output with latex.

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

I want this to be formatted using latex:

Input to be formatted


I read a bunch of forums but the fraction wasn't working for 2digit numbers

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

The best I could get:

Input to be formatted


Any suggestions would be very helpful :)

2 Answers 2

1

You can directly display it as Latex using Latex. To keep the curly brackets as literals for Latex you need to use double {{ }}. Otherwise the \frac does not obtain the full operands.

from IPython.display import display, Latex

x=1
y=0
n=10

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

Output in Jupyterlab: enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

OP wants to print the formatted string... The above code note giving the desired output for 2-digit number(n)
0

This can be done with the jupyprint package: https://pypi.org/project/jupyprint/

You could use the following code:

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.