Show More
@@ -62,7 +62,7 b' def can_print_latex(o):' | |||||
62 | can be printed with LaTeX. |
|
62 | can be printed with LaTeX. | |
63 | """ |
|
63 | """ | |
64 | import sympy |
|
64 | import sympy | |
65 | if isinstance(o, (list, tuple)): |
|
65 | if isinstance(o, (list, tuple, set, frozenset)): | |
66 | return all(can_print_latex(i) for i in o) |
|
66 | return all(can_print_latex(i) for i in o) | |
67 | elif isinstance(o, dict): |
|
67 | elif isinstance(o, dict): | |
68 | return all((isinstance(i, basestring) or can_print_latex(i)) and can_print_latex(o[i]) for i in o) |
|
68 | return all((isinstance(i, basestring) or can_print_latex(i)) and can_print_latex(o[i]) for i in o) | |
@@ -85,13 +85,22 b' _loaded = False' | |||||
85 |
|
85 | |||
86 | def load_ipython_extension(ip): |
|
86 | def load_ipython_extension(ip): | |
87 | """Load the extension in IPython.""" |
|
87 | """Load the extension in IPython.""" | |
|
88 | import sympy | |||
88 | global _loaded |
|
89 | global _loaded | |
89 | if not _loaded: |
|
90 | if not _loaded: | |
90 | plaintext_formatter = ip.display_formatter.formatters['text/plain'] |
|
91 | plaintext_formatter = ip.display_formatter.formatters['text/plain'] | |
91 |
|
92 | |||
92 |
for cls in (object, |
|
93 | for cls in (object, str): | |
93 | # set and frozen set are currently broken with SymPy's latex() |
|
94 | plaintext_formatter.for_type(cls, print_basic_unicode) | |
94 | # function. See http://code.google.com/p/sympy/issues/detail?id=3062. |
|
95 | ||
|
96 | printable_containers = [list, tuple] | |||
|
97 | ||||
|
98 | # set and frozen set were broken with SymPy's latex() function, but | |||
|
99 | # was fixed in the 0.7.1-git development version. See | |||
|
100 | # http://code.google.com/p/sympy/issues/detail?id=3062. | |||
|
101 | if sympy.__version__ > '0.7.1': | |||
|
102 | printable_containers += [set, frozenset] | |||
|
103 | else: | |||
95 | plaintext_formatter.for_type(cls, print_basic_unicode) |
|
104 | plaintext_formatter.for_type(cls, print_basic_unicode) | |
96 |
|
105 | |||
97 | plaintext_formatter.for_type_by_name( |
|
106 | plaintext_formatter.for_type_by_name( | |
@@ -106,7 +115,7 b' def load_ipython_extension(ip):' | |||||
106 | png_formatter.for_type_by_name( |
|
115 | png_formatter.for_type_by_name( | |
107 | 'sympy.core.basic', 'Basic', print_png |
|
116 | 'sympy.core.basic', 'Basic', print_png | |
108 | ) |
|
117 | ) | |
109 |
for cls in |
|
118 | for cls in [dict, int, long, float] + printable_containers: | |
110 | png_formatter.for_type(cls, print_png) |
|
119 | png_formatter.for_type(cls, print_png) | |
111 |
|
120 | |||
112 | latex_formatter = ip.display_formatter.formatters['text/latex'] |
|
121 | latex_formatter = ip.display_formatter.formatters['text/latex'] | |
@@ -117,7 +126,7 b' def load_ipython_extension(ip):' | |||||
117 | 'sympy.matrices.matrices', 'Matrix', print_latex |
|
126 | 'sympy.matrices.matrices', 'Matrix', print_latex | |
118 | ) |
|
127 | ) | |
119 |
|
128 | |||
120 |
for cls in |
|
129 | for cls in printable_containers: | |
121 | # Use LaTeX only if every element is printable by latex |
|
130 | # Use LaTeX only if every element is printable by latex | |
122 | latex_formatter.for_type(cls, print_latex) |
|
131 | latex_formatter.for_type(cls, print_latex) | |
123 |
|
132 |
General Comments 0
You need to be logged in to leave comments.
Login now