Ask Your Question
3

show command latex

asked 2020-11-06 18:05:38 +0100

UncountableSet gravatar image

updated 2020-11-06 18:06:44 +0100

I use sage both within the cocalc interface and the jupyter interface. The show() command behaves differently in each and I'm trying to understand. Here's an example in cocalc: https://drive.google.com/file/d/1ZVMg...

The same example in jupyter: https://drive.google.com/file/d/1ZXaN...

The in-line latex in cocalc is rendered nicely, the same latex in jupyter isn't. I've included the %display latex directive in the jupyter example, but it doesn't seem to make a difference.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2020-11-06 18:30:14 +0100

eric_g gravatar image

As a workaround, in the Jupyter notebook, use latex instead of show:

%display latex
x, y = var('x y')
f = x^2 + y^2
latex("f_x = " + latex(diff(f, x)))

$f_x = 2 x$

edit flag offensive delete link more
1

answered 2020-12-12 17:09:14 +0100

Juanjo gravatar image

For a good control of the output in a Jupyter notebook, you could combine show, html and f-strings. For example,

var("x,y")
f = x^2 + y^2
show(html(f"The partial derivative of $f(x,y)={f}$ is $f_x(x,y)={latex(diff(f,x))}$"))

This yields

The partial derivative of $f(x,y)=x^2+y^2$ is $f_x(x,y)=2x$

Another example:

u = vector([1,2,3])
v = vector([4,5,6])
text = fr"""
<strong>Solution</strong><br>
Let $\mathbf{{u}}={u}$ and $\mathbf{{v}}={v}$.
Then, $\mathbf{{u}}\times \mathbf{{v}} = {u.cross_product(v)}.
"""
show(html(text))

This is rendered as

Solution
Let $\mathbf{u}=(1,2,3)$ and $\mathbf{v}=(4,5,6)$. Then, $\mathbf{u}\times \mathbf{v} = (-3,6,-3)$.

edit flag offensive delete link more
1

answered 2020-11-07 20:50:59 +0100

UncountableSet gravatar image

Is there a way to get this approach to print something like u x v? This doesn't work:

latex("u \times v")

edit flag offensive delete link more

Comments

You have to prefix the string by r (for "raw") because of the backslah in \times and use LatexExpr:

LatexExpr(r"u\times v")
eric_g gravatar imageeric_g ( 2020-11-07 23:33:28 +0100 )edit

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: 2020-11-06 18:05:38 +0100

Seen: 1,001 times

Last updated: Dec 12 '20