Dear Maxima community,
I' am new on this list, so I have first to introduce me.
My name is Waldemar, I' m a student of Physics Science
at the University of Karlsruhe, Germany.
I use Maxima in my study most for calculating some
Integrals, to solve some Equations and odes.
I was annoying of to have some mistakes at the input
(most forgot some brackets) which yields to wrong answer.
So I thought it would be nice if Maxima can display me my
input in a pretty print form, so I can easily recheck if my
input was correct.
I went on and did some investigation in Maxima source code.
Luckily I find a way to implement this behavior and put a patch
together.
Usage of the patch:
Simply copy and paste the code bellow in an editor of your choice
and save the file as "input2d.lisp".
Then you can load the code in Maxima with:
load("input2d.lisp");
Now you are done. Try to enter some expression and let Maxima
evaluate it. See what occurs.
You can switch this behavior of by typing:
toggle_display_input_2d();
And switch on again, by typing again:
toggle_display_input_2d();
If you want that the input should be displayed in the middle of the
screen, just like the output you can set the global Lisp variable
*display-input-2d-leftjust* to nil by typing:
:lisp (setq *display-input-2d-leftjust* nil)
This works only for command line Maxima and XMaxima.
Now when I reread my mail I think the global Lisp variable
*display-input-2d-leftjust* should be a Maxima variable something
like: $display_input_2d_leftjust to be more consistent with the output
variable $leftjust (what do you think?).
Finally I' m interesting in your feedback, what do you think about
this all?
I have to say I' m not a coder, so there are maybe some bugs, please
have a look in the code.
And on all Maxima developer a big thank you for Maxima!!!
Ok here is the code:
;;;;;;;;;;;;;;;;;input2d.lisp;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :maxima)
(defvar *display-input-2d* t)
(defvar *display-input-2d-leftjust* t)
(defvar *alt-main-prompt* 'display-input-2d-main-prompt)
(defun $toggle_display_input_2d ()
(cond (*display-input-2d*
(setq *display-input-2d* nil)
(setq *alt-main-prompt* nil)
(format t "~% display-input-2d disabled ~%"))
(t
(setq *display-input-2d* t)
(setq *alt-main-prompt* 'display-input-2d-main-prompt)
(format t "~% display-input-2d enabled ~%")))
*display-input-2d*)
(defun subst-by-atom (new old tree)
(if (string-equal
(format nil "~A" tree)
(format nil "~A" old))
new
(if (atom tree) tree
(cons (subst-by-atom new old (car tree))
(subst-by-atom new old (cdr tree))))))
(defun subst-by-list (subst-list tree)
(if (atom subst-list) tree
(subst-by-list (cdr subst-list)
(subst-by-atom (first (car subst-list))
(second (car subst-list))
tree))))
(defun display-input-2d (input)
;;Substitutions list of the type: ((new1 old1) (new2 old2) ...)
(let ((subst-list (list '((%INTEGRATE) ($INTEGRATE))
'((%DERIVATIVE) ($DIFF))
'((%PRODUCT) ($PRODUCT))
'((%SUM) ($SUM))
'((%LIMIT) ($LIMIT))
'((%AT) ($AT))))
($leftjust *display-input-2d-leftjust*))
;;Send the input expression to display.
(displa
(list '(mlable) (makelabel $inchar)
;;Do some substitutions for nicer looking outputs.
(subst-by-list subst-list input)))))
(defun display-input-2d-main-prompt ()
(format nil "~AIn[~D]> ~A"
*prompt-prefix* $linenum *prompt-suffix*))
;;;Redifinition of two Maxima functions:
;;; - main-prompt ()
;;; added an If condition.
;;; - toplevel-macsyma-eval (x)
;;; added an IF condition.
;;;Both functions were originally defined in macsys.lisp
(defun main-prompt ()
;; instead off using this STRIPDOLLAR hackery, the
;; MREAD function should call MFORMAT to print the prompt,
;; and take a format string and format arguments.
;; Even easier and more general is for MREAD to take
;; a FUNARG as the prompt. -gjc
(declare (special *display-labels-p*))
(if *alt-main-prompt* (funcall *alt-main-prompt*)
;;else default promt like in macsys.lisp
(if *display-labels-p*
(format nil "~A(~A~D) ~A"
*prompt-prefix*
(print-invert-case (stripdollar $inchar))
$linenum
*prompt-suffix*)
"")))
(defun toplevel-macsyma-eval (input)
(if *display-input-2d* (display-input-2d input))
(meval* input))
;;;;;;;;;;;;;;;;;end of input2d.lisp;;;;;;;;;;;;;;;;;;;;;;
PS: sorry for my bad English.