This question is not a duplicate of this one, even if it is closely related.
When I use sympy on a jupyter notebook, it nicely format the output of my equations with MathJax, like this:
If we have a look at the source of the notebook, we can see that the output saved is made of two parts text/plain
and text/latex
:
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\frac{- b - \\sqrt{- 4 a c + b^{2}}}{2 a}$"
],
"text/plain": [
"(-b - sqrt(-4*a*c + b**2))/(2*a)"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import sympy\n",
"\n",
"a, b, c = sympy.symbols('a b c')\n",
"(-b - sympy.sqrt(b**2 - 4*a*c)) / (2*a)"
]
Even if I know how to print in a latex form (cf. link above), I would like to make a custom object behave as a sympy one, and be able to be displayed naturally as latex math in a jupyter notebook (and if I could fill both the text/latex and text/plain fields it would be nice !). If anyone had a clue on how to do it :)