Ask Your Question

Sebastien's profile - activity

2019-12-30 10:53:39 -0600 received badge  Self-Learner (source)
2019-12-30 10:53:39 -0600 received badge  Teacher (source)
2019-12-30 06:34:32 -0600 received badge  Editor (source)
2019-12-30 06:33:49 -0600 answered a question The function "view(" doesn't seem to work with jupyter notebook

I found a hack that "works sufficiently well" (but requires to put a symbolic link in your working directory). It goes as follows:

  • At the root of your tree (the directory which is displayed when you visit http://localhost:8888/tree), put a symbolic link to your temporary sage folder. In bash (linux) I did it via the command ln -s .sage/temp/ ./tmp_sage_cells
  • then define the function my_view below:

def my_view(e,density=150,extra=""):
    tf=tmp_filename(name="png_cell",ext=".png")
    sage.misc.latex.png(e,tf,density=density)
    pretty_print(html('<img src="http://localhost:8888/tree/tmp_sage_cells/%s" %s>'%(tf.split(r".sage/temp/")[1],extra)))

You can test the function with my_view(graphs.CompleteGraph(4)) or my_view(graphs.CompleteGraph(4),density=50,extra='style="height:100px;"') for fancier options. This function my_view is a small variation from the functions defined in /sagemath/local/lib/python2.7/site-packages/sage/misc/latex.py

2019-12-27 07:08:16 -0600 received badge  Student (source)
2019-12-27 05:05:32 -0600 commented question The function "view(" doesn't seem to work with jupyter notebook

Actually, the example graphs.CompleteGraph(4) is a bad example because pretty_print already does what I wish, for this example (it is the example that was in the documentation of sage).

But the question remains with, for instance view(Tableau([[1,2],[3]])), for which pretty_print doesn't work (due to limitation of MathJax with respect to tables).

But if someone is able to explain to me how pretty_print(graphs.CompleteGraph(4)) works, that will already be something (it displays more than what latex(graphs.CompleteGraph(4)) has).

2019-12-27 03:08:16 -0600 asked a question The function "view(" doesn't seem to work with jupyter notebook

I'm sorry if the question was already answered somewhere, but I did not find out an answer by myself:

In the "old" sagemath notebooks, there was a function "view" to display latex that MathJax cannot display. For instance the sage documentation proposes the following:

from sage.graphs.graph_latex import setup_latex_preamble    
setup_latex_preamble()    
latex.engine('pdflatex')    
latex.add_to_mathjax_avoid_list('tikzpicture')    
view(graphs.CompleteGraph(4))
  • In the "old" sage notebook, this produces a png version of a graph (compiled from latex), which is inserted into the output of the cell
  • In the Jupyter netbook, by contrast, it opens a pdf version of the graph into an external window.

Is there some way to obtain, in the Jupyter notebook, the same behaviour as in the "old netbook" ?

Thanks