MCPcopy Create free account
hub / github.com/ipython/ipython / latex_to_png_mpl

Function latex_to_png_mpl

IPython/lib/latextools.py:110–129  ·  view source on GitHub ↗
(s, wrap, color='Black', scale=1.0)

Source from the content-addressed store, hash-verified

108
109
110def latex_to_png_mpl(s, wrap, color='Black', scale=1.0):
111 try:
112 from matplotlib import mathtext
113 from pyparsing import ParseFatalException
114 except ImportError:
115 return None
116
117 # mpl mathtext doesn't support display math, force inline
118 s = s.replace('$$', '$')
119 if wrap:
120 s = u'${0}$'.format(s)
121
122 try:
123 mt = mathtext.MathTextParser('bitmap')
124 f = BytesIO()
125 dpi = 120*scale
126 mt.to_png(f, s, fontsize=12, dpi=dpi, color=color)
127 return f.getvalue()
128 except (ValueError, RuntimeError, ParseFatalException):
129 return None
130
131
132def latex_to_png_dvipng(s, wrap, color='Black', scale=1.0):

Callers

nothing calls this directly

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected