1 ;; This is mostly from texmacs-maxima-5.9.2.lisp
2 ;; Small changes to mactex.lisp for interfacing with TeXmacs
3 ;; Andrey Grozin, 2001-2005
7 (setq $maxima_frontend
"emaxima")
8 (setq $maxima_frontend_version
*autoconf-version
*)
9 (setq $maxima_frontend_bugreportinfo
"emaxima is part of maxima.")
11 (declare-top (special lop rop $gcprint $inchar
))
15 (print-invert-case (stripdollar $inchar
)) $linenum
))
17 (defun tex-stripdollar (x)
18 (let ((s (quote-%
(maybe-invert-string-case (symbol-name (stripdollar x
))))))
20 (concatenate 'string
"\\mathrm{" s
"}")
22 ;(defun tex-stripdollar (sym)
23 ; (or (symbolp sym) (return-from tex-stripdollar sym))
24 ; (let* ((name (quote-% (print-invert-case sym)))
25 ; (name1 (if (memq (elt name 0) '(#\$ #\&)) (subseq name 1) name))
27 ; (if (eql l 1) name1 (concatenate 'string "\\mathrm{" name1 "}"))))
30 ;; Also, we should output f(x)^2, not f^2(x)
32 (defun tex-mexpt (x l r
)
33 (let((nc (eq (caar x
) 'mncexpt
))) ; true if a^^b rather than a^b
34 (setq l
(if (and (numberp (cadr x
)) (numneedsparen (cadr x
)))
35 (tex (cadr x
) (cons "\\left(" l
) '("\\right)") lop
(caar x
))
36 (tex (cadr x
) l nil lop
(caar x
)))
37 r
(if (mmminusp (setq x
(nformat (caddr x
))))
38 ;; the change in base-line makes parens unnecessary
40 (tex (cadr x
) '("^ {-\\langle ")(cons "\\rangle }" r
) 'mparen
'mparen
)
41 (tex (cadr x
) '("^ {- ")(cons " }" r
) 'mparen
'mparen
))
43 (tex x
(list "^{\\langle ")(cons "\\rangle}" r
) 'mparen
'mparen
)
44 (if (and (integerp x
) (< x
10))
45 (tex x
(list "^")(cons "" r
) 'mparen
'mparen
)
46 (tex x
(list "^{")(cons "}" r
) 'mparen
'mparen
)))))
49 ;; binomial coefficients
51 (defun tex-choose (x l r
)
54 ,@(tex (cadr x
) nil nil
'mparen
'mparen
)
56 ,@(tex (caddr x
) nil nil
'mparen
'mparen
)
60 ;; Integrals, sums, products
62 (defun tex-int (x l r
)
63 (let ((s1 (tex (cadr x
) nil nil
'mparen
'mparen
)) ;;integrand delims / & d
64 (var (tex (caddr x
) nil nil
'mparen rop
))) ;; variable
65 (cond((= (length x
) 3)
66 (append l
`("\\int {" ,@s1
"}{\\;d" ,@var
"}\\big.") r
))
67 (t ;; presumably length 5
68 (let ((low (tex (nth 3 x
) nil nil
'mparen
'mparen
))
70 (hi (tex (nth 4 x
) nil nil
'mparen
'mparen
)))
71 (append l
`("\\int_{" ,@low
"}^{" ,@hi
"}{" ,@s1
"\\;d" ,@var
"}\\big.") r
))))))
74 (let ((op (cond ((eq (caar x
) '%sum
) "\\sum_{")
75 ((eq (caar x
) '%product
) "\\prod_{")
78 ;; gotta be one of those above
79 (s1 (tex (cadr x
) nil nil
'mparen rop
)) ;; summand
80 (index ;; "index = lowerlimit"
81 (tex `((mequal simp
) ,(caddr x
),(cadddr x
)) nil nil
'mparen
'mparen
))
82 (toplim (tex (car(cddddr x
)) nil nil
'mparen
'mparen
)))
83 (append l
`( ,op
,@index
"}^{" ,@toplim
"}{" ,@s1
"}\\big.") r
)))
85 (defun tex-lsum(x l r
)
86 (let ((op (cond ((eq (caar x
) '%lsum
) "\\sum_{")
89 ;; gotta be one of those above
90 (s1 (tex (cadr x
) nil nil
'mparen rop
)) ;; summand
91 (index ;; "index = lowerlimit"
92 (tex `((min simp
) , (caddr x
), (cadddr x
)) nil nil
'mparen
'mparen
)))
93 (append l
`( ,op
,@index
"}}{" ,@s1
"}\\big.") r
)))
95 ;; This is a hack for math input of integrals, sums, products
97 (defmfun $tmint
(a b f x
) ($integrate f x a b
))
99 (defmspec $tmsum
(l) (setq l
(cdr l
))
101 (dosum (caddr l
) (cadar l
) (meval (caddar l
)) (meval (cadr l
)) t
)
104 (defmspec $tmlsum
(l) (setq l
(cdr l
))
105 (or (= (length l
) 2) (wna-err '$tmlsum
))
106 (let ((form (cadr l
))
108 (lis (meval (caddar l
)))
110 (or (symbolp ind
) (merror "Second argument not a variable ~M" ind
))
112 (loop for v in
(cdr lis
)
113 with lind
= (cons ind nil
)
116 (setq ans
(add* ans
(mbinding (lind w
) (meval form
)))))
118 (t `((%lsum
) ,form
,ind
,lis
)))))
120 (defmspec $tmprod
(l) (setq l
(cdr l
))
122 (dosum (caddr l
) (cadar l
) (meval (caddar l
)) (meval (cadr l
)) nil
)
125 (defun tex-mlabel (x l r
)
129 (list (format nil
"(~A) "
130 (print-invert-case (stripdollar (cadr x
)))))
134 (defun qndispla (form)
135 (let (($display2d nil
))
140 (if (and (listp x
) (cdr x
)
141 (equal (string-right-trim '(#\Space
) (cadr x
)) "Is"))
144 ") 'mparen
'mparen
))))
146 (let ((old-displa (symbol-function 'displa
)))
148 (if (eq $display2d
'$emaxima
)
150 (funcall old-displa form
))))