ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 12 Dec 2020 17:09:14 +0100show command latexhttps://ask.sagemath.org/question/54132/show-command-latex/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/1ZVMg5d3DMKGsXLfWcrZmBZm19yTH8G2L/view?usp=sharing
The same example in jupyter:
https://drive.google.com/file/d/1ZXaNv44HEpzSoyG6pz6I_PVKkwEd1_YH/view?usp=sharing
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.Fri, 06 Nov 2020 18:05:38 +0100https://ask.sagemath.org/question/54132/show-command-latex/Answer by Juanjo for <p>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:
<a href="https://drive.google.com/file/d/1ZVMg5d3DMKGsXLfWcrZmBZm19yTH8G2L/view?usp=sharing">https://drive.google.com/file/d/1ZVMg...</a></p>
<p>The same example in jupyter:
<a href="https://drive.google.com/file/d/1ZXaNv44HEpzSoyG6pz6I_PVKkwEd1_YH/view?usp=sharing">https://drive.google.com/file/d/1ZXaN...</a></p>
<p>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.</p>
https://ask.sagemath.org/question/54132/show-command-latex/?answer=54659#post-id-54659For 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
> <strong>Solution</strong><br> Let
> $\mathbf{u}=(1,2,3)$ and
> $\mathbf{v}=(4,5,6)$. Then,
> $\mathbf{u}\times \mathbf{v} =
> (-3,6,-3)$.
Sat, 12 Dec 2020 17:09:14 +0100https://ask.sagemath.org/question/54132/show-command-latex/?answer=54659#post-id-54659Answer by UncountableSet for <p>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:
<a href="https://drive.google.com/file/d/1ZVMg5d3DMKGsXLfWcrZmBZm19yTH8G2L/view?usp=sharing">https://drive.google.com/file/d/1ZVMg...</a></p>
<p>The same example in jupyter:
<a href="https://drive.google.com/file/d/1ZXaNv44HEpzSoyG6pz6I_PVKkwEd1_YH/view?usp=sharing">https://drive.google.com/file/d/1ZXaN...</a></p>
<p>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.</p>
https://ask.sagemath.org/question/54132/show-command-latex/?answer=54148#post-id-54148Is there a way to get this approach to print something like u x v? This doesn't work:
latex("u \times v")Sat, 07 Nov 2020 20:50:59 +0100https://ask.sagemath.org/question/54132/show-command-latex/?answer=54148#post-id-54148Comment by eric_g for <p>Is there a way to get this approach to print something like u x v? This doesn't work:</p>
<p>latex("u \times v")</p>
https://ask.sagemath.org/question/54132/show-command-latex/?comment=54150#post-id-54150You have to prefix the string by `r` (for "raw") because of the backslah in `\times` and use `LatexExpr`:
LatexExpr(r"u\times v")Sat, 07 Nov 2020 23:33:28 +0100https://ask.sagemath.org/question/54132/show-command-latex/?comment=54150#post-id-54150Answer by eric_g for <p>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:
<a href="https://drive.google.com/file/d/1ZVMg5d3DMKGsXLfWcrZmBZm19yTH8G2L/view?usp=sharing">https://drive.google.com/file/d/1ZVMg...</a></p>
<p>The same example in jupyter:
<a href="https://drive.google.com/file/d/1ZXaNv44HEpzSoyG6pz6I_PVKkwEd1_YH/view?usp=sharing">https://drive.google.com/file/d/1ZXaN...</a></p>
<p>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.</p>
https://ask.sagemath.org/question/54132/show-command-latex/?answer=54133#post-id-54133As 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$Fri, 06 Nov 2020 18:30:14 +0100https://ask.sagemath.org/question/54132/show-command-latex/?answer=54133#post-id-54133