re-used mathjax <-> self_contained logic