Mac – How to enable automatic LaTeX math preview in org-mode/Emacs


I am using org-mode 8.0, Emacs 24.3, Auctex 11.87, in Windows.

I was able to use LaTeX preview functions in org-mode files by pressing Ctrl + X, Ctrl + C, Ctrl + L. However, I think it would be more useful if the math preview can be done automatically when the cursor leaves the math equation, e.g. for $$a=b+c$$, when my cursor is out of $$, Emacs should automatically enable preview. This may not be so important for .tex file, but is quite useful for org-mode, especially when you input equations during note taking, you want instantaneous preview.

I thought that latex-math-preview.el should provide such function but seems it is just another implementation of preview-latex.el.

How to enable automatic LaTeX math preview in org-mode/Emacs?

Best Answer

Hmmm...An ugly and not imperfect solution:

(define-key org-mode-map (kbd "$") (lambda ()
                                     (insert "$")
                                       (left-char 1)
                                       (if (org-inside-LaTeX-fragment-p)
                                             (right-char 2)

Anyway, it works on some degree.