[IPython-User] Printing a string and latex together in a notebook
Aaron Meurer
asmeurer@gmail....
Sun Nov 18 22:16:25 CST 2012
On Sun, Nov 18, 2012 at 3:53 PM, Matthias BUSSONNIER <
bussonniermatthias@gmail.com> wrote:
>
> 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.
>
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).
>
>
> 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).
Also, would this allow arbitrary code to be executed, or just variable
names?
Aaron Meurer
> >
> > 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
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20121118/b85ad73c/attachment-0001.html
More information about the IPython-User
mailing list