[IPython-dev] mimetypes from format()

Jason Moore moorepants at gmail.com
Sun Dec 29 14:14:20 EST 2013


Ok this works:

In [32]: ip = get_ipython()

In [33]: inst = ip.instance()

In [34]: from sympy import Symbol, init_printing

In [35]: init_printing(use_latex=True)

In [36]: inst.display_formatter.formatters['text/latex'].enabled = True

In [37]: inst.display_formatter.format({Symbol("a"): 3.14})
Out[37]:
({u'text/latex': '$$\\begin{Bmatrix}a : 3.14\\end{Bmatrix}$$',
  u'text/plain': u'{a: 3.14}'},
 {})

Thanks, for the help!


Jason
moorepants.info
+01 530-601-9791


On Sun, Dec 29, 2013 at 2:04 PM, Jason Moore <moorepants at gmail.com> wrote:

> Thanks. I just tried this:
>
> In [16]: ip = get_ipython()
>
> In [17]: inst = ip.instance()
>
> In [18]: inst.display_formatter.formatters['text/latex'].enabled = True
>
> In [19]: inst.display_formatter.format('1.0')
> Out[19]: ({u'text/plain': "'1.0'"}, {})
>
>
> And the plaint text representation is the only that that was returned. Am
> I missing something else?
>
>
> Jason
> moorepants.info
> +01 530-601-9791
>
>
> On Sun, Dec 29, 2013 at 1:39 PM, MinRK <benjaminrk at gmail.com> wrote:
>
>> If it's a plain terminal session, only the plaintext formatter is enabled
>> by default, since no other formats are renderable. You probably just want
>> to set `display_formatter.formatters['text/latex'].enabled = True`.
>>
>>
>> On Sun, Dec 29, 2013 at 9:36 AM, Jason Moore <moorepants at gmail.com>wrote:
>>
>>> I'm having trouble figuring out how to get the DisplayFormatter to
>>> return the latex representation, in particular the format function seems to
>>> be able to return many mimetypes:
>>> http://ipython.org/ipython-doc/dev/api/generated/IPython.core.formatters.html#IPython.core.formatters.DisplayFormatter.format
>>>
>>> I'm writing this test:
>>>
>>>
>>> https://github.com/moorepants/sympy/blob/b748fae55c2cc3e973340b5e85cadd83a80f3405/sympy/interactive/tests/test_ipythonprinting.py#L59
>>>
>>> And want to verify that the 'text/plain' and 'text/latex' function as
>>> expected after changing settings in SymPy. I can only get the 'text/plain'
>>> to output from 'format()'.
>>>
>>> How do I output other mimetypes?
>>> Jason
>>> moorepants.info
>>> +01 530-601-9791
>>>
>>> _______________________________________________
>>> IPython-dev mailing list
>>> IPython-dev at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>>
>>>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20131229/716fdcfe/attachment.html>


More information about the IPython-dev mailing list