Skip to content

Commit

Permalink
Add Math display support for qtconsole
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Aug 17, 2014
1 parent 614c36e commit cdf5ead
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions IPython/qt/console/rich_ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from IPython.external.qt import QtCore, QtGui

from IPython.lib.latextools import latex_to_png
from IPython.utils.path import ensure_dir_exists
from IPython.utils.traitlets import Bool
from IPython.qt.svg import save_svg, svg_to_clipboard, svg_to_image
Expand Down Expand Up @@ -126,6 +127,18 @@ def _handle_execute_result(self, msg):
jpg = decodestring(data['image/jpeg'].encode('ascii'))
self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None))
self._append_html(self.output_sep2, True)
elif 'text/latex' in data:
self._pre_image_append(msg, prompt_number)
latex = data['text/latex'].encode('ascii')
# latex_to_png takes care of handling $
latex = latex.strip('$')
png = latex_to_png(latex, wrap=True)
if png is not None:
self._append_png(png, True)
self._append_html(self.output_sep2, True)
else:
# Print plain text if png can't be generated
return super(RichIPythonWidget, self)._handle_execute_result(msg)
else:
# Default back to the plain text representation.
return super(RichIPythonWidget, self)._handle_execute_result(msg)
Expand Down

0 comments on commit cdf5ead

Please sign in to comment.