[IPython-User] Printing a string and latex together in a notebook
Matthias BUSSONNIER
bussonniermatthias@gmail....
Mon Nov 19 03:39:37 CST 2012
Le 19 nov. 2012 à 09:07, Aaron Meurer a écrit :
> On Mon, Nov 19, 2012 at 12:46 AM, Matthias BUSSONNIER <bussonniermatthias@gmail.com> wrote:
>
> > 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).
>
> I understand better now.
> This could be a good project for json plugin.
>
> > 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
> >
> > 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).
>
> Good point.
>
> > Also, would this allow arbitrary code to be executed, or just variable names?
>
> To make it work with any code could be done easily.
> Though I would like to avoid side effect, and nothing prevent you from precomputing part of the string in the previous code-cell.
>
> Arbitrary code vs. variables has nothing to do with side-effects. str(obj) (i.e., obj.__str__) already allows arbitrary code execution.
Yes, Side effect might have been a bad chosen word.
> I think it matters more from a parsing side, and also from a conceptual side. If you really want to avoid side-effects, you could require that the variable be a str.
I think it will be a little difficult, because you would have to precompute the Tex/Latex/.. repr in different variable,
like explicitly say tex_x = latex(x), then use ::tex_x::. Whereas I think you should be able to just ask for ::tex::x:: or ::html::x:: ...
> If you do that, you might even be able to do some smart caching to avoid additional calls to the kernel.
Maybe, but I think this could be implemented in a separate manner than displaying.
>
> By the way, if x changes, would ::x:: update automatically, or only when the Markdown cell is "reexecuted"? If you want the former without side-effects, again you will want to restrict to str objects only.
Only when the md cell is re-rendered.
You can have a look at the PR:
https://github.com/ipython/ipython/pull/2592
I'll be happy to get you feedback and discuss modification.
--
Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20121119/47925d79/attachment.html
More information about the IPython-User
mailing list