#23330 closed defect (fixed)
Broken typeset in pdf export of Jupyter notebook
Reported by:  egourgoulhon  Owned by:  

Priority:  major  Milestone:  sage9.2 
Component:  notebook  Keywords:  jupyter pdf 
Cc:  Merged in:  
Authors:  Vincent Vanlaer  Reviewers:  Eric Gourgoulhon 
Report Upstream:  N/A  Work issues:  
Branch:  6885636 (Commits, GitHub, GitLab)  Commit:  
Dependencies:  Stopgaps: 
Description (last modified by )
In the Jupyter notebook, typeset outputs, either obtained by show
or by %display latex
, are no longer typeset in the pdf file generated by File>Download as>PDF via LaTeX (.pdf).
See https://groups.google.com/d/msg/sagedevel/LC_4PSjyx2M/I9ip8c0bCAAJ for more details, and in particular https://groups.google.com/d/msg/sagedevel/LC_4PSjyx2M/coAzvbo1CAAJ
Part of #29889.
Change History (11)
comment:1 Changed 4 years ago by
 Keywords jupyter pdf added
comment:2 Changed 4 years ago by
comment:3 Changed 3 years ago by
As discussed on sagedevel, we need to make the Sage kernel be more explicit about when the output's mimetype is text/latex (instead of using text/html, which is generally unnecessaryI don't think we need to wrap the output in an HTML fragment or <script type="text/math">
. I could be wrong, but I think that might be a vestige from older versions of IPython notebook...
comment:4 Changed 2 years ago by
A solution could be to use Jupyter's native rich output for LaTeX, not the Sage's mechanism through the IPython extension %display. For this, it suffices to implement the method _repr_latex_
to all Sage objects, i.e. add the following to SageObject
:
def _repr_latex_(self): from sage.misc.latex import latex return '$' + str(latex(self)) + '$'
See e.g. this presentation of Jupyter display logic. This solves the pdf issue reported here.
comment:5 Changed 2 years ago by
See https://groups.google.com/d/msg/sagedevel/nP7PKQyqxKw/IAWZb9nlAAAJ for a related sagedevel discussion.
comment:6 Changed 14 months ago by
 Description modified (diff)
comment:7 Changed 14 months ago by
 Branch set to u/ghVincentVanlaer/jupyter_pdf_latex
 Commit set to 68856362d59b530bb7093573e9480811b2e80b6f
 Status changed from new to needs_review
New commits:
6885636  Provide raw latex to Jupyter for latex/pdf export

comment:8 Changed 14 months ago by
 Reviewers set to Eric Gourgoulhon
 Status changed from needs_review to positive_review
Thank you very much for the fix! I've tested it on a few notebooks and everything works perfectly.
comment:9 Changed 14 months ago by
 Milestone changed from sage8.0 to sage9.2
comment:10 Changed 14 months ago by
 Branch changed from u/ghVincentVanlaer/jupyter_pdf_latex to 68856362d59b530bb7093573e9480811b2e80b6f
 Resolution set to fixed
 Status changed from positive_review to closed
comment:11 Changed 4 months ago by
 Commit 68856362d59b530bb7093573e9480811b2e80b6f deleted
The fix introduced here broke ipywidgets in Jupyter notebooks, see #31513.
See also: https://github.com/sagemathinc/cocalc/issues/2030