Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
;; This file: ;; http://anggtwu.net/MAXIMA/2025-displa-tex.lisp.html ;; http://anggtwu.net/MAXIMA/2025-displa-tex.lisp ;; (find-angg "MAXIMA/2025-displa-tex.lisp") ;; Author: Eduardo Ochs <eduardoochs@gmail.com> ;; See: http://anggtwu.net/eev-maxima.html#LaTeX-instead-of-TeX ;; ;; This file redefines the `display' and `tex' properties of some ;; standard Maxima operators and defines several new operations with ;; non-trivial `display' and `tex' properties. ;; ;; Based on: (find-angg "MAXIMA/2025-Integrate.lisp") ;; (find-angg "MAXIMA/lazynouns.lisp") ;; (find-angg "MAXIMA/barematrix2.lisp") ;; ;; «.matrix» (to "matrix") ;; «.bmatrix» (to "bmatrix") ;; «.matrix-tests» (to "matrix-tests") ;; «.quotient» (to "quotient") ;; «.quotient-tests» (to "quotient-tests") ;; «.lazy-nouns» (to "lazy-nouns") ;; «.lazy-nouns-tests» (to "lazy-nouns-tests") ;; «.lazy-ops» (to "lazy-ops") ;; «.lazy-ops-tests» (to "lazy-ops-tests") ;; «.displa_delegate» (to "displa_delegate") ;; «.displa_delegate-tests» (to "displa_delegate-tests") ;; «.vira» (to "vira") ;; «.vira-tests» (to "vira-tests") ;; «matrix» (to ".matrix") ;; «bmatrix» (to ".bmatrix") ;; In this block we redefine `tex-matrix' to use LaTeX instead of TeX: ;; ;; (%i1) tex1(matrix([42])); ;; (%o1) \ifx\endpmatrix\undefined\pmatrix{\else\begin{pmatrix}\fi 42\cr <-- TeX ;; \ifx\endpmatrix\undefined}\else\end{pmatrix}\fi ;; (%i2) load("2025-displa-tex.lisp")$ ;; (%i3) tex1(matrix([42])); ;; (%o3) \begin{pmatrix}42\cr \end{pmatrix} <-- LaTeX ;; ;; and we also define a `bmatrix', that is displayed like a `matrix' ;; but is `tex'ed using square brackets instead of parentheses. ;; ;; See: (find-maximagitfile "src/mactex.lisp" "(defun tex-matrix") ;; (find-maximagitfile "src/mactex.lisp" "(defun tex-matrix" "ifx") ;; ;; In the code below a "matrix" looks like ;; ((mmatrix) ((mlist) a b) ...) ;; and a "row" looks like this: ;; ((mlist) a b). ;; (defprop $matrix tex-matrix tex) (defprop $bmatrix tex-bmatrix tex) (setf (get '$bmatrix 'dimension) 'dim-$matrix) (defun tex-matrix (matrix l r) `(,@l "\\begin{pmatrix}" ,@(mapcan #'(lambda (row) (tex-list (cdr row) nil (list "\\cr ") "&")) (cdr matrix)) "\\end{pmatrix}" ,@r)) (defun tex-bmatrix (matrix l r) `(,@l "\\begin{bmatrix}" ,@(mapcan #'(lambda (row) (tex-list (cdr row) nil (list "\\cr ") "&")) (cdr matrix)) "\\end{bmatrix}" ,@r)) #| ** «matrix-tests» (to ".matrix-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) tex1(matrix([42])); load("2025-displa-tex.lisp"); tex1(matrix([42])); tex1(bmatrix([42])); bmatrix([42]); |# ;; «quotient» (to ".quotient") ;; In this block we redefine `tex-mquotient' to use LaTeX instead of TeX: ;; ;; (%i1) tex1(a/b); ;; (%o1) {{a}\over{b}} <-- TeX ;; (%i2) load("2025-displa-tex.lisp")$ ;; (%i3) tex1(a/b); ;; (%o3) {\frac{a}{b}} <-- LaTeX ;; (defun tex-mquotient (q l r) (twoargcheck q) `(,@(tex (cadr q) `(,@l "{\\frac{") () 'mparen 'mparen) ,@(tex (caddr q) (list "}{") `("}}" ,@r) 'mparen 'mparen) )) #| ** «quotient-tests» (to ".quotient-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) tex1(a/b); load("2025-displa-tex.lisp"); tex1(a/b); |# ;; «lazy-nouns» (to ".lazy-nouns") ;; See: (find-angg "MAXIMA/lazynouns.lisp") (defun my-copy-properties (tosymbol fromsymbol keys) (loop for key in keys do (setf (get tosymbol key) (get fromsymbol key)))) (my-copy-properties '$_diff '%derivative '(dimension tex)) (my-copy-properties '$_integrate '%integrate '(dimension tex)) (my-copy-properties '$_at '%at '(dimension tex)) (my-copy-properties '$_limit '%limit '(dimension tex)) #| ** «lazy-nouns-tests» (to ".lazy-nouns-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("2025-displa-tex.lisp"); [o1,o2] : [2*x^3, 1]; matrix(["", "diff", "'diff", "_diff"], [o1, diff(o1,x), 'diff(o1,x), _diff(o1,x)], [o2, diff(o2,x), 'diff(o2,x), _diff(o2,x)]); [o1,o2] : [2*f(x), 2*x]; matrix(["", "integrate", "'integrate", "_integrate"], [o1, integrate(o1,x), 'integrate(o1,x), _integrate(o1,x)], [o2, integrate(o2,x), 'integrate(o2,x), _integrate(o2,x)]); at(a,b=c); 'at(a,b=c); _at(a,b=c); _limit(a,x,x0); |# ;; «lazy-ops» (to ".lazy-ops") ;; See: (find-angg "MAXIMA/lazynouns.lisp") ($infix "*." 120) ($nary "*.") (my-copy-properties '|$*.| 'mtimes '($nary lbp rbp dimension dissym tex texsym)) ($infix "/." 120 120) ($nary "/.") ; why? (my-copy-properties '|$/.| 'mquotient '($nary lbp rbp dimension dissym tex texsym)) ($infix "+." 100 134) ($nary "+.") (my-copy-properties '|$+.| 'mplus '($nary lbp rbp dimension dissym tex texsym)) ($infix "-." 100 134) ($nary "-.") (my-copy-properties '|$-.| 'mminus '($nary lbp rbp dimension dissym tex texsym)) #| ** «lazy-ops-tests» (to ".lazy-ops-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("2025-displa-tex.lisp"); |# ;; «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 ;; (setf (get ',$CCC 'dimension) ',DIM-CCC) (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))) ;; )) (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-tests» (to ".displa_delegate-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("2025-displa-tex.lisp"); o : _At2(g(u),u,2,3); displa_delegate('_At2, '_At2_translate); _At2_translate (o) := apply(_At2_, args(o)); _At2_ (fx,x,a,b) := matrix(["", "|", x=b], [fx, "|", ""], ["", "|", x=a]); o; |# ;; «vira» (to ".vira") ;; (find-es "maxima" "vira") (displa-def $vira dimension-infix " := " 80 80) (defprop $vira tex-infix tex) (defprop $vira (" := ") texsym) #| ** «vira-tests» (to ".vira-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("2025-displa-tex.lisp"); o : vira(f(x),42*x); tex1(o); |# #| * (eepitch-sbcl) * (eepitch-kill) * (eepitch-sbcl) (load "2025-displa-tex.lisp") |# ;; lazy-ops ;; lazy-diff ;; vira ;; becomes ;; Local Variables: ;; coding: utf-8-unix ;; End: