I have SymPy code that generate complex expressions that I want to display in a Markdown cell to discuss the result. Generally, I do
print sympy.latex(an_expression_i_want_to_display)
in a code cell and I copy-and-paste the result in my Markdown cell between $$ markers. Of course, this is not nice since if things are changed in the code and the latex expression change, it is not automatically updated in the Markdown cell. Updating it manually is cumbersome and opens the door to errors. So, I was wondering if there is a user-friendly way to execute code within a Markdown cell and display its output. For example, lets pretend that anything between the symbols @@ get executed and its content is displayed. For example, we could simply write a Markdown cell such as:
The outcome of blablabla is $@print sympy.latex(an_expression_i_want_to_display)@$.
and it would translate to
The outcome of blablabla is $x + \omega$.
and it would display as
The outcome of blablabla is x + ϖ.
So the question is, what would be the easiest way (the more user-friendly, efficient) to obtain such as behavior?