Opened 3 years ago

Closed 4 months ago

#23330 closed defect (fixed)

Broken typeset in pdf export of Jupyter notebook

Reported by: egourgoulhon Owned by:
Priority: major Milestone: sage-9.2
Component: notebook Keywords: jupyter pdf
Cc: Merged in:
Authors: Vincent Vanlaer Reviewers: Eric Gourgoulhon
Report Upstream: N/A Work issues:
Branch: 6885636 (Commits) Commit: 68856362d59b530bb7093573e9480811b2e80b6f
Dependencies: Stopgaps:

Description (last modified by kcrisman)

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/sage-devel/LC_4PSjyx2M/I9ip8c0bCAAJ for more details, and in particular https://groups.google.com/d/msg/sage-devel/LC_4PSjyx2M/coAzvbo1CAAJ

Part of #29889.

Change History (10)

comment:1 Changed 3 years ago by egourgoulhon

  • Keywords jupyter pdf added

comment:3 Changed 2 years 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 17 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 17 months ago by egourgoulhon

comment:6 Changed 4 months ago by kcrisman

  • Description modified (diff)

comment:7 Changed 4 months ago by gh-VincentVanlaer

  • Authors set to Vincent Vanlaer
  • Branch set to u/gh-VincentVanlaer/jupyter_pdf_latex
  • Commit set to 68856362d59b530bb7093573e9480811b2e80b6f
  • Status changed from new to needs_review

New commits:

6885636Provide raw latex to Jupyter for latex/pdf export

comment:8 Changed 4 months ago by egourgoulhon

  • 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 4 months ago by chapoton

  • Milestone changed from sage-8.0 to sage-9.2

comment:10 Changed 4 months ago by vbraun

  • Branch changed from u/gh-VincentVanlaer/jupyter_pdf_latex to 68856362d59b530bb7093573e9480811b2e80b6f
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.