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