Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
;; This file:
;;   https://anggtwu.net/MAXIMA/dim-underbrace.lisp.html
;;   https://anggtwu.net/MAXIMA/dim-underbrace.lisp
;;           (find-angg "MAXIMA/dim-underbrace.lisp")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;;
;; Superseded by:
;; (find-angg "MAXIMA/edrxbox-examples.lisp" "underbrace")
;;    https://anggtwu.net/maxima-edrxbox.html#underbrace
;;
;; See: (find-maximamsg "59269958 202512 08" "Edrx: dim-underbrace")
;;
;; (defun e () (interactive) (find-angg "MAXIMA/dim-underbrace.lisp"))
;; (defun o () (interactive) (find-angg "MAXIMA/dim-antideriv.lisp"))
;; (defun oe () (interactive) (find-2a '(o) '(e)))

;; «.underbrace»	(to "underbrace")
;; «.underbrace-tests»	(to "underbrace-tests")

(if (not (fboundp 'display2d-unicode-enabled))
    (defun display2d-unicode-enabled () nil))

(setf (get '$underbrace 'dimension) 'dim-underbrace)
(defprop $underbrace tex-underbrace tex)

;; «underbrace»  (to ".underbrace")
(defun dim-underbrace (form result)
  (unless (= (length (cdr form)) 2)
    (return-from dim-underbrace (dimension-function form result)))
  (let* ((args     (rest form))
	 ;;
	 (a        (first args))
	 (a-result (dimension a nil 'mparen 'mparen nil 0))
	 (a-width  width)
	 (a-height height)
	 (a-depth  depth)
	 ;;
	 (b        (second args))
	 (b-result (dimension b nil 'mparen 'mparen nil 0))
	 (b-width  width)
	 (b-height height)
	 (b-depth  depth)
	 ;;
	 (bar-width (max a-width b-width))
	 (bar-dx    (- a-width))
	 (bar-dy    (- (+ a-depth 1)))
	 ;;
	 (b-dx      (- bar-width))
	 (b-dy      (- (+ a-depth 1 b-height)))
	 ;;
	 (max-width (max a-width b-width))
	 (end-dx    (- max-width b-width)))
	 ;;
    (setq height a-height
	  depth  (+ a-depth 1 b-height b-depth)
	  width  (max a-width b-width)
	  result `((,end-dx 0)
		   (,b-dx ,b-dy ,@b-result)
		   (,bar-dx ,bar-dy (d-hbar-underbrace ,bar-width #\:))
		   (0 0 ,@a-result)
		   ,@result))
    ;;
    (update-heights height depth)
    result))


(defun pr (list) (format t "~S~%" list))

;; (find-maximagitfile "src/displa.lisp" "(defun d-hbar ")
(defun d-hbar-underbrace (linear? w &optional char &aux nl)
  (declare (ignore linear?))
  (when (null char)
    (setq char (if (display2d-unicode-enabled) d-hbar-char-unicode d-hbar-char-ascii)))
  (dotimes (i w)
    (push char nl))
  (pr `(nl ,nl))
  (prog1 (draw-linear nl oldrow oldcol)))


#|
** «underbrace-tests»  (to ".underbrace-tests")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("dim-underbrace.lisp");
linel : 40;
mybox(o) := [box(o)];
o1 : underbrace(12, 3456);
o1 : underbrace(23/4565, a[b]^3);
mybox(o1);

texput(underbrace, underbrace_tex)$
underbrace_tex(o) :=
  block([a,b], [a,b]:args(o),
        format("\\underbrace{~a}_{~a}", tex1(a),tex1(b)))$

tex1(o1);

** (find-fline "~/MAXIMA/2025-1-s.mac")
** (find-fline "~/MAXIMA/2025-1-s.mac" "RC")
load          ("~/MAXIMA/2025-1-s.mac");

S1 : [g(x)=x^2, gp(x)=2*x];
S2 : [f(x)=sin(x), fp(x)=cos(x)];

RCV;
RCV _ss_ S1;
RCV _ss_ S1 _ss_ S2;

o2 : underbrace(RCV _ss_ S1,
                RCV _s_  S1);
o3 : underbrace(o2 _ss_ S2, 
                RCV _s_ S1 _s_ S2);

texput(fp, "f'")$
texput(gp, "g'")$

linenum:0;
/* block foo */
o3;

o1 : (2+.3) *. (4+.5);
upart(5, o1, 1,2);
upart(5, o1, 1);


** (find-es "maxima" "lpart-and-dpart")

|#


(defun $upart (bottom obj &rest pathtosubpart)
  (let* ((subpart (apply '$part obj pathtosubpart))
	 (newsubpart `(($underbrace) ,subpart ,bottom)))
    (meval* `(($substpart) ,newsubpart ,obj ,@pathtosubpart))))



#|
* (eepitch-slime-kill 'show-only)
* (eepitch-slime-kill)
* (eepitch-b '(slime "sbcl"))
* (eepitch-slime-select)
*   (eepitch-maxima)
*   (eepitch-kill)
*   (eepitch-maxima)
      load("startslime");
* (eepitch-b '(slime-connect "localhost" 4005))
* (eepitch-slime-set-pkgbuffers)
* (eepitch-slime-select-pkgbuffer "COMMON-LISP-USER")
* (eepitch-slime-select-pkgbuffer "MAXIMA")
(load "dim-underbrace.lisp")
(trace d-hbar)
(trace d-hbar :break t)

* (eepitch-maxima)
load("dim-underbrace.lisp");
(a+b)/(c+d);

|#







;; Local Variables:
;; coding:  utf-8-unix
;; End: