# Render LaTeX expression in SageMath 9.3

In SageMath up to version 9.2 calling a cell consisting of the line show(LatexExpr(r'\infty')) in a Jupyter notebook would display the infinity symbol using LaTeX rendering. In SageMath 9.3 it displays the LaTeX string itself. How do I revert to the previous behavior?

This is unrelated to whether or not one has set %display latex. The command view is not an option because it opens a separate viewer which is not what I want.

Since this change of behavior breaks a lot of my notebooks, any help is much appreciated.

edit retag close merge delete

Welcome to Ask Sage! Thank you for this report!

( 2021-06-02 09:34:40 +0200 )edit

Sort by » oldest newest most voted

Known bug, fixed at

which already has positive review and should go in Sage 9.4.

Since the branch at that ticket only tchanges .py files, it is easy enough to apply to your Sage.

If you installed Sage 9.3 from source or from binaries (rather than "via a package manager"), you can apply the fix to your current Sage installation by running the following commands in a terminal:

$cd$(sage -c "print(SAGE_ROOT)")
$git remote add trac git://trac.sagemath.org/sage.git -t develop$ git checkout -b 31629
$git fetch trac u/klee/31629$ git merge FETCH_HEAD
$./sage -b  Next time you start Sage, it should have the fix. Next time you want to upgrade Sage, start by checking out the develop branch: $ git checkout develop
$git pull origin develop$ ./bootstrap -q && ./configure -q && make -s V=0

more

Until Trac #31629 is merged (cf. @slelievre 's answer), a possible workaround is to define a subclass of LatexExpr relying on Jupyter's native LaTeX rendering (not Sage's one), as follows:

class LatexExprFix(LatexExpr):
def _repr_latex_(self):
return '$' + str(self) + '$'


It suffices to type the above code in a cell of the Jupyter notebook. Then

LatexExprFix(r'\infty')


displays the LaTeX-rendered formula.

However this does not work with %display latex. If you have some part of the notebook with %display latex, you have to revert to plain display with %display plain before using LatexExprFix. Maybe this can be improved...

more