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
*)
11 (special lop rop $gcprint $inchar
)
12 (*expr tex-lbp tex-rbp
))
16 (print-invert-case (stripdollar $inchar
)) $linenum
))
18 (defun tex-stripdollar (x)
19 (let ((s (quote-%
(maybe-invert-string-case (symbol-name (stripdollar x
))))))
21 (concatenate 'string
"\\mathrm{" s
"}")
23 ;(defun tex-stripdollar (sym)
24 ; (or (symbolp sym) (return-from tex-stripdollar sym))
25 ; (let* ((name (quote-% (print-invert-case sym)))
26 ; (name1 (if (memq (elt name 0) '(#\$ #\&)) (subseq name 1) name))
28 ; (if (eql l 1) name1 (concatenate 'string "\\mathrm{" name1 "}"))))
31 ;; Also, we should output f(x)^2, not f^2(x)
33 (defun tex-mexpt (x l r
)
34 (let((nc (eq (caar x
) 'mncexpt
))) ; true if a^^b rather than a^b
35 (setq l
(if (and (numberp (cadr x
)) (numneedsparen (cadr x
)))
36 (tex (cadr x
) (cons "\\left(" l
) '("\\right)") lop
(caar x
))
37 (tex (cadr x
) l nil lop
(caar x
)))
38 r
(if (mmminusp (setq x
(nformat (caddr x
))))
39 ;; the change in base-line makes parens unnecessary
41 (tex (cadr x
) '("^ {-\\langle ")(cons "\\rangle }" r
) 'mparen
'mparen
)
42 (tex (cadr x
) '("^ {- ")(cons " }" r
) 'mparen
'mparen
))
44 (tex x
(list "^{\\langle ")(cons "\\rangle}" r
) 'mparen
'mparen
)
45 (if (and (integerp x
) (< x
10))
46 (tex x
(list "^")(cons "" r
) 'mparen
'mparen
)
47 (tex x
(list "^{")(cons "}" r
) 'mparen
'mparen
)))))
50 ;; binomial coefficients
52 (defun tex-choose (x l r
)
55 ,@(tex (cadr x
) nil nil
'mparen
'mparen
)
57 ,@(tex (caddr x
) nil nil
'mparen
'mparen
)
61 ;; Integrals, sums, products
63 (defun tex-int (x l r
)
64 (let ((s1 (tex (cadr x
) nil nil
'mparen
'mparen
)) ;;integrand delims / & d
65 (var (tex (caddr x
) nil nil
'mparen rop
))) ;; variable
66 (cond((= (length x
) 3)
67 (append l
`("\\int {" ,@s1
"}{\\;d" ,@var
"}\\big.") r
))
68 (t ;; presumably length 5
69 (let ((low (tex (nth 3 x
) nil nil
'mparen
'mparen
))
71 (hi (tex (nth 4 x
) nil nil
'mparen
'mparen
)))
72 (append l
`("\\int_{" ,@low
"}^{" ,@hi
"}{" ,@s1
"\\;d" ,@var
"}\\big.") r
))))))
75 (let ((op (cond ((eq (caar x
) '%sum
) "\\sum_{")
76 ((eq (caar x
) '%product
) "\\prod_{")
79 ;; gotta be one of those above
80 (s1 (tex (cadr x
) nil nil
'mparen rop
)) ;; summand
81 (index ;; "index = lowerlimit"
82 (tex `((mequal simp
) ,(caddr x
),(cadddr x
)) nil nil
'mparen
'mparen
))
83 (toplim (tex (car(cddddr x
)) nil nil
'mparen
'mparen
)))
84 (append l
`( ,op
,@index
"}^{" ,@toplim
"}{" ,@s1
"}\\big.") r
)))
86 (defun tex-lsum(x l r
)
87 (let ((op (cond ((eq (caar x
) '%lsum
) "\\sum_{")
90 ;; gotta be one of those above
91 (s1 (tex (cadr x
) nil nil
'mparen rop
)) ;; summand
92 (index ;; "index = lowerlimit"
93 (tex `((min simp
) , (caddr x
), (cadddr x
)) nil nil
'mparen
'mparen
)))
94 (append l
`( ,op
,@index
"}}{" ,@s1
"}\\big.") r
)))
96 ;; This is a hack for math input of integrals, sums, products
98 (defmfun $tmint
(a b f x
) ($integrate f x a b
))
100 (defmspec $tmsum
(l) (setq l
(cdr l
))
102 (dosum (caddr l
) (cadar l
) (meval (caddar l
)) (meval (cadr l
)) t
)
105 (defmspec $tmlsum
(l) (setq l
(cdr l
))
106 (or (= (length l
) 2) (wna-err '$tmlsum
))
107 (let ((form (cadr l
))
109 (lis (meval (caddar l
)))
111 (or (symbolp ind
) (merror "Second argument not a variable ~M" ind
))
113 (loop for v in
(cdr lis
)
114 with lind
= (cons ind nil
)
117 (setq ans
(add* ans
(mbinding (lind w
) (meval form
)))))
119 (t `((%lsum
) ,form
,ind
,lis
)))))
121 (defmspec $tmprod
(l) (setq l
(cdr l
))
123 (dosum (caddr l
) (cadar l
) (meval (caddar l
)) (meval (cadr l
)) nil
)
126 (defun tex-mlabel (x l r
)
130 (list (format nil
"(~A) "
131 (print-invert-case (stripdollar (cadr x
)))))
135 (defun qndispla (form)
136 (let (($display2d nil
))
141 (if (and (listp x
) (cdr x
)
142 (equal (string-right-trim '(#\Space
) (cadr x
)) "Is"))
145 ") 'mparen
'mparen
))))
147 (let ((old-displa (symbol-function 'displa
)))
149 (if (eq $display2d
'$emaxima
)
151 (funcall old-displa form
))))