Skip to content
Advertisement

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement