Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display sympy expressions in latex using pycharm/ipython

I am using SymPy and the scientific mode of PyCharm for symbolic calculations.

I would like to display latex code for printed out expressions in the integrated console. Using qtconsole this works fine, but i don't know how to make this work in the PyCharm console. I use sympy.init_printing() but the equations often look messy and are hard to read. Sympy also can convert symbolic expressions into strings containing the latex code.

so i would only need to know how to display the compiled latex expression, although it would be more convenient to make it work directly like in qtconsole.

I am using PyCharm 2019.3.1 with python 3.8.1 and the ipython console.

Does anyone know how to do this?

like image 647
depletedboi Avatar asked Jan 06 '20 23:01

depletedboi


1 Answers

Assuming I understand your question correctly, this can be done using display from IPython:

import sympy as sym
from IPython.display import display

x, a, b = sym.symbols('x a b')
func = (a*x**b)/(a+b)

display(func)

This will print the compiled LaTeX .

like image 101
Pascià Avatar answered Nov 10 '22 09:11

Pascià