[IPython-dev] [IPython-User] Runtime selection of the default pretty display

Matthias Bussonnier bussonniermatthias at gmail.com
Mon Jun 2 03:46:28 EDT 2014


Le 2 juin 2014 à 03:30, Aaron Meurer a écrit :

> This sort of thing has come up in the context of SymPy before as well.
> SymPy can render equations using MathJax, but it can also render them
> as png using LaTeX itself (if it is installed). The notebook always
> prefers MathJax to png, so the only way to force png output is to not
> include the mathjax output, which is what
> sympy.init_printing(use_latex='png') does. But this is obviously not
> ideal (if something else pulls the latex off an object, it will think
> that these objects don't have that representation). So I definitely
> think there should be a way to change IPython's preferred order of
> printing for different front ends.

But this shouldn't come from the library side but from the specific frontend you are using. 
And for having thought of this many time you always end up in an infinite number of layer where
you want to overwrite the preference in the previous layer.

Also technically in the notebook it is not super hard to implement on a user-facing drop down. 

The display priority is exposed as the following in javascript. 
IPython.OutputArea.display_order // ["application/javascript", "text/html", "text/markdown", "text/latex", "image/svg+xml", "image/png", "image/jpeg", "application/pdf", "text/plain"]
Just monkey-patch it, Sympy will compute all and notebook store all, but display only the first.

-- 
M



> 
> Aaron Meurer
> 
> On Sun, Jun 1, 2014 at 3:42 PM, Akim Demaille <akim at lrde.epita.fr> wrote:
>> 
>> Le 1 juin 2014 à 22:11, Matthias Bussonnier <bussonniermatthias at gmail.com> a écrit :
>> 
>>> Hi Akim.
>> 
>> hi!
>> 
>>>>>> So what I'd like is a means to control which _repr_ IPython's
>>>>>> display will chose.  Is there such a feature?
>>>>> 
>>>>> No, there is not.
>>>> 
>>>> Do you think that would be useful?
>>> 
>>> No it is by design. If you need the functionality, you are probably misunderstanding the way it works.
>>> As a library author you shouldn't decide for the user, if the user really want to change, he/she import
>>> display_whatever from IPython.display and call it on your object. Any tentative to do something else,
>>> will break things in weird ways.
>> 
>> Well, I think I agree with what you are saying, but let me
>> reemphasize that my problem here is rendering automata.
>> Small automata should be rendered with _repr_svg_, bigger
>> ones should just display some metrics by default, such as
>> their size.  So I would have _repr_svg_ return None in such
>> a case.  And that's a means to control which _repr_ will
>> chose.  Except that it's decentralized: the logic of which
>> _repr_ is 'enabled' is spread in each one of them.  As a
>> library author I do not want to prevent what the user
>> will see, I'm trying to provide them with the best _default_
>> behavior possible.
>> 
>> _repr_widget_ would be my best bet currently, as it allows
>> me to select the best default behavior, and leave at the user
>> the choice to select other formats.
>> 
>> (And btw, I'm not pushing my users to call IPython.display
>> at all, I'm really referring to the default display of values).
>> _______________________________________________
>> IPython-User mailing list
>> IPython-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-user
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev




More information about the IPython-dev mailing list