Ask Your Question
1

The function "view(" doesn't seem to work with jupyter notebook

asked 2019-12-26 15:54:13 +0100

Sebastien gravatar image

updated 2019-12-30 13:55:20 +0100

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

edit retag flag offensive close merge delete

Comments

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).

Sebastien gravatar imageSebastien ( 2019-12-27 12:05:32 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-12-30 13:33:49 +0100

Sebastien gravatar image

updated 2019-12-30 13:54:40 +0100

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-12-26 15:54:13 +0100

Seen: 626 times

Last updated: Dec 30 '19