##// END OF EJS Templates
support latex in display messages in qt
Min RK -
Show More
@@ -153,20 +153,29 b' class RichIPythonWidget(IPythonWidget):'
153 153 metadata = msg['content']['metadata']
154 154 # Try to use the svg or html representations.
155 155 # FIXME: Is this the right ordering of things to try?
156 self.log.debug("display: %s", msg.get('content', ''))
156 157 if 'image/svg+xml' in data:
157 self.log.debug("display: %s", msg.get('content', ''))
158 158 svg = data['image/svg+xml']
159 159 self._append_svg(svg, True)
160 160 elif 'image/png' in data:
161 self.log.debug("display: %s", msg.get('content', ''))
162 161 # PNG data is base64 encoded as it passes over the network
163 162 # in a JSON structure so we decode it.
164 163 png = decodestring(data['image/png'].encode('ascii'))
165 164 self._append_png(png, True, metadata=metadata.get('image/png', None))
166 165 elif 'image/jpeg' in data and self._jpg_supported:
167 self.log.debug("display: %s", msg.get('content', ''))
168 166 jpg = decodestring(data['image/jpeg'].encode('ascii'))
169 167 self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None))
168 elif 'text/latex' in data:
169 try:
170 png = latex_to_png(data['text/latex'], wrap=False)
171 except Exception:
172 self.log.error("Failed to render latex: %r", data['text/latex'], exc_info=True)
173 png = None
174 if png is not None:
175 self._append_png(png, True)
176 else:
177 # Print plain text if png can't be generated
178 return super(RichIPythonWidget, self)._handle_display_data(msg)
170 179 else:
171 180 # Default back to the plain text representation.
172 181 return super(RichIPythonWidget, self)._handle_display_data(msg)
General Comments 0
You need to be logged in to leave comments. Login now