Vlas Sokolov Vlas Sokolov - 18 days ago 7
LaTeX Question

Display an astropy Quantity within a LaTeX string

I'm looking for a way to render

astropy
variables inside LaTeX strings within an IPython notebook. For example, given a simple premise,

from astropy.constants import c
import astropy.units as u
from astropy import log


the speed of light is beautifully rendered by default as:

latex-rendering

by simply typing it in the ipython prompt. Now, what if I would like to embed this in a string? How to hop on the same rendering train already used by astropy to print an example string like
'Speed limit: {}'.format(c)
?

Everything I've tried so far, including variations of LaTeX-formatted strings, only displays an ASCII string as an output:
ascii-rendering

Answer

There is probably a more elegant solution, but this works: enter image description here