Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty_print_default fails in a terminal session #15271

Closed
gvol opened this issue Oct 12, 2013 · 13 comments
Closed

pretty_print_default fails in a terminal session #15271

gvol opened this issue Oct 12, 2013 · 13 comments

Comments

@gvol
Copy link

gvol commented Oct 12, 2013

Calling pretty_print_default in a terminal fails:

┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 5.12, Release Date: 2013-10-07                        │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: pretty_print_default(True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-b70acc55a8d2> in <module>()
----> 1 pretty_print_default(True)

/Users/ivanandres/SageStuff/sage-5.12/local/lib/python2.7/site-packages/sage/misc/latex.pyc in pretty_print_default(enable)
   2463     """
   2464     import sys
-> 2465     sys.displayhook.set_display('typeset' if enable else 'simple')
   2466
   2467

AttributeError: 'DisplayHook' object has no attribute 'set_display'
sage:

Perhaps calling pretty_print_default doesn't make much sense in the terminal, but it's used in the emacs interface to be able to display typeset output.

I think doctests pass because the doctesting framework sets sys.displayhook to something else, namely sage.misc.displayhook.DisplayHook(sys.displayhook). I think the regression was introduced in #15168, and so I have cc'ed the people involved there in case they want to weigh in on how this should be fixed.

CC: @vbraun @ppurka @novoselt

Component: user interface

Issue created by migration from https://trac.sagemath.org/ticket/15271

@gvol gvol added this to the sage-6.1 milestone Oct 12, 2013
@ppurka
Copy link
Member

ppurka commented Oct 12, 2013

comment:1

As commented in the function, this should probably be removed from the global namespace. It is really not useful in the terminal.

@vbraun
Copy link
Member

vbraun commented Oct 12, 2013

comment:2

Correct, the terminal uses IPython's machinery instead of sys.displayhook. The doctests and the notebook run commands in non-ipython sessions, so our displayhook is used. IMHO the best way to switch IPython's behavior is with the %display magic, that is,

sage: %display typeset
sage: 1+1
<html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}2</script></html>

I see that we don't actually doctest that, this ought to be added to sage/misc/sage_extension.py

@ppurka
Copy link
Member

ppurka commented Oct 12, 2013

comment:3

If we want to fix this function, can this be made to call whatever the magic %display typeset runs?

Maybe run the current code inside a try: except: construct?

@vbraun
Copy link
Member

vbraun commented Oct 12, 2013

comment:4

We can, but imho we should just remove pretty_print_default.

@ppurka
Copy link
Member

ppurka commented Oct 12, 2013

comment:5

Let's use this ticket for removing the function from the global namespace.

@ppurka
Copy link
Member

ppurka commented Oct 12, 2013

comment:6

@gvol - Would the emacs interface work if you set sys.displayhook = sage.misc.displayhook.DisplayHook from emacs?

@gvol
Copy link
Author

gvol commented Oct 12, 2013

comment:7

Replying to @ppurka:

@gvol - Would the emacs interface work if you set sys.displayhook = sage.misc.displayhook.DisplayHook from emacs?

Yes that works. Just to be clear, sage.misc.displayhook.DisplayHook only exists in 5.12 (and later), right?

@ppurka
Copy link
Member

ppurka commented Oct 12, 2013

comment:8

Replying to @gvol:

Replying to @ppurka:

@gvol - Would the emacs interface work if you set sys.displayhook = sage.misc.displayhook.DisplayHook from emacs?

Yes that works. Just to be clear, sage.misc.displayhook.DisplayHook only exists in 5.12 (and later), right?

No. That exists from earlier, probably sage-5.11 (#12719).

@gvol
Copy link
Author

gvol commented Oct 13, 2013

comment:9

Replying to @gvol:

Replying to @ppurka:

@gvol - Would the emacs interface work if you set sys.displayhook = sage.misc.displayhook.DisplayHook from emacs?

Yes that works. Just to be clear, sage.misc.displayhook.DisplayHook only exists in 5.12 (and later), right?

I spoke too soon. Using sage.misc.displayhook.DisplayHook makes plots not appear (in DOCTEST_MODE so they can be viewed inline as well). I haven't had a change to debug into it yet.

@vbraun
Copy link
Member

vbraun commented Oct 13, 2013

comment:10

No graphics is shown in DOCTEST_MODE, this is the expected behavior.

Whats wrong with %display typeset?

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@gvol
Copy link
Author

gvol commented Jun 10, 2014

comment:13

Sage mode now uses %display typeset, so I no longer care about this--we can just remove pretty_print_default.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@kcrisman
Copy link
Member

comment:15

Sage mode now uses %display typeset, so I no longer care about this--we can just remove pretty_print_default.

At least from the command line. Possibly also pretty_print?

However, this is needed in all_notebook.py, so don't just remove it completely!

@gvol
Copy link
Author

gvol commented Apr 14, 2015

comment:16

pretty_print_default seems to no longer be in the global namespace in a terminal session, so I move we close this as won't fix.

@gvol gvol removed this from the sage-6.4 milestone Apr 14, 2015
@vbraun vbraun closed this as completed Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants