Can init_printing() be forced to print mathjax/latex in a "dumb" console?

366 views
Skip to first unread message

singlets

unread,
Jul 24, 2016, 4:44:17 PM7/24/16
to sympy
(Probably a newbie question here, but not finding it in ggroup or docs)

Can I convince init_printing() to give the mathjax/latex representation of an expression in an IPython terminal session without using latex(expr)?

For example (Anaconda/python3, linux, sympy 1.0 in an xterm or emacs console):

from sympy import *
init_printing(use_latex='mathjax')
var('x')
expr = x**2
expr

desired output:
x^{2}

I have tried various options to init_printing() like use_latex=True, use_latex='mathjax', 'matplotlib', etc., but sympy falls back to simple forms (str, pretty-printers) unless in a qtconsole or notebook. I must be misunderstanding how init_printing() works (or maybe there's another approach I should be using?).

Motivation: I'm using org mode and it's support for mathjax/latex to generate content that can be migrated directly into Jupyter notebooks. I'm hoping to avoid translating latex(expr) into expr everywhere.

Thanks,
Steve

Aaron Meurer

unread,
Jul 24, 2016, 5:56:19 PM7/24/16
to sy...@googlegroups.com
I believe you can set str_printer=latex.

Aaron Meurer 
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/9f4b3633-77b2-41b7-826b-64c09355be70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Meurer

unread,
Jul 24, 2016, 6:05:52 PM7/24/16
to sy...@googlegroups.com
I believe you can set str_printer=latex.

Aaron Meurer 

On Sunday, July 24, 2016, singlets <ssin...@coe.edu> wrote:

singlets

unread,
Jul 24, 2016, 6:30:45 PM7/24/16
to sympy


On Sunday, July 24, 2016 at 5:05:52 PM UTC-5, Aaron Meurer wrote:
I believe you can set str_printer=latex.

I gave this a go with no joy:

In [1]: from sympy import *

In [2]: init_printing(str_printer=latex)

In [3]: var('x')
Out[3]: x

In [4]: x**2
Out[4]:
 2
x

Thanks,
Steve
 

singlets

unread,
Jul 24, 2016, 6:54:43 PM7/24/16
to sympy


On Sunday, July 24, 2016 at 5:30:45 PM UTC-5, singlets wrote:


On Sunday, July 24, 2016 at 5:05:52 PM UTC-5, Aaron Meurer wrote:
I believe you can set str_printer=latex.

I gave this a go with no joy:

In [1]: from sympy import *

In [2]: init_printing(str_printer=latex)

In [3]: var('x')
Out[3]: x

In [4]: x**2
Out[4]:
 2
x

Thanks,
Steve

But this looks promising:

In [2]: from sympy import *

In [3]: init_printing(pretty_printer=latex)

In [4]: var('x')
Out[4]: x

In [5]: x**2
Out[5]: x^{2}

Thanks for pointer,
Steve
 

Aaron Meurer

unread,
Jul 25, 2016, 8:49:07 AM7/25/16
to sy...@googlegroups.com
I see. I guess for str_printer to work you need
init_printing(str_printer=latex, pretty_print=False). I would at least
expect str_printer to change the output of str(), but it doesn't seem
to affect it.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/d8629428-04b7-4dac-852d-7dbb09935766%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages