summaryrefslogtreecommitdiff
path: root/src/guile
diff options
context:
space:
mode:
authorLudovic Courtes2006-12-02 10:43:59 +0000
committerLudovic Courtes2006-12-02 10:43:59 +0000
commita7a4342d6efd74f7231994b4cc5b4255b36e13f4 (patch)
tree2167b61ded7fdbebe613c232d902203943871258 /src/guile
parent32136d000be5c570133c48c3650d5d7b51efa2fc (diff)
downloadskribilo-a7a4342d6efd74f7231994b4cc5b4255b36e13f4.tar.gz
skribilo-a7a4342d6efd74f7231994b4cc5b4255b36e13f4.tar.lz
skribilo-a7a4342d6efd74f7231994b4cc5b4255b36e13f4.zip
eq: Properly handle operator precedence.
* src/guile/skribilo/package/eq.scm (%operator-precedence): Fixed according to Wikipedia. (simple-markup-writer): Honor operator precedence. * src/guile/skribilo/package/eq/lout.scm (simple-lout-markup-writer): Likewise. git-archimport-id: skribilo@sv.gnu.org--2006/skribilo--devo--1.2--patch-25
Diffstat (limited to 'src/guile')
-rw-r--r--src/guile/skribilo/package/eq.scm39
-rw-r--r--src/guile/skribilo/package/eq/lout.scm28
2 files changed, 38 insertions, 29 deletions
diff --git a/src/guile/skribilo/package/eq.scm b/src/guile/skribilo/package/eq.scm
index c45f698..a3eb99c 100644
--- a/src/guile/skribilo/package/eq.scm
+++ b/src/guile/skribilo/package/eq.scm
@@ -116,18 +116,27 @@ a symbol representing the mathematical operator denoted by @var{m} (e.g.,
;;;
(define %operator-precedence
- ;; FIXME: This needs to be augmented.
- '((+ . 1)
- (- . 1)
- (* . 2)
- (/ . 2)
- (sum . 3)
+ ;; Taken from http://en.wikipedia.org/wiki/Order_of_operations .
+ '((expt . 2)
+ (sqrt . 2)
+
+ (* . 3)
+ (/ . 3)
(product . 3)
- (= . 0)
- (< . 0)
- (> . 0)
- (<= . 0)
- (>= . 0)))
+
+ (+ . 4)
+ (- . 4)
+ (sum . 4)
+
+ (< . 6)
+ (> . 6)
+ (<= . 6)
+ (>= . 6)
+
+ (= . 7)
+ (!= . 7)
+ (~= . 7)))
+
(define-public (operator-precedence op)
(let ((p (assq op %operator-precedence)))
@@ -329,10 +338,10 @@ a symbol representing the mathematical operator denoted by @var{m} (e.g.,
(nested-eq? (equation-markup? o))
(need-paren?
(and nested-eq?
-; (< (operator-precedence
-; (equation-markup-name->operator
-; (markup-markup o)))
-; ,precedence)
+ (>= (operator-precedence
+ (equation-markup-name->operator
+ (markup-markup o)))
+ ,precedence)
)
))
diff --git a/src/guile/skribilo/package/eq/lout.scm b/src/guile/skribilo/package/eq/lout.scm
index 563fdbf..9cd594b 100644
--- a/src/guile/skribilo/package/eq/lout.scm
+++ b/src/guile/skribilo/package/eq/lout.scm
@@ -85,8 +85,12 @@
;; Note: We could use `pmatrix' here but it precludes line-breaking
;; within equations.
- (open-par `(if need-paren? "{ @VScale ( }" ""))
- (close-par `(if need-paren? "{ @VScale ) }" "")))
+ (open-par (if parentheses?
+ `(if need-paren? "{ @VScale ( }" "")
+ ""))
+ (close-par (if parentheses?
+ `(if need-paren? "{ @VScale ) }" "")
+ "")))
`(markup-writer ',(symbol-append 'eq: sym)
(find-engine 'lout)
@@ -102,25 +106,21 @@
(eq-op? (equation-markup? op))
(need-paren?
(and eq-op?
- (< (operator-precedence
- (equation-markup-name->operator
- (markup-markup op)))
- ,precedence)))
+ (>= (operator-precedence
+ (equation-markup-name->operator
+ (markup-markup op)))
+ ,precedence)))
(column (port-column
(current-output-port))))
;; Work around Lout's limitations...
(if (> column 1000) (display "\n"))
- (display (string-append " { "
- ,(if parentheses?
- open-par
- "")))
+ (display
+ (string-append " { " ,open-par))
(output op engine)
- (display (string-append ,(if parentheses?
- close-par
- "")
- " }"))
+ (display
+ (string-append ,close-par " }"))
(if (pair? (cdr operands))
(display (string-append " "
lout-name