Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 4 years ago

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)=x2+y2 is fx(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 u=(1,2,3) and v=(4,5,6). Then, u×v=(3,6,3).