]> code.delx.au - gnu-emacs/commitdiff
calccomp.el (math-compose-expr): Add extra argument indicating that
authorJay Belanger <jay.p.belanger@gmail.com>
Thu, 9 Aug 2012 14:46:03 +0000 (09:46 -0500)
committerJay Belanger <jay.p.belanger@gmail.com>
Thu, 9 Aug 2012 14:46:03 +0000 (09:46 -0500)
parentheses should be put around products in denominators.  Give
multiplication precedence over division during composition.

lisp/ChangeLog
lisp/calc/calccomp.el

index 23cd53f12466afcba293ecd390f74e3a5f134bd3..fef050e6d024faf85c3d3b17a5f36174aac600d9 100644 (file)
@@ -1,3 +1,10 @@
+2012-08-09  Jay Belanger  <jay.p.belanger@gmail.com>
+
+       * calc/calccomp.el (math-compose-expr): Add extra argument
+       indicating that parentheses should be put around products in
+       denominators.  Give multiplication precedence over division during
+       composition.
+
 2012-08-09  Chong Yidong  <cyd@gnu.org>
 
        * man.el (Man-switches, Man-sed-command, Man-awk-command)
index d8ad7e2cede671c18d48fbafb6024749178d8460..51ea8e7b7a3f542aef8f26023bf5c4a4d442dccf 100644 (file)
           (setq sn (math-to-underscores sn)))
       sn)))
 
-(defun math-compose-expr (a prec)
-  (let ((math-compose-level (1+ math-compose-level))
+;;; Give multiplication precendence when composing to avoid
+;;; writing a*(b c) instead of a b c
+(defun math-compose-expr (a prec &optional div)
+  (let ((calc-multiplication-has-precedence t)
+        (math-compose-level (1+ math-compose-level))
         (math-expr-opers (math-expr-ops))
         spfn)
     (cond
                    (or (= (length a) 3) (eq (car a) 'calcFunc-if))
                    (/= (nth 3 op) -1))
               (cond
-               ((> prec (or (nth 4 op) (min (nth 2 op) (nth 3 op))))
+               ((or
+                  (> prec (or (nth 4 op) (min (nth 2 op) (nth 3 op))))
+                  (and div (eq (car a) '*)))
                 (if (and (memq calc-language '(tex latex))
                          (not (math-tex-expr-is-flat a)))
                     (if (eq (car-safe a) '/)
                                      nil)
                                  math-compose-level))
                        (lhs (math-compose-expr (nth 1 a) (nth 2 op)))
-                       (rhs (math-compose-expr (nth 2 a) (nth 3 op))))
+                       (rhs (math-compose-expr (nth 2 a) (nth 3 op) (eq (nth 1 op) '/))))
                   (and (equal (car op) "^")
                        (eq (math-comp-first-char lhs) ?-)
                        (setq lhs (list 'horiz "(" lhs ")")))