5

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?

Amit
  • 19,780
  • 6
  • 46
  • 54
Christian O'Reilly
  • 1,864
  • 3
  • 18
  • 33
  • 1
    We're wary of adding something like that because it means making up yet more custom Markdown syntax. Maybe once Commonmark has worked out a standard extension mechanism for Markdown, we'll have a go at it. In the meantime, it's probably possible as a frontend extension, but it might be tricky to write. – Thomas K Jan 22 '15 at 19:18
  • I want to implement notebook as a backend to sympy. Currently there is a PR in sympy Gamma to export notebook , but I want a better solution. But this might take a couple of weeks. – sahil shekhawat Jan 23 '15 at 09:15
  • 1
    There is an open issue in IPython to implement this https://github.com/ipython/ipython/issues/2958. – asmeurer Jan 25 '15 at 19:21

0 Answers0