On Sun, Nov 18, 2012 at 3:53 PM, Matthias BUSSONNIER <span dir="ltr"><<a href="mailto:bussonniermatthias@gmail.com" target="_blank">bussonniermatthias@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Le 18 nov. 2012 à 22:31, Aaron Meurer a écrit :<br>
<div class="im"><br>
> Would it make sense to create (or does one already exist) a Markdown<br>
> object (or Markdown output type) which takes a string input and<br>
> renders it like a Markdown cell would? Then it would just be something<br>
> like Markdown("The answer is %s" % latex(x**2, mode='inline')) (note<br>
> that latex(mode='inline') includes the $ delimiters).<br>
<br>
</div>Not sure I fully understand, py2tex does allow to do some nice things.<br></blockquote><div><br></div><div>I mean, objects can define their own rich printing types in the notebook. Latex() renders LaTeX because it's output type is LaTeX. I am suggesting to create Markdown(), whose output type is markdown rendered text (if one does not already exist).<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
And we are also working on having the ability to do<br>
<br>
the value of x is ::x::<br>
in a markdown cell,<br>
where ::x:: will be replace by the actual repr of x in the kernel.<br>
Still thinking on the best syntax and how to choose between tex/html/.../ repr.<br>
<span class=""><font color="#888888">--<br>
Matthias<br></font></span></blockquote><div><br></div><div>That would also work, though obviously for non-trivial string manipulations, it would be better to do it directly in code (for example, appending "s" to the end of a word iff a certain variable is greater than 1).</div>
<div><br></div><div>Also, would this allow arbitrary code to be executed, or just variable names?</div><div><br></div><div>Aaron Meurer</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><font color="#888888">
</font></span><div class=""><div class="h5"><br>
><br>
> Aaron Meurer<br>
><br>
> On Nov 18, 2012, at 3:46 AM, Matthias BUSSONNIER<br>
> <<a href="mailto:bussonniermatthias@gmail.com">bussonniermatthias@gmail.com</a>> wrote:<br>
><br>
>><br>
>> Le 18 nov. 2012 à 00:40, Mike Witt a écrit :<br>
>><br>
>>> In an ipython notebook, I'd like to do something like this:<br>
>>><br>
>>> x = Symbol('x')<br>
>>> print('The answer is: $%s$' %latex(x**2))<br>
>>><br>
>>> The closest I've figured out how to get is:<br>
>>><br>
>>> print('The answer is:')<br>
>>> display(x**2)<br>
>>><br>
>>> Or something equivalent to that. I'd like to mix the string<br>
>>> and the math output on the same line, but I can't figure<br>
>>> out the syntax.<br>
>><br>
>> Hi,<br>
>> In the general case, I don't think it is super simple.<br>
>> You will have to get the function that compute the repr_tex of x**2 and use<br>
>><br>
>> from IPython.display import Latex<br>
>> Latex('your formatted latex string here')<br>
>><br>
>> In your case, sympy provide an easy way to get latex repr when possible.<br>
>> So in your case this should work (watch out for sympy.latex with lowercase L an IPython.Latex with Upper Case L)<br>
>><br>
>> from sympy import Symbol, latex<br>
>> from IPython.display import Latex<br>
>> x= Symbol('x')<br>
>> Latex(' I can have inline latex : $%s$'% latex(x**2))<br>
>><br>
>>> Note that I'm in a code cell, not a markdown cell. I want to<br>
>>> calculate the answer and then print it with informative strings<br>
>>> intermixed with the math. Is this possible?<br>
>><br>
>> This is not yet alway possible or easy, but we are working on way to improve that.<br>
>> --<br>
>> Matthias<br>
>><br>
>><br>
>>><br>
>>> -Mike<br>
>>> _______________________________________________<br>
>>> IPython-User mailing list<br>
>>> <a href="mailto:IPython-User@scipy.org">IPython-User@scipy.org</a><br>
>>> <a href="http://mail.scipy.org/mailman/listinfo/ipython-user" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-user</a><br>
>><br>
>> _______________________________________________<br>
>> IPython-User mailing list<br>
>> <a href="mailto:IPython-User@scipy.org">IPython-User@scipy.org</a><br>
>> <a href="http://mail.scipy.org/mailman/listinfo/ipython-user" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-user</a><br>
> _______________________________________________<br>
> IPython-User mailing list<br>
> <a href="mailto:IPython-User@scipy.org">IPython-User@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/ipython-user" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-user</a><br>
<br>
_______________________________________________<br>
IPython-User mailing list<br>
<a href="mailto:IPython-User@scipy.org">IPython-User@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-user" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-user</a><br>
</div></div></blockquote></div><br></div>