Opened 11 years ago

Closed 8 years ago

#9683 closed defect (fixed)

pretty_print clobbers _ (history)

Reported by: mguaypaq Owned by: was
Priority: major Milestone: sage-6.2
Component: user interface Keywords: pretty_print, history, days57
Cc: mhansen Merged in:
Authors: Mike Hansen Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: 3cc45a8 (Commits, GitHub, GitLab) Commit: 3cc45a855a6be42cd9b0bdae15b6fc64d1fdf3cc
Dependencies: Stopgaps:

Status badges

Description

After using pretty_print, the first history variable (_) no longer updates.

----------------------------------------------------------------------
| Sage Version 4.5.1, Release Date: 2010-07-19                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
Loading Sage library. Current Mercurial branch is: combinat
sage: 17
17
sage: _
17
sage: 23
23
sage: _
23
sage: pretty_print(17)
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}17</span></html>
sage: _
17
sage: 23
23
sage: _
17

The relevant function seems to be pretty_print in /sage/misc/latex.py, but I don't know the right way to fix it. The function and pretty_print_default in same file, and the functions displayhook and install in /sage/misc/displayhook.py may also be relevant.

Attachments (1)

trac_9683.patch (925 bytes) - added by mhansen 8 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 9 years ago by iandrus

In the ipython displayhook it checks to see if underscore was set explicitly and if so, it stops tracking. We are setting it explicitly in pretty_print. Maybe if we just stop doing this it will work. Also we probably need to fix pretty_print_default to set it to the ipython displayhook instead of the default one.

    def check_for_underscore(self):
        """Check if the user has set the '_' variable by hand."""
        # If something injected a '_' variable in __builtin__, delete
        # ipython's automatic one so we don't clobber that.  gettext() in
        # particular uses _, so we need to stay away from it.
        if '_' in __builtin__.__dict__:
            try:
                del self.shell.user_ns['_']
            except KeyError:
                pass

Changed 8 years ago by mhansen

comment:2 Changed 8 years ago by mhansen

  • Authors set to Mike Hansen
  • Status changed from new to needs_review

I've posted a patch. It doesn't have a test for this problem. I could make one, but it's slightly annoying since you have to do everything indirectly through an IPython shell object.

comment:3 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:4 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:5 Changed 8 years ago by vbraun

  • Branch set to u/vbraun/pretty_print_clobbers____history_

comment:6 Changed 8 years ago by vbraun

  • Commit set to 3cc45a855a6be42cd9b0bdae15b6fc64d1fdf3cc
  • Keywords days57 added
  • Reviewers set to Volker Braun
  • Status changed from needs_review to positive_review

New commits:

3cc45a8#9683: pretty_print clobbers _ (history)

comment:7 Changed 8 years ago by vbraun

  • Branch changed from u/vbraun/pretty_print_clobbers____history_ to 3cc45a855a6be42cd9b0bdae15b6fc64d1fdf3cc
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.