First time here? Check out the FAQ!

Ask Your Question
2

Render Latex in IPython notebook and display on output line

asked 9 years ago

xentity1x gravatar image

So let's say I generate a Latex expression like so

def polar_gradient(f):
    return (derivative(f, x), derivative(f, r), derivative(f,theta)) 

x, r, theta = var('x', 'r', 'theta')
f = r * sin(theta)
grad = polar_gradient(f)
expr=latex(grad)

Is there a way I can render expr and display it on the output line in an Ipython notebook?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 9 years ago

eric_g gravatar image

In the Ipython notebook (now called Jupyter notebook), simply type

%display latex
grad

Note the % in front of display. After this command, all outputs will be displayed using LaTeX (MathJax rendering) (there is no need to type %display latex in subsequent cells). Note also that you don't need to write expr=latex(grad).

Preview: (hide)
link

Comments

Seems like %display was deprecated? UsageError: Line magic function%displaynot found.

MaxGhenis gravatar imageMaxGhenis ( 5 years ago )
0

answered 1 year ago

Dan-K gravatar image

updated 1 year ago

I just wanted to add an alternative to @eric_g's answer which also worked for me.

If you're using Sage with VSCode, there is a way to toggle the output between text/plain, text/html, and text/latex:

image description

image description

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 9 years ago

Seen: 16,675 times

Last updated: Jul 06 '23