[IPython-User] Printing a string and latex together in a notebook
Matthias BUSSONNIER
bussonniermatthias@gmail....
Sun Nov 18 16:53:08 CST 2012
Le 18 nov. 2012 à 22:31, Aaron Meurer a écrit :
> Would it make sense to create (or does one already exist) a Markdown
> object (or Markdown output type) which takes a string input and
> renders it like a Markdown cell would? Then it would just be something
> like Markdown("The answer is %s" % latex(x**2, mode='inline')) (note
> that latex(mode='inline') includes the $ delimiters).
Not sure I fully understand, py2tex does allow to do some nice things.
And we are also working on having the ability to do
the value of x is ::x::
in a markdown cell,
where ::x:: will be replace by the actual repr of x in the kernel.
Still thinking on the best syntax and how to choose between tex/html/.../ repr.
--
Matthias
>
> Aaron Meurer
>
> On Nov 18, 2012, at 3:46 AM, Matthias BUSSONNIER
> <bussonniermatthias@gmail.com> wrote:
>
>>
>> Le 18 nov. 2012 à 00:40, Mike Witt a écrit :
>>
>>> In an ipython notebook, I'd like to do something like this:
>>>
>>> x = Symbol('x')
>>> print('The answer is: $%s$' %latex(x**2))
>>>
>>> The closest I've figured out how to get is:
>>>
>>> print('The answer is:')
>>> display(x**2)
>>>
>>> Or something equivalent to that. I'd like to mix the string
>>> and the math output on the same line, but I can't figure
>>> out the syntax.
>>
>> Hi,
>> In the general case, I don't think it is super simple.
>> You will have to get the function that compute the repr_tex of x**2 and use
>>
>> from IPython.display import Latex
>> Latex('your formatted latex string here')
>>
>> In your case, sympy provide an easy way to get latex repr when possible.
>> So in your case this should work (watch out for sympy.latex with lowercase L an IPython.Latex with Upper Case L)
>>
>> from sympy import Symbol, latex
>> from IPython.display import Latex
>> x= Symbol('x')
>> Latex(' I can have inline latex : $%s$'% latex(x**2))
>>
>>> Note that I'm in a code cell, not a markdown cell. I want to
>>> calculate the answer and then print it with informative strings
>>> intermixed with the math. Is this possible?
>>
>> This is not yet alway possible or easy, but we are working on way to improve that.
>> --
>> Matthias
>>
>>
>>>
>>> -Mike
>>> _______________________________________________
>>> IPython-User mailing list
>>> IPython-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/ipython-user
>>
>> _______________________________________________
>> IPython-User mailing list
>> IPython-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-user
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
More information about the IPython-User
mailing list