Opened 3 years ago

Last modified 8 months ago

#23330 new defect

Broken typeset in pdf export of Jupyter notebook

Reported by: egourgoulhon Owned by:
Priority: major Milestone: sage-8.0
Component: notebook Keywords: jupyter pdf
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:


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 for more details, and in particular

Change History (5)

comment:1 Changed 3 years ago by egourgoulhon

  • Keywords jupyter pdf added

comment:3 Changed 18 months ago by embray

As discussed on sage-devel, 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 unnecessary--I 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 8 months ago by egourgoulhon

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 8 months ago by egourgoulhon

Note: See TracTickets for help on using tickets.