I'm a beginner when it comes to Emacs (Lisp) but the following seems to work (at least for me). I'm also using the Spacemacs configuration framework so there's a possibility of some stuff being Spacemacs-only (feel free to edit such stuff).
For those not yet familiar with imaxima, it's an Emacs package that comes prepackaged with Maxima. To start using it, add the folder in which the scripts reside to your
load-path and load the necessary files, like this (you may have to adapt the path) (taken from the Emacs Wiki):
(add-to-list 'load-path "/usr/local/share/maxima/5.18.1/emacs/")
(autoload 'imaxima "imaxima" "Frontend for maxima with Image support" t)
(autoload 'imath-mode "imath" "Imath mode for math formula input" t)
You'll also want to set a few variables since the rendered output is pretty small (at least to me) and because you want imaxima to use the *maxima* buffer:
(setq imaxima-use-maxima-mode-flag t)
(setq imaxima-fnt-size "large")
(setq imaxima-pt-size 12)
From my experimenting and poking around, I conluded that
imaxima-use-maxima-mode-flag only makes imaxima use the *maxima* buffer instead of its own *imaxima*. That's pretty much it.
Now, if maxima hasn't been started,
imaxima will start maxima, switch to *maxima* (assuming
imaxima-use-maxima-mode-flag has been set) and load the appropriate code that is used to render the LaTeX maxima outputs.
However, if maxima has been already been started using
maxima-start (which is automatically run for you when you call
maxima-display-buffer and maxima isn't running),
imaxima will do nothing but switch to the *maxima* buffer (again, assuming
imaxima-use-maxima-mode-flag has been set), i.e. the LaTeX rendering code won't be loaded (unless you loaded it yourself manually or something).
The solution to this is to always run
imaxima (with the
imaxima-use-maxima-mode-flag set) first and only then run
maxima-display-buffer. Since the flag is active,
imaxima will start and load the necessary code inside *maxima* which
maxima-display-buffer will subsequently switch to and to which other
maxima-* commands will send expressions to.
maxima-display-buffer is bound to
C-c C-p and I've bound
C-c C-o with the following code:
(define-key maxima-mode-map (kbd "C-c C-o") 'imaxima)))
I tried redefining the original
maxima-display-buffer to first run
imaxima and then the original
maxima-display-buffer but I failed. I'm not really sure how to go about doing that yet so if anyone has any ideas, feel free to comment/edit this answer.
For now, whenever I want to interactively evaluate maxima code I'll first run
C-c C-o) and only after that use the
maxima-* commands (such as