Show More
@@ -1,57 +1,57 b'' | |||||
1 | """A print function that pretty prints sympy Basic objects. |
|
1 | """A print function that pretty prints sympy Basic objects. | |
2 |
|
2 | |||
3 | Authors: |
|
3 | Authors: | |
4 | * Brian Granger |
|
4 | * Brian Granger | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (C) 2008-2011 The IPython Development Team |
|
7 | # Copyright (C) 2008-2011 The IPython Development Team | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | from IPython.lib.latextools import latex_to_png |
|
17 | from IPython.lib.latextools import latex_to_png | |
18 |
|
18 | |||
19 | from sympy import pretty, latex |
|
19 | from sympy import pretty, latex | |
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Definitions of magic functions for use with IPython |
|
22 | # Definitions of magic functions for use with IPython | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | def print_basic_unicode(o, p, cycle): |
|
25 | def print_basic_unicode(o, p, cycle): | |
26 | """A function to pretty print sympy Basic objects.""" |
|
26 | """A function to pretty print sympy Basic objects.""" | |
27 | if cycle: |
|
27 | if cycle: | |
28 | return p.text('Basic(...)') |
|
28 | return p.text('Basic(...)') | |
29 | out = pretty(o, use_unicode=True) |
|
29 | out = pretty(o, use_unicode=True) | |
30 | if '\n' in out: |
|
30 | if '\n' in out: | |
31 | p.text(u'\n') |
|
31 | p.text(u'\n') | |
32 | p.text(out) |
|
32 | p.text(out) | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | def print_png(o): |
|
35 | def print_png(o): | |
36 | """A funciton to display sympy expression using LaTex -> PNG.""" |
|
36 | """A funciton to display sympy expression using LaTex -> PNG.""" | |
37 | s = latex(o) |
|
37 | s = latex(o, mode='inline') | |
38 | png = latex_to_png(s, encode=True) |
|
38 | png = latex_to_png(s, encode=True) | |
39 | return png |
|
39 | return png | |
40 |
|
40 | |||
41 | _loaded = False |
|
41 | _loaded = False | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | def load_ipython_extension(ip): |
|
44 | def load_ipython_extension(ip): | |
45 | """Load the extension in IPython.""" |
|
45 | """Load the extension in IPython.""" | |
46 | global _loaded |
|
46 | global _loaded | |
47 | if not _loaded: |
|
47 | if not _loaded: | |
48 | plaintext_formatter = ip.display_formatter.formatters['text/plain'] |
|
48 | plaintext_formatter = ip.display_formatter.formatters['text/plain'] | |
49 | plaintext_formatter.for_type_by_name( |
|
49 | plaintext_formatter.for_type_by_name( | |
50 | 'sympy.core.basic', 'Basic', print_basic_unicode |
|
50 | 'sympy.core.basic', 'Basic', print_basic_unicode | |
51 | ) |
|
51 | ) | |
52 | png_formatter = ip.display_formatter.formatters['image/png'] |
|
52 | png_formatter = ip.display_formatter.formatters['image/png'] | |
53 | png_formatter.for_type_by_name( |
|
53 | png_formatter.for_type_by_name( | |
54 | 'sympy.core.basic', 'Basic', print_png |
|
54 | 'sympy.core.basic', 'Basic', print_png | |
55 | ) |
|
55 | ) | |
56 | _loaded = True |
|
56 | _loaded = True | |
57 |
|
57 |
General Comments 0
You need to be logged in to leave comments.
Login now