Opened 19 months ago

Last modified 3 weeks ago

#30854 needs_info defect

the view command silently does nothing in Jupyter notebooks

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

Status badges

Description

  1. Try typing view(2/3) in a Jupyter notebook.
  2. No visible output appears.

I don't think ever worked in Jupyter, but it did in sagenb. This is one of those things that got forgotten (?) when switching from sagenb to Jupyter.

Under the hood what happens looks like this:

sage: sage.misc.latex.EMBEDDED_MODE = True
sage: view(2/3)
<html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{2}{3}</script></html>

I think this <html> thing in the output is something I made up long long ago to signal that the output should be displayed as HTML. In Jupyter, one instead uses

from IPython.core.display import HTML
HTML(r'<script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{2}{3}</script>')

And the above does properly show a fraction.

So a slightly rewrite of view to work with Jupyter (and probably not with sagenb) is the way to go?

Change History (13)

comment:1 Changed 19 months ago by alexjbest

I think #19515 and #26101 are relevant, I've been monkey patching the first one into my notebooks to render tikz diagrams inline, but it seems more is needed for inline math.

comment:2 Changed 16 months ago by mkoeppe

  • Cc yzh added

comment:3 follow-up: Changed 16 months ago by yzh

Typing view(2/3) in a Jupyter notebook works fine for me: it opens a pdf file containing the fraction 2/3

comment:4 Changed 16 months ago by alexjbest

I think this current behaviour (though it does make a pdf for me too) is non-optimal, Jupyter has the capacity to render TeX using mathjax in a cell. So rather than spawning TeX to make a pdf, pushing the TeX code to Jupyter to render via mathjax or at least copy the rendered tex to an image to be displayed inline should be the goal of this ticket.

comment:5 in reply to: ↑ 3 Changed 14 months ago by egourgoulhon

Replying to yzh:

Typing view(2/3) in a Jupyter notebook works fine for me: it opens a pdf file containing the fraction 2/3

It works for me too with Sage 9.3.rc0: view(2/3) generates a pdf file, which is automatically opened by the default pdf viewer of my system (evince). This is with Firefox 86.0.1 on Ubuntu 20.04.

comment:6 Changed 14 months ago by mkoeppe

  • Status changed from new to needs_info

@was Sounds like we need more info about the system on which you observed this behavior. Perhaps a broken pdf viewer?

comment:7 Changed 14 months ago by was

@was Sounds like we need more info about the system on which you observed this behavior. Perhaps a broken pdf viewer?

CoCalc?.com. There is no X11 server running at all. I should maybe amend the title of the ticket to say "the view command silently does nothing in Jupyter notebooks when there is no X11 server"?

comment:8 Changed 14 months ago by was

I would be happy with view(2/3) showing an error message rather than silently failing, though I don't know if that's even possible (given the asynchronous nature) of this.

Anyway, it's possible this is a problem for me to deal with on my end. E.g., I could patch the view command on cocalc.

comment:9 Changed 14 months ago by alexjbest

#31536 seems related, I would say that if view fails for any reasons mathjax output should be attempted in the notebook isntead of an error.

There are other non-silent failures where this would be useful too: running a binder notebook https://mybinder.org/v2/gh/alexjbest/cluster-pictures/master?filepath=notebooks%2Fdemo.ipynb one sees an error that pdftex is not installed when you try view(2/3).

comment:10 Changed 13 months ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

Moving to 9.4, as 9.3 has been released.

comment:11 Changed 10 months ago by mkoeppe

  • Milestone changed from sage-9.4 to sage-9.5

Setting a new milestone for this ticket based on a cursory review.

comment:12 Changed 5 months ago by mkoeppe

  • Milestone changed from sage-9.5 to sage-9.6

comment:13 Changed 3 weeks ago by mkoeppe

  • Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.