12
votes

How can user macros and packages be included in the latex rendered in markdown cells in ipython?

e.g.:

\usepackage{amssymb}
\newcommand{kms}{\ensuremath{\mathrm{km~s}^{-1}}
2
I'm curious. Have you found a way to do this? - jmbejara

2 Answers

6
votes

It is possible to define macros in cells with markdown. Just put the \newcommand between $'s:

$\newcommand{kms}{{\mathrm{km~s}^{-1}}}$

(Note that I removed the \ensuremath command, as it is not accessible.)

In any following statement (in the whole notebook) you can call the macro (in a markdown cell only, of course):

$\kms$

I do not know a way to include extra packages :( If you ever learn how, I would also encourage you to use the siuntx package to format units.

2
votes

The Html notebook use mathjax to render LaTeX, I suggest reading its doc to know wether it is possible and how.