Ermolai
Ermolai

Reputation: 323

SymPy: How can i output multiple LaTex equations in one cell in Google Colab?

I am using SymPy in Google Colab. Each cell outputs only 1 pretty LaTex output. Can i have multiple pretty outputs in one cell or do i have to create a new cell for each pretty output?

Upvotes: 2

Views: 764

Answers (1)

Colton Campbell
Colton Campbell

Reputation: 300

I was struggling with this as well, but I found some information here: https://www.roelpeters.be/jupyter-notebooks-how-to-print-multiple-outputs-in-a-cell/

With your import statements, put

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'

Now you can print multiple outputs (LaTeX in this case) to the cell output. Technically this command concatenates the outputs but because we are using dataframes in this case (correct me if I'm wrong) then the output is actually placed on a new line in the cell output area.

Example

from sympy import *
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'

x = symbols('x')
f = exp(x**2);#f
df = diff(f,x);#df

f
df

I cannot guarantee this is the correct or most efficient way to implement such behavior, but it works for my purposes.

Upvotes: 5

Related Questions