Ask Your Question

Render Latex in IPython notebook and display on output line

asked 2015-12-16 19:11:42 +0200

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)

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-12-16 23:17:05 +0200

eric_g gravatar image

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

%display latex

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).

edit flag offensive delete link more


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

MaxGhenis gravatar imageMaxGhenis ( 2020-02-09 04:13:29 +0200 )edit

answered 2023-07-06 03:39:34 +0200

Dan-K gravatar image

updated 2023-07-06 03:46:15 +0200

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

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2015-12-16 19:11:42 +0200

Seen: 15,405 times

Last updated: Jul 06 '23