Try to change not texnumformat, but write a function
(defun numneedsparen(atom)
(let (r exponent)
(cond ((integerp atom) nil)
(t (setq r (exploden atom)
exponent (member 'e r :test #'string-equal))
exponent)))
and change tex-mexpt as follows:
(defun tex-mexpt (x l r)
(let((nc (eq (caar x) 'mncexpt))) ; true if a^^b rather than a^b
(cond ;; this whole clause
[snip]
(cond (doit
[snip]
))
(t nil))))) ; won't doit. fall through
;; changes here! Write parens if a number needs it!
(t (setq l (cond ((and (numberp (cadr x))
(numneedsparen (cadr x)))
(tex (cadr x) (cons "\left(" l) '("\right)") lop (caar x)))
(t (tex (cadr x) l nil lop (caar x))))
r ( ;;; leave untouched
--
Andrei Zorine
Barton Willis wrote:
> No, in TeX $${5.6 \times 10^{+99}}^{x}$$ means 5.6 10^(99^x) and not
> (5.6 10^99)^x. Something like your idea
>
> (defun texnumformat(atom)
> (let (r firstpart exponent)
> (cond ((integerp atom)
> atom)
> (t
> (setq r (exploden atom))
> (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 "\\left(" (apply #'strcat firstpart )
> " \\times 10^{"
> (apply #'strcat (cdr exponent))
> "}" "\\right)")))))))
>
> eliminates the bug, BUT this code gratuitously puts parens around all
> floats.
>
> (%i10) tex(5.6e99^x);
> $$\left(5.6 \times 10^{+99}\right)^{x}$$
> (%o10) false
> (%i11) tex(5.6e99);
> $$\left(5.6 \times 10^{+99}\right)$$
> (%o11) false
>
> I think texnumformat doesn't have enough information to know if the
> parens are needed---maybe texnumformat needs more arguments?
>
> With gcl, there is the ugly +99 (instead of just 99) as well ...
>
> Barton
>
>
>
>
> Raymond Toy
> Sent by: maxima-admin@math.utexas.edu
> 01/27/2005 09:15 AM
>
>
> To: Barton Willis
> cc: zycentre-sub@yahoo.com.cn, maxima@math.utexas.edu
> Subject: Re: [Maxima] A problem when convert to Tex
>
>
>
> Here is a simple solution. The very end of texnumformat could be
> replaced with
>
> (strcat "{"
> (apply #'strcat
> firstpart )
> " \\times 10^{"
> (apply #'strcat (cdr
> exponent))
> "}"
> "}")
>
> This places an extra set of braces around the number. That causes tex
> to produce
>
> (%i4) tex(5.6e99^x);
> $${5.6 \times 10^{+99}}^{x}$$
> (%o4) false
>
> That should be ok, right? (Hmm, why does my version of maxima say +99
> instead of just 99?) Also, the (%o4) line is actually on the same
> line as the tex output. I don't think that's what we want. Some
> recent change in maxima?
>
> Ray
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>