Embed URL


SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Strings with embedded LaTeX in IPython

View gist:4170308
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
from string import Formatter
from sympy import latex
class LatexFormatter(Formatter):
def convert_field(self, value, conversion):
if conversion == 'L':
return value._repr_latex()
except AttributeError:
return latex(value)
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.