Ask Your Question

Revision history [back]

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 is 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 a plain display with %display plain before using LatexExprFix. Maybe this can be improved...

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 is 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 a plain display with %display plain before using LatexExprFix. Maybe this can be improved...