# [IPython-User] Notebook, mathjax, string substitution

Derek O'Connell doc@doconnel.f9.co...
Wed Oct 2 16:58:29 CDT 2013

On 02/10/13 17:17, Matthias BUSSONNIER wrote:
> 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
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

Got it, thanks Matthias!