Display python runtime form results in markdown cell of ipython laptop

I have SymPy code that generates complex expressions that I want to display in a Markdown cell to discuss the result. I usually do

print sympy.latex(an_expression_i_want_to_display)

in the code cell, and I copy and paste the result into the Markdown cell between the $$ markers. Of course, this is not pleasant, because if things change in the code and in case of changes in latex expressions, they are not updated automatically in the Markdown cell. Manually updating manually is cumbersome and opens the door to errors. So, I was wondering if there is a convenient way to execute code in a Markdown cell and display its output. For example, let's pretend that something between the @@ characters will be executed and its contents displayed. For example, we could just write a Markdown cell, such as:

The outcome of blablabla is $@print sympy.latex(an_expression_i_want_to_display)@$.

and he will be translated into

The outcome of blablabla is $x + \omega$.

and it will display as

The outcome of blablabla is x + ϖ.

So the question is, what would be the easiest way (more convenient, efficient) to get things like behavior?

+4

All Articles