Skip to content

@rlamy /gist:4170308
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Strings with embedded LaTeX in IPython
from string import Formatter
from sympy import latex
class LatexFormatter(Formatter):
def convert_field(self, value, conversion):
if conversion == 'L':
try:
return value._repr_latex()
except AttributeError:
return latex(value)
else:
return super(LatexFormatter, self).convert_field(value, conversion)
def vformat(self, *args):
latex_string = super(LatexFormatter, self).vformat(*args)
return Latex(latex_string)
format_latex = LatexFormatter().format
# Example
from sympy import pi
format_latex('With $\\tt sympy$, to get ${x!L}$, type $\\tt {x!s}$', x=pi**2/6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.