Mercurial > emacs
annotate lisp/calc/calccomp.el @ 109085:6a23dfd2048b
* startup.el (command-line): Don't call tool-bar-setup in a tty-only build.
author | Andreas Schwab <schwab@linux-m68k.org> |
---|---|
date | Thu, 01 Jul 2010 00:58:19 +0200 |
parents | d150a25a0eb9 |
children | bc0b9af387a7 |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1 ;;; calccomp.el --- composition functions for Calc |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, 2005, |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
6 ;; Author: David Gillespie <daveg@synaptics.com> |
77465
1154f082efd9
Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
76595
diff
changeset
|
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94654
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
94654
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
40785 | 15 |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
19 ;; GNU General Public License for more details. |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
20 |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
94654
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
40785 | 23 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
24 ;;; Commentary: |
40785 | 25 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
26 ;;; Code: |
40785 | 27 |
28 ;; This file is autoloaded from calc-ext.el. | |
58683
1752ff980918
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58465
diff
changeset
|
29 |
40785 | 30 (require 'calc-ext) |
31 (require 'calc-macs) | |
32 | |
33 ;;; A "composition" has one of the following forms: | |
34 ;;; | |
35 ;;; "string" A literal string | |
36 ;;; | |
37 ;;; (horiz C1 C2 ...) Horizontally abutted sub-compositions | |
38 ;;; | |
39 ;;; (set LEVEL OFF) Set left margin + offset for line-break level | |
40 ;;; (break LEVEL) A potential line-break point | |
41 ;;; | |
42 ;;; (vleft N C1 C2 ...) Vertically stacked, left-justified sub-comps | |
43 ;;; (vcent N C1 C2 ...) Vertically stacked, centered sub-comps | |
44 ;;; (vright N C1 C2 ...) Vertically stacked, right-justified sub-comps | |
45 ;;; N specifies baseline of the stack, 0=top line. | |
46 ;;; | |
47 ;;; (supscr C1 C2) Composition C1 with superscript C2 | |
48 ;;; (subscr C1 C2) Composition C1 with subscript C2 | |
49 ;;; (rule X) Horizontal line of X, full width of enclosing comp | |
50 ;;; | |
51 ;;; (tag X C) Composition C corresponds to sub-expression X | |
52 | |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
53 ;; math-comp-just and math-comp-comma-spc are local to |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
54 ;; math-compose-expr, but are used by math-compose-matrix, which is |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
55 ;; called by math-compose-expr |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
56 (defvar math-comp-just) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
57 (defvar math-comp-comma-spc) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
58 |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
59 ;; math-comp-vector-prec is local to math-compose-expr, but is used by |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
60 ;; math-compose-matrix and math-compose-rows, which are called by |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
61 ;; math-compose-expr. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
62 (defvar math-comp-vector-prec) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
63 |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
64 ;; math-comp-left-bracket, math-comp-right-bracket and math-comp-comma are |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
65 ;; local to math-compose-expr, but are used by math-compose-rows, which is |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
66 ;; called by math-compose-expr. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
67 (defvar math-comp-left-bracket) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
68 (defvar math-comp-right-bracket) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
69 (defvar math-comp-comma) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
70 |
86968
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
71 (defun math-compose-var (a) |
87417
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
72 (let (v sn) |
86968
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
73 (if (and math-compose-hash-args |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
74 (let ((p calc-arg-values)) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
75 (setq v 1) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
76 (while (and p (not (equal (car p) a))) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
77 (setq p (and (eq math-compose-hash-args t) (cdr p)) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
78 v (1+ v))) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
79 p)) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
80 (if (eq math-compose-hash-args 1) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
81 "#" |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
82 (format "#%d" v)) |
87417
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
83 (setq sn (symbol-name (nth 1 a))) |
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
84 (if (memq calc-language calc-lang-allow-percentsigns) |
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
85 (setq sn (math-to-percentsigns sn))) |
86968
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
86 (if (memq calc-language calc-lang-allow-underscores) |
87417
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
87 (setq sn (math-to-underscores sn))) |
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
88 sn))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
89 |
40785 | 90 (defun math-compose-expr (a prec) |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
91 (let ((math-compose-level (1+ math-compose-level)) |
81473
834afc8fa2e5
(math-compose-expr): Let math-expr-opers equal math-expr-ops.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
92 (math-expr-opers (math-expr-ops)) |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
93 spfn) |
40785 | 94 (cond |
95 ((or (and (eq a math-comp-selected) a) | |
96 (and math-comp-tagged | |
97 (not (eq math-comp-tagged a)))) | |
98 (let ((math-comp-selected nil)) | |
99 (and math-comp-tagged (setq math-comp-tagged a)) | |
100 (list 'tag a (math-compose-expr a prec)))) | |
101 ((and (not (consp a)) (not (integerp a))) | |
102 (concat "'" (prin1-to-string a))) | |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
103 ((setq spfn (assq (car-safe a) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
104 (get calc-language 'math-special-function-table))) |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
105 (setq spfn (cdr spfn)) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
106 (if (consp spfn) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
107 (funcall (car spfn) a spfn) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
108 (funcall spfn a))) |
40785 | 109 ((math-scalarp a) |
110 (if (or (eq (car-safe a) 'frac) | |
111 (and (nth 1 calc-frac-format) (Math-integerp a))) | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
112 (if (and |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
113 calc-language |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
114 (not (memq calc-language |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
115 '(flat big unform)))) |
40785 | 116 (let ((aa (math-adjust-fraction a)) |
117 (calc-frac-format nil)) | |
118 (math-compose-expr (list '/ | |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
119 (if (memq calc-language |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
120 calc-lang-slash-idiv) |
40785 | 121 (math-float (nth 1 aa)) |
122 (nth 1 aa)) | |
123 (nth 2 aa)) prec)) | |
124 (if (and (eq calc-language 'big) | |
125 (= (length (car calc-frac-format)) 1)) | |
126 (let* ((aa (math-adjust-fraction a)) | |
127 (calc-frac-format nil) | |
128 (math-radix-explicit-format nil) | |
129 (c (list 'horiz | |
130 (if (math-negp (nth 1 aa)) | |
131 "- " "") | |
132 (list 'vcent 1 | |
133 (math-format-number | |
134 (math-abs (nth 1 aa))) | |
135 '(rule ?-) | |
136 (math-format-number (nth 2 aa)))))) | |
137 (if (= calc-number-radix 10) | |
138 c | |
139 (list 'horiz "(" c | |
140 (list 'subscr ")" | |
141 (int-to-string calc-number-radix))))) | |
142 (math-format-number a))) | |
143 (if (not (eq calc-language 'big)) | |
144 (math-format-number a prec) | |
145 (if (memq (car-safe a) '(cplx polar)) | |
146 (if (math-zerop (nth 2 a)) | |
147 (math-compose-expr (nth 1 a) prec) | |
148 (list 'horiz "(" | |
149 (math-compose-expr (nth 1 a) 0) | |
150 (if (eq (car a) 'cplx) ", " "; ") | |
151 (math-compose-expr (nth 2 a) 0) ")")) | |
152 (if (or (= calc-number-radix 10) | |
153 (not (Math-realp a)) | |
154 (and calc-group-digits | |
155 (not (assoc calc-group-char '((",") (" ")))))) | |
156 (math-format-number a prec) | |
157 (let ((s (math-format-number a prec)) | |
158 (c nil)) | |
159 (while (string-match (if (> calc-number-radix 14) | |
160 "\\([0-9]+\\)#\\([0-9a-zA-Z., ]+\\)" | |
161 "\\([0-9]+\\)#\\([0-9a-dA-D., ]+\\)") | |
162 s) | |
163 (setq c (nconc c (list (substring s 0 (match-beginning 0)) | |
164 (list 'subscr | |
165 (math-match-substring s 2) | |
166 (math-match-substring s 1)))) | |
167 s (substring s (match-end 0)))) | |
168 (if (string-match | |
169 "\\*\\([0-9.]+\\)\\^\\(-?[0-9]+\\)\\()?\\)\\'" s) | |
170 (setq s (list 'horiz | |
171 (substring s 0 (match-beginning 0)) " " | |
172 (list 'supscr | |
173 (math-match-substring s 1) | |
174 (math-match-substring s 2)) | |
175 (math-match-substring s 3)))) | |
176 (if c (cons 'horiz (nconc c (list s))) s))))))) | |
177 ((and (get (car a) 'math-compose-forms) | |
178 (not (eq calc-language 'unform)) | |
179 (let ((comps (get (car a) 'math-compose-forms)) | |
180 temp temp2) | |
181 (or (and (setq temp (assq calc-language comps)) | |
182 (or (and (setq temp2 (assq (1- (length a)) (cdr temp))) | |
183 (setq temp (apply (cdr temp2) (cdr a))) | |
184 (math-compose-expr temp prec)) | |
185 (and (setq temp2 (assq nil (cdr temp))) | |
186 (funcall (cdr temp2) a)))) | |
187 (and (setq temp (assq nil comps)) | |
188 (or (and (setq temp2 (assq (1- (length a)) (cdr temp))) | |
189 (setq temp (apply (cdr temp2) (cdr a))) | |
190 (math-compose-expr temp prec)) | |
191 (and (setq temp2 (assq nil (cdr temp))) | |
192 (funcall (cdr temp2) a)))))))) | |
193 ((eq (car a) 'vec) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
194 (let* ((math-comp-left-bracket (if calc-vector-brackets |
40785 | 195 (substring calc-vector-brackets 0 1) "")) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
196 (math-comp-right-bracket (if calc-vector-brackets |
40785 | 197 (substring calc-vector-brackets 1 2) "")) |
198 (inner-brackets (memq 'R calc-matrix-brackets)) | |
199 (outer-brackets (memq 'O calc-matrix-brackets)) | |
200 (row-commas (memq 'C calc-matrix-brackets)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
201 (math-comp-comma-spc (or calc-vector-commas " ")) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
202 (math-comp-comma (or calc-vector-commas "")) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
203 (math-comp-vector-prec (if (or (and calc-vector-commas |
40785 | 204 (math-vector-no-parens a)) |
205 (memq 'P calc-matrix-brackets)) 0 1000)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
206 (math-comp-just (cond ((eq calc-matrix-just 'right) 'vright) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
207 ((eq calc-matrix-just 'center) 'vcent) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
208 (t 'vleft))) |
40785 | 209 (break calc-break-vectors)) |
210 (if (and (memq calc-language '(nil big)) | |
211 (not calc-break-vectors) | |
212 (math-matrixp a) (not (math-matrixp (nth 1 a))) | |
213 (or calc-full-vectors | |
214 (and (< (length a) 7) (< (length (nth 1 a)) 7)) | |
215 (progn (setq break t) nil))) | |
216 (if (progn | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
217 (setq math-comp-vector-prec (if (or (and calc-vector-commas |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
218 (math-vector-no-parens |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
219 (nth 1 a))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
220 (memq 'P calc-matrix-brackets)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
221 0 1000)) |
40785 | 222 (= (length a) 2)) |
223 (list 'horiz | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
224 (concat math-comp-left-bracket math-comp-left-bracket " ") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
225 (math-compose-vector (cdr (nth 1 a)) (concat math-comp-comma " ") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
226 math-comp-vector-prec) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
227 (concat " " math-comp-right-bracket math-comp-right-bracket)) |
40785 | 228 (let* ((rows (1- (length a))) |
229 (cols (1- (length (nth 1 a)))) | |
230 (base (/ (1- rows) 2)) | |
231 (calc-language 'flat)) | |
232 (append '(horiz) | |
233 (list (append '(vleft) | |
234 (list base) | |
235 (list (concat (and outer-brackets | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
236 (concat math-comp-left-bracket |
40785 | 237 " ")) |
238 (and inner-brackets | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
239 (concat math-comp-left-bracket |
40785 | 240 " ")))) |
241 (make-list (1- rows) | |
242 (concat (and outer-brackets | |
243 " ") | |
244 (and inner-brackets | |
245 (concat | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
246 math-comp-left-bracket |
40785 | 247 " ")))))) |
248 (math-compose-matrix (cdr a) 1 cols base) | |
249 (list (append '(vleft) | |
250 (list base) | |
251 (make-list (1- rows) | |
252 (if inner-brackets | |
253 (concat " " | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
254 math-comp-right-bracket |
40785 | 255 (and row-commas |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
256 math-comp-comma)) |
40785 | 257 (if (and outer-brackets |
258 row-commas) | |
259 ";" ""))) | |
260 (list (concat | |
261 (and inner-brackets | |
262 (concat " " | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
263 math-comp-right-bracket)) |
40785 | 264 (and outer-brackets |
265 (concat | |
266 " " | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
267 math-comp-right-bracket))))))))) |
40785 | 268 (if (and calc-display-strings |
269 (cdr a) | |
270 (math-vector-is-string a)) | |
271 (math-vector-to-string a t) | |
272 (if (and break (cdr a) | |
273 (not (eq calc-language 'flat))) | |
274 (let* ((full (or calc-full-vectors (< (length a) 7))) | |
275 (rows (if full (1- (length a)) 5)) | |
276 (base (/ (1- rows) 2)) | |
277 (calc-break-vectors nil)) | |
278 (list 'horiz | |
279 (cons 'vleft (cons base | |
280 (math-compose-rows | |
281 (cdr a) | |
282 (if full rows 3) t))))) | |
283 (if (or calc-full-vectors (< (length a) 7)) | |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
284 (if (and |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
285 (setq spfn (get calc-language 'math-matrix-formatter)) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
286 (math-matrixp a)) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
287 (funcall spfn a) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
288 (list 'horiz |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
289 math-comp-left-bracket |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
290 (math-compose-vector (cdr a) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
291 (concat math-comp-comma " ") |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
292 math-comp-vector-prec) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
293 math-comp-right-bracket)) |
40785 | 294 (list 'horiz |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
295 math-comp-left-bracket |
40785 | 296 (math-compose-vector (list (nth 1 a) (nth 2 a) (nth 3 a)) |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
297 (concat math-comp-comma " ") |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
298 math-comp-vector-prec) |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
299 math-comp-comma |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
300 (if (setq spfn (get calc-language 'math-dots)) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
301 (concat " " spfn) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
302 " ...") |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
303 math-comp-comma " " |
40785 | 304 (list 'break math-compose-level) |
305 (math-compose-expr (nth (1- (length a)) a) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
306 (if (equal math-comp-comma "") 1000 0)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
307 math-comp-right-bracket))))))) |
40785 | 308 ((eq (car a) 'incomplete) |
309 (if (cdr (cdr a)) | |
310 (cond ((eq (nth 1 a) 'vec) | |
311 (list 'horiz "[" | |
312 (math-compose-vector (cdr (cdr a)) ", " 0) | |
313 " ...")) | |
314 ((eq (nth 1 a) 'cplx) | |
315 (list 'horiz "(" | |
316 (math-compose-vector (cdr (cdr a)) ", " 0) | |
317 ", ...")) | |
318 ((eq (nth 1 a) 'polar) | |
319 (list 'horiz "(" | |
320 (math-compose-vector (cdr (cdr a)) "; " 0) | |
321 "; ...")) | |
322 ((eq (nth 1 a) 'intv) | |
323 (list 'horiz | |
324 (if (memq (nth 2 a) '(0 1)) "(" "[") | |
325 (math-compose-vector (cdr (cdr (cdr a))) " .. " 0) | |
326 " .. ...")) | |
327 (t (format "%s" a))) | |
328 (cond ((eq (nth 1 a) 'vec) "[ ...") | |
329 ((eq (nth 1 a) 'intv) | |
330 (if (memq (nth 2 a) '(0 1)) "( ..." "[ ...")) | |
331 (t "( ...")))) | |
332 ((eq (car a) 'var) | |
333 (let ((v (rassq (nth 2 a) math-expr-variable-mapping))) | |
334 (if v | |
335 (symbol-name (car v)) | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
336 (if (setq spfn (get calc-language 'math-var-formatter)) |
86968
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
337 (funcall spfn a prec) |
7c7322501bc1
(math-compose-var): Adjust argument list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86930
diff
changeset
|
338 (math-compose-var a))))) |
40785 | 339 ((eq (car a) 'intv) |
340 (list 'horiz | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
341 (if (memq (nth 1 a) '(0 1)) "(" "[") |
40785 | 342 (math-compose-expr (nth 2 a) 0) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
343 " .. " |
40785 | 344 (math-compose-expr (nth 3 a) 0) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
345 (if (memq (nth 1 a) '(0 2)) ")" "]"))) |
40785 | 346 ((eq (car a) 'date) |
347 (if (eq (car calc-date-format) 'X) | |
348 (math-format-date a) | |
349 (concat "<" (math-format-date a) ">"))) | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
350 ((and (eq (car a) 'calcFunc-subscr) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
351 (setq spfn (get calc-language 'math-compose-subscr))) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
352 (funcall spfn a)) |
40785 | 353 ((and (eq (car a) 'calcFunc-subscr) (= (length a) 3) |
354 (eq calc-language 'big)) | |
355 (let* ((a1 (math-compose-expr (nth 1 a) 1000)) | |
356 (calc-language 'flat) | |
357 (a2 (math-compose-expr (nth 2 a) 0))) | |
358 (if (or (eq (car-safe a1) 'subscr) | |
359 (and (eq (car-safe a1) 'tag) | |
360 (eq (car-safe (nth 2 a1)) 'subscr) | |
361 (setq a1 (nth 2 a1)))) | |
362 (list 'subscr | |
363 (nth 1 a1) | |
364 (list 'horiz | |
365 (nth 2 a1) | |
366 ", " | |
367 a2)) | |
368 (list 'subscr a1 a2)))) | |
369 ((and (eq (car a) '^) | |
370 (eq calc-language 'big)) | |
371 (list 'supscr | |
372 (if (or (math-looks-negp (nth 1 a)) | |
373 (memq (car-safe (nth 1 a)) '(^ / frac calcFunc-sqrt)) | |
374 (and (eq (car-safe (nth 1 a)) 'cplx) | |
375 (math-negp (nth 1 (nth 1 a))) | |
376 (eq (nth 2 (nth 1 a)) 0))) | |
377 (list 'horiz "(" (math-compose-expr (nth 1 a) 0) ")") | |
378 (math-compose-expr (nth 1 a) 201)) | |
379 (let ((calc-language 'flat) | |
106138
18198cdc91fa
(math-compose-expr): Let `calc-twos-complement-mode' be nil.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
100908
diff
changeset
|
380 (calc-number-radix 10) |
18198cdc91fa
(math-compose-expr): Let `calc-twos-complement-mode' be nil.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
100908
diff
changeset
|
381 (calc-twos-complement-mode nil)) |
40785 | 382 (math-compose-expr (nth 2 a) 0)))) |
383 ((and (eq (car a) '/) | |
384 (eq calc-language 'big)) | |
385 (let ((a1 (let ((calc-language (if (memq (car-safe (nth 1 a)) '(/ frac)) | |
386 'flat 'big))) | |
387 (math-compose-expr (nth 1 a) 0))) | |
388 (a2 (let ((calc-language (if (memq (car-safe (nth 2 a)) '(/ frac)) | |
389 'flat 'big))) | |
390 (math-compose-expr (nth 2 a) 0)))) | |
391 (list 'vcent | |
392 (math-comp-height a1) | |
393 a1 '(rule ?-) a2))) | |
394 ((and (eq (car a) 'calcFunc-lambda) | |
395 (> (length a) 2) | |
396 (memq calc-language '(nil flat big))) | |
397 (let ((p (cdr a)) | |
398 (ap calc-arg-values) | |
399 (math-compose-hash-args (if (= (length a) 3) 1 t))) | |
400 (while (and (cdr p) (equal (car p) (car ap))) | |
401 (setq p (cdr p) ap (cdr ap))) | |
402 (append '(horiz "<") | |
403 (if (cdr p) | |
404 (list (math-compose-vector | |
405 (nreverse (cdr (reverse (cdr a)))) ", " 0) | |
406 " : ") | |
407 nil) | |
408 (list (math-compose-expr (nth (1- (length a)) a) 0) | |
409 ">")))) | |
410 ((and (eq (car a) 'calcFunc-string) | |
411 (= (length a) 2) | |
412 (math-vectorp (nth 1 a)) | |
413 (math-vector-is-string (nth 1 a))) | |
414 (if (eq calc-language 'unform) | |
415 (concat "string(" (math-vector-to-string (nth 1 a) t) ")") | |
416 (math-vector-to-string (nth 1 a) nil))) | |
417 ((and (eq (car a) 'calcFunc-bstring) | |
418 (= (length a) 2) | |
419 (math-vectorp (nth 1 a)) | |
420 (math-vector-is-string (nth 1 a))) | |
421 (if (eq calc-language 'unform) | |
422 (concat "bstring(" (math-vector-to-string (nth 1 a) t) ")") | |
423 (let ((c nil) | |
424 (s (math-vector-to-string (nth 1 a) nil)) | |
425 p) | |
426 (while (string-match "[^ ] +[^ ]" s) | |
427 (setq p (1- (match-end 0)) | |
428 c (cons (list 'break math-compose-level) | |
429 (cons (substring s 0 p) | |
430 c)) | |
431 s (substring s p))) | |
432 (setq c (nreverse (cons s c))) | |
433 (or (= prec -123) | |
434 (setq c (cons (list 'set math-compose-level 2) c))) | |
435 (cons 'horiz c)))) | |
436 ((and (eq (car a) 'calcFunc-cprec) | |
437 (not (eq calc-language 'unform)) | |
438 (= (length a) 3) | |
439 (integerp (nth 2 a))) | |
440 (let ((c (math-compose-expr (nth 1 a) -1))) | |
441 (if (> prec (nth 2 a)) | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
442 (if (setq spfn (get calc-language 'math-big-parens)) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
443 (list 'horiz (car spfn) c (cdr spfn)) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
444 (list 'horiz "(" c ")")) |
40785 | 445 c))) |
446 ((and (eq (car a) 'calcFunc-choriz) | |
447 (not (eq calc-language 'unform)) | |
448 (memq (length a) '(2 3 4)) | |
449 (math-vectorp (nth 1 a)) | |
450 (if (integerp (nth 2 a)) | |
451 (or (null (nth 3 a)) | |
452 (and (math-vectorp (nth 3 a)) | |
453 (math-vector-is-string (nth 3 a)))) | |
454 (or (null (nth 2 a)) | |
455 (and (math-vectorp (nth 2 a)) | |
456 (math-vector-is-string (nth 2 a)))))) | |
457 (let* ((cprec (and (integerp (nth 2 a)) (nth 2 a))) | |
458 (sep (nth (if cprec 3 2) a)) | |
459 (bprec nil)) | |
460 (if sep | |
461 (math-compose-vector (cdr (nth 1 a)) | |
462 (math-vector-to-string sep nil) | |
463 (or cprec prec)) | |
464 (cons 'horiz (mapcar (function | |
465 (lambda (x) | |
466 (if (eq (car-safe x) 'calcFunc-bstring) | |
467 (prog1 | |
468 (math-compose-expr | |
469 x (or bprec cprec prec)) | |
470 (setq bprec -123)) | |
471 (math-compose-expr x (or cprec prec))))) | |
472 (cdr (nth 1 a))))))) | |
473 ((and (memq (car a) '(calcFunc-cvert calcFunc-clvert calcFunc-crvert)) | |
474 (not (eq calc-language 'unform)) | |
475 (memq (length a) '(2 3)) | |
476 (math-vectorp (nth 1 a)) | |
477 (or (null (nth 2 a)) | |
478 (integerp (nth 2 a)))) | |
479 (let* ((base 0) | |
480 (v 0) | |
481 (prec (or (nth 2 a) prec)) | |
482 (c (mapcar (function | |
483 (lambda (x) | |
484 (let ((b nil) (cc nil) a d) | |
485 (if (and (memq (car-safe x) '(calcFunc-cbase | |
486 calcFunc-ctbase | |
487 calcFunc-cbbase)) | |
488 (memq (length x) '(1 2))) | |
489 (setq b (car x) | |
490 x (nth 1 x))) | |
491 (if (and (eq (car-safe x) 'calcFunc-crule) | |
492 (memq (length x) '(1 2)) | |
493 (or (null (nth 1 x)) | |
494 (and (math-vectorp (nth 1 x)) | |
495 (= (length (nth 1 x)) 2) | |
496 (math-vector-is-string | |
497 (nth 1 x))) | |
498 (and (natnump (nth 1 x)) | |
499 (<= (nth 1 x) 255)))) | |
500 (setq cc (list | |
501 'rule | |
502 (if (math-vectorp (nth 1 x)) | |
503 (aref (math-vector-to-string | |
504 (nth 1 x) nil) 0) | |
505 (or (nth 1 x) ?-)))) | |
506 (or (and (memq (car-safe x) '(calcFunc-cvspace | |
507 calcFunc-ctspace | |
508 calcFunc-cbspace)) | |
509 (memq (length x) '(2 3)) | |
510 (eq (nth 1 x) 0)) | |
511 (null x) | |
512 (setq cc (math-compose-expr x prec)))) | |
513 (setq a (if cc (math-comp-ascent cc) 0) | |
514 d (if cc (math-comp-descent cc) 0)) | |
515 (if (eq b 'calcFunc-cbase) | |
516 (setq base (+ v a -1)) | |
517 (if (eq b 'calcFunc-ctbase) | |
518 (setq base v) | |
519 (if (eq b 'calcFunc-cbbase) | |
520 (setq base (+ v a d -1))))) | |
521 (setq v (+ v a d)) | |
522 cc))) | |
523 (cdr (nth 1 a))))) | |
524 (setq c (delq nil c)) | |
525 (if c | |
526 (cons (if (eq (car a) 'calcFunc-cvert) 'vcent | |
527 (if (eq (car a) 'calcFunc-clvert) 'vleft 'vright)) | |
528 (cons base c)) | |
529 " "))) | |
530 ((and (memq (car a) '(calcFunc-csup calcFunc-csub)) | |
531 (not (eq calc-language 'unform)) | |
532 (memq (length a) '(3 4)) | |
533 (or (null (nth 3 a)) | |
534 (integerp (nth 3 a)))) | |
535 (list (if (eq (car a) 'calcFunc-csup) 'supscr 'subscr) | |
536 (math-compose-expr (nth 1 a) (or (nth 3 a) 0)) | |
537 (math-compose-expr (nth 2 a) 0))) | |
538 ((and (eq (car a) 'calcFunc-cflat) | |
539 (not (eq calc-language 'unform)) | |
540 (memq (length a) '(2 3)) | |
541 (or (null (nth 2 a)) | |
542 (integerp (nth 2 a)))) | |
543 (let ((calc-language (if (memq calc-language '(nil big)) | |
544 'flat calc-language))) | |
545 (math-compose-expr (nth 1 a) (or (nth 2 a) 0)))) | |
546 ((and (eq (car a) 'calcFunc-cspace) | |
547 (memq (length a) '(2 3)) | |
548 (natnump (nth 1 a))) | |
549 (if (nth 2 a) | |
550 (cons 'horiz (make-list (nth 1 a) | |
551 (if (and (math-vectorp (nth 2 a)) | |
552 (math-vector-is-string (nth 2 a))) | |
553 (math-vector-to-string (nth 2 a) nil) | |
554 (math-compose-expr (nth 2 a) 0)))) | |
555 (make-string (nth 1 a) ?\ ))) | |
556 ((and (memq (car a) '(calcFunc-cvspace calcFunc-ctspace calcFunc-cbspace)) | |
557 (memq (length a) '(2 3)) | |
558 (natnump (nth 1 a))) | |
559 (if (= (nth 1 a) 0) | |
560 "" | |
561 (let* ((c (if (nth 2 a) | |
562 (if (and (math-vectorp (nth 2 a)) | |
563 (math-vector-is-string (nth 2 a))) | |
564 (math-vector-to-string (nth 2 a) nil) | |
565 (math-compose-expr (nth 2 a) 0)) | |
566 " ")) | |
567 (ca (math-comp-ascent c)) | |
568 (cd (math-comp-descent c))) | |
569 (cons 'vleft | |
570 (cons (if (eq (car a) 'calcFunc-ctspace) | |
571 (1- ca) | |
572 (if (eq (car a) 'calcFunc-cbspace) | |
573 (+ (* (1- (nth 1 a)) (+ ca cd)) (1- ca)) | |
574 (/ (1- (* (nth 1 a) (+ ca cd))) 2))) | |
575 (make-list (nth 1 a) c)))))) | |
576 ((and (eq (car a) 'calcFunc-evalto) | |
577 (setq calc-any-evaltos t) | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
578 (setq spfn (get calc-language 'math-evalto)) |
40785 | 579 (= math-compose-level (if math-comp-tagged 2 1)) |
580 (= (length a) 3)) | |
581 (list 'horiz | |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
582 (car spfn) |
40785 | 583 (math-compose-expr (nth 1 a) 0) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
584 (cdr spfn) |
40785 | 585 (math-compose-expr (nth 2 a) 0))) |
586 (t | |
587 (let ((op (and (not (eq calc-language 'unform)) | |
588 (if (and (eq (car a) 'calcFunc-if) (= (length a) 4)) | |
589 (assoc "?" math-expr-opers) | |
590 (math-assq2 (car a) math-expr-opers))))) | |
591 (cond ((and op | |
592 (or (= (length a) 3) (eq (car a) 'calcFunc-if)) | |
593 (/= (nth 3 op) -1)) | |
594 (cond | |
595 ((> prec (or (nth 4 op) (min (nth 2 op) (nth 3 op)))) | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
596 (if (and (memq calc-language '(tex latex)) |
40785 | 597 (not (math-tex-expr-is-flat a))) |
598 (if (eq (car-safe a) '/) | |
599 (list 'horiz "{" (math-compose-expr a -1) "}") | |
600 (list 'horiz "\\left( " | |
601 (math-compose-expr a -1) | |
602 " \\right)")) | |
603 (if (eq calc-language 'eqn) | |
604 (if (or (eq (car-safe a) '/) | |
605 (= (/ prec 100) 9)) | |
606 (list 'horiz "{" (math-compose-expr a -1) "}") | |
607 (if (math-tex-expr-is-flat a) | |
608 (list 'horiz "( " (math-compose-expr a -1) " )") | |
609 (list 'horiz "{left ( " | |
610 (math-compose-expr a -1) | |
611 " right )}"))) | |
612 (list 'horiz "(" (math-compose-expr a 0) ")")))) | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
613 ((and (memq calc-language '(tex latex)) |
40785 | 614 (memq (car a) '(/ calcFunc-choose calcFunc-evalto)) |
615 (>= prec 0)) | |
616 (list 'horiz "{" (math-compose-expr a -1) "}")) | |
617 ((eq (car a) 'calcFunc-if) | |
618 (list 'horiz | |
619 (math-compose-expr (nth 1 a) (nth 2 op)) | |
620 " ? " | |
621 (math-compose-expr (nth 2 a) 0) | |
622 " : " | |
623 (math-compose-expr (nth 3 a) (nth 3 op)))) | |
624 (t | |
625 (let* ((math-comp-tagged (and math-comp-tagged | |
626 (not (math-primp a)) | |
627 math-comp-tagged)) | |
628 (setlev (if (= prec (min (nth 2 op) (nth 3 op))) | |
629 (progn | |
630 (setq math-compose-level | |
631 (1- math-compose-level)) | |
632 nil) | |
633 math-compose-level)) | |
634 (lhs (math-compose-expr (nth 1 a) (nth 2 op))) | |
635 (rhs (math-compose-expr (nth 2 a) (nth 3 op)))) | |
636 (and (equal (car op) "^") | |
637 (eq (math-comp-first-char lhs) ?-) | |
638 (setq lhs (list 'horiz "(" lhs ")"))) | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
639 (and (memq calc-language '(tex latex)) |
40785 | 640 (or (equal (car op) "^") (equal (car op) "_")) |
641 (not (and (stringp rhs) (= (length rhs) 1))) | |
642 (setq rhs (list 'horiz "{" rhs "}"))) | |
643 (or (and (eq (car a) '*) | |
644 (or (null calc-language) | |
645 (assoc "2x" math-expr-opers)) | |
646 (let* ((prevt (math-prod-last-term (nth 1 a))) | |
647 (nextt (math-prod-first-term (nth 2 a))) | |
648 (prevc (or (math-comp-last-char lhs) | |
649 (and (memq (car-safe prevt) | |
650 '(^ calcFunc-subscr | |
651 calcFunc-sqrt | |
652 frac)) | |
653 (eq calc-language 'big) | |
654 ?0))) | |
655 (nextc (or (math-comp-first-char rhs) | |
656 (and (memq (car-safe nextt) | |
657 '(calcFunc-sqrt | |
658 calcFunc-sum | |
659 calcFunc-prod | |
660 calcFunc-integ)) | |
661 (eq calc-language 'big) | |
662 ?0)))) | |
663 (and prevc nextc | |
664 (or (and (>= nextc ?a) (<= nextc ?z)) | |
665 (and (>= nextc ?A) (<= nextc ?Z)) | |
108590
c84578d13e42
calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
106815
diff
changeset
|
666 (and (>= nextc ?α) (<= nextc ?ω)) |
c84578d13e42
calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
106815
diff
changeset
|
667 (and (>= nextc ?Α) (<= nextc ?Ω)) |
40785 | 668 (and (>= nextc ?0) (<= nextc ?9)) |
669 (memq nextc '(?. ?_ ?# | |
670 ?\( ?\[ ?\{)) | |
671 (and (eq nextc ?\\) | |
672 (not (string-match | |
673 "\\`\\\\left(" | |
674 (math-comp-first-string | |
675 rhs))))) | |
676 (not (and (eq (car-safe prevt) 'var) | |
677 (eq nextc ?\())) | |
678 (list 'horiz | |
679 (list 'set setlev 1) | |
680 lhs | |
681 (list 'break math-compose-level) | |
682 " " | |
683 rhs)))) | |
684 (list 'horiz | |
685 (list 'set setlev 1) | |
686 lhs | |
687 (list 'break math-compose-level) | |
688 (if (or (equal (car op) "^") | |
689 (equal (car op) "_") | |
690 (equal (car op) "**") | |
691 (and (equal (car op) "*") | |
692 (math-comp-last-char lhs) | |
693 (math-comp-first-char rhs)) | |
694 (and (equal (car op) "/") | |
695 (math-num-integerp (nth 1 a)) | |
696 (math-integerp (nth 2 a)))) | |
697 (car op) | |
698 (if (and (eq calc-language 'big) | |
699 (equal (car op) "=>")) | |
700 " => " | |
701 (concat " " (car op) " "))) | |
702 rhs)))))) | |
703 ((and op (= (length a) 2) (= (nth 3 op) -1)) | |
704 (cond | |
705 ((or (> prec (or (nth 4 op) (nth 2 op))) | |
706 (and (not (eq (assoc (car op) math-expr-opers) op)) | |
707 (> prec 0))) ; don't write x% + y | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
708 (if (and (memq calc-language '(tex latex)) |
40785 | 709 (not (math-tex-expr-is-flat a))) |
710 (list 'horiz "\\left( " | |
711 (math-compose-expr a -1) | |
712 " \\right)") | |
713 (if (eq calc-language 'eqn) | |
714 (if (= (/ prec 100) 9) | |
715 (list 'horiz "{" (math-compose-expr a -1) "}") | |
716 (if (math-tex-expr-is-flat a) | |
717 (list 'horiz "{( " (math-compose-expr a -1) " )}") | |
718 (list 'horiz "{left ( " | |
719 (math-compose-expr a -1) | |
720 " right )}"))) | |
721 (list 'horiz "(" (math-compose-expr a 0) ")")))) | |
722 (t | |
723 (let ((lhs (math-compose-expr (nth 1 a) (nth 2 op)))) | |
724 (list 'horiz | |
725 lhs | |
726 (if (or (> (length (car op)) 1) | |
727 (not (math-comp-is-flat lhs))) | |
728 (concat " " (car op)) | |
729 (car op))))))) | |
730 ((and op (= (length a) 2) (= (nth 2 op) -1)) | |
731 (cond | |
732 ((eq (nth 3 op) 0) | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
733 (let ((lr (and (memq calc-language '(tex latex)) |
40785 | 734 (not (math-tex-expr-is-flat (nth 1 a)))))) |
735 (list 'horiz | |
736 (if lr "\\left" "") | |
108590
c84578d13e42
calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
106815
diff
changeset
|
737 (if (string-match "\\`u\\([^a-zA-Zα-ωΑ-Ω]\\)\\'" (car op)) |
40785 | 738 (substring (car op) 1) |
739 (car op)) | |
740 (if (or lr (> (length (car op)) 2)) " " "") | |
741 (math-compose-expr (nth 1 a) -1) | |
742 (if (or lr (> (length (car op)) 2)) " " "") | |
743 (if lr "\\right" "") | |
744 (car (nth 1 (memq op math-expr-opers)))))) | |
745 ((> prec (or (nth 4 op) (nth 3 op))) | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
746 (if (and (memq calc-language '(tex latex)) |
40785 | 747 (not (math-tex-expr-is-flat a))) |
748 (list 'horiz "\\left( " | |
749 (math-compose-expr a -1) | |
750 " \\right)") | |
751 (if (eq calc-language 'eqn) | |
752 (if (= (/ prec 100) 9) | |
753 (list 'horiz "{" (math-compose-expr a -1) "}") | |
754 (if (math-tex-expr-is-flat a) | |
755 (list 'horiz "{( " (math-compose-expr a -1) " )}") | |
756 (list 'horiz "{left ( " | |
757 (math-compose-expr a -1) | |
758 " right )}"))) | |
759 (list 'horiz "(" (math-compose-expr a 0) ")")))) | |
760 (t | |
761 (let ((rhs (math-compose-expr (nth 1 a) (nth 3 op)))) | |
762 (list 'horiz | |
108590
c84578d13e42
calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
106815
diff
changeset
|
763 (let ((ops (if (string-match "\\`u\\([^a-zA-Zα-ωΑ-Ω]\\)\\'" |
40785 | 764 (car op)) |
765 (substring (car op) 1) | |
766 (car op)))) | |
767 (if (or (> (length ops) 1) | |
768 (not (math-comp-is-flat rhs))) | |
769 (concat ops " ") | |
770 ops)) | |
771 rhs))))) | |
772 ((and (eq calc-language 'big) | |
773 (setq op (get (car a) 'math-compose-big)) | |
774 (funcall op a prec))) | |
775 ((and (setq op (assq calc-language | |
776 '( ( nil . math-compose-normal ) | |
777 ( flat . math-compose-normal ) | |
778 ( big . math-compose-normal ) | |
779 ( c . math-compose-c ) | |
780 ( pascal . math-compose-pascal ) | |
781 ( fortran . math-compose-fortran ) | |
782 ( tex . math-compose-tex ) | |
59814
53059b002005
(math-compose-expr, math-compose-rows): Add LaTeX support.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58683
diff
changeset
|
783 ( latex . math-compose-latex ) |
40785 | 784 ( eqn . math-compose-eqn ) |
87459
16247015d17b
(math-compose-expr): Add new languages.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87437
diff
changeset
|
785 ( yacas . math-compose-yacas ) |
16247015d17b
(math-compose-expr): Add new languages.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87437
diff
changeset
|
786 ( maxima . math-compose-maxima ) |
16247015d17b
(math-compose-expr): Add new languages.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87437
diff
changeset
|
787 ( giac . math-compose-giac ) |
40785 | 788 ( math . math-compose-math ) |
789 ( maple . math-compose-maple )))) | |
790 (setq op (get (car a) (cdr op))) | |
791 (funcall op a prec))) | |
792 (t | |
793 (let* ((func (car a)) | |
794 (func2 (assq func '(( mod . calcFunc-makemod ) | |
795 ( sdev . calcFunc-sdev ) | |
796 ( + . calcFunc-add ) | |
797 ( - . calcFunc-sub ) | |
798 ( * . calcFunc-mul ) | |
799 ( / . calcFunc-div ) | |
800 ( % . calcFunc-mod ) | |
801 ( ^ . calcFunc-pow ) | |
802 ( neg . calcFunc-neg ) | |
803 ( | . calcFunc-vconcat )))) | |
804 left right args) | |
805 (if func2 | |
806 (setq func (cdr func2))) | |
807 (if (setq func2 (rassq func math-expr-function-mapping)) | |
808 (setq func (car func2))) | |
809 (setq func (math-remove-dashes | |
810 (if (string-match | |
108590
c84578d13e42
calc-aent.el (math-read-token, math-find-user-tokens):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
106815
diff
changeset
|
811 "\\`calcFunc-\\([a-zA-Zα-ωΑ-Ω0-9']+\\)\\'" |
40785 | 812 (symbol-name func)) |
813 (math-match-substring (symbol-name func) 1) | |
814 (symbol-name func)))) | |
87417
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
815 (if (memq calc-language calc-lang-allow-percentsigns) |
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
816 (setq func (math-to-percentsigns func))) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
817 (if (memq calc-language calc-lang-allow-underscores) |
40785 | 818 (setq func (math-to-underscores func))) |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
819 (if (setq spfn (get calc-language 'math-func-formatter)) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
820 (funcall spfn func a) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
821 |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
822 (list 'horiz func calc-function-open |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
823 (math-compose-vector (cdr a) ", " 0) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
824 calc-function-close)))))))))) |
40785 | 825 |
826 | |
827 (defun math-prod-first-term (x) | |
828 (while (eq (car-safe x) '*) | |
829 (setq x (nth 1 x))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
830 x) |
40785 | 831 |
832 (defun math-prod-last-term (x) | |
833 (while (eq (car-safe x) '*) | |
834 (setq x (nth 2 x))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
835 x) |
40785 | 836 |
837 (defun math-compose-vector (a sep prec) | |
838 (if a | |
839 (cons 'horiz | |
840 (cons (list 'set math-compose-level) | |
841 (let ((c (list (math-compose-expr (car a) prec)))) | |
842 (while (setq a (cdr a)) | |
843 (setq c (cons (if (eq (car-safe (car a)) | |
844 'calcFunc-bstring) | |
845 (let ((math-compose-level | |
846 (1- math-compose-level))) | |
847 (math-compose-expr (car a) -123)) | |
848 (math-compose-expr (car a) prec)) | |
849 (cons (list 'break math-compose-level) | |
850 (cons sep c))))) | |
851 (nreverse c)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
852 "")) |
40785 | 853 |
854 (defun math-vector-no-parens (a) | |
855 (or (cdr (cdr a)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
856 (not (eq (car-safe (nth 1 a)) '*)))) |
40785 | 857 |
858 (defun math-compose-matrix (a col cols base) | |
859 (let ((col 0) | |
860 (res nil)) | |
861 (while (<= (setq col (1+ col)) cols) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
862 (setq res (cons (cons math-comp-just |
40785 | 863 (cons base |
864 (mapcar (function | |
865 (lambda (r) | |
866 (list 'horiz | |
867 (math-compose-expr | |
868 (nth col r) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
869 math-comp-vector-prec) |
40785 | 870 (if (= col cols) |
871 "" | |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
872 (concat |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
873 math-comp-comma-spc " "))))) |
40785 | 874 a))) |
875 res))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
876 (nreverse res))) |
40785 | 877 |
878 (defun math-compose-rows (a count first) | |
879 (if (cdr a) | |
880 (if (<= count 0) | |
881 (if (< count 0) | |
882 (math-compose-rows (cdr a) -1 nil) | |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
883 (cons (concat |
86930
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
884 (let ((mdots (get calc-language 'math-dots))) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
885 (if mdots |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
886 (concat " " mdots) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
887 " ...")) |
cf4da0940e73
(math-compose-var): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82140
diff
changeset
|
888 math-comp-comma) |
40785 | 889 (math-compose-rows (cdr a) -1 nil))) |
890 (cons (list 'horiz | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
891 (if first (concat math-comp-left-bracket " ") " ") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
892 (math-compose-expr (car a) math-comp-vector-prec) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
893 math-comp-comma) |
40785 | 894 (math-compose-rows (cdr a) (1- count) nil))) |
895 (list (list 'horiz | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
896 (if first (concat math-comp-left-bracket " ") " ") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
897 (math-compose-expr (car a) math-comp-vector-prec) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
898 (concat " " math-comp-right-bracket))))) |
40785 | 899 |
900 (defun math-vector-is-string (a) | |
901 (while (and (setq a (cdr a)) | |
902 (or (and (natnump (car a)) | |
903 (<= (car a) 255)) | |
904 (and (eq (car-safe (car a)) 'cplx) | |
905 (natnump (nth 1 (car a))) | |
906 (eq (nth 2 (car a)) 0) | |
907 (<= (nth 1 (car a)) 255))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
908 (null a)) |
40785 | 909 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
910 (defconst math-vector-to-string-chars '( ( ?\" . "\\\"" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
911 ( ?\\ . "\\\\" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
912 ( ?\a . "\\a" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
913 ( ?\b . "\\b" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
914 ( ?\e . "\\e" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
915 ( ?\f . "\\f" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
916 ( ?\n . "\\n" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
917 ( ?\r . "\\r" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
918 ( ?\t . "\\t" ) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
919 ( ?\^? . "\\^?" ))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
920 |
40785 | 921 (defun math-vector-to-string (a &optional quoted) |
922 (setq a (concat (mapcar (function (lambda (x) (if (consp x) (nth 1 x) x))) | |
923 (cdr a)))) | |
924 (if (string-match "[\000-\037\177\\\"]" a) | |
925 (let ((p 0) | |
926 (pat (if quoted "[\000-\037\177\\\"]" "[\000-\037\177]")) | |
927 (codes (if quoted math-vector-to-string-chars '((?\^? . "^?")))) | |
928 (fmt (if quoted "\\^%c" "^%c")) | |
929 new) | |
930 (while (setq p (string-match pat a p)) | |
931 (if (setq new (assq (aref a p) codes)) | |
932 (setq a (concat (substring a 0 p) | |
933 (cdr new) | |
934 (substring a (1+ p))) | |
935 p (+ p (length (cdr new)))) | |
936 (setq a (concat (substring a 0 p) | |
937 (format fmt (+ (aref a p) 64)) | |
938 (substring a (1+ p))) | |
939 p (+ p 2)))))) | |
940 (if quoted | |
941 (concat "\"" a "\"") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
942 a)) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
943 |
40785 | 944 |
945 (defun math-to-underscores (x) | |
946 (if (string-match "\\`\\(.*\\)#\\(.*\\)\\'" x) | |
947 (math-to-underscores | |
948 (concat (math-match-substring x 1) "_" (math-match-substring x 2))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
949 x)) |
40785 | 950 |
87417
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
951 (defun math-to-percentsigns (x) |
87437
f18b45437f89
(math-to-percentsigns): Change placeholder for percent signs.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87417
diff
changeset
|
952 (if (string-match "\\`\\(.*\\)o'o\\(.*\\)\\'" x) |
f18b45437f89
(math-to-percentsigns): Change placeholder for percent signs.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87417
diff
changeset
|
953 (math-to-underscores |
87417
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
954 (concat (math-match-substring x 1) "%" (math-match-substring x 2))) |
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
955 x)) |
ee7bf7cfd6b4
(math-to-percentsigns): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86968
diff
changeset
|
956 |
40785 | 957 (defun math-tex-expr-is-flat (a) |
958 (or (Math-integerp a) | |
959 (memq (car a) '(float var)) | |
960 (and (memq (car a) '(+ - * neg)) | |
961 (progn | |
962 (while (and (setq a (cdr a)) | |
963 (math-tex-expr-is-flat (car a)))) | |
964 (null a))) | |
965 (and (memq (car a) '(^ calcFunc-subscr)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
966 (math-tex-expr-is-flat (nth 1 a))))) |
40785 | 967 |
968 (put 'calcFunc-log 'math-compose-big 'math-compose-log) | |
969 (defun math-compose-log (a prec) | |
970 (and (= (length a) 3) | |
971 (list 'horiz | |
972 (list 'subscr "log" | |
973 (let ((calc-language 'flat)) | |
974 (math-compose-expr (nth 2 a) 1000))) | |
975 "(" | |
976 (math-compose-expr (nth 1 a) 1000) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
977 ")"))) |
40785 | 978 |
979 (put 'calcFunc-log10 'math-compose-big 'math-compose-log10) | |
980 (defun math-compose-log10 (a prec) | |
981 (and (= (length a) 2) | |
982 (list 'horiz | |
983 (list 'subscr "log" "10") | |
984 "(" | |
985 (math-compose-expr (nth 1 a) 1000) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
986 ")"))) |
40785 | 987 |
988 (put 'calcFunc-deriv 'math-compose-big 'math-compose-deriv) | |
989 (put 'calcFunc-tderiv 'math-compose-big 'math-compose-deriv) | |
990 (defun math-compose-deriv (a prec) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
991 (when (= (length a) 3) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
992 (math-compose-expr (list '/ |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
993 (list 'calcFunc-choriz |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
994 (list 'vec |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
995 '(calcFunc-string (vec ?d)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
996 (nth 1 a))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
997 (list 'calcFunc-choriz |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
998 (list 'vec |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
999 '(calcFunc-string (vec ?d)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1000 (nth 2 a)))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1001 prec))) |
40785 | 1002 |
1003 (put 'calcFunc-sqrt 'math-compose-big 'math-compose-sqrt) | |
1004 (defun math-compose-sqrt (a prec) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1005 (when (= (length a) 2) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1006 (let* ((c (math-compose-expr (nth 1 a) 0)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1007 (a (math-comp-ascent c)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1008 (d (math-comp-descent c)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1009 (h (+ a d)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1010 (w (math-comp-width c))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1011 (list 'vleft |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1012 a |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1013 (concat (if (= h 1) " " " ") |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1014 (make-string (+ w 2) ?\_)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1015 (list 'horiz |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1016 (if (= h 1) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1017 "V" |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1018 (append (list 'vleft (1- a)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1019 (make-list (1- h) " |") |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1020 '("\\|"))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1021 " " |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1022 c))))) |
40785 | 1023 |
1024 (put 'calcFunc-choose 'math-compose-big 'math-compose-choose) | |
1025 (defun math-compose-choose (a prec) | |
1026 (let ((a1 (math-compose-expr (nth 1 a) 0)) | |
1027 (a2 (math-compose-expr (nth 2 a) 0))) | |
1028 (list 'horiz | |
1029 "(" | |
1030 (list 'vcent | |
1031 (math-comp-height a1) | |
1032 a1 " " a2) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1033 ")"))) |
40785 | 1034 |
1035 (put 'calcFunc-integ 'math-compose-big 'math-compose-integ) | |
1036 (defun math-compose-integ (a prec) | |
1037 (and (memq (length a) '(3 5)) | |
1038 (eq (car-safe (nth 2 a)) 'var) | |
1039 (let* ((parens (and (>= prec 196) (/= prec 1000))) | |
1040 (var (math-compose-expr (nth 2 a) 0)) | |
1041 (over (and (eq (car-safe (nth 2 a)) 'var) | |
1042 (or (and (eq (car-safe (nth 1 a)) '/) | |
1043 (math-numberp (nth 1 (nth 1 a)))) | |
1044 (and (eq (car-safe (nth 1 a)) '^) | |
1045 (math-looks-negp (nth 2 (nth 1 a))))))) | |
1046 (expr (math-compose-expr (if over | |
1047 (math-mul (nth 1 a) | |
1048 (math-build-var-name | |
1049 (format | |
1050 "d%s" | |
1051 (nth 1 (nth 2 a))))) | |
1052 (nth 1 a)) 185)) | |
1053 (calc-language 'flat) | |
1054 (low (and (nth 3 a) (math-compose-expr (nth 3 a) 0))) | |
1055 (high (and (nth 4 a) (math-compose-expr (nth 4 a) 0)))) | |
1056 (list 'horiz | |
1057 (if parens "(" "") | |
1058 (append (list 'vcent (if high 3 2)) | |
1059 (and high (list (list 'horiz " " high))) | |
1060 '(" /" | |
1061 " | " | |
1062 " | " | |
1063 " | " | |
1064 "/ ") | |
1065 (and low (list (list 'horiz low " ")))) | |
1066 expr | |
1067 (if over | |
1068 "" | |
1069 (list 'horiz " d" var)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1070 (if parens ")" ""))))) |
40785 | 1071 |
1072 (put 'calcFunc-sum 'math-compose-big 'math-compose-sum) | |
1073 (defun math-compose-sum (a prec) | |
1074 (and (memq (length a) '(3 5 6)) | |
1075 (let* ((expr (math-compose-expr (nth 1 a) 185)) | |
1076 (calc-language 'flat) | |
1077 (var (math-compose-expr (nth 2 a) 0)) | |
1078 (low (and (nth 3 a) (math-compose-expr (nth 3 a) 0))) | |
1079 (high (and (nth 4 a) (math-compose-vector (nthcdr 4 a) ", " 0)))) | |
1080 (list 'horiz | |
1081 (if (memq prec '(180 201)) "(" "") | |
1082 (append (list 'vcent (if high 3 2)) | |
1083 (and high (list high)) | |
1084 '("---- " | |
1085 "\\ " | |
1086 " > " | |
1087 "/ " | |
1088 "---- ") | |
1089 (if low | |
1090 (list (list 'horiz var " = " low)) | |
1091 (list var))) | |
1092 (if (memq (car-safe (nth 1 a)) '(calcFunc-sum calcFunc-prod)) | |
1093 " " "") | |
1094 expr | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1095 (if (memq prec '(180 201)) ")" ""))))) |
40785 | 1096 |
1097 (put 'calcFunc-prod 'math-compose-big 'math-compose-prod) | |
1098 (defun math-compose-prod (a prec) | |
1099 (and (memq (length a) '(3 5 6)) | |
1100 (let* ((expr (math-compose-expr (nth 1 a) 198)) | |
1101 (calc-language 'flat) | |
1102 (var (math-compose-expr (nth 2 a) 0)) | |
1103 (low (and (nth 3 a) (math-compose-expr (nth 3 a) 0))) | |
1104 (high (and (nth 4 a) (math-compose-vector (nthcdr 4 a) ", " 0)))) | |
1105 (list 'horiz | |
1106 (if (memq prec '(196 201)) "(" "") | |
1107 (append (list 'vcent (if high 3 2)) | |
1108 (and high (list high)) | |
1109 '("----- " | |
1110 " | | " | |
1111 " | | " | |
1112 " | | ") | |
1113 (if low | |
1114 (list (list 'horiz var " = " low)) | |
1115 (list var))) | |
1116 (if (memq (car-safe (nth 1 a)) '(calcFunc-sum calcFunc-prod)) | |
1117 " " "") | |
1118 expr | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1119 (if (memq prec '(196 201)) ")" ""))))) |
40785 | 1120 |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1121 ;; The variables math-svo-c, math-svo-wid and math-svo-off are local |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1122 ;; to math-stack-value-offset in calc.el, but are used by |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1123 ;; math-stack-value-offset-fancy, which is called by math-stack-value-offset.. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1124 (defvar math-svo-c) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1125 (defvar math-svo-wid) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1126 (defvar math-svo-off) |
40785 | 1127 |
1128 (defun math-stack-value-offset-fancy () | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1129 (let ((cwid (+ (math-comp-width math-svo-c)))) |
40785 | 1130 (cond ((eq calc-display-just 'right) |
1131 (if calc-display-origin | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1132 (setq math-svo-wid (max calc-display-origin 5)) |
40785 | 1133 (if (integerp calc-line-breaking) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1134 (setq math-svo-wid calc-line-breaking))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1135 (setq math-svo-off (- math-svo-wid cwid |
40785 | 1136 (max (- (length calc-right-label) |
1137 (if (and (integerp calc-line-breaking) | |
1138 calc-display-origin) | |
1139 (max (- calc-line-breaking | |
1140 calc-display-origin) | |
1141 0) | |
1142 0)) | |
1143 0)))) | |
1144 (t | |
1145 (if calc-display-origin | |
1146 (progn | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1147 (setq math-svo-off (- calc-display-origin (/ cwid 2))) |
40785 | 1148 (if (integerp calc-line-breaking) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1149 (setq math-svo-off (min math-svo-off (- calc-line-breaking cwid |
40785 | 1150 (length calc-right-label))))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1151 (if (>= math-svo-off 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1152 (setq math-svo-wid (max math-svo-wid (+ math-svo-off cwid))))) |
40785 | 1153 (if (integerp calc-line-breaking) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1154 (setq math-svo-wid calc-line-breaking)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1155 (setq math-svo-off (/ (- math-svo-wid cwid) 2))))) |
40785 | 1156 (and (integerp calc-line-breaking) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1157 (or (< math-svo-off 0) |
40785 | 1158 (and calc-display-origin |
1159 (> calc-line-breaking calc-display-origin))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1160 (setq math-svo-wid calc-line-breaking)))) |
40785 | 1161 |
1162 | |
1163 ;;; Convert a composition to string form, with embedded \n's if necessary. | |
1164 | |
1165 (defun math-composition-to-string (c &optional width) | |
1166 (or width (setq width (calc-window-width))) | |
1167 (if calc-display-raw | |
1168 (math-comp-to-string-raw c 0) | |
1169 (if (math-comp-is-flat c) | |
1170 (math-comp-to-string-flat c width) | |
1171 (math-vert-comp-to-string | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1172 (math-comp-simplify c width))))) |
40785 | 1173 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1174 (defvar math-comp-buf-string (make-vector 10 "")) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1175 (defvar math-comp-buf-margin (make-vector 10 0)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1176 (defvar math-comp-buf-level (make-vector 10 0)) |
40785 | 1177 (defun math-comp-is-flat (c) ; check if c's height is 1. |
1178 (cond ((not (consp c)) t) | |
1179 ((memq (car c) '(set break)) t) | |
1180 ((eq (car c) 'horiz) | |
1181 (while (and (setq c (cdr c)) | |
1182 (math-comp-is-flat (car c)))) | |
1183 (null c)) | |
1184 ((memq (car c) '(vleft vcent vright)) | |
1185 (and (= (length c) 3) | |
1186 (= (nth 1 c) 0) | |
1187 (math-comp-is-flat (nth 2 c)))) | |
1188 ((eq (car c) 'tag) | |
1189 (math-comp-is-flat (nth 2 c))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1190 (t nil))) |
40785 | 1191 |
1192 | |
1193 ;;; Convert a one-line composition to a string. Break into multiple | |
1194 ;;; lines if necessary, choosing break points according to the structure | |
1195 ;;; of the formula. | |
1196 | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1197 ;; The variables math-comp-full-width, math-comp-highlight, math-comp-word, |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1198 ;; math-comp-level, math-comp-margin and math-comp-buf are local to |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1199 ;; math-comp-to-string-flat, but are used by math-comp-to-string-flat-term, |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1200 ;; which is called by math-comp-to-string-flat. |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1201 ;; math-comp-highlight and math-comp-buf are also local to |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1202 ;; math-comp-simplify-term and math-comp-simplify respectively, but are used |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1203 ;; by math-comp-add-string. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1204 (defvar math-comp-full-width) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1205 (defvar math-comp-highlight) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1206 (defvar math-comp-word) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1207 (defvar math-comp-level) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1208 (defvar math-comp-margin) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1209 (defvar math-comp-buf) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1210 ;; The variable math-comp-pos is local to math-comp-to-string-flat, but |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1211 ;; is used by math-comp-to-string-flat-term and math-comp-sel-first-term, |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1212 ;; which are called by math-comp-to-string-flat. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1213 (defvar math-comp-pos) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1214 |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1215 (defun math-comp-to-string-flat (c math-comp-full-width) |
40785 | 1216 (if math-comp-sel-hpos |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1217 (let ((math-comp-pos 0)) |
40785 | 1218 (math-comp-sel-flat-term c)) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1219 (let ((math-comp-buf "") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1220 (math-comp-word "") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1221 (math-comp-pos 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1222 (math-comp-margin 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1223 (math-comp-highlight (and math-comp-selected calc-show-selections)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1224 (math-comp-level -1)) |
40785 | 1225 (math-comp-to-string-flat-term '(set -1 0)) |
1226 (math-comp-to-string-flat-term c) | |
1227 (math-comp-to-string-flat-term '(break -1)) | |
1228 (let ((str (aref math-comp-buf-string 0)) | |
1229 (prefix "")) | |
1230 (and (> (length str) 0) (= (aref str 0) ? ) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1231 (> (length math-comp-buf) 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1232 (let ((k (length math-comp-buf))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1233 (while (not (= (aref math-comp-buf (setq k (1- k))) ?\n))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1234 (aset math-comp-buf k ? ) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1235 (if (and (< (1+ k) (length math-comp-buf)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1236 (= (aref math-comp-buf (1+ k)) ? )) |
40785 | 1237 (progn |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1238 (aset math-comp-buf (1+ k) ?\n) |
40785 | 1239 (setq prefix " ")) |
1240 (setq prefix "\n")))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1241 (concat math-comp-buf prefix str))))) |
40785 | 1242 |
1243 (defun math-comp-to-string-flat-term (c) | |
1244 (cond ((not (consp c)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1245 (if math-comp-highlight |
40785 | 1246 (setq c (math-comp-highlight-string c))) |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1247 (setq math-comp-word (if (= (length math-comp-word) 0) c |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1248 (concat math-comp-word c)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1249 math-comp-pos (+ math-comp-pos (length c)))) |
40785 | 1250 |
1251 ((eq (car c) 'horiz) | |
1252 (while (setq c (cdr c)) | |
1253 (math-comp-to-string-flat-term (car c)))) | |
1254 | |
1255 ((eq (car c) 'set) | |
1256 (if (nth 1 c) | |
1257 (progn | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1258 (setq math-comp-level (1+ math-comp-level)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1259 (if (>= math-comp-level (length math-comp-buf-string)) |
40785 | 1260 (setq math-comp-buf-string (vconcat math-comp-buf-string |
1261 math-comp-buf-string) | |
1262 math-comp-buf-margin (vconcat math-comp-buf-margin | |
1263 math-comp-buf-margin) | |
1264 math-comp-buf-level (vconcat math-comp-buf-level | |
1265 math-comp-buf-level))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1266 (aset math-comp-buf-string math-comp-level "") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1267 (aset math-comp-buf-margin math-comp-level (+ math-comp-pos |
40785 | 1268 (or (nth 2 c) 0))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1269 (aset math-comp-buf-level math-comp-level (nth 1 c))))) |
40785 | 1270 |
1271 ((eq (car c) 'break) | |
1272 (if (not calc-line-breaking) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1273 (setq math-comp-buf (concat math-comp-buf math-comp-word) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1274 math-comp-word "") |
40785 | 1275 (let ((i 0) str) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1276 (if (and (> math-comp-pos math-comp-full-width) |
40785 | 1277 (progn |
1278 (while (progn | |
1279 (setq str (aref math-comp-buf-string i)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1280 (and (= (length str) 0) (< i math-comp-level))) |
40785 | 1281 (setq i (1+ i))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1282 (or (> (length str) 0) (> (length math-comp-buf) 0)))) |
40785 | 1283 (let ((prefix "") mrg wid) |
1284 (setq mrg (aref math-comp-buf-margin i)) | |
1285 (if (> mrg 12) ; indenting too far, go back to far left | |
1286 (let ((j i) (new (if calc-line-numbering 5 1))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1287 '(while (<= j math-comp-level) |
40785 | 1288 (aset math-comp-buf-margin j |
1289 (+ (aref math-comp-buf-margin j) (- new mrg))) | |
1290 (setq j (1+ j))) | |
1291 (setq mrg new))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1292 (setq wid (+ (length str) math-comp-margin)) |
40785 | 1293 (and (> (length str) 0) (= (aref str 0) ? ) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1294 (> (length math-comp-buf) 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1295 (let ((k (length math-comp-buf))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1296 (while (not (= (aref math-comp-buf (setq k (1- k))) ?\n))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1297 (aset math-comp-buf k ? ) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1298 (if (and (< (1+ k) (length math-comp-buf)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1299 (= (aref math-comp-buf (1+ k)) ? )) |
40785 | 1300 (progn |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1301 (aset math-comp-buf (1+ k) ?\n) |
40785 | 1302 (setq prefix " ")) |
1303 (setq prefix "\n")))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1304 (setq math-comp-buf (concat math-comp-buf prefix str "\n" |
40785 | 1305 (make-string mrg ? )) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1306 math-comp-pos (+ math-comp-pos (- mrg wid)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1307 math-comp-margin mrg) |
40785 | 1308 (aset math-comp-buf-string i "") |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1309 (while (<= (setq i (1+ i)) math-comp-level) |
40785 | 1310 (if (> (aref math-comp-buf-margin i) wid) |
1311 (aset math-comp-buf-margin i | |
1312 (+ (aref math-comp-buf-margin i) | |
1313 (- mrg wid)))))))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1314 (if (and (= (nth 1 c) (aref math-comp-buf-level math-comp-level)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1315 (< math-comp-pos (+ (aref math-comp-buf-margin math-comp-level) 2))) |
40785 | 1316 () ; avoid stupid breaks, e.g., "1 +\n really_long_expr" |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1317 (let ((str (aref math-comp-buf-string math-comp-level))) |
40785 | 1318 (setq str (if (= (length str) 0) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1319 math-comp-word |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1320 (concat str math-comp-word)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1321 math-comp-word "") |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1322 (while (< (nth 1 c) (aref math-comp-buf-level math-comp-level)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1323 (setq math-comp-level (1- math-comp-level)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1324 (or (= (length (aref math-comp-buf-string math-comp-level)) 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1325 (setq str (concat (aref math-comp-buf-string math-comp-level) |
40785 | 1326 str)))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1327 (aset math-comp-buf-string math-comp-level str))))) |
40785 | 1328 |
1329 ((eq (car c) 'tag) | |
1330 (cond ((eq (nth 1 c) math-comp-selected) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1331 (let ((math-comp-highlight (not calc-show-selections))) |
40785 | 1332 (math-comp-to-string-flat-term (nth 2 c)))) |
1333 ((eq (nth 1 c) t) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1334 (let ((math-comp-highlight nil)) |
40785 | 1335 (math-comp-to-string-flat-term (nth 2 c)))) |
1336 (t (math-comp-to-string-flat-term (nth 2 c))))) | |
1337 | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1338 (t (math-comp-to-string-flat-term (nth 2 c))))) |
40785 | 1339 |
1340 (defun math-comp-highlight-string (s) | |
1341 (setq s (copy-sequence s)) | |
1342 (let ((i (length s))) | |
1343 (while (>= (setq i (1- i)) 0) | |
1344 (or (memq (aref s i) '(32 ?\n)) | |
1345 (aset s i (if calc-show-selections ?\. ?\#))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1346 s) |
40785 | 1347 |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1348 |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1349 ;; The variable math-comp-sel-tag is local to calc-find-selected-part |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1350 ;; in calc-sel.el, but is used by math-comp-sel-flat-term and |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1351 ;; math-comp-add-string-sel, which are called (indirectly) by |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1352 ;; calc-find-selected-part. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1353 (defvar math-comp-sel-tag) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1354 |
40785 | 1355 (defun math-comp-sel-flat-term (c) |
1356 (cond ((not (consp c)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1357 (setq math-comp-pos (+ math-comp-pos (length c)))) |
40785 | 1358 ((memq (car c) '(set break))) |
1359 ((eq (car c) 'horiz) | |
1360 (while (and (setq c (cdr c)) (< math-comp-sel-cpos 1000000)) | |
1361 (math-comp-sel-flat-term (car c)))) | |
1362 ((eq (car c) 'tag) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1363 (if (<= math-comp-pos math-comp-sel-cpos) |
40785 | 1364 (progn |
1365 (math-comp-sel-flat-term (nth 2 c)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1366 (if (> math-comp-pos math-comp-sel-cpos) |
40785 | 1367 (setq math-comp-sel-tag c |
1368 math-comp-sel-cpos 1000000))) | |
1369 (math-comp-sel-flat-term (nth 2 c)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1370 (t (math-comp-sel-flat-term (nth 2 c))))) |
40785 | 1371 |
1372 | |
1373 ;;; Simplify a composition to a canonical form consisting of | |
1374 ;;; (vleft n "string" "string" "string" ...) | |
1375 ;;; where 0 <= n < number-of-strings. | |
1376 | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1377 ;; The variables math-comp-base, math-comp-hgt, math-comp-tag, |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1378 ;; math-comp-hpos and math-comp-vpos are local to math-comp-simplify, |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1379 ;; but are used by math-comp-add-string (math-comp-base, math-comp-hgt), |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1380 ;; math-comp-add-string-sel (math-comp-tag) and math-comp-simplify-term |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1381 ;; (math-comp-tag, math-comp-vpos, math-comp-hpos), which are called by |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1382 ;; math-comp-simplify. |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1383 (defvar math-comp-base) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1384 (defvar math-comp-hgt) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1385 (defvar math-comp-tag) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1386 (defvar math-comp-hpos) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1387 (defvar math-comp-vpos) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1388 |
40785 | 1389 (defun math-comp-simplify (c full-width) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1390 (let ((math-comp-buf (list "")) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1391 (math-comp-base 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1392 (math-comp-hgt 1) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1393 (math-comp-hpos 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1394 (math-comp-vpos 0) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1395 (math-comp-highlight (and math-comp-selected calc-show-selections)) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1396 (math-comp-tag nil)) |
40785 | 1397 (math-comp-simplify-term c) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1398 (cons 'vleft (cons math-comp-base math-comp-buf)))) |
40785 | 1399 |
1400 (defun math-comp-add-string (s h v) | |
1401 (and (> (length s) 0) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1402 (let ((vv (+ v math-comp-base))) |
40785 | 1403 (if math-comp-sel-hpos |
1404 (math-comp-add-string-sel h vv (length s) 1) | |
1405 (if (< vv 0) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1406 (setq math-comp-buf (nconc (make-list (- vv) "") math-comp-buf) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1407 math-comp-base (- v) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1408 math-comp-hgt (- math-comp-hgt vv) |
40785 | 1409 vv 0) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1410 (if (>= vv math-comp-hgt) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1411 (setq math-comp-buf (nconc math-comp-buf |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1412 (make-list (1+ (- vv math-comp-hgt)) "")) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1413 math-comp-hgt (1+ vv)))) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1414 (let ((str (nthcdr vv math-comp-buf))) |
40785 | 1415 (setcar str (concat (car str) |
1416 (make-string (- h (length (car str))) 32) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1417 (if math-comp-highlight |
40785 | 1418 (math-comp-highlight-string s) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1419 s)))))))) |
40785 | 1420 |
1421 (defun math-comp-add-string-sel (x y w h) | |
1422 (if (and (<= y math-comp-sel-vpos) | |
1423 (> (+ y h) math-comp-sel-vpos) | |
1424 (<= x math-comp-sel-hpos) | |
1425 (> (+ x w) math-comp-sel-hpos)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1426 (setq math-comp-sel-tag math-comp-tag |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1427 math-comp-sel-vpos 10000))) |
40785 | 1428 |
1429 (defun math-comp-simplify-term (c) | |
1430 (cond ((stringp c) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1431 (math-comp-add-string c math-comp-hpos math-comp-vpos) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1432 (setq math-comp-hpos (+ math-comp-hpos (length c)))) |
40785 | 1433 ((memq (car c) '(set break)) |
1434 nil) | |
1435 ((eq (car c) 'horiz) | |
1436 (while (setq c (cdr c)) | |
1437 (math-comp-simplify-term (car c)))) | |
1438 ((memq (car c) '(vleft vcent vright)) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1439 (let* ((math-comp-vpos (+ (- math-comp-vpos (nth 1 c)) |
40785 | 1440 (1- (math-comp-ascent (nth 2 c))))) |
1441 (widths (mapcar 'math-comp-width (cdr (cdr c)))) | |
1442 (maxwid (apply 'max widths)) | |
1443 (bias (cond ((eq (car c) 'vleft) 0) | |
1444 ((eq (car c) 'vcent) 1) | |
1445 (t 2)))) | |
1446 (setq c (cdr c)) | |
1447 (while (setq c (cdr c)) | |
1448 (if (eq (car-safe (car c)) 'rule) | |
1449 (math-comp-add-string (make-string maxwid (nth 1 (car c))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1450 math-comp-hpos math-comp-vpos) |
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1451 (let ((math-comp-hpos (+ math-comp-hpos (/ (* bias (- maxwid |
40785 | 1452 (car widths))) |
1453 2)))) | |
1454 (math-comp-simplify-term (car c)))) | |
1455 (and (cdr c) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1456 (setq math-comp-vpos (+ math-comp-vpos |
40785 | 1457 (+ (math-comp-descent (car c)) |
1458 (math-comp-ascent (nth 1 c)))) | |
1459 widths (cdr widths)))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1460 (setq math-comp-hpos (+ math-comp-hpos maxwid)))) |
40785 | 1461 ((eq (car c) 'supscr) |
1462 (let* ((asc (or 1 (math-comp-ascent (nth 1 c)))) | |
1463 (desc (math-comp-descent (nth 2 c))) | |
1464 (oldh (prog1 | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1465 math-comp-hpos |
40785 | 1466 (math-comp-simplify-term (nth 1 c)))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1467 (math-comp-vpos (- math-comp-vpos (+ asc desc)))) |
40785 | 1468 (math-comp-simplify-term (nth 2 c)) |
1469 (if math-comp-sel-hpos | |
1470 (math-comp-add-string-sel oldh | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1471 (- math-comp-vpos |
40785 | 1472 -1 |
1473 (math-comp-ascent (nth 2 c))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1474 (- math-comp-hpos oldh) |
40785 | 1475 (math-comp-height c))))) |
1476 ((eq (car c) 'subscr) | |
1477 (let* ((asc (math-comp-ascent (nth 2 c))) | |
1478 (desc (math-comp-descent (nth 1 c))) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1479 (oldv math-comp-vpos) |
40785 | 1480 (oldh (prog1 |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1481 math-comp-hpos |
40785 | 1482 (math-comp-simplify-term (nth 1 c)))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1483 (math-comp-vpos (+ math-comp-vpos (+ asc desc)))) |
40785 | 1484 (math-comp-simplify-term (nth 2 c)) |
1485 (if math-comp-sel-hpos | |
1486 (math-comp-add-string-sel oldh oldv | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1487 (- math-comp-hpos oldh) |
40785 | 1488 (math-comp-height c))))) |
1489 ((eq (car c) 'tag) | |
1490 (cond ((eq (nth 1 c) math-comp-selected) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1491 (let ((math-comp-highlight (not calc-show-selections))) |
40785 | 1492 (math-comp-simplify-term (nth 2 c)))) |
1493 ((eq (nth 1 c) t) | |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1494 (let ((math-comp-highlight nil)) |
40785 | 1495 (math-comp-simplify-term (nth 2 c)))) |
58465
02afd0c73e8e
(math-svo-c, math-svo-wid, math-svo-off): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
1496 (t (let ((math-comp-tag c)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1497 (math-comp-simplify-term (nth 2 c)))))))) |
40785 | 1498 |
1499 | |
1500 ;;; Measuring a composition. | |
1501 | |
1502 (defun math-comp-first-char (c) | |
1503 (cond ((stringp c) | |
1504 (and (> (length c) 0) | |
1505 (elt c 0))) | |
1506 ((memq (car c) '(horiz subscr supscr)) | |
1507 (while (and (setq c (cdr c)) | |
1508 (math-comp-is-null (car c)))) | |
1509 (and c (math-comp-first-char (car c)))) | |
1510 ((eq (car c) 'tag) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1511 (math-comp-first-char (nth 2 c))))) |
40785 | 1512 |
1513 (defun math-comp-first-string (c) | |
1514 (cond ((stringp c) | |
1515 (and (> (length c) 0) | |
1516 c)) | |
1517 ((eq (car c) 'horiz) | |
1518 (while (and (setq c (cdr c)) | |
1519 (math-comp-is-null (car c)))) | |
1520 (and c (math-comp-first-string (car c)))) | |
1521 ((eq (car c) 'tag) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1522 (math-comp-first-string (nth 2 c))))) |
40785 | 1523 |
1524 (defun math-comp-last-char (c) | |
1525 (cond ((stringp c) | |
1526 (and (> (length c) 0) | |
1527 (elt c (1- (length c))))) | |
1528 ((eq (car c) 'horiz) | |
1529 (let ((c (reverse (cdr c)))) | |
1530 (while (and c (math-comp-is-null (car c))) | |
1531 (setq c (cdr c))) | |
1532 (and c (math-comp-last-char (car c))))) | |
1533 ((eq (car c) 'tag) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1534 (math-comp-last-char (nth 2 c))))) |
40785 | 1535 |
1536 (defun math-comp-is-null (c) | |
1537 (cond ((stringp c) (= (length c) 0)) | |
1538 ((memq (car c) '(horiz subscr supscr)) | |
1539 (while (and (setq c (cdr c)) | |
1540 (math-comp-is-null (car c)))) | |
1541 (null c)) | |
1542 ((eq (car c) 'tag) | |
1543 (math-comp-is-null (nth 2 c))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1544 ((memq (car c) '(set break)) t))) |
40785 | 1545 |
1546 (defun math-comp-width (c) | |
1547 (cond ((not (consp c)) (length c)) | |
1548 ((memq (car c) '(horiz subscr supscr)) | |
1549 (let ((accum 0)) | |
1550 (while (setq c (cdr c)) | |
1551 (setq accum (+ accum (math-comp-width (car c))))) | |
1552 accum)) | |
1553 ((memq (car c) '(vcent vleft vright)) | |
1554 (setq c (cdr c)) | |
1555 (let ((accum 0)) | |
1556 (while (setq c (cdr c)) | |
1557 (setq accum (max accum (math-comp-width (car c))))) | |
1558 accum)) | |
1559 ((eq (car c) 'tag) | |
1560 (math-comp-width (nth 2 c))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1561 (t 0))) |
40785 | 1562 |
1563 (defun math-comp-height (c) | |
1564 (if (stringp c) | |
1565 1 | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1566 (+ (math-comp-ascent c) (math-comp-descent c)))) |
40785 | 1567 |
1568 (defun math-comp-ascent (c) | |
1569 (cond ((not (consp c)) 1) | |
1570 ((eq (car c) 'horiz) | |
1571 (let ((accum 0)) | |
1572 (while (setq c (cdr c)) | |
1573 (setq accum (max accum (math-comp-ascent (car c))))) | |
1574 accum)) | |
1575 ((memq (car c) '(vcent vleft vright)) | |
1576 (if (> (nth 1 c) 0) (1+ (nth 1 c)) 1)) | |
1577 ((eq (car c) 'supscr) | |
1578 (max (math-comp-ascent (nth 1 c)) (1+ (math-comp-height (nth 2 c))))) | |
1579 ((eq (car c) 'subscr) | |
1580 (math-comp-ascent (nth 1 c))) | |
1581 ((eq (car c) 'tag) | |
1582 (math-comp-ascent (nth 2 c))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1583 (t 1))) |
40785 | 1584 |
1585 (defun math-comp-descent (c) | |
1586 (cond ((not (consp c)) 0) | |
1587 ((eq (car c) 'horiz) | |
1588 (let ((accum 0)) | |
1589 (while (setq c (cdr c)) | |
1590 (setq accum (max accum (math-comp-descent (car c))))) | |
1591 accum)) | |
1592 ((memq (car c) '(vcent vleft vright)) | |
1593 (let ((accum (- (nth 1 c)))) | |
1594 (setq c (cdr c)) | |
1595 (while (setq c (cdr c)) | |
1596 (setq accum (+ accum (math-comp-height (car c))))) | |
1597 (max (1- accum) 0))) | |
1598 ((eq (car c) 'supscr) | |
1599 (math-comp-descent (nth 1 c))) | |
1600 ((eq (car c) 'subscr) | |
1601 (+ (math-comp-descent (nth 1 c)) (math-comp-height (nth 2 c)))) | |
1602 ((eq (car c) 'tag) | |
1603 (math-comp-descent (nth 2 c))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1604 (t 0))) |
40785 | 1605 |
1606 (defun calcFunc-cwidth (a &optional prec) | |
1607 (if (and prec (not (integerp prec))) (math-reject-arg prec 'fixnump)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1608 (math-comp-width (math-compose-expr a (or prec 0)))) |
40785 | 1609 |
1610 (defun calcFunc-cheight (a &optional prec) | |
1611 (if (and prec (not (integerp prec))) (math-reject-arg prec 'fixnump)) | |
1612 (if (and (memq (car a) '(calcFunc-cvspace calcFunc-ctspace calcFunc-cbspace)) | |
1613 (memq (length a) '(2 3)) | |
1614 (eq (nth 1 a) 0)) | |
1615 0 | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1616 (math-comp-height (math-compose-expr a (or prec 0))))) |
40785 | 1617 |
1618 (defun calcFunc-cascent (a &optional prec) | |
1619 (if (and prec (not (integerp prec))) (math-reject-arg prec 'fixnump)) | |
1620 (if (and (memq (car a) '(calcFunc-cvspace calcFunc-ctspace calcFunc-cbspace)) | |
1621 (memq (length a) '(2 3)) | |
1622 (eq (nth 1 a) 0)) | |
1623 0 | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1624 (math-comp-ascent (math-compose-expr a (or prec 0))))) |
40785 | 1625 |
1626 (defun calcFunc-cdescent (a &optional prec) | |
1627 (if (and prec (not (integerp prec))) (math-reject-arg prec 'fixnump)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1628 (math-comp-descent (math-compose-expr a (or prec 0)))) |
40785 | 1629 |
1630 | |
1631 ;;; Convert a simplified composition into string form. | |
1632 | |
1633 (defun math-vert-comp-to-string (c) | |
1634 (if (stringp c) | |
1635 c | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1636 (math-vert-comp-to-string-step (cdr (cdr c))))) |
40785 | 1637 |
1638 (defun math-vert-comp-to-string-step (c) | |
1639 (if (cdr c) | |
1640 (concat (car c) "\n" (math-vert-comp-to-string-step (cdr c))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1641 (car c))) |
40785 | 1642 |
1643 | |
1644 ;;; Convert a composition to a string in "raw" form (for debugging). | |
1645 | |
1646 (defun math-comp-to-string-raw (c indent) | |
1647 (cond ((or (not (consp c)) (eq (car c) 'set)) | |
1648 (prin1-to-string c)) | |
1649 ((null (cdr c)) | |
1650 (concat "(" (symbol-name (car c)) ")")) | |
1651 (t | |
1652 (let ((next-indent (+ indent 2 (length (symbol-name (car c)))))) | |
1653 (concat "(" | |
1654 (symbol-name (car c)) | |
1655 " " | |
1656 (math-comp-to-string-raw (nth 1 c) next-indent) | |
1657 (math-comp-to-string-raw-step (cdr (cdr c)) | |
1658 next-indent) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1659 ")"))))) |
40785 | 1660 |
1661 (defun math-comp-to-string-raw-step (cl indent) | |
1662 (if cl | |
1663 (concat "\n" | |
1664 (make-string indent 32) | |
1665 (math-comp-to-string-raw (car cl) indent) | |
1666 (math-comp-to-string-raw-step (cdr cl) indent)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1667 "")) |
40785 | 1668 |
58683
1752ff980918
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58465
diff
changeset
|
1669 (provide 'calccomp) |
1752ff980918
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58465
diff
changeset
|
1670 |
109033
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1671 ;; Local variables: |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1672 ;; coding: utf-8 |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1673 ;; End: |
d150a25a0eb9
Add some utf-8 coding cookies.
Glenn Morris <rgm@gnu.org>
parents:
108590
diff
changeset
|
1674 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1675 ;; arch-tag: 7c45d10a-a286-4dab-af49-7ae8989fbf78 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1676 ;;; calccomp.el ends here |