Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

% dispay latex vs. ipywidgets

This is part informational and part a question of style In sage manifolds %display latex is set to produce "pretty" output like thus

%display  plain
var('a','g')
display(sqrt(a+g))
%display latex
sqrt(a+g)

Which everybody knows, but a more insidious thing is that it breaks ipywidgets.Hbox() "display". I did a hack in this code below; but does anybody know of a more elegant (re. automatic) means. This is a little long but illustrates what is lost.
Try changing %display lines at the bottom.

%display latex  # Just to copy the problem in 
import matplotlib.pyplot as plt 
from IPython.display import display, HTML
import ipywidgets


# Save 

file_name = 'rings.html'
save_desc = 'save as '+file_name
save_box = ipywidgets.Checkbox(False,description = save_desc)
#Red ring
red_ring = Horizon()
red_box=red_ring.box(desc='red ring')
red_ring.color = 'red'
red_ring.radius =2
#Black ring
black_ring = Horizon()
black_box = black_ring.box(desc='black ring')
black_ring.color = 'black'
black_ring.radius = 3
#Green ring
green_ring = Horizon()
green_box = green_ring.box(desc='green ring')
green_ring.color = 'green'
green_ring.radius = 4

ui = ipywidgets.HBox([red_box,black_box,green_box,save_box])
def f(red,black,green,save_f): 
    global plt_obj
    plt_obj = sphere((1,0,0),.6)
    if red:
    plt_obj += red_ring.gobject()
    if black:
     plt_obj += black_ring.gobject()
    if green:
     plt_obj += green_ring.gobject()
    if save_f:
    save(plt_obj,file_name)
    show(plt_obj,viewer='threejs')
out_show = ipywidgets.interactive_output(f, {'red': red_box,
                                'black': black_box,
                                'green': green_box,
                                'save_f' : save_box})
%display plain
display(ui);
display(out_show)
%display  latex

% dispay latex vs. ipywidgets

This is part informational and part a question of style In sage manifolds %display latex Sage Manifolds, %display latex is set to produce "pretty" output like thus

%display  plain
var('a','g')
display(sqrt(a+g))
var('a, g')
display(sqrt(a + g))
%display latex
sqrt(a+g)
sqrt(a + g)

Which which everybody knows, but a more insidious thing is that it breaks ipywidgets.Hbox() "display". ipywidgets.Hbox() "display". I did a hack in this code below; but does anybody know of a more elegant (re. automatic) means. means. This is a little long but illustrates what is lost.
Try changing %display %display lines at the bottom.

%display latex  # Just to copy the problem in 
in
import matplotlib.pyplot as plt 
plt
from IPython.display import display, HTML
import ipywidgets

 # Save 

Save
file_name = 'rings.html'
save_desc = 'save as '+file_name
as' + file_name
save_box = ipywidgets.Checkbox(False,description = save_desc)
#Red ipywidgets.Checkbox(False, description=save_desc)

# Red ring
red_ring = Horizon()
red_box=red_ring.box(desc='red ring')
red_ring.color = 'red'
red_ring.radius =2
#Black 
# Black ring
black_ring = Horizon()
black_box = black_ring.box(desc='black ring')
black_ring.color = 'black'
black_ring.radius = 3
#Green 
# Green ring
green_ring = Horizon()
green_box = green_ring.box(desc='green ring')
green_ring.color = 'green'
green_ring.radius = 4

ui = ipywidgets.HBox([red_box,black_box,green_box,save_box])
ipywidgets.HBox([red_box, black_box, green_box, save_box])

def f(red,black,green,save_f): 
f(red, black, green, save_f):
    global plt_obj
    plt_obj = sphere((1,0,0),.6)
sphere((1, 0, 0), .6)
    if red:
     plt_obj += red_ring.gobject()
    if black:
      plt_obj += black_ring.gobject()
    if green:
      plt_obj += green_ring.gobject()
    if save_f:
     save(plt_obj,file_name)
    show(plt_obj,viewer='threejs')
show(plt_obj, viewer='threejs')

out_show = ipywidgets.interactive_output(f, {'red': red_box,
                                 'black': black_box,
                                 'green': green_box,
                                 'save_f' : save_box})
 %display plain
display(ui);
display(ui)
display(out_show)
%display  latex

% dispay latex vs. ipywidgets

This is part informational and part a question of style In Sage Manifolds, %display latex is set to produce "pretty" output like thus

%display plain
var('a, g')
display(sqrt(a + g))
%display latex
sqrt(a + g)

which everybody knows, but a more insidious thing is that it breaks ipywidgets.Hbox() "display". I did a hack in this code below; but does anybody know of a more elegant (re. automatic) means. This is a little long but illustrates what is lost. Try changing %display lines at the bottom.

%display latex  # Just to copy the problem in
import matplotlib.pyplot as plt
from IPython.display import display, HTML
import ipywidgets

# Save
file_name = 'rings.html'
save_desc = 'save as' + file_name
save_box = ipywidgets.Checkbox(False, description=save_desc)

# Red ring
red_ring = Horizon()
red_box=red_ring.box(desc='red ring')
red_ring.color = 'red'
red_ring.radius =2

# Black ring
black_ring = Horizon()
black_box = black_ring.box(desc='black ring')
black_ring.color = 'black'
black_ring.radius = 3

# Green ring
green_ring = Horizon()
green_box = green_ring.box(desc='green ring')
green_ring.color = 'green'
green_ring.radius = 4

ui = ipywidgets.HBox([red_box, black_box, green_box, save_box])

def f(red, black, green, save_f):
    global plt_obj
    plt_obj = sphere((1, 0, 0), .6)
    if red:
        plt_obj += red_ring.gobject()
    if black:
        plt_obj += black_ring.gobject()
    if green:
        plt_obj += green_ring.gobject()
    if save_f:
       save(plt_obj,file_name)
    show(plt_obj, viewer='threejs')

out_show = ipywidgets.interactive_output(f, {'red': red_box,
                                             'black': black_box,
                                             'green': green_box,
                                             'save_f' : save_box})

%display plain
display(ui)
display(out_show)
%display latex