ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 02 Jun 2021 10:41:05 +0200Render LaTeX expression in SageMath 9.3https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/ 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.Wed, 02 Jun 2021 08:53:35 +0200https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/Comment by slelievre for <p>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?</p>
<p>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.</p>
<p>Since this change of behavior breaks a lot of my notebooks, any help is much appreciated.</p>
https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/?comment=57398#post-id-57398Welcome to Ask Sage!
Thank you for this report!Wed, 02 Jun 2021 09:34:40 +0200https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/?comment=57398#post-id-57398Answer by eric_g for <p>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?</p>
<p>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.</p>
<p>Since this change of behavior breaks a lot of my notebooks, any help is much appreciated.</p>
https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/?answer=57401#post-id-57401Until [Trac #31629](https://trac.sagemath.org/ticket/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...Wed, 02 Jun 2021 10:41:05 +0200https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/?answer=57401#post-id-57401Answer by slelievre for <p>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?</p>
<p>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.</p>
<p>Since this change of behavior breaks a lot of my notebooks, any help is much appreciated.</p>
https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/?answer=57397#post-id-57397Known bug, fixed at
- [Sage Trac ticket 31629](https://trac.sagemath.org/ticket/31629)
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=0Wed, 02 Jun 2021 09:34:11 +0200https://ask.sagemath.org/question/57396/render-latex-expression-in-sagemath-93/?answer=57397#post-id-57397