Skip to content

Commit

Permalink
Use LaTeX to print various built-in types with the SymPy printing ext…
Browse files Browse the repository at this point in the history
…ension

SymPy's latex() function supports printing lists, tuples, and dicts using
latex notation (it uses bmatrix, pmatrix, and Bmatrix, respectively).  This
provides a more unified experience with SymPy functions that return these
types (such as solve()).

Also print ints, longs, and floats using LaTeX, to get a more unified printing
experience (so that, e.g., `x/x` will print the same as just `1`).  The string
form can always be obtained by using `print`, or 2d unicode printing using
pprint().

SymPy's latex() function doesn't treat set() or frosenset() correctly
presently (see http://code.google.com/p/sympy/issues/detail?id=3062), so for
the present, we leave those alone.

Currently, the printing of lists, tuples, and dicts does not work correctly in
the qtconsole.
  • Loading branch information
asmeurer committed Feb 12, 2012
1 parent 920beab commit e21221c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions IPython/extensions/sympyprinting.py
Expand Up @@ -72,7 +72,7 @@ def load_ipython_extension(ip):
if not _loaded:
plaintext_formatter = ip.display_formatter.formatters['text/plain']

for cls in (object, tuple, list, set, frozenset, dict, str):
for cls in (object, set, frozenset, str):
plaintext_formatter.for_type(cls, print_basic_unicode)

plaintext_formatter.for_type_by_name(
Expand All @@ -87,6 +87,8 @@ def load_ipython_extension(ip):
png_formatter.for_type_by_name(
'sympy.core.basic', 'Basic', print_png
)
for cls in (list, tuple, dict, int, long, float):
png_formatter.for_type(cls, print_png)

latex_formatter = ip.display_formatter.formatters['text/latex']
latex_formatter.for_type_by_name(
Expand All @@ -95,5 +97,7 @@ def load_ipython_extension(ip):
latex_formatter.for_type_by_name(
'sympy.matrices.matrices', 'Matrix', print_latex
)
_loaded = True
for cls in (list, tuple, dict, int, long, float):
latex_formatter.for_type(cls, print_latex)

_loaded = True

0 comments on commit e21221c

Please sign in to comment.