##// END OF EJS Templates
Misc updates the display system....
Brian Granger -
Show More
@@ -449,6 +449,10 class HTMLFormatter(BaseFormatter):
449 449 objects, define a :meth:`_repr_html_` method or use the :meth:`for_type`
450 450 or :meth:`for_type_by_name` methods to register functions that handle
451 451 this.
452
453 The return value of this formatter should be a valid HTML snippet that
454 could be injected into an existing DOM. It should *not* include the
455 ```<html>`` or ```<body>`` tags.
452 456 """
453 457 format_type = Str('text/html')
454 458
@@ -462,6 +466,10 class SVGFormatter(BaseFormatter):
462 466 objects, define a :meth:`_repr_svg_` method or use the :meth:`for_type`
463 467 or :meth:`for_type_by_name` methods to register functions that handle
464 468 this.
469
470 The return value of this formatter should be valid SVG enclosed in
471 ```<svg>``` tags, that could be injected into an existing DOM. It should
472 *not* include the ```<html>`` or ```<body>`` tags.
465 473 """
466 474 format_type = Str('image/svg+xml')
467 475
@@ -476,7 +484,8 class PNGFormatter(BaseFormatter):
476 484 or :meth:`for_type_by_name` methods to register functions that handle
477 485 this.
478 486
479 The raw data should be the base64 encoded raw png data.
487 The return value of this formatter should be raw PNG data, *not*
488 base64 encoded.
480 489 """
481 490 format_type = Str('image/png')
482 491
@@ -490,6 +499,9 class LatexFormatter(BaseFormatter):
490 499 objects, define a :meth:`_repr_latex_` method or use the :meth:`for_type`
491 500 or :meth:`for_type_by_name` methods to register functions that handle
492 501 this.
502
503 The return value of this formatter should be a valid LaTeX equation,
504 enclosed in either ```$``` or ```$$```.
493 505 """
494 506 format_type = Str('text/latex')
495 507
@@ -503,6 +515,8 class JSONFormatter(BaseFormatter):
503 515 your objects, define a :meth:`_repr_json_` method or use the :meth:`for_type`
504 516 or :meth:`for_type_by_name` methods to register functions that handle
505 517 this.
518
519 The return value of this formatter should be a valid JSON string.
506 520 """
507 521 format_type = Str('application/json')
508 522
@@ -516,6 +530,9 class JavascriptFormatter(BaseFormatter):
516 530 your objects, define a :meth:`_repr_javascript_` method or use the
517 531 :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
518 532 that handle this.
533
534 The return value of this formatter should be valid Javascript code and
535 should *not* be enclosed in ```<script>``` tags.
519 536 """
520 537 format_type = Str('application/javascript')
521 538
@@ -45,7 +45,7 def print_png(o):
45 45 # them with suitable subs.
46 46 s = s.replace('\\operatorname','')
47 47 s = s.replace('\\overline', '\\bar')
48 png = latex_to_png(s, encode=True)
48 png = latex_to_png(s)
49 49 return png
50 50
51 51 _loaded = False
@@ -25,7 +25,7 from base64 import encodestring
25 25 #-----------------------------------------------------------------------------
26 26
27 27
28 def latex_to_png(s, encode=True):
28 def latex_to_png(s, encode=False):
29 29 """Render a LaTeX string to PNG using matplotlib.mathtext.
30 30
31 31 Parameters
@@ -16,6 +16,7 machinery. This should thus be thought of as scaffolding.
16 16 from __future__ import print_function
17 17
18 18 # Stdlib
19 from base64 import encodestring
19 20 import inspect
20 21 import os
21 22
@@ -67,6 +68,9 class ZMQDisplayHook(DisplayHook):
67 68 self.msg['content']['execution_count'] = self.prompt_count
68 69
69 70 def write_format_data(self, format_dict):
71 pngdata = format_dict.get('image/png')
72 if pngdata is not None:
73 format_dict['image/png'] = encodestring(pngdata)
70 74 self.msg['content']['data'] = format_dict
71 75
72 76 def finish_displayhook(self):
@@ -1,9 +1,10
1 1 """Code that shows off the IPython display logic.
2 2 """
3 3
4 from IPython.lib.latextools import latex_to_png
4 5 from IPython.core.display import (
5 6 display, display_pretty, display_html,
6 display_svg, display_json
7 display_svg, display_json, display_png
7 8 )
8 9
9 10 class Circle(object):
@@ -22,3 +23,5 class Circle(object):
22 23 <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
23 24 </svg>"""
24 25
26 def _repr_png_(self):
27 return latex_to_png('$\circle$')
General Comments 0
You need to be logged in to leave comments. Login now