Ask Your Question
2

Render LaTeX expression in SageMath 9.3

asked 2021-06-02 08:53:35 +0100

CBaer gravatar image

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 flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for this report!

slelievre gravatar imageslelievre ( 2021-06-02 09:34:40 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-06-02 10:41:05 +0100

eric_g gravatar image

updated 2021-06-02 13:10:36 +0100

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...

edit flag offensive delete link more
1

answered 2021-06-02 09:34:11 +0100

slelievre gravatar image

updated 2021-06-02 14:18:47 +0100

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-06-02 08:53:35 +0100

Seen: 711 times

Last updated: Jun 02 '21