On 1/5/12, andre maute <andre.maute at gmx.de> wrote:
> if someone thinks it is possible to colorize some matrix elements.
That's an interesting idea. I see a couple of ways to do it.
(1) colorized MathML (XML) output. There is a share package to
generate MathML if I recall correctly. Maybe colors can be imposed
as attributes or something?
(2) colorized wxMaxima output. I think wxMaxima generates HTML
or XML for display. Same idea here -- use attributes to set the color.
(3) colorized console pretty printer output. I spent a few minutes
experimenting with that. It's easy enough to introduce colors via
VT100 escape codes. I tried to convert elements to strings, and
colorize those, and then punt to the existing display code, but
appending color codes makes the strings longer (more characters)
and the matrix display then misjudges the display width of the matrix;
the matrix is actually narrower.
Now that I think about it, I guess a better way to do it is to append
the colorization stuff after calculating the size of the element.
I would have to go back & dig around in DIM-$MATRIX to figure it out.
Anyway perhaps this is interesting in some way.
best,
Robert Dodier
------------------- begin patch for src/displa.lisp -------------------
$ diff -u /tmp/dim-\$matrix.lisp
'/home/robert/maxima/playpen/dim-$matrix-color.lisp'
--- /tmp/dim-$matrix.lisp 2012-01-07 11:36:54.000000000 -0700
+++ /home/robert/maxima/playpen/dim-$matrix-color.lisp 2012-01-07
12:10:54.000000000 -0700
@@ -1,7 +1,7 @@
-(displa-def $matrix dim-$matrix)
+(displa-def $matrix dim-$matrix-color)
-(defun dim-$matrix (form result)
- (prog (dmstr rstr cstr consp cols)
+(defun dim-$matrix-color (form result)
+ (prog (dmstr rstr cstr consp cols element-string element-string-display)
(setq cols (if ($listp (cadr form)) (length (cadr form)) 0))
(if (or (null (cdr form))
(memalike '((mlist simp)) (cdr form))
@@ -24,7 +24,9 @@
(nc dmstr (cdr nc))
(cs cstr (cdr cs)) (dummy) (h2 0) (d2 0))
((null c) (setq d1 (+ d1 h1 h2) h1 (1+ d2)))
- (setq dummy (dimension (car c) nil 'mparen 'mparen nil 0)
+ (setq element-string (strgrind (car c)))
+ (setq element-string-display (concatenate 'string ($vt100
'$red) element-string ($vt100 '$black)))
+ (setq dummy (dimension element-string-display nil 'mparen 'mparen nil 0)
h2 (max h2 height) d2 (max d2 depth))
(cond ((not (checkfit (+ 14. width))) (setq consp t) (return nil))
(t (rplaca nc (cons (list* width height depth dummy) (car nc)))
------------------- end patch for src/displa.lisp -------------------
--------------------- begin vt00.lisp -------------------
;; vt100.lisp -- change VT100 terminal output foreground color
;; copyright 2012 by Robert Dodier
;; I release this work under terms of the GNU General Public License
;; VT100 foreground colors -- nicked from share/contrib/colorterm.lisp
;;; 30 Black
;;; 31 Red
;;; 32 Green
;;; 33 Yellow
;;; 34 Blue
;;; 35 Magenta
;;; 36 Cyan
;;; 37 White
(let ((vt100-colors (make-hash-table)))
(setf (gethash '$black vt100-colors) 30.)
(setf (gethash '$red vt100-colors) 31.)
(setf (gethash '$green vt100-colors) 32.)
(setf (gethash '$yellow vt100-colors) 33.)
(setf (gethash '$blue vt100-colors) 34.)
(setf (gethash '$magenta vt100-colors) 35.)
(setf (gethash '$cyan vt100-colors) 36.)
(setf (gethash '$white vt100-colors) 37.)
(defun $vt100 (color-symbol)
(let
((color-code (gethash color-symbol vt100-colors))
(escape-char (code-char 27)))
(if color-code
(format nil "~a[00;~am" escape-char color-code)))))
--------------------- end vt100.lisp -------------------