diff options
author | Jay Belanger <jay.p.belanger@gmail.com> | 2012-08-09 09:46:03 -0500 |
---|---|---|
committer | Jay Belanger <jay.p.belanger@gmail.com> | 2012-08-09 09:46:03 -0500 |
commit | 31673780356f219c7a26251b2f79fb00c8e29f0b (patch) | |
tree | 31e041714b6c5fc56ee6ba259f3d3a637e561053 /lisp/calc/calccomp.el | |
parent | dee4ef9388bd6cf5530e71736e0298b42382f32e (diff) | |
download | emacs-31673780356f219c7a26251b2f79fb00c8e29f0b.tar.gz |
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.
Diffstat (limited to 'lisp/calc/calccomp.el')
-rw-r--r-- | lisp/calc/calccomp.el | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lisp/calc/calccomp.el b/lisp/calc/calccomp.el index d8ad7e2cede..51ea8e7b7a3 100644 --- a/lisp/calc/calccomp.el +++ b/lisp/calc/calccomp.el @@ -86,8 +86,11 @@ (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 @@ -591,7 +594,9 @@ (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) '/) @@ -631,7 +636,7 @@ 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 ")"))) |