Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
;; This file:
;;   http://anggtwu.net/MAXIMA/displa-delegate.lisp.html
;;   http://anggtwu.net/MAXIMA/displa-delegate.lisp
;;          (find-angg "MAXIMA/displa-delegate.lisp")
;;  Author: Eduardo Ochs <eduardoochs@gmail.com>
;; License: Public Domain
;;    Date: 2025sep25
;;     See: http://anggtwu.net/eev-maxima.html#displa_delegate
;;
;; This file implements a new way of telling to `display2d' how to
;; display Maxima objects. The new way is the Maxima function
;; `displa_delegate', that is inspired by the Lisp function
;; `displa-def', but `displa-def' does everything in Lisp, and
;; `displa_delegate' defines a translation in Maxima and delegates the
;; hard work to other functions.
;;
;; Old comments:
;;   (defun e () (interactive) (find-angg "MAXIMA/displa-delegate.lisp"))
;; See: (find-es "maxima" "displa-delegate")
;;      (find-es "maxima" "dimension-ccc")
;; This file generalizes this prototype:
;;   (find-angg "MAXIMA/2025-displa-delegate-1.lisp")

;; «.ancestors»	(to "ancestors")
;; «.introduction»		(to "introduction")
;; «.introduction-test»		(to "introduction-test")
;; «.displa_delegate»		(to "displa_delegate")
;; «.displa_delegate-test1»	(to "displa_delegate-test1")
;; «.displa_delegate-test2»	(to "displa_delegate-test2")

;; «ancestors»  (to ".ancestors")
;; My notes on the ancestors of `displa_delegate' are here:
;;   (find-es "maxima" "dimension-ccc")
;;   (find-maximamsg "59114438 202501 04" "Edrx: (displa-def $ket ...)")
;;   (find-maximamsg "59114461 202501 04" "RDodier: (defun reform-ccc ...)")
;;   (find-maximamsg "59114492 202501 04" "Edrx: that people can test in a Maxima REPL")
;;   (find-maximamsg "59114658 202501 04" "RDodier: second attempt")



;; «introduction»  (to ".introduction")
;; When we run the code inside `aaa-bbb-ccc', below - note that
;; the `defun' _sort of_ comments it out - its first `displa-def'
;; makes objects like aaa(x,y,z) be displayed as "x:y:z"; its
;; second `displa-def' makes objects like bbb(aaa(x,y,z)) be
;; displayed as "<x:y:z>"; and the `setf' and the `defun' makes
;; objects like ccc(x,y,z) be displayed as bbb(aaa(x,y,z)), that
;; in its turn is displayed as "<x:y:z>". This last part is quite
;; tricky: when Maxima is asked to display a ccc(x,y,z) it looks
;; at the `dimension' property of `ccc', and finds `dim-ccc';
;; then Maxima calls `dim-ccc', that translates ccc(x,y,z) to
;; bbb(aaa(x,y,z)) _internally_, and delegates that displaying to
;; the `dimension' property of `bbb', that does the rest.

(defun aaa-bbb-ccc ()
  ;;
  (displa-def $aaa dimension-nary ":")
  (displa-def $bbb dimension-match "<" ">")
  ;;
  (setf (get '$ccc 'dimension) 'dim-ccc)
  (defun dim-ccc (o result)
    (let* ((translated-o `(($bbb) (($aaa) ,@(cdr o))))
	   (op-translated-o (caar translated-o))
	   (dim-translated-o (get op-translated-o 'dimension)))
      (funcall dim-translated-o translated-o result)))
  ;;
  )

;; «introduction-test»  (to ".introduction-test")
#|
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("displa-delegate.lisp");
    aaa(x,y,z);
bbb(aaa(x,y,z));

to_lisp();
  (aaa-bbb-ccc)
  (to-maxima)

o1 :     aaa(x,y,z);    /*  x:y:z  */
o2 : bbb(aaa(x,y,z));   /* <x:y:z> */
o3 : ccc(x,y,z);        /* <x:y:z> */
[op(o3), args(o3)];     /* [ccc, [x, y, z]] */

|#



;; «displa_delegate»  (to ".displa_delegate")
;; The Maxima function `displa_delegate', defined below, implements
;; another way to define how Maxima objects will be displayed - for
;; example,
;;
;;   displa_delegate('ccc, 'ccc_translate);
;; 
;; tells Maxima that an object like ccc(x,y,z) should be displayed by
;; first running ccc_translate(ccc(x,y,z)) and then delegating the
;; displaying to the result.

(defun displa-delegate-3 ($CCC $CCC_TRANSLATE DIM-CCC)
  `(progn
     ;;
     (defun ,DIM-CCC (o result)
       (let* ((list-o (list '(mlist simp) o))
	      (translated-o ($apply ',$CCC_TRANSLATE list-o))
	      (op-translated-o (caar translated-o))
	      (dim-translated-o (get op-translated-o 'dimension)))
	 (funcall dim-translated-o translated-o result)))
     ;;
     (setf (get ',$CCC 'dimension) ',DIM-CCC)
     ;;
     ))

(defun displa-delegate-2 ($CCC $CCC_TRANSLATE)
  (let ((DIM-CCC (intern (format nil "DIM-~a" (symbol-name $CCC)))))
    (displa-delegate-3 $CCC $CCC_TRANSLATE DIM-CCC)))

(defun $displa_delegate ($CCC &optional $CCC_TRANSLATE)
  (if $CCC_TRANSLATE
      (eval (displa-delegate-2 $CCC $CCC_TRANSLATE))
      (setf (get $CCC 'dimension) nil)))
      

;; «displa_delegate-test1»  (to ".displa_delegate-test1")
#|
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("displa-delegate.lisp");

o1 :     aaa(x,y,z);    /*     aaa(x, y, z)  */
o2 : bbb(aaa(x,y,z));   /* bbb(aaa(x, y, z)) */
o3 : ccc(x,y,z);        /* ccc(x, y, z)      */

ccc_translate(o) := bbb(apply('aaa, args(o)));
ccc_translate(o3);      /* bbb(aaa(x, y, z)) */

to_lisp();
  (displa-def $aaa dimension-nary ":")
  (displa-def $bbb dimension-match "<" ">")
  (to-maxima)

o1;                     /*  x:y:z            */
o2;                     /* <x:y:z>           */
o3;                     /* ccc(x, y, z)      */
ccc_translate(o3);      /* <x:y:z>           */
displa_delegate('ccc, 'ccc_translate);
o3;                     /* <x:y:z>           */
[op(o3), args(o3)];     /* [ccc, [x, y, z]]  */
displa_delegate('ccc);
o3;                     /* ccc(x, y, z)      */

|#



;; «displa_delegate-test2»  (to ".displa_delegate-test2")
#|
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
** (find-lisptree "lisptree.mac")
load  ("~/lisptree/lisptree.mac")$
load("displa-delegate.lisp")$
lisptree0_config('q)$

_At2_translate(o) := block([fx,x,a,b],
                           [fx,x,a,b] : args(o),
                           matrix(["", "|", x=a],
                                  [fx, "|",  ""],
                                  ["", "|", x=b]))$
o  : _At2(sin(t),t,3,4);
o2 : _At2_translate(o);
displa_delegate('_At2, '_At2_translate);
o;

lisptree(o);
lisptree(_At2_translate(o));

texput(_At2, _At2_tex)$
_At2_tex(o) := block([fx,x,a,b],
                     [fx,x,a,b]:args(o),
                     format("\\left.~a\\right|_{~a=~a}^{~a=~a}",
                            tex1(fx), tex1(x),tex1(a), tex1(x),tex1(b)))$

tex1(o);     /* \left.\sin t\right|_{t=3}^{t=4} */
tex1(o2);    /* SOMETHING UGLY */

|#