comparison lisp/calc/calc-lang.el @ 109033:d150a25a0eb9

Add some utf-8 coding cookies. * lisp/calc/calc-aent.el, lisp/calc/calc-ext.el, lisp/calc/calc-lang.el: * lisp/calc/calc-store.el, lisp/calc/calc-units.el, lisp/calc/calc.el: * lisp/calc/calccomp.el: Add explicit utf-8 coding cookies to files with utf-8 characters. Also delete trailing whitespace.
author Glenn Morris <rgm@gnu.org>
date Tue, 22 Jun 2010 00:41:10 -0700
parents c84578d13e42
children 4e76c4e4f20f
comparison
equal deleted inserted replaced
109032:d8720405694a 109033:d150a25a0eb9
1 ;;; calc-lang.el --- calc language functions 1 ;;; calc-lang.el --- calc language functions
2 2
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, 2005,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 5
6 ;; Author: David Gillespie <daveg@synaptics.com> 6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> 7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 8
9 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
333 333
334 (add-to-list 'calc-lang-slash-idiv 'fortran) 334 (add-to-list 'calc-lang-slash-idiv 'fortran)
335 (add-to-list 'calc-lang-allow-underscores 'fortran) 335 (add-to-list 'calc-lang-allow-underscores 'fortran)
336 (add-to-list 'calc-lang-parens-are-subscripts 'fortran) 336 (add-to-list 'calc-lang-parens-are-subscripts 'fortran)
337 337
338 ;; The next few variables are local to math-read-exprs in calc-aent.el 338 ;; The next few variables are local to math-read-exprs in calc-aent.el
339 ;; and math-read-expr in calc-ext.el, but are set in functions they call. 339 ;; and math-read-expr in calc-ext.el, but are set in functions they call.
340 340
341 (defvar math-exp-token) 341 (defvar math-exp-token)
342 (defvar math-expr-data) 342 (defvar math-expr-data)
343 (defvar math-exp-old-pos) 343 (defvar math-exp-old-pos)
377 ((= n 0) 377 ((= n 0)
378 (message "TeX language mode with multiline matrices")) 378 (message "TeX language mode with multiline matrices"))
379 ((= n 1) 379 ((= n 1)
380 (message "TeX language mode with \\hbox{func}(\\hbox{var})")) 380 (message "TeX language mode with \\hbox{func}(\\hbox{var})"))
381 ((> n 1) 381 ((> n 1)
382 (message 382 (message
383 "TeX language mode with \\hbox{func}(\\hbox{var}) and multiline matrices")) 383 "TeX language mode with \\hbox{func}(\\hbox{var}) and multiline matrices"))
384 ((= n -1) 384 ((= n -1)
385 (message "TeX language mode with \\func(\\hbox{var})")) 385 (message "TeX language mode with \\func(\\hbox{var})"))
386 ((< n -1) 386 ((< n -1)
387 (message 387 (message
388 "TeX language mode with \\func(\\hbox{var}) and multiline matrices"))))) 388 "TeX language mode with \\func(\\hbox{var}) and multiline matrices")))))
389 389
390 (defun calc-latex-language (n) 390 (defun calc-latex-language (n)
391 (interactive "P") 391 (interactive "P")
392 (calc-wrapper 392 (calc-wrapper
397 ((= n 0) 397 ((= n 0)
398 (message "LaTeX language mode with multiline matrices")) 398 (message "LaTeX language mode with multiline matrices"))
399 ((= n 1) 399 ((= n 1)
400 (message "LaTeX language mode with \\text{func}(\\text{var})")) 400 (message "LaTeX language mode with \\text{func}(\\text{var})"))
401 ((> n 1) 401 ((> n 1)
402 (message 402 (message
403 "LaTeX language mode with \\text{func}(\\text{var}) and multiline matrices")) 403 "LaTeX language mode with \\text{func}(\\text{var}) and multiline matrices"))
404 ((= n -1) 404 ((= n -1)
405 (message "LaTeX language mode with \\func(\\text{var})")) 405 (message "LaTeX language mode with \\func(\\text{var})"))
406 ((< n -1) 406 ((< n -1)
407 (message 407 (message
408 "LaTeX language mode with \\func(\\text{var}) and multiline matrices"))))) 408 "LaTeX language mode with \\func(\\text{var}) and multiline matrices")))))
409 409
410 (put 'tex 'math-lang-name "TeX") 410 (put 'tex 'math-lang-name "TeX")
411 (put 'latex 'math-lang-name "LaTeX") 411 (put 'latex 'math-lang-name "LaTeX")
412 412
496 (calcFunc-prod . (math-compose-tex-sum "\\prod")) 496 (calcFunc-prod . (math-compose-tex-sum "\\prod"))
497 (calcFunc-sqrt . math-compose-tex-sqrt) 497 (calcFunc-sqrt . math-compose-tex-sqrt)
498 (intv . math-compose-tex-intv))) 498 (intv . math-compose-tex-intv)))
499 499
500 (put 'tex 'math-variable-table 500 (put 'tex 'math-variable-table
501 '( 501 '(
502 ;; The Greek letters 502 ;; The Greek letters
503 ( \\alpha . var-alpha ) 503 ( \\alpha . var-alpha )
504 ( \\beta . var-beta ) 504 ( \\beta . var-beta )
505 ( \\gamma . var-gamma ) 505 ( \\gamma . var-gamma )
506 ( \\Gamma . var-Gamma ) 506 ( \\Gamma . var-Gamma )
628 (setq math-exp-str (copy-sequence math-exp-str)) 628 (setq math-exp-str (copy-sequence math-exp-str))
629 (aset math-exp-str right ?\])))))))))) 629 (aset math-exp-str right ?\]))))))))))
630 630
631 (defun math-compose-tex-matrix (a &optional ltx) 631 (defun math-compose-tex-matrix (a &optional ltx)
632 (if (cdr a) 632 (if (cdr a)
633 (cons (append (math-compose-vector (cdr (car a)) " & " 0) 633 (cons (append (math-compose-vector (cdr (car a)) " & " 0)
634 (if ltx '(" \\\\ ") '(" \\cr "))) 634 (if ltx '(" \\\\ ") '(" \\cr ")))
635 (math-compose-tex-matrix (cdr a) ltx)) 635 (math-compose-tex-matrix (cdr a) ltx))
636 (list (math-compose-vector (cdr (car a)) " & " 0)))) 636 (list (math-compose-vector (cdr (car a)) " & " 0))))
637 637
638 (defun math-compose-tex-sum (a fn) 638 (defun math-compose-tex-sum (a fn)
720 (or (Math-realp (nth 1 a)) 720 (or (Math-realp (nth 1 a))
721 (memq (car (nth 1 a)) '(var *)))) 721 (memq (car (nth 1 a)) '(var *))))
722 (setq left "{" right "}")) 722 (setq left "{" right "}"))
723 (t (setq left calc-function-open 723 (t (setq left calc-function-open
724 right calc-function-close))) 724 right calc-function-close)))
725 (list 'horiz func 725 (list 'horiz func
726 left 726 left
727 (math-compose-vector (cdr a) ", " 0) 727 (math-compose-vector (cdr a) ", " 0)
728 right))) 728 right)))
729 729
730 (put 'latex 'math-oper-table 730 (put 'latex 'math-oper-table
864 math-expr-data "[") 864 math-expr-data "[")
865 (let ((right (string-match "}" math-exp-str math-exp-pos))) 865 (let ((right (string-match "}" math-exp-str math-exp-pos)))
866 (and right 866 (and right
867 (setq math-exp-str (copy-sequence math-exp-str)) 867 (setq math-exp-str (copy-sequence math-exp-str))
868 (aset math-exp-str right ?\])))))))))) 868 (aset math-exp-str right ?\]))))))))))
869 869
870 (defun math-latex-parse-frac (f val) 870 (defun math-latex-parse-frac (f val)
871 (let (numer denom) 871 (let (numer denom)
872 (setq numer (car (math-read-expr-list))) 872 (setq numer (car (math-read-expr-list)))
873 (math-read-token) 873 (math-read-token)
874 (setq denom (math-read-factor)) 874 (setq denom (math-read-factor))
986 (append '(horiz "matrix { ") 986 (append '(horiz "matrix { ")
987 (math-compose-eqn-matrix 987 (math-compose-eqn-matrix
988 (cdr (math-transpose a))) 988 (cdr (math-transpose a)))
989 '("}"))))) 989 '("}")))))
990 990
991 (put 'eqn 'math-var-formatter 991 (put 'eqn 'math-var-formatter
992 (function 992 (function
993 (lambda (a prec) 993 (lambda (a prec)
994 (let (v) 994 (let (v)
995 (if (and math-compose-hash-args 995 (if (and math-compose-hash-args
996 (let ((p calc-arg-values)) 996 (let ((p calc-arg-values))
1009 'var 1009 'var
1010 (intern (substring (symbol-name (nth 1 a)) 0 -1)) 1010 (intern (substring (symbol-name (nth 1 a)) 0 -1))
1011 (intern (substring (symbol-name (nth 2 a)) 0 -1)))) 1011 (intern (substring (symbol-name (nth 2 a)) 0 -1))))
1012 prec) 1012 prec)
1013 (symbol-name (nth 1 a)))))))) 1013 (symbol-name (nth 1 a))))))))
1014 1014
1015 (defconst math-eqn-special-funcs 1015 (defconst math-eqn-special-funcs
1016 '( calcFunc-log 1016 '( calcFunc-log
1017 calcFunc-ln calcFunc-exp 1017 calcFunc-ln calcFunc-exp
1018 calcFunc-sin calcFunc-cos calcFunc-tan 1018 calcFunc-sin calcFunc-cos calcFunc-tan
1019 calcFunc-sec calcFunc-csc calcFunc-cot 1019 calcFunc-sec calcFunc-csc calcFunc-cot
1020 calcFunc-sinh calcFunc-cosh calcFunc-tanh 1020 calcFunc-sinh calcFunc-cosh calcFunc-tanh
1021 calcFunc-sech calcFunc-csch calcFunc-coth 1021 calcFunc-sech calcFunc-csch calcFunc-coth
1022 calcFunc-arcsin calcFunc-arccos calcFunc-arctan 1022 calcFunc-arcsin calcFunc-arccos calcFunc-arctan
1023 calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh)) 1023 calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh))
1024 1024
1025 (put 'eqn 'math-func-formatter 1025 (put 'eqn 'math-func-formatter
1026 (function 1026 (function
1027 (lambda (func a) 1027 (lambda (func a)
1028 (let (left right) 1028 (let (left right)
1029 (if (string-match "[^']'+\\'" func) 1029 (if (string-match "[^']'+\\'" func)
1030 (let ((n (- (length func) (match-beginning 0) 1))) 1030 (let ((n (- (length func) (match-beginning 0) 1)))
1033 (setq func (concat func " prime"))))) 1033 (setq func (concat func " prime")))))
1034 (cond ((or (> (length a) 2) 1034 (cond ((or (> (length a) 2)
1035 (not (math-tex-expr-is-flat (nth 1 a)))) 1035 (not (math-tex-expr-is-flat (nth 1 a))))
1036 (setq left "{left ( " 1036 (setq left "{left ( "
1037 right " right )}")) 1037 right " right )}"))
1038 1038
1039 ((and 1039 ((and
1040 (memq (car a) math-eqn-special-funcs) 1040 (memq (car a) math-eqn-special-funcs)
1041 (= (length a) 2) 1041 (= (length a) 2)
1042 (or (Math-realp (nth 1 a)) 1042 (or (Math-realp (nth 1 a))
1043 (memq (car (nth 1 a)) '(var *)))) 1043 (memq (car (nth 1 a)) '(var *))))
1044 (setq left "~{" right "}")) 1044 (setq left "~{" right "}"))
1067 ("arc" ("sin") ("cos") ("tan") ("sinh") ("cosh") ("tanh")) 1067 ("arc" ("sin") ("cos") ("tan") ("sinh") ("cosh") ("tanh"))
1068 ("size" n) ("font" n) ("fwd" n) ("back" n) ("up" n) ("down" n) 1068 ("size" n) ("font" n) ("fwd" n) ("back" n) ("up" n) ("down" n)
1069 ("above" punc ","))) 1069 ("above" punc ",")))
1070 1070
1071 (put 'eqn 'math-lang-adjust-words 1071 (put 'eqn 'math-lang-adjust-words
1072 (function 1072 (function
1073 (lambda () 1073 (lambda ()
1074 (let ((code (assoc math-expr-data math-eqn-ignore-words))) 1074 (let ((code (assoc math-expr-data math-eqn-ignore-words)))
1075 (cond ((null code)) 1075 (cond ((null code))
1076 ((null (cdr code)) 1076 ((null (cdr code))
1077 (math-read-token)) 1077 (math-read-token))
1187 ( E . var-e) ;; Not really in Yacas 1187 ( E . var-e) ;; Not really in Yacas
1188 ( GoldenRatio . var-phi) 1188 ( GoldenRatio . var-phi)
1189 ( Gamma . var-gamma))) 1189 ( Gamma . var-gamma)))
1190 1190
1191 (put 'yacas 'math-parse-table 1191 (put 'yacas 'math-parse-table
1192 '((("Deriv(" 0 ")" 0) 1192 '((("Deriv(" 0 ")" 0)
1193 calcFunc-deriv (var ArgB var-ArgB) (var ArgA var-ArgA)) 1193 calcFunc-deriv (var ArgB var-ArgB) (var ArgA var-ArgA))
1194 (("D(" 0 ")" 0) 1194 (("D(" 0 ")" 0)
1195 calcFunc-deriv (var ArgB var-ArgB) (var ArgA var-ArgA)) 1195 calcFunc-deriv (var ArgB var-ArgB) (var ArgA var-ArgA))
1196 (("Integrate(" 0 ")" 0) 1196 (("Integrate(" 0 ")" 0)
1197 calcFunc-integ (var ArgB var-ArgB)(var ArgA var-ArgA)) 1197 calcFunc-integ (var ArgB var-ArgB)(var ArgA var-ArgA))
1198 (("Integrate(" 0 "," 0 "," 0 ")" 0) 1198 (("Integrate(" 0 "," 0 "," 0 ")" 0)
1199 calcFunc-integ (var ArgD var-ArgD) (var ArgA var-ArgA) 1199 calcFunc-integ (var ArgD var-ArgD) (var ArgA var-ArgA)
1200 (var ArgB var-ArgB) (var ArgC var-ArgC)) 1200 (var ArgB var-ArgB) (var ArgC var-ArgC))
1201 (("Subst(" 0 "," 0 ")" 0) 1201 (("Subst(" 0 "," 0 ")" 0)
1202 calcFunc-subst (var ArgC var-ArgC) (var ArgA var-ArgA) 1202 calcFunc-subst (var ArgC var-ArgC) (var ArgA var-ArgA)
1203 (var ArgB var-ArgB)) 1203 (var ArgB var-ArgB))
1204 (("Taylor(" 0 "," 0 "," 0 ")" 0) 1204 (("Taylor(" 0 "," 0 "," 0 ")" 0)
1205 calcFunc-taylor (var ArgD var-ArgD) 1205 calcFunc-taylor (var ArgD var-ArgD)
1206 (calcFunc-eq (var ArgA var-ArgA) (var ArgB var-ArgB)) 1206 (calcFunc-eq (var ArgA var-ArgA) (var ArgB var-ArgB))
1207 (var ArgC var-ArgC)))) 1207 (var ArgC var-ArgC))))
1208 1208
1209 (put 'yacas 'math-oper-table 1209 (put 'yacas 'math-oper-table
1210 '(("+" + 30 30) 1210 '(("+" + 30 30)
1211 ("-" - 30 60) 1211 ("-" - 30 60)
1354 (nth 1 fn) 1354 (nth 1 fn)
1355 "(" 1355 "("
1356 (math-compose-expr (nth 2 a) -1) 1356 (math-compose-expr (nth 2 a) -1)
1357 (if (not (nth 3 a)) 1357 (if (not (nth 3 a))
1358 ")" 1358 ")"
1359 (concat 1359 (concat
1360 "," 1360 ","
1361 (math-compose-expr (nth 3 a) -1) 1361 (math-compose-expr (nth 3 a) -1)
1362 "," 1362 ","
1363 (math-compose-expr (nth 4 a) -1) 1363 (math-compose-expr (nth 4 a) -1)
1364 ")")) 1364 ")"))
1391 1391
1392 (put 'maxima 'math-oper-table 1392 (put 'maxima 'math-oper-table
1393 '(("+" + 100 100) 1393 '(("+" + 100 100)
1394 ("-" - 100 134) 1394 ("-" - 100 134)
1395 ("*" * 120 120) 1395 ("*" * 120 120)
1396 ("." * 130 129) 1396 ("." * 130 129)
1397 ("/" / 120 120) 1397 ("/" / 120 120)
1398 ("u-" neg -1 180) 1398 ("u-" neg -1 180)
1399 ("u+" ident -1 180) 1399 ("u+" ident -1 180)
1400 ("^" ^ 140 139) 1400 ("^" ^ 140 139)
1401 ("**" ^ 140 139) 1401 ("**" ^ 140 139)
1492 (nth 1 args) 1492 (nth 1 args)
1493 (nth 2 args)) 1493 (nth 2 args))
1494 (nth 3 args)))) 1494 (nth 3 args))))
1495 1495
1496 (put 'maxima 'math-parse-table 1496 (put 'maxima 'math-parse-table
1497 '((("if" 0 "then" 0 "else" 0) 1497 '((("if" 0 "then" 0 "else" 0)
1498 calcFunc-if 1498 calcFunc-if
1499 (var ArgA var-ArgA) 1499 (var ArgA var-ArgA)
1500 (var ArgB var-ArgB) 1500 (var ArgB var-ArgB)
1501 (var ArgC var-ArgC)))) 1501 (var ArgC var-ArgC))))
1502 1502
1503 (put 'maxima 'math-special-function-table 1503 (put 'maxima 'math-special-function-table
1504 '(( calcFunc-taylor . math-maxima-compose-taylor) 1504 '(( calcFunc-taylor . math-maxima-compose-taylor)
1570 (put 'maxima 'math-matrix-formatter 1570 (put 'maxima 'math-matrix-formatter
1571 (function 1571 (function
1572 (lambda (a) 1572 (lambda (a)
1573 (list 'horiz 1573 (list 'horiz
1574 "matrix(" 1574 "matrix("
1575 (math-compose-vector (cdr a) 1575 (math-compose-vector (cdr a)
1576 (concat math-comp-comma " ") 1576 (concat math-comp-comma " ")
1577 math-comp-vector-prec) 1577 math-comp-vector-prec)
1578 ")")))) 1578 ")"))))
1579 1579
1580 1580
1732 (list (nth 2 f) 1732 (list (nth 2 f)
1733 (nth 1 args) 1733 (nth 1 args)
1734 (nth 0 args)))) 1734 (nth 0 args))))
1735 1735
1736 (put 'giac 'math-parse-table 1736 (put 'giac 'math-parse-table
1737 '((("set" 0) 1737 '((("set" 0)
1738 calcFunc-rdup 1738 calcFunc-rdup
1739 (var ArgA var-ArgA)))) 1739 (var ArgA var-ArgA))))
1740 1740
1741 (put 'giac 'math-special-function-table 1741 (put 'giac 'math-special-function-table
1742 '((calcFunc-cons . (math-lang-compose-switch-args "prepend")) 1742 '((calcFunc-cons . (math-lang-compose-switch-args "prepend"))
1746 1746
1747 (defun math-lang-compose-switch-args (a fn) 1747 (defun math-lang-compose-switch-args (a fn)
1748 "Compose the arguments to a Calc function in reverse order. 1748 "Compose the arguments to a Calc function in reverse order.
1749 This is used for various language modes which have functions in reverse 1749 This is used for various language modes which have functions in reverse
1750 order to Calc's." 1750 order to Calc's."
1751 (list 'horiz (nth 1 fn) 1751 (list 'horiz (nth 1 fn)
1752 "(" 1752 "("
1753 (math-compose-expr (nth 2 a) 0) 1753 (math-compose-expr (nth 2 a) 0)
1754 "," 1754 ","
1755 (math-compose-expr (nth 1 a) 0) 1755 (math-compose-expr (nth 1 a) 0)
1756 ")")) 1756 ")"))
1768 (lambda (a) 1768 (lambda (a)
1769 (let ((args (cdr (cdr a)))) 1769 (let ((args (cdr (cdr a))))
1770 (list 'horiz 1770 (list 'horiz
1771 (math-compose-expr (nth 1 a) 1000) 1771 (math-compose-expr (nth 1 a) 1000)
1772 "[" 1772 "["
1773 (math-compose-expr 1773 (math-compose-expr
1774 (calc-normalize (list '- (nth 2 a) 1)) 0) 1774 (calc-normalize (list '- (nth 2 a) 1)) 0)
1775 "]"))))) 1775 "]")))))
1776 1776
1777 (defun math-read-giac-subscr (x op) 1777 (defun math-read-giac-subscr (x op)
1778 (let ((idx (math-read-expr-level 0))) 1778 (let ((idx (math-read-expr-level 0)))
1999 (function 1999 (function
2000 (lambda (a) 2000 (lambda (a)
2001 (list 'horiz 2001 (list 'horiz
2002 "matrix(" 2002 "matrix("
2003 math-comp-left-bracket 2003 math-comp-left-bracket
2004 (math-compose-vector (cdr a) 2004 (math-compose-vector (cdr a)
2005 (concat math-comp-comma " ") 2005 (concat math-comp-comma " ")
2006 math-comp-vector-prec) 2006 math-comp-vector-prec)
2007 math-comp-right-bracket 2007 math-comp-right-bracket
2008 ")")))) 2008 ")"))))
2009 2009
2042 ;; local to math-read-big-expr in calc-ext.el, but used by 2042 ;; local to math-read-big-expr in calc-ext.el, but used by
2043 ;; math-read-big-rec. 2043 ;; math-read-big-rec.
2044 (defvar math-read-big-baseline) 2044 (defvar math-read-big-baseline)
2045 (defvar math-read-big-h2) 2045 (defvar math-read-big-h2)
2046 2046
2047 ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2 2047 ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2
2048 ;; are local to math-read-big-rec, but are used by math-read-big-char, 2048 ;; are local to math-read-big-rec, but are used by math-read-big-char,
2049 ;; math-read-big-emptyp and math-read-big-balance which are called by 2049 ;; math-read-big-emptyp and math-read-big-balance which are called by
2050 ;; math-read-big-rec. 2050 ;; math-read-big-rec.
2051 ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el, 2051 ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el,
2052 ;; which calls math-read-big-balance. 2052 ;; which calls math-read-big-balance.
2053 (defvar math-rb-h1) 2053 (defvar math-rb-h1)
2054 (defvar math-rb-h2) 2054 (defvar math-rb-h2)
2055 (defvar math-rb-v1) 2055 (defvar math-rb-v1)
2056 (defvar math-rb-v2) 2056 (defvar math-rb-v2)
2057 2057
2058 (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2 2058 (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2
2059 &optional baseline prec short) 2059 &optional baseline prec short)
2060 (or prec (setq prec 0)) 2060 (or prec (setq prec 0))
2061 2061
2062 ;; Clip whitespace above or below. 2062 ;; Clip whitespace above or below.
2063 (while (and (< math-rb-v1 math-rb-v2) 2063 (while (and (< math-rb-v1 math-rb-v2)
2064 (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2 (1+ math-rb-v1))) 2064 (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2 (1+ math-rb-v1)))
2065 (setq math-rb-v1 (1+ math-rb-v1))) 2065 (setq math-rb-v1 (1+ math-rb-v1)))
2066 (while (and (< math-rb-v1 math-rb-v2) 2066 (while (and (< math-rb-v1 math-rb-v2)
2067 (math-read-big-emptyp math-rb-h1 (1- math-rb-v2) math-rb-h2 math-rb-v2)) 2067 (math-read-big-emptyp math-rb-h1 (1- math-rb-v2) math-rb-h2 math-rb-v2))
2068 (setq math-rb-v2 (1- math-rb-v2))) 2068 (setq math-rb-v2 (1- math-rb-v2)))
2069 2069
2070 ;; If formula is a single line high, normal parser can handle it. 2070 ;; If formula is a single line high, normal parser can handle it.
2071 (if (<= math-rb-v2 (1+ math-rb-v1)) 2071 (if (<= math-rb-v2 (1+ math-rb-v1))
2072 (if (or (<= math-rb-v2 math-rb-v1) 2072 (if (or (<= math-rb-v2 math-rb-v1)
2073 (> math-rb-h1 (length (setq math-rb-v2 2073 (> math-rb-h1 (length (setq math-rb-v2
2074 (nth math-rb-v1 math-read-big-lines))))) 2074 (nth math-rb-v1 math-read-big-lines)))))
2075 (math-read-big-error math-rb-h1 math-rb-v1) 2075 (math-read-big-error math-rb-h1 math-rb-v1)
2076 (setq math-read-big-baseline math-rb-v1 2076 (setq math-read-big-baseline math-rb-v1
2077 math-read-big-h2 math-rb-h2 2077 math-read-big-h2 math-rb-h2
2078 math-rb-v2 (nth math-rb-v1 math-read-big-lines) 2078 math-rb-v2 (nth math-rb-v1 math-read-big-lines)
2079 math-rb-h2 (math-read-expr 2079 math-rb-h2 (math-read-expr
2080 (substring math-rb-v2 math-rb-h1 2080 (substring math-rb-v2 math-rb-h1
2081 (min math-rb-h2 (length math-rb-v2))))) 2081 (min math-rb-h2 (length math-rb-v2)))))
2082 (if (eq (car-safe math-rb-h2) 'error) 2082 (if (eq (car-safe math-rb-h2) 'error)
2083 (math-read-big-error (+ math-rb-h1 (nth 1 math-rb-h2)) 2083 (math-read-big-error (+ math-rb-h1 (nth 1 math-rb-h2))
2084 math-rb-v1 (nth 2 math-rb-h2)) 2084 math-rb-v1 (nth 2 math-rb-h2))
2085 math-rb-h2)) 2085 math-rb-h2))
2086 2086
2087 ;; Clip whitespace at left or right. 2087 ;; Clip whitespace at left or right.
2088 (while (and (< math-rb-h1 math-rb-h2) 2088 (while (and (< math-rb-h1 math-rb-h2)
2089 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) math-rb-v2)) 2089 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) math-rb-v2))
2090 (setq math-rb-h1 (1+ math-rb-h1))) 2090 (setq math-rb-h1 (1+ math-rb-h1)))
2091 (while (and (< math-rb-h1 math-rb-h2) 2091 (while (and (< math-rb-h1 math-rb-h2)
2092 (math-read-big-emptyp (1- math-rb-h2) math-rb-v1 math-rb-h2 math-rb-v2)) 2092 (math-read-big-emptyp (1- math-rb-h2) math-rb-v1 math-rb-h2 math-rb-v2))
2093 (setq math-rb-h2 (1- math-rb-h2))) 2093 (setq math-rb-h2 (1- math-rb-h2)))
2094 2094
2095 ;; Scan to find widest left-justified "----" in the region. 2095 ;; Scan to find widest left-justified "----" in the region.
2096 (let* ((widest nil) 2096 (let* ((widest nil)
2105 len (min math-rb-h2 (length line))) 2105 len (min math-rb-h2 (length line)))
2106 (and (< math-rb-h1 len) 2106 (and (< math-rb-h1 len)
2107 (/= (aref line math-rb-h1) ?\ ) 2107 (/= (aref line math-rb-h1) ?\ )
2108 (if (and (= (aref line math-rb-h1) ?\-) 2108 (if (and (= (aref line math-rb-h1) ?\-)
2109 ;; Make sure it's not a minus sign. 2109 ;; Make sure it's not a minus sign.
2110 (or (and (< (1+ math-rb-h1) len) 2110 (or (and (< (1+ math-rb-h1) len)
2111 (= (aref line (1+ math-rb-h1)) ?\-)) 2111 (= (aref line (1+ math-rb-h1)) ?\-))
2112 (/= (math-read-big-char math-rb-h1 (1- v)) ?\ ) 2112 (/= (math-read-big-char math-rb-h1 (1- v)) ?\ )
2113 (/= (math-read-big-char math-rb-h1 (1+ v)) ?\ ))) 2113 (/= (math-read-big-char math-rb-h1 (1+ v)) ?\ )))
2114 (progn 2114 (progn
2115 (setq h math-rb-h1) 2115 (setq h math-rb-h1)
2164 v math-read-big-baseline)) 2164 v math-read-big-baseline))
2165 2165
2166 ;; Binomial coefficient. 2166 ;; Binomial coefficient.
2167 ((and (= other-char ?\() 2167 ((and (= other-char ?\()
2168 (= (math-read-big-char (1+ math-rb-h1) v) ?\ ) 2168 (= (math-read-big-char (1+ math-rb-h1) v) ?\ )
2169 (= (string-match "( *)" (nth v math-read-big-lines) 2169 (= (string-match "( *)" (nth v math-read-big-lines)
2170 math-rb-h1) math-rb-h1)) 2170 math-rb-h1) math-rb-h1))
2171 (setq h (match-end 0)) 2171 (setq h (match-end 0))
2172 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) 2172 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
2173 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) 2173 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
2174 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) 2174 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
2178 (math-read-big-rec (1+ math-rb-h1) (1+ v) 2178 (math-read-big-rec (1+ math-rb-h1) (1+ v)
2179 (1- h) math-rb-v2)))) 2179 (1- h) math-rb-v2))))
2180 2180
2181 ;; Minus sign. 2181 ;; Minus sign.
2182 ((= other-char ?\-) 2182 ((= other-char ?\-)
2183 (setq p (list 'neg (math-read-big-rec (1+ math-rb-h1) math-rb-v1 2183 (setq p (list 'neg (math-read-big-rec (1+ math-rb-h1) math-rb-v1
2184 math-rb-h2 math-rb-v2 v 250 t)) 2184 math-rb-h2 math-rb-v2 v 250 t))
2185 v math-read-big-baseline 2185 v math-read-big-baseline
2186 h math-read-big-h2)) 2186 h math-read-big-h2))
2187 2187
2188 ;; Parentheses. 2188 ;; Parentheses.
2197 (if (= sep ?\.) 2197 (if (= sep ?\.)
2198 (setq h (1+ h))) 2198 (setq h (1+ h)))
2199 (if (= sep ?\]) 2199 (if (= sep ?\])
2200 (math-read-big-error (1- h) v "Expected `)'")) 2200 (math-read-big-error (1- h) v "Expected `)'"))
2201 (if (= sep ?\)) 2201 (if (= sep ?\))
2202 (setq p (math-read-big-rec 2202 (setq p (math-read-big-rec
2203 (1+ math-rb-h1) math-rb-v1 (1- h) math-rb-v2 v)) 2203 (1+ math-rb-h1) math-rb-v1 (1- h) math-rb-v2 v))
2204 (setq hmid (math-read-big-balance h v "(") 2204 (setq hmid (math-read-big-balance h v "(")
2205 p (list p 2205 p (list p
2206 (math-read-big-rec h math-rb-v1 (1- hmid) math-rb-v2 v)) 2206 (math-read-big-rec h math-rb-v1 (1- hmid) math-rb-v2 v))
2207 h hmid) 2207 h hmid)
2208 (cond ((= sep ?\.) 2208 (cond ((= sep ?\.)
2209 (setq p (cons 'intv (cons (if (= (math-read-big-char 2209 (setq p (cons 'intv (cons (if (= (math-read-big-char
2210 (1- h) v) 2210 (1- h) v)
2345 (setq h (match-end 0) 2345 (setq h (match-end 0)
2346 p (math-read-number (math-match-substring line 0))) 2346 p (math-read-number (math-match-substring line 0)))
2347 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) 2347 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
2348 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t))) 2348 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)))
2349 2349
2350 ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2; 2350 ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2;
2351 ;; baseline = v. 2351 ;; baseline = v.
2352 (if baseline 2352 (if baseline
2353 (or (= v baseline) 2353 (or (= v baseline)
2354 (math-read-big-error math-rb-h1 v "Inconsistent baseline in formula")) 2354 (math-read-big-error math-rb-h1 v "Inconsistent baseline in formula"))
2355 (setq baseline v)) 2355 (setq baseline v))
2387 h)) 2387 h))
2388 (setq widest '("2x" * 196 195))))) 2388 (setq widest '("2x" * 196 195)))))
2389 (cond ((eq (nth 3 widest) -1) 2389 (cond ((eq (nth 3 widest) -1)
2390 (setq p (list (nth 1 widest) p))) 2390 (setq p (list (nth 1 widest) p)))
2391 ((equal (car widest) "?") 2391 ((equal (car widest) "?")
2392 (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2 2392 (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2
2393 math-rb-v2 baseline nil t))) 2393 math-rb-v2 baseline nil t)))
2394 (or (= (math-read-big-char math-read-big-h2 baseline) ?\:) 2394 (or (= (math-read-big-char math-read-big-h2 baseline) ?\:)
2395 (math-read-big-error math-read-big-h2 baseline "Expected `:'")) 2395 (math-read-big-error math-read-big-h2 baseline "Expected `:'"))
2396 (setq p (list (nth 1 widest) p y 2396 (setq p (list (nth 1 widest) p y
2397 (math-read-big-rec 2397 (math-read-big-rec
2398 (1+ math-read-big-h2) math-rb-v1 math-rb-h2 math-rb-v2 2398 (1+ math-read-big-h2) math-rb-v1 math-rb-h2 math-rb-v2
2399 baseline (nth 3 widest) t)) 2399 baseline (nth 3 widest) t))
2400 h math-read-big-h2))) 2400 h math-read-big-h2)))
2401 (t 2401 (t
2402 (setq p (list (nth 1 widest) p 2402 (setq p (list (nth 1 widest) p
2481 (setq h (1+ h)))) 2481 (setq h (1+ h))))
2482 h)) 2482 h))
2483 2483
2484 (provide 'calc-lang) 2484 (provide 'calc-lang)
2485 2485
2486 ;; Local variables:
2487 ;; coding: utf-8
2488 ;; End:
2489
2486 ;; arch-tag: 483bfe15-f290-4fef-bb7d-ce65be687f2e 2490 ;; arch-tag: 483bfe15-f290-4fef-bb7d-ce65be687f2e
2487 ;;; calc-lang.el ends here 2491 ;;; calc-lang.el ends here