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