##// END OF EJS Templates
Update posix process piping to use pexpect-u with a unicode interface.
Update posix process piping to use pexpect-u with a unicode interface.

File last commit:

r4888:1326c3f6
r5432:8ceb9ae0
Show More
sympyprinting.py
98 lines | 2.9 KiB | text/x-python | PythonLexer
Pauli Virtanen
DOC: extensions: add documentation for the bundled extensions
r4888 """
A print function that pretty prints sympy Basic objects.
:moduleauthor: Brian Granger
Usage
=====
Once the extension is loaded, Sympy Basic objects are automatically
pretty-printed.
Brian Granger
Display system is fully working now....
r3278
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Brian Granger
More improvements to the display system....
r3279 from IPython.lib.latextools import latex_to_png
Paul Ivanov
skip sympy tests if sympy not installed
r3504 from IPython.testing import decorators as dec
Paul Ivanov
removed skipif decorators from non-tests
r3507 # use @dec.skipif_not_sympy to skip tests requiring sympy
Paul Ivanov
skip sympy tests if sympy not installed
r3504
try:
from sympy import pretty, latex
except ImportError:
pass
Brian Granger
More improvements to the display system....
r3279
Brian Granger
Display system is fully working now....
r3278
#-----------------------------------------------------------------------------
# Definitions of magic functions for use with IPython
#-----------------------------------------------------------------------------
def print_basic_unicode(o, p, cycle):
"""A function to pretty print sympy Basic objects."""
if cycle:
return p.text('Basic(...)')
out = pretty(o, use_unicode=True)
if '\n' in out:
p.text(u'\n')
p.text(out)
Brian Granger
More improvements to the display system....
r3279 def print_png(o):
Brian Granger
Renaming the special methods of the formatters....
r3878 """A function to display sympy expression using LaTex -> PNG."""
Brian Granger
Using inline mode for rendering sympy Expr to latex.
r3283 s = latex(o, mode='inline')
Brian Granger
Fixing Matrix/overbar printing for sympy.
r3285 # mathtext does not understand certain latex flags, so we try to replace
# them with suitable subs.
Brian Granger
Small fixes for latex/png printing....
r3284 s = s.replace('\\operatorname','')
Brian Granger
Fixing Matrix/overbar printing for sympy.
r3285 s = s.replace('\\overline', '\\bar')
Brian Granger
Misc updates the display system....
r3880 png = latex_to_png(s)
Brian Granger
More improvements to the display system....
r3279 return png
Brian Granger
Initial latex printing for sympy and fixes to autogrow.
r4316
def print_latex(o):
"""A function to generate the latex representation of sympy expressions."""
s = latex(o, mode='equation', itex=True)
Brian Granger
Minor fix to sympy latex printing....
r4327 s = s.replace('\\dag','\\dagger')
Brian Granger
Initial latex printing for sympy and fixes to autogrow.
r4316 return s
Brian Granger
Display system is fully working now....
r3278 _loaded = False
def load_ipython_extension(ip):
"""Load the extension in IPython."""
global _loaded
if not _loaded:
plaintext_formatter = ip.display_formatter.formatters['text/plain']
Brian E. Granger
Adding basic types (list, dict ,etc) to the sympy profile....
r4270
for cls in (object, tuple, list, set, frozenset, dict, str):
plaintext_formatter.for_type(cls, print_basic_unicode)
Brian Granger
Display system is fully working now....
r3278 plaintext_formatter.for_type_by_name(
'sympy.core.basic', 'Basic', print_basic_unicode
)
Brian Granger
Fixing Matrix/overbar printing for sympy.
r3285 plaintext_formatter.for_type_by_name(
'sympy.matrices.matrices', 'Matrix', print_basic_unicode
)
Brian Granger
More improvements to the display system....
r3279 png_formatter = ip.display_formatter.formatters['image/png']
Brian E. Granger
Adding basic types (list, dict ,etc) to the sympy profile....
r4270
Brian Granger
More improvements to the display system....
r3279 png_formatter.for_type_by_name(
'sympy.core.basic', 'Basic', print_png
)
Brian Granger
Initial latex printing for sympy and fixes to autogrow.
r4316
latex_formatter = ip.display_formatter.formatters['text/latex']
latex_formatter.for_type_by_name(
'sympy.core.basic', 'Basic', print_latex
)
latex_formatter.for_type_by_name(
'sympy.matrices.matrices', 'Matrix', print_latex
)
Brian Granger
Display system is fully working now....
r3278 _loaded = True