]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calccomp.el
Update copyright date.
[gnu-emacs] / lisp / calc / calccomp.el
index e76b3a34e093016c2929ac291a90b022a8b11bf8..305e155843e8632fd93718c77ac36b4f3fca06ca 100644 (file)
@@ -35,7 +35,9 @@
   '( calcFunc-log
      calcFunc-ln calcFunc-exp
      calcFunc-sin calcFunc-cos calcFunc-tan
+     calcFunc-sec calcFunc-csc calcFunc-cot
      calcFunc-sinh calcFunc-cosh calcFunc-tanh
+     calcFunc-sech calcFunc-csch calcFunc-coth
      calcFunc-arcsin calcFunc-arccos calcFunc-arctan
      calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh))
 
@@ -79,7 +81,8 @@
 
 
 (defun math-compose-expr (a prec)
-  (let ((math-compose-level (1+ math-compose-level)))
+  (let ((math-compose-level (1+ math-compose-level))
+        spfn)
     (cond
      ((or (and (eq a math-comp-selected) a)
          (and math-comp-tagged
        (list 'tag a (math-compose-expr a prec))))
      ((and (not (consp a)) (not (integerp a)))
       (concat "'" (prin1-to-string a)))
+     ((setq spfn (assq (car-safe a) math-expr-special-function-mapping))
+      (setq spfn (cdr spfn))
+      (funcall (car spfn) a spfn))
      ((math-scalarp a)
       (if (or (eq (car-safe a) 'frac)
              (and (nth 1 calc-frac-format) (Math-integerp a)))
-         (if (memq calc-language '(tex eqn math maple c fortran pascal))
+         (if (memq calc-language '(tex latex eqn math maple c fortran pascal))
              (let ((aa (math-adjust-fraction a))
                    (calc-frac-format nil))
                (math-compose-expr (list '/
              (if (or calc-full-vectors (< (length a) 7))
                  (if (and (eq calc-language 'tex)
                           (math-matrixp a))
-                     (append '(horiz "\\matrix{ ")
-                             (math-compose-tex-matrix (cdr a))
-                             '(" }"))
-                   (if (and (eq calc-language 'eqn)
-                            (math-matrixp a))
-                       (append '(horiz "matrix { ")
-                               (math-compose-eqn-matrix
-                                (cdr (math-transpose a)))
-                               '("}"))
-                     (if (and (eq calc-language 'maple)
-                              (math-matrixp a))
-                         (list 'horiz
-                               "matrix("
-                               math-comp-left-bracket
-                               (math-compose-vector (cdr a) 
+                      (if (and (integerp calc-language-option)
+                               (or (= calc-language-option 0)
+                                   (> calc-language-option 1)
+                                   (< calc-language-option -1)))
+                          (append '(vleft 0 "\\matrix{")
+                                  (math-compose-tex-matrix (cdr a))
+                                  '("}"))
+                        (append '(horiz "\\matrix{ ")
+                                (math-compose-tex-matrix (cdr a))
+                                '(" }")))
+                    (if (and (eq calc-language 'latex)
+                             (math-matrixp a))
+                        (if (and (integerp calc-language-option)
+                                 (or (= calc-language-option 0)
+                                     (> calc-language-option 1)
+                                     (< calc-language-option -1)))
+                            (append '(vleft 0 "\\begin{pmatrix}")
+                                    (math-compose-tex-matrix (cdr a))
+                                    '("\\end{pmatrix}"))
+                          (append '(horiz "\\begin{pmatrix} ")
+                                  (math-compose-tex-matrix (cdr a))
+                                  '(" \\end{pmatrix}")))
+                      (if (and (eq calc-language 'eqn)
+                               (math-matrixp a))
+                          (append '(horiz "matrix { ")
+                                  (math-compose-eqn-matrix
+                                   (cdr (math-transpose a)))
+                                  '("}"))
+                        (if (and (eq calc-language 'maple)
+                                 (math-matrixp a))
+                            (list 'horiz
+                                  "matrix("
+                                  math-comp-left-bracket
+                                  (math-compose-vector (cdr a) 
+                                                       (concat math-comp-comma " ")
+                                                       math-comp-vector-prec)
+                                  math-comp-right-bracket
+                                  ")")
+                          (list 'horiz
+                                math-comp-left-bracket
+                                (math-compose-vector (cdr a) 
                                                      (concat math-comp-comma " ")
-                                                    math-comp-vector-prec)
-                               math-comp-right-bracket
-                               ")")
-                       (list 'horiz
-                             math-comp-left-bracket
-                             (math-compose-vector (cdr a) 
-                                                   (concat math-comp-comma " ")
-                                                  math-comp-vector-prec)
-                             math-comp-right-bracket))))
+                                                     math-comp-vector-prec)
+                                math-comp-right-bracket)))))
                (list 'horiz
                      math-comp-left-bracket
                      (math-compose-vector (list (nth 1 a) (nth 2 a) (nth 3 a))
                                           (concat math-comp-comma " ") 
                                            math-comp-vector-prec)
-                     math-comp-comma (if (eq calc-language 'tex) " \\ldots" " ...")
+                     math-comp-comma (if (memq calc-language '(tex latex)) 
+                                          " \\ldots" " ...")
                      math-comp-comma " "
                      (list 'break math-compose-level)
                      (math-compose-expr (nth (1- (length a)) a)
       (let ((v (rassq (nth 2 a) math-expr-variable-mapping)))
        (if v
            (symbol-name (car v))
-         (if (and (eq calc-language 'tex)
+         (if (and (memq calc-language '(tex latex))
                   calc-language-option
                   (not (= calc-language-option 0))
                   (string-match "\\`[a-zA-Z][a-zA-Z0-9]+\\'"
                                 (symbol-name (nth 1 a))))
-             (format "\\hbox{%s}" (symbol-name (nth 1 a)))
+              (if (eq calc-language 'latex)
+                  (format "\\text{%s}" (symbol-name (nth 1 a)))
+                (format "\\hbox{%s}" (symbol-name (nth 1 a))))
            (if (and math-compose-hash-args
                     (let ((p calc-arg-values))
                       (setq v 1)
            (if (eq calc-language 'maple) ""
              (if (memq (nth 1 a) '(0 1)) "(" "["))
            (math-compose-expr (nth 2 a) 0)
-           (if (eq calc-language 'tex) " \\ldots "
+           (if (memq calc-language '(tex latex)) " \\ldots "
              (if (eq calc-language 'eqn) " ... " " .. "))
            (math-compose-expr (nth 3 a) 0)
            (if (eq calc-language 'maple) ""
            (math-compose-expr (nth 2 a) 0)
            "]]"))
      ((and (eq (car a) 'calcFunc-sqrt)
-          (eq calc-language 'tex))
+          (memq calc-language '(tex latex)))
       (list 'horiz
            "\\sqrt{"
            (math-compose-expr (nth 1 a) 0)
              (math-comp-height a1)
              a1 '(rule ?-) a2)))
      ((and (memq (car a) '(calcFunc-sum calcFunc-prod))
-          (eq calc-language 'tex)
+          (memq calc-language '(tex latex))
           (= (length a) 5))
       (list 'horiz (if (eq (car a) 'calcFunc-sum) "\\sum" "\\prod")
            "_{" (math-compose-expr (nth 2 a) 0)
           (integerp (nth 2 a)))
       (let ((c (math-compose-expr (nth 1 a) -1)))
        (if (> prec (nth 2 a))
-           (if (eq calc-language 'tex)
+           (if (memq calc-language '(tex latex))
                (list 'horiz "\\left( " c " \\right)")
              (if (eq calc-language 'eqn)
                  (list 'horiz "{left ( " c " right )}")
                      (make-list (nth 1 a) c))))))
      ((and (eq (car a) 'calcFunc-evalto)
           (setq calc-any-evaltos t)
-          (memq calc-language '(tex eqn))
+          (memq calc-language '(tex latex eqn))
           (= math-compose-level (if math-comp-tagged 2 1))
           (= (length a) 3))
       (list 'horiz
-           (if (eq calc-language 'tex) "\\evalto " "evalto ")
+           (if (memq calc-language '(tex latex)) "\\evalto " "evalto ")
            (math-compose-expr (nth 1 a) 0)
-           (if (eq calc-language 'tex) " \\to " " -> ")
+           (if (memq calc-language '(tex latex)) " \\to " " -> ")
            (math-compose-expr (nth 2 a) 0)))
      (t
       (let ((op (and (not (eq calc-language 'unform))
                    (/= (nth 3 op) -1))
               (cond
                ((> prec (or (nth 4 op) (min (nth 2 op) (nth 3 op))))
-                (if (and (eq calc-language 'tex)
+                (if (and (memq calc-language '(tex latex))
                          (not (math-tex-expr-is-flat a)))
                     (if (eq (car-safe a) '/)
                         (list 'horiz "{" (math-compose-expr a -1) "}")
                                 (math-compose-expr a -1)
                                 " right )}")))
                     (list 'horiz "(" (math-compose-expr a 0) ")"))))
-               ((and (eq calc-language 'tex)
+               ((and (memq calc-language '(tex latex))
                      (memq (car a) '(/ calcFunc-choose calcFunc-evalto))
                      (>= prec 0))
                 (list 'horiz "{" (math-compose-expr a -1) "}"))
                   (and (equal (car op) "^")
                        (eq (math-comp-first-char lhs) ?-)
                        (setq lhs (list 'horiz "(" lhs ")")))
-                  (and (eq calc-language 'tex)
+                  (and (memq calc-language '(tex latex))
                        (or (equal (car op) "^") (equal (car op) "_"))
                        (not (and (stringp rhs) (= (length rhs) 1)))
                        (setq rhs (list 'horiz "{" rhs "}")))
                ((or (> prec (or (nth 4 op) (nth 2 op)))
                     (and (not (eq (assoc (car op) math-expr-opers) op))
                          (> prec 0)))   ; don't write x% + y
-                (if (and (eq calc-language 'tex)
+                (if (and (memq calc-language '(tex latex))
                          (not (math-tex-expr-is-flat a)))
                     (list 'horiz "\\left( "
                           (math-compose-expr a -1)
              ((and op (= (length a) 2) (= (nth 2 op) -1))
               (cond
                ((eq (nth 3 op) 0)
-                (let ((lr (and (eq calc-language 'tex)
+                (let ((lr (and (memq calc-language '(tex latex))
                                (not (math-tex-expr-is-flat (nth 1 a))))))
                   (list 'horiz
                         (if lr "\\left" "")
                         (if lr "\\right" "")
                         (car (nth 1 (memq op math-expr-opers))))))
                ((> prec (or (nth 4 op) (nth 3 op)))
-                (if (and (eq calc-language 'tex)
+                (if (and (memq calc-language '(tex latex))
                          (not (math-tex-expr-is-flat a)))
                     (list 'horiz "\\left( "
                           (math-compose-expr a -1)
                                      ( pascal . math-compose-pascal )
                                      ( fortran . math-compose-fortran )
                                      ( tex . math-compose-tex )
+                                     ( latex . math-compose-latex )
                                      ( eqn . math-compose-eqn )
                                      ( math . math-compose-math )
                                      ( maple . math-compose-maple ))))
                               (symbol-name func))))
                 (if (memq calc-language '(c fortran pascal maple))
                     (setq func (math-to-underscores func)))
-                (if (and (eq calc-language 'tex)
+                (if (and (memq calc-language '(tex latex))
                          calc-language-option
                          (not (= calc-language-option 0))
                          (string-match "\\`[a-zA-Z][a-zA-Z0-9]+\\'" func))
                     (if (< (prefix-numeric-value calc-language-option) 0)
                         (setq func (format "\\%s" func))
-                      (setq func (format "\\hbox{%s}" func))))
+                      (setq func (if (eq calc-language 'latex)
+                                      (format "\\text{%s}" func)
+                                    (format "\\hbox{%s}" func)))))
                 (if (and (eq calc-language 'eqn)
                          (string-match "[^']'+\\'" func))
                     (let ((n (- (length func) (match-beginning 0) 1)))
                       (setq func (substring func 0 (- n)))
                       (while (>= (setq n (1- n)) 0)
                         (setq func (concat func " prime")))))
-                (cond ((and (eq calc-language 'tex)
+                (cond ((and (memq calc-language '(tex latex))
                             (or (> (length a) 2)
                                 (not (math-tex-expr-is-flat (nth 1 a)))))
                        (setq left "\\left( "
                                 (not (math-tex-expr-is-flat (nth 1 a)))))
                        (setq left "{left ( "
                              right " right )}"))
-                      ((and (or (and (eq calc-language 'tex)
+                      ((and (or (and (memq calc-language '(tex latex))
                                      (eq (aref func 0) ?\\))
                                 (and (eq calc-language 'eqn)
                                      (memq (car a) math-eqn-special-funcs)))
-                            (not (string-match "\\hbox{" func))
+                            (not (or
+                                   (string-match "\\hbox{" func)
+                                   (string-match "\\text{" func)))
                             (= (length a) 2)
                             (or (Math-realp (nth 1 a))
                                 (memq (car (nth 1 a)) '(var *))))
       (if (<= count 0)
          (if (< count 0)
              (math-compose-rows (cdr a) -1 nil)
-           (cons (concat (if (eq calc-language 'tex) "  \\ldots" "  ...")
+           (cons (concat (if (memq calc-language '(tex latex)) "  \\ldots" "  ...")
                          math-comp-comma)
                  (math-compose-rows (cdr a) -1 nil)))
        (cons (list 'horiz
 
 (defun math-compose-tex-matrix (a)
   (if (cdr a)
-      (cons (math-compose-vector (cdr (car a)) " & " 0)
-           (cons " \\\\ "
-                 (math-compose-tex-matrix (cdr a))))
+      (cons (append (math-compose-vector (cdr (car a)) " & " 0) '(" \\\\ "))
+            (math-compose-tex-matrix (cdr a)))
     (list (math-compose-vector (cdr (car a)) " & " 0))))
 
 (defun math-compose-eqn-matrix (a)