annotate lisp/calc/calccomp.el @ 76867:89798bc7980d

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