tex() function problem.



Earlier, I took a wild guess, and changed explode to explodec.  Another 
problem is that
tex-mexpt has a hiccup near the end 

  (if nc
      (tex (cadr x) '("^ {-\\langle ")(cons "\\rangle }" r) 'mparen 
'mparen)
                                  (tex (cadr x) '("^ {- ")(cons " }" r) 
'mparen 'mparen))
  (if nc
          (tex x (list "^{\\langle ")(cons "\\rangle}" r) 'mparen 'mparen)
                          (if (and (numberp x) (< x 10))
                                      (tex x (list "^")(cons "" r) 'mparen 
'mparen)
                                                      (tex x (list 
"^{")(cons "}" r) 'mparen 'mparen))
                                          )))))

Why (if nc ...) twice? Also the (numberp x) (< x 10)) needs to be 
(integerp x) ...
But I'm puzzled---I don't think explode changed recently. My changes are

(defun texnumformat(atom)
  (let (r firstpart exponent)
    (cond ((integerp atom)
           atom)
          (t
           (setq r (explodec atom)) ;; was explode 
           (setq exponent (member 'e r :test #'string-equal)) ;; is it 
ddd.ddde+EE
           (cond ((null exponent)
                  ;; it is not. go with it as given
                  atom)
                 (t
                  (setq firstpart
                        (nreverse (cdr (member 'e (reverse r) :test 
#'string-equal))))
                  (strcat (apply #'strcat firstpart )
                          " \\times 10^{"
                          (apply #'strcat (cdr exponent))
                          "}")))))))

(defun tex-mexpt (x l r)
  (let((nc (eq (caar x) 'mncexpt)))     ; true if a^^b rather than a^b
    ;; here is where we have to check for f(x)^b to be displayed
    ;; as f^b(x), as is the case for sin(x)^2 .
    ;; which should be sin^2 x rather than (sin x)^2 or (sin(x))^2.
    ;; yet we must not display (a+b)^2 as +^2(a,b)...
    ;; or (sin(x))^(-1) as sin^(-1)x, which would be arcsine x
    (cond ;; this whole clause
      ;; should be deleted if this hack is unwanted and/or the
      ;; time it takes is of concern.
      ;; it shouldn't be too expensive.
      ((and (eq (caar x) 'mexpt)      ; don't do this hack for mncexpt
            (let*
                ((fx (cadr x))          ; this is f(x)
                 (f (and (not (atom fx)) (atom (caar fx)) (caar fx))) ; 
this is f [or nil]
                 (bascdr (and f (cdr fx))) ; this is (x) [maybe (x,y..), 
or nil]
                 (expon (caddr x)) ;; this is the exponent
                 (doit (and
                        f               ; there is such a function
                        (memq (getchar f 1) '(% $)) ;; insist it is a % or 
$ function
                        (not (eq (car (last (car fx))) 'array)) ; fix for 
x[i]^2
                                        ; Jesper Harder <harder@ifa.au.dk>
                        (not (memq f '(%sum %product %derivative 
%integrate %at
                                       %lsum %limit))) ;; what else? what 
a hack...
                        (or (and (atom expon) (not (numberp expon))) ; 
f(x)^y is ok
                            (and (atom expon) (numberp expon) (> expon 
0))))))
                                        ; f(x)^3 is ok, but not f(x)^-1, 
which could
                                        ; inverse of f, if written f^-1 x
                                        ; what else? f(x)^(1/2) is 
sqrt(f(x)), ??
              (cond (doit
                     (setq l (tex `((mexpt) ,f ,expon) l nil 'mparen 
'mparen))
                     (if (and (null (cdr bascdr))
                              (eq (get f 'tex) 'tex-prefix))
                         (setq r (tex (car bascdr) nil r f 'mparen))
                         (setq r (tex (cons '(mprogn) bascdr) nil r 
'mparen 'mparen))))
                    (t nil)))))         ; won't doit. fall through
      (t (setq l (tex (cadr x) l nil lop (caar x))
               r (if (mmminusp (setq x (nformat (caddr x))))
                     ;; the change in base-line makes parens unnecessary

                     (if nc
                         (tex (cadr x) '("^ {-\\langle ")(cons "\\rangle 
}" r) 'mparen 'mparen)
                       (tex (cadr x) '("^ {- ") (cons " }" r)  'mparen 
'mparen))
 
                   (if (and (integerp x) (< x 10)) ;; was numberp
                       (tex x (list "^")(cons "" r) 'mparen 'mparen)
                     (tex x (list "^{") (cons "}" r) 'mparen 'mparen))))
         (append l r)))))

Barton