Fixed that MathJax works in preview, but not in page display

Use proper hooks, inspired by SmoothGallery extension