Opened 7 years ago

Closed 6 years ago

#16444 closed task (duplicate)

ipython notebook

Reported by: elixyre Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: notebook Keywords:
Cc: nthiery, slabbe Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: u/elixyre/ticket/16444 (Commits, GitHub, GitLab) Commit: 2aba37ed7ac56db82d156c8e5aebac328ff88f5c
Dependencies: Stopgaps:

Status badges

Description

The ipython notebook is really simple and ergonomic.

To me the only problem is if we want plot something or show something like in the sage notebook... That is not easy... and I did find a deterministic way to plot what I want easily.

For example, if I want plot a tree, I can do that

from IPython.display import Image, display
file = "/blabla/myfiles/foo/img.png"
b = BinaryTree([[[],[]],[]])
latex.eval(latex(b), locals(), filename=file)
display(Image(filename=file))

Ok, that is really not sexy but that's work.

One problem is:

f = x^2 + x + 3
latex.eval(latex(b), locals(), filename=file)
display(Image(filename=file))

doesn't work!

One has to append $:

latex.eval("$" + latex(f) + "$", locals(), filename=file)

and ok...

So my questions are:

  • what is the good way to do that? (especially, I would like to (re)use the sage notebook technology)
  • Is it possible to add this feature in the ipython patch? I means something like :
    class SageObject:
        ...
    
        def _repr_png_(self):
             return do_something_to_compute_img_of_self(self)
    

(Like in that tutorial: http://nbviewer.ipython.org/github/ipython/ipython/blob/1.x/examples/notebooks/Custom%20Display%20Logic.ipynb)

  • and obviously, how to lunch automatically the ipython notebook with the magic command %load_ext sage?

Thanks! Jean-Baptiste Priez

Attachments (2)

Untitled2.html (198.7 KB) - added by elixyre 7 years ago.
Untitled2.ipynb (18.2 KB) - added by elixyre 7 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 follow-up: Changed 7 years ago by tmonteil

Hi,

you can be interested by this wiki page. Also, i went to ipython IRC a few days ago and it seems (at least from their point of view) the best way is indeed to propose a _repr_html_ (and similar) method. So i guess (without being completely sure) this should be advocated within the Sage community.

comment:2 in reply to: ↑ 1 Changed 7 years ago by elixyre

Hi Thierry,

Replying to tmonteil:

you can be interested by this wiki page.

Thanks you ! That is a good idea!

Replying to tmonteil:

the best way is indeed to propose a _repr_html_ (and similar) method.

Why not... Just there is lot of tikz code (particulary mine) in sage, so I expect you don't forget all the latex code which can't be interpreted by mathjax.

Now, I would like code a(n ugly) hack to use (quickly) ipython notebook... if someone understands the bowels of the sage-notebook, I would be grateful to show me the way.

In a second time, this ticket could be used and merged in your long project.

comment:3 Changed 7 years ago by elixyre

  • Branch set to u/elixyre/ticket/16444
  • Commit set to 2aba37ed7ac56db82d156c8e5aebac328ff88f5c

this hack could be usefull for anyone whoever want use nice display in the notebook...

Then to load sage lib ( %load_ext sage ), I create a ipy file in .../.sage/ipython-x.xx/profile_**default**/startup/ with the content

%load_ext sage
sage.misc.latex.EMBEDDED_MODE = True

And tada!!!


New commits:

2aba37eTicket 16444 : Hack to obtain nice ipython notebook output

Changed 7 years ago by elixyre

Changed 7 years ago by elixyre

comment:4 Changed 7 years ago by elixyre

The file in .sage/ipython-x.xx/profile_**default**/startup/ is a ipython file (toto.ipy)...

The complete file must be some thing like that ...

%load_ext sage
sage.misc.latex.EMBEDDED_MODE = True

from sage.misc.latex import latex
latex.add_package_to_preamble_if_available("tikz")
latex.add_to_mathjax_avoid_list("tikz")

(I don't know why but we need the 3 last lines... with my hack...)

comment:5 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:6 Changed 7 years ago by kcrisman

Is #16270 a duplicate of this? If so, we can close that one.

comment:7 Changed 7 years ago by elixyre

Yep, it's my fault for the duplicate! you can close this ticket.

comment:8 follow-up: Changed 7 years ago by elixyre

No... sorry... you can close the other ticket... this one contains some code about how to display latex figure.

comment:9 in reply to: ↑ 8 Changed 7 years ago by kcrisman

No... sorry... you can close the other ticket... this one contains some code about how to display latex figure.

Okay, if you are sure about this then go to #16270 and set it to positive review. Thanks!

comment:10 Changed 7 years ago by slabbe

I do not understand the goal of this ticket. The description looks like a question on ask.sagemath.org and mentions many things. Also, the ticket title does not contain any verb. Elixyre, can you reformat the description and the title of the ticket so that I can understand what should be done to achieve the task?

comment:11 Changed 6 years ago by kcrisman

  • Status changed from new to needs_info

Is this now a duplicate of #16996? Or is there still the LaTeX-specific thing going on? In that case, the summary and description should really be changed.

comment:12 Changed 6 years ago by novoselt

  • Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
  • Status changed from needs_info to positive_review

I think it is a duplicate and originators don't seem to object.

comment:13 Changed 6 years ago by vbraun

  • Resolution set to duplicate
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.