2

How can I setup emacs to evaluate maxima code from a buffer in maxima-mode in the *imaxima* buffer rather than the default *maxima* one?

While I can copy and paste the code between buffers, I'm afraid of crashing emacs since my natural use of emacs makes extensive use of frames.

I've tried setting:

(setq imaxima-use-maxima-mode-flag t)

following this email thread but that only made (imaxima) start a normal *maxima* repl.

1
  • From looking at Maxima code this doesn't seem to be possible (the name of the buffer holding the output of Maxima's process is hard-coded into the functions dealing with sending contents to the Maxima shell.
    – wvxvw
    Sep 29, 2015 at 7:12

1 Answer 1

3

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.

For me, maxima-display-buffer is bound to C-c C-p and I've bound imaxima to C-c C-o with the following code:

(add-hook 'maxima-mode-hook
          (lambda ()
            (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 imaxima (using C-c C-o) and only after that use the maxima-* commands (such as maxima-display-buffer, maxima-send-line, etc.).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.