[IPython-User] Notebook, mathjax, string substitution

Matthias BUSSONNIER bussonniermatthias@gmail....
Wed Oct 2 11:17:31 CDT 2013


Le 2 oct. 2013 à 18:05, Derek O'Connell a écrit :

> myn=3
> Math('F(k) = \int_{-\infty}^{\infty} f(x) e^{{{{myn}}}\pi i k} 
> dx'.format(myn=99))

{...} -> interpolated
{{...}} -> as is with 1 pair of bracket around
{{{...}}} -> interpolated with one pair of bracket around

>>> '{foo}'.format(foo=1)
'1'
>>> '{{foo}}'.format(foo=1)
'{foo}'
>>> '{{{foo}}}'.format(foo=1)
'{1}'
>>> '{{{{foo}}}}'.format(foo=1)
'{{foo}}'
>>> '{{{{{foo}}}}}'.format(foo=1)
'{{1}}'
>>> '{{{{{{foo}}}}}}'.format(foo=1)
'{{{foo}}}'
>>>

>>> print r'F(k) = \int_{{-\infty}}^{{\infty}} f(x) e^{{{{{myn}}}\pi i k}}'.format(myn=r'\infty')
F(k) = \int_{-\infty}^{\infty} f(x) e^{{\infty}\pi i k}
>>> print r'F(k) = \int_{{-\infty}}^{{\infty}} f(x) e^{{{{{myn}}}\pi i k}}'.format(myn=18)
F(k) = \int_{-\infty}^{\infty} f(x) e^{{18}\pi i k}
>>> print r'F(k) = \int_{{-\infty}}^{{\infty}} f(x) e^{{{{{myn}}}\pi i k}}'.format(myn='18\over3')
F(k) = \int_{-\infty}^{\infty} f(x) e^{{18\over3}\pi i k}

should then work. basically you need 2n or 2n+1 bracket depending on wether you want the value
to be captured by .format or not, n being the number of final bracket you want.
--
M


More information about the IPython-User mailing list