C Y <smustudent1@yahoo.com> writes:
> Holy cow. Between this and Emaxima, we've got some seriously cool
> stuff going on here. We are so close to a notebook style interface
> it's not even funny. Guess I'll be upgrading to emacs 21.
>
> How does this work for saving/printing?
It doesn't work. As far as I know, you can't print or save a buffer with
images ... at least not easily.
To print would require that ps-print.el is aware of images (which it
isn't at the moment), and to save you'd have to invent your own file
format -- maybe that's not so hard after all.
> One question. I know the standard display for maxima is one expression
> after the other, but would it be possible in this mode to it like
> Mathematica does, i.e. being able to do something like :
>
> (C1) integrate(sin(x),x);
> (D1) -COS(x)
> (C2) diff(x^2,x);
> (D2) 2x
>
> and then be able to change the integral in place, so what you wind up
> seeing on screen is
>
> (C3) integrate(cos(x),x);
> (D3) SIN(x)
> (C2) diff(x^2,x);
> (D2) 2x
No, it doesn't work like that. The mode is basically just eye-candy for
the usual command line interface, i.e. instead of seeing the output as
ASCII graphics, you get a picture.
Let me explain a bit about how it works. When you make a
process-in-a-buffer mode, Emacs lets you specify a
preoutput-filter-function. This filter receives all output from the
process, which it can manipulate and pass on to the function that
actually inserts it in the buffer.
So I made a filter which scans the output from Maxima for LaTeX
expressions, converts them to images and attaches an image property to
the expressions. As far as Emacs is concerned all of it is still text
(some of it just happens to have an image property) and all the other
shell-like commands work as usual.
> rather than having to do a strictly linear setup - i.e. being able to
> have the result like the above as opposed to
>
> (C1) integrate(sin(x),x);
> (D1) -COS(x)
> (C2) diff(x^2,x);
> (D2) 2x
> (C3) integrate(cos(x),x);
> (D3) SIN(x)
What you *can* do today is move point to (C1), edit the expression and
press enter, but the output will appear at the bottom like above.
> Instead of presenting the user with the (C#) prompt, we could just wait
> for them to type on the next line, and when they tell it to evaluate
> then assume it is (C#), label it as such, and send it. That way, we
> would allow comments between lines, and only lines on which they use
> the evaluate command sequence would be sent to Maxima.
I don't know how difficult this would be, but it sounds somewhat similar
to what "Emacs Lisp interaction mode" does.
BTW, have you tried bookmode.el in the Maxima distribution? It also
works a bit like that.
I have now cleaned up the image code a bit, and put it at:
<http://purl.org/harder/imaxima.tar.gz>
Here's the commentary from the file:
;;; Commentary:
;;
;; This file (and imaxima.lisp) provides image support for interacting
;; with the computer algebra system Maxima.
;;
;; The command `imaxima' provides a simple comint derived CLI mode.
;;
;; The function `imaxima-setup' is intended to be used with the modes
;; in maxima.el. Maxima.el doesn't provide an exit-hook, so you'll
;; have to run `imaxima-clean-up' manually to clean up temporary files
;; and stop the running gs process.
;;
;; To turn off images, evaluate "display2d:true" in Maxima. To turn
;; them on again, evaluate "display2d:imaxima".
;;
;; The package requires Emacs 21 with image support (the ms-windows
;; port doesn't support images yet).
;;
;; It may or may not work with recent versions of XEmacs -- my version
;; of XEmacs (21.1) doesn't provide `comint-preoutput-filter', so I
;; couldn't test it.
;;
;; A fairly recent version of Ghostscript is recommended (at least
;; newer than v. 5.5). If your version is too old, you can either set
;; `imaxima-image-type' to 'ps or remove the options
;; "-dTextAlphaBits=4" and "-dGraphicsAlphaBits=4" from
;; `imaxima-gs-options'. The images won't look nearly as attractive,
;; though -- the text looks ragged because it isn't anti aliased.
;;
;; The file "imaxima.lisp" is a slightly modified version of
;; "texmacs.lisp" in the TeXmacs distribution. Several of the image
;; routines are borrowed from David Kastrup's preview-latex.el.
;;
;;
;; Installation:
;;
;; * Copy imaxima.el and imaxima.lisp to somewhere in Emacs' load path,
;; and byte-compile imaxima.el
;;
;; * Get the LaTeX package `breqn' from <ftp://ftp.ams.org/pub/tex/>.
;; Install the package where TeX can find it -- e.g. install in your
;; texmf or local.texmf tree and run texhash.
;;
;; * To use with maxima.el, put
;;
;; (add-hook 'inferior-maxima-mode-hook 'imaxima-setup t)
;;
;; in .emacs.
;;
;; Bugs/TODO:
;;
;; * Special LaTeX characters aren't always quoted by Maxima.
;; print("}") shows the problem. example(syntax) provides more
;; examples. `imaxima-quote' tries to make it a little more robust,
;; but as a result characters inside \verb are incorrectly quoted.
;;
;; * It would be nice to put something more useful in the strings
;; behind the images. Maybe something like string(%) would be a good
;; idea. It would make a "copy-last-output" command really useful.
;; It has to be done in imaxima.lisp, but how?
;;
;; * Printing and saving the buffer doesn't use the images. This is
;; mainly a missing feature in Emacs.
;;
;; * According to Jonathan Fine's paper in the EuroTeX 2001
;; proceedings <http://www.ntg.nl/eurotex/Fine.pdf>, feeding input
;; to a TeX daemon is 20 times as fast as starting a new TeX every
;; time. Interesting, but maybe not worth the effort.