Vlas Sokolov Vlas Sokolov - 10 months ago 64
LaTeX Question

Display an astropy Quantity within a LaTeX string

I'm looking for a way to render

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:


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:

Answer Source

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