2

How do you get iPython to output results using latex?

For example, like on this page: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/master/examples/notebooks/SymPy%20Examples.ipynb

If I execute the code:

Rational(3,2)*pi + exp(I*x) / (x**2 + y)

I get output:

Out[13]: 3*pi/2 + exp(I*x)/(x**2 + y)

I want to see output in latex as shown in the link above.

2
  • Did you run all the imports include at that link? Commented Oct 19, 2013 at 20:38
  • docs.sympy.org/dev/modules/… Commented Oct 19, 2013 at 20:38

2 Answers 2

7

An updated answer for those googlers:

from IPython.display import Math
Math('3 \cdot \\frac{\pi}{2} + e^{\\frac{I*x}{x^2 + y}}')

A bit more clumsy than SymPy, but doesn't need an extra package.

Sign up to request clarification or add additional context in comments.

Comments

3

As done in the link you posted and mentioned by @tcaswell you need to "activate" the latex printing using

from sympy.interactive import printing
printing.init_printing(use_latex=True)

the use_latex=True statement is required with sympy 0.7.2 but not with 0.7.3.

1 Comment

The issue in my case was i had an older version of sympy, but your answer led me to checking what version i had and updating my sympy and it now works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.