ipython notebook, sympy, latex, and mathjax

2,461 views
Skip to first unread message

lutusp

unread,
Feb 4, 2012, 4:35:11 AM2/4/12
to sy...@googlegroups.com
The sympy sampler located at http://live.sympy.org/ has an option setting to allow cell output to be rendered as plain text, unicode and latex (rendered by way of mathjax. But it seems the ipython notebook does have this feature (or I can't find it).

It would be a nice enhancement to allow this output-format option in the ipython notebook and the qtconsole. Or have I just missed it?

Brian Granger

unread,
Feb 6, 2012, 6:38:43 PM2/6/12
to sy...@googlegroups.com
To enable MathJax printing in the notebook do:

* Start with the sympy profile:

ipython notebook --profile sympy

OR

* Load the sympyprinting extension in a notebook:

%load_ext sympyprinting

Cheers,

Brian

> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/GgaOYkjX7joJ.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

--
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgra...@calpoly.edu and elli...@gmail.com

lutusp

unread,
Feb 11, 2012, 2:01:49 PM2/11/12
to sy...@googlegroups.com, elli...@gmail.com
To enable MathJax printing in the notebook do:

* Start with the sympy profile:

ipython notebook --profile sympy

OR

* Load the sympyprinting extension in a notebook:

%load_ext sympyprinting


Yes, I've tried both. Since my original post, I've uncovered more detail -- neither of the above remedies work for "solve()", although virtually all other cases are rendered as LaTeX. Here is some example output. It's clear that the first example is being rendered by MathJax based on embedded LaTeX strings, but the second relies on a different renderer, which defaults to a Unicode font rather than LaTeX rendering.

I have done quite a lot of online searching, but I can't find a reference to this specific issue. Thanks for reading!

someone

unread,
Feb 11, 2012, 2:24:04 PM2/11/12
to sy...@googlegroups.com
Hi,

> > * Load the sympyprinting extension in a notebook:
> >
> > %load_ext sympyprinting
> >
>
> Yes, I've tried both. Since my original post, I've uncovered more
> detail -- neither of the above remedies work for "solve()", although
> virtually all other cases are rendered as LaTeX. Here is some example

> output.<http://i.imgur.com/oA5R2.png>It's clear that the first


> example is being rendered by MathJax based on embedded LaTeX strings,
> but the second relies on a different renderer, which defaults to a
> Unicode font rather than LaTeX rendering.

Yes, I know the problem. It occurs when the output is a list or tuple.
And I assumed this to be a bug in the sympyprt extension not recognising
expressions if they are not on the top level in the expression tree.
For true latex rendering in the notebook I use the script from:

http://research.scios.ch/inet/doku.php?id=ipy_tex

which works quite well up to this bug. Interesting to hear that
the same bug hits the mathjax rendering. (Hence it is probably
not in this script but somewhere deeper.)

Aaron Meurer

unread,
Feb 11, 2012, 10:37:52 PM2/11/12
to sy...@googlegroups.com
No, the problem is definitely in the sympyprinting IPython extension.
If you look at the IPython source code
(IPython/extensions/sympyprinting.py), you can see that it's passing
all container types to the unicode pretty printer. But it should be
passing at least list, tuple, and dict to latex(), which converts
these the proper Matrix type to print big [], (), and {} (apparently
set and frozenset are not rendered correctly, by the way; I'll open a
SymPy issue for this).

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups "sympy" group.

Aaron Meurer

unread,
Feb 11, 2012, 11:10:24 PM2/11/12
to sy...@googlegroups.com
I submitted a pull request to IPython to fix this:
https://github.com/ipython/ipython/pull/1399. I also opened
http://code.google.com/p/sympy/issues/detail?id=3062 about the set()
problem.

Aaron Meurer

hm70

unread,
Feb 17, 2012, 12:11:33 PM2/17/12
to sympy
I recommend the extension http://research.scios.ch/inet/doku.php?id=sympyprt

Place it into the IPython extension directory and
%load_ext sympyprt

It has a picture cache and various options to display the output.
Greets Hans

hm70

unread,
Feb 17, 2012, 7:31:32 PM2/17/12
to sympy
By the way, some links for sample output of the aforementioned script.
The code is in sympyprt.py_

http://edu.scios.ch/sympy/qt_sample_sympy.html
http://edu.scios.ch/sympy/nb_sample_sympy.ipynb
http://edu.scios.ch/sympy/sympyprt.py_

One should have the following LaTeX packages installed (otherwise it
won't work):
self.default_template = r'''\documentclass[%ipt]{article}
\usepackage{amssymb,amsmath,bm,color}
\usepackage[latin1]{inputenc}
\usepackage{flexisym}
\usepackage{breqn}
\pagestyle{empty}
\begin{document}
%s
\end{document}'''

One may edit the above preamble in the sympyprt.py code since some
packages doesn't seem necessary.


On 17 Feb., 18:11, hm70 <hans.mose...@gmx.at> wrote:
> I recommend the extensionhttp://research.scios.ch/inet/doku.php?id=sympyprt
Reply all
Reply to author
Forward
0 new messages