Can I use variables on an IPython notebook markup cell?

Solution 1:

If you don't mind a code cell that does the job, there is a possibility without adding any extensions.

from IPython.display import Markdown as md

fr=2 #GHz

md("$f_r = %i$ GHz"%(fr))

This will show a markdown cell in a nicely LaTeX formatted output

Solution 2:

Currently, this is not possible, however there is a large discussion on this topic here https://github.com/ipython/ipython/pull/2592. The PR is currently closed, but a corresponding issue is opened https://github.com/ipython/ipython/issues/2958 and marked as wishlist.

Update

In the meantime an IPython extension has appeared which allows to render python variables in markdown cells. This extension is part of the IPython notebook extensions and works with IPython 2.x and 3.x. For a detailed description see the wiki page.

Solution 3:

It is not officially supported, but installing the python markdown extension will allow you to do so. It is part of the nbextensions, for which you will find installation instructions on their github page. Make sure you'll enable the python markdown extension using a jupyter command or the extension configurator.

Calling python variables then should work with the {{var-name}} syntax, which is described in the readme of the corresponding github page (linked in the wiki):

For example: If you set variable a in Python

a = 1.23

and write the following line in a markdown cell:

a is {{a}}

It will be displayed as:

a is 1.23

Further info on this functionality being integrated into ipython/jupyter is discussed in the issue trackers for ipython and jupyter.