From 2d3ce3f29290628c20bf36db7b87c9a908ac16c9 Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Mon, 31 Jan 2005 06:25:17 +0000 Subject: (calc-latex-language, math-latex-parse-frac) (math-latex-print-frac): New functions. (math-oper-table, math-function-table, math-variable-table) (math-complex-format, math-input-filter): Add latex properties. (calc-set-language): Set math-expr-special-function-mapping. --- lisp/calc/calc-lang.el | 167 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) (limited to 'lisp/calc/calc-lang.el') diff --git a/lisp/calc/calc-lang.el b/lisp/calc/calc-lang.el index cfbe3313d8e..c691e2bcc2b 100644 --- a/lisp/calc/calc-lang.el +++ b/lisp/calc/calc-lang.el @@ -36,6 +36,7 @@ (defun calc-set-language (lang &optional option no-refresh) (setq math-expr-opers (or (get lang 'math-oper-table) math-standard-opers) math-expr-function-mapping (get lang 'math-function-table) + math-expr-special-function-mapping (get lang 'math-special-function-table) math-expr-variable-mapping (get lang 'math-variable-table) calc-language-input-filter (get lang 'math-input-filter) calc-language-output-filter (get lang 'math-output-filter) @@ -296,6 +297,26 @@ "TeX language mode with \\func{\\hbox{var}}") "TeX language mode")))) +(defun calc-latex-language (n) + (interactive "P") + (calc-wrapper + (and n (setq n (prefix-numeric-value n))) + (calc-set-language 'latex n) + (cond ((not n) + (message "LaTeX language mode")) + ((= n 0) + (message "LaTeX language mode with multiline matrices")) + ((= n 1) + (message "LaTeX language mode with \\text{func}(\\text{var})")) + ((> n 1) + (message + "LaTeX language mode with \\text{func}(\\text{var}) and multiline matrices")) + ((= n -1) + (message "LaTeX language mode with \\func(\\text{var})")) + ((< n -1) + (message + "LaTeX language mode with \\func(\\text{var}) and multiline matrices"))))) + (put 'tex 'math-oper-table '( ( "u+" ident -1 1000 ) ( "u-" neg -1 1000 ) @@ -406,6 +427,152 @@ str) (put 'tex 'math-input-filter 'math-tex-input-filter) +(put 'latex 'math-oper-table + '( ( "u+" ident -1 1000 ) + ( "u-" neg -1 1000 ) + ( "\\hat" calcFunc-hat -1 950 ) + ( "\\check" calcFunc-check -1 950 ) + ( "\\tilde" calcFunc-tilde -1 950 ) + ( "\\acute" calcFunc-acute -1 950 ) + ( "\\grave" calcFunc-grave -1 950 ) + ( "\\dot" calcFunc-dot -1 950 ) + ( "\\ddot" calcFunc-dotdot -1 950 ) + ( "\\breve" calcFunc-breve -1 950 ) + ( "\\bar" calcFunc-bar -1 950 ) + ( "\\vec" calcFunc-Vec -1 950 ) + ( "\\underline" calcFunc-under -1 950 ) + ( "\\Hat" calcFunc-Hat -1 950 ) + ( "\\Check" calcFunc-Check -1 950 ) + ( "\\Tilde" calcFunc-Tilde -1 950 ) + ( "\\Acute" calcFunc-Acute -1 950 ) + ( "\\Grave" calcFunc-Grave -1 950 ) + ( "\\Dot" calcFunc-Dot -1 950 ) + ( "\\Ddot" calcFunc-Dotdot -1 950 ) + ( "\\Breve" calcFunc-Breve -1 950 ) + ( "\\Bar" calcFunc-Bar -1 950 ) + ( "\\Vec" calcFunc-VEC -1 950 ) + ( "\\dddot" calcFunc-dddot -1 950 ) + ( "\\ddddot" calcFunc-ddddot -1 950 ) + ( "u|" calcFunc-abs -1 0 ) + ( "|" closing 0 -1 ) + ( "\\lfloor" calcFunc-floor -1 0 ) + ( "\\rfloor" closing 0 -1 ) + ( "\\lceil" calcFunc-ceil -1 0 ) + ( "\\rceil" closing 0 -1 ) + ( "\\pm" sdev 300 300 ) + ( "!" calcFunc-fact 210 -1 ) + ( "^" ^ 201 200 ) + ( "_" calcFunc-subscr 201 200 ) + ( "\\times" * 191 190 ) + ( "*" * 191 190 ) + ( "2x" * 191 190 ) + ( "+" + 180 181 ) + ( "-" - 180 181 ) + ( "\\over" / 170 171 ) + ( "/" / 170 171 ) + ( "\div" / 170 171 ) + ( "\\choose" calcFunc-choose 170 171 ) + ( "\\mod" % 170 171 ) + ( "<" calcFunc-lt 160 161 ) + ( ">" calcFunc-gt 160 161 ) + ( "\\leq" calcFunc-leq 160 161 ) + ( "\\le" calcFunc-leq 160 161 ) + ( "\\leqq" calcFunc-leq 160 161 ) + ( "\\leqsland" calcFunc-leq 160 161 ) + ( "\\geq" calcFunc-geq 160 161 ) + ( "\\ge" calcFunc-geq 160 161 ) + ( "\\geqq" calcFunc-geq 160 161 ) + ( "\\geqslant" calcFunc-geq 160 161 ) + ( "=" calcFunc-eq 160 161 ) + ( "\\neq" calcFunc-neq 160 161 ) + ( "\\ne" calcFunc-neq 160 161 ) + ( "\\lnot" calcFunc-lnot -1 121 ) + ( "\\land" calcFunc-land 110 111 ) + ( "\\lor" calcFunc-lor 100 101 ) + ( "?" (math-read-if) 91 90 ) + ( "!!!" calcFunc-pnot -1 85 ) + ( "&&&" calcFunc-pand 80 81 ) + ( "|||" calcFunc-por 75 76 ) + ( "\\gets" calcFunc-assign 51 50 ) + ( ":=" calcFunc-assign 51 50 ) + ( "::" calcFunc-condition 45 46 ) + ( "\\to" calcFunc-evalto 40 41 ) + ( "\\to" calcFunc-evalto 40 -1 ) + ( "=>" calcFunc-evalto 40 41 ) + ( "=>" calcFunc-evalto 40 -1 ))) + +(put 'latex 'math-function-table + '( ( \\arccos . calcFunc-arccos ) + ( \\arcsin . calcFunc-arcsin ) + ( \\arctan . calcFunc-arctan ) + ( \\arg . calcFunc-arg ) + ( \\cos . calcFunc-cos ) + ( \\cosh . calcFunc-cosh ) + ( \\det . calcFunc-det ) + ( \\exp . calcFunc-exp ) + ( \\gcd . calcFunc-gcd ) + ( \\ln . calcFunc-ln ) + ( \\log . calcFunc-log10 ) + ( \\max . calcFunc-max ) + ( \\min . calcFunc-min ) + ( \\tan . calcFunc-tan ) + ( \\sin . calcFunc-sin ) + ( \\sinh . calcFunc-sinh ) + ( \\sqrt . calcFunc-sqrt ) + ( \\tanh . calcFunc-tanh ) + ( \\frac . (math-latex-parse-frac /)) + ( \\tfrac . (math-latex-parse-frac /)) + ( \\dfrac . (math-latex-parse-frac /)) + ( \\binom . (math-latex-parse-frac calcFunc-choose)) + ( \\tbinom . (math-latex-parse-frac calcFunc-choose)) + ( \\dbinom . (math-latex-parse-frac calcFunc-choose)) + ( \\phi . calcFunc-totient ) + ( \\mu . calcFunc-moebius ))) + +(put 'latex 'math-special-function-table + '((/ . (math-latex-print-frac "\\frac")) + (calcFunc-choose . (math-latex-print-frac "\\binom")))) + +(put 'latex 'math-variable-table + '( ( \\pi . var-pi ) + ( \\infty . var-inf ) + ( \\infty . var-uinf ) + ( \\phi . var-phi ) + ( \\gamma . var-gamma ) + ( \\sum . (math-parse-tex-sum calcFunc-sum) ) + ( \\prod . (math-parse-tex-sum calcFunc-prod) ))) + +(put 'latex 'math-complex-format 'i) + +(defun math-latex-parse-frac (f val) + (let (numer denom) + (setq args (math-read-expr-list)) + (math-read-token) + (setq margs (math-read-factor)) + (list (nth 2 f) (car args) margs))) + +(defun math-latex-print-frac (a fn) + (list 'horiz (nth 1 fn) "{" (math-compose-expr (nth 1 a) -1) + "}{" + (math-compose-expr (nth 2 a) -1) + "}")) + +(defun math-latex-input-filter (str) ; allow parsing of 123\,456\,789. + (while (string-match "[0-9]\\\\,[0-9]" str) + (setq str (concat (substring str 0 (1+ (match-beginning 0))) + (substring str (1- (match-end 0)))))) + (while (string-match "\\\\begin{\\(small\\|[bp]\\)?matrix}" str) + (setq str (concat (substring str 0 (match-beginning 0)) + "\\matrix{" + (substring str (match-end 0))))) + (while (string-match "\\\\end{\\(small\\|[bp]\\)?matrix}" str) + (setq str (concat (substring str 0 (match-beginning 0)) + "}" + (substring str (match-end 0))))) + + str) + +(put 'latex 'math-input-filter 'math-latex-input-filter) (defun calc-eqn-language (n) (interactive "P") -- cgit v1.2.3 From cfa083161b51d2ebfc65f2d6a9e2440af44accff Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Mon, 31 Jan 2005 09:08:34 +0000 Subject: (math-latex-input-filter): Remove function. --- lisp/calc/calc-lang.el | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'lisp/calc/calc-lang.el') diff --git a/lisp/calc/calc-lang.el b/lisp/calc/calc-lang.el index c691e2bcc2b..48612f4cfd5 100644 --- a/lisp/calc/calc-lang.el +++ b/lisp/calc/calc-lang.el @@ -557,22 +557,7 @@ (math-compose-expr (nth 2 a) -1) "}")) -(defun math-latex-input-filter (str) ; allow parsing of 123\,456\,789. - (while (string-match "[0-9]\\\\,[0-9]" str) - (setq str (concat (substring str 0 (1+ (match-beginning 0))) - (substring str (1- (match-end 0)))))) - (while (string-match "\\\\begin{\\(small\\|[bp]\\)?matrix}" str) - (setq str (concat (substring str 0 (match-beginning 0)) - "\\matrix{" - (substring str (match-end 0))))) - (while (string-match "\\\\end{\\(small\\|[bp]\\)?matrix}" str) - (setq str (concat (substring str 0 (match-beginning 0)) - "}" - (substring str (match-end 0))))) - - str) - -(put 'latex 'math-input-filter 'math-latex-input-filter) +(put 'latex 'math-input-filter 'math-tex-input-filter) (defun calc-eqn-language (n) (interactive "P") -- cgit v1.2.3 From 62a54f6ca5cf9b66ee35ad348097dc285c884f38 Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Mon, 31 Jan 2005 21:53:21 +0000 Subject: (math-function-table, math-oper-table, math-variable-table): Adjust the LaTeX portions. --- lisp/calc/calc-lang.el | 153 ++++++++++++++++--------------------------------- 1 file changed, 48 insertions(+), 105 deletions(-) (limited to 'lisp/calc/calc-lang.el') diff --git a/lisp/calc/calc-lang.el b/lisp/calc/calc-lang.el index 48612f4cfd5..d91d78fc461 100644 --- a/lisp/calc/calc-lang.el +++ b/lisp/calc/calc-lang.el @@ -428,119 +428,62 @@ (put 'tex 'math-input-filter 'math-tex-input-filter) (put 'latex 'math-oper-table - '( ( "u+" ident -1 1000 ) - ( "u-" neg -1 1000 ) - ( "\\hat" calcFunc-hat -1 950 ) - ( "\\check" calcFunc-check -1 950 ) - ( "\\tilde" calcFunc-tilde -1 950 ) - ( "\\acute" calcFunc-acute -1 950 ) - ( "\\grave" calcFunc-grave -1 950 ) - ( "\\dot" calcFunc-dot -1 950 ) - ( "\\ddot" calcFunc-dotdot -1 950 ) - ( "\\breve" calcFunc-breve -1 950 ) - ( "\\bar" calcFunc-bar -1 950 ) - ( "\\vec" calcFunc-Vec -1 950 ) - ( "\\underline" calcFunc-under -1 950 ) - ( "\\Hat" calcFunc-Hat -1 950 ) - ( "\\Check" calcFunc-Check -1 950 ) - ( "\\Tilde" calcFunc-Tilde -1 950 ) - ( "\\Acute" calcFunc-Acute -1 950 ) - ( "\\Grave" calcFunc-Grave -1 950 ) - ( "\\Dot" calcFunc-Dot -1 950 ) - ( "\\Ddot" calcFunc-Dotdot -1 950 ) - ( "\\Breve" calcFunc-Breve -1 950 ) - ( "\\Bar" calcFunc-Bar -1 950 ) - ( "\\Vec" calcFunc-VEC -1 950 ) - ( "\\dddot" calcFunc-dddot -1 950 ) - ( "\\ddddot" calcFunc-ddddot -1 950 ) - ( "u|" calcFunc-abs -1 0 ) - ( "|" closing 0 -1 ) - ( "\\lfloor" calcFunc-floor -1 0 ) - ( "\\rfloor" closing 0 -1 ) - ( "\\lceil" calcFunc-ceil -1 0 ) - ( "\\rceil" closing 0 -1 ) - ( "\\pm" sdev 300 300 ) - ( "!" calcFunc-fact 210 -1 ) - ( "^" ^ 201 200 ) - ( "_" calcFunc-subscr 201 200 ) - ( "\\times" * 191 190 ) - ( "*" * 191 190 ) - ( "2x" * 191 190 ) - ( "+" + 180 181 ) - ( "-" - 180 181 ) - ( "\\over" / 170 171 ) - ( "/" / 170 171 ) - ( "\div" / 170 171 ) - ( "\\choose" calcFunc-choose 170 171 ) - ( "\\mod" % 170 171 ) - ( "<" calcFunc-lt 160 161 ) - ( ">" calcFunc-gt 160 161 ) - ( "\\leq" calcFunc-leq 160 161 ) - ( "\\le" calcFunc-leq 160 161 ) - ( "\\leqq" calcFunc-leq 160 161 ) - ( "\\leqsland" calcFunc-leq 160 161 ) - ( "\\geq" calcFunc-geq 160 161 ) - ( "\\ge" calcFunc-geq 160 161 ) - ( "\\geqq" calcFunc-geq 160 161 ) - ( "\\geqslant" calcFunc-geq 160 161 ) - ( "=" calcFunc-eq 160 161 ) - ( "\\neq" calcFunc-neq 160 161 ) - ( "\\ne" calcFunc-neq 160 161 ) - ( "\\lnot" calcFunc-lnot -1 121 ) - ( "\\land" calcFunc-land 110 111 ) - ( "\\lor" calcFunc-lor 100 101 ) - ( "?" (math-read-if) 91 90 ) - ( "!!!" calcFunc-pnot -1 85 ) - ( "&&&" calcFunc-pand 80 81 ) - ( "|||" calcFunc-por 75 76 ) - ( "\\gets" calcFunc-assign 51 50 ) - ( ":=" calcFunc-assign 51 50 ) - ( "::" calcFunc-condition 45 46 ) - ( "\\to" calcFunc-evalto 40 41 ) - ( "\\to" calcFunc-evalto 40 -1 ) - ( "=>" calcFunc-evalto 40 41 ) - ( "=>" calcFunc-evalto 40 -1 ))) + (append (get 'tex 'math-oper-table) + '(( "\\Hat" calcFunc-Hat -1 950 ) + ( "\\Check" calcFunc-Check -1 950 ) + ( "\\Tilde" calcFunc-Tilde -1 950 ) + ( "\\Acute" calcFunc-Acute -1 950 ) + ( "\\Grave" calcFunc-Grave -1 950 ) + ( "\\Dot" calcFunc-Dot -1 950 ) + ( "\\Ddot" calcFunc-Dotdot -1 950 ) + ( "\\Breve" calcFunc-Breve -1 950 ) + ( "\\Bar" calcFunc-Bar -1 950 ) + ( "\\Vec" calcFunc-VEC -1 950 ) + ( "\\dddot" calcFunc-dddot -1 950 ) + ( "\\ddddot" calcFunc-ddddot -1 950 ) + ( "\div" / 170 171 ) + ( "\\le" calcFunc-leq 160 161 ) + ( "\\leqq" calcFunc-leq 160 161 ) + ( "\\leqsland" calcFunc-leq 160 161 ) + ( "\\ge" calcFunc-geq 160 161 ) + ( "\\geqq" calcFunc-geq 160 161 ) + ( "\\geqslant" calcFunc-geq 160 161 ) + ( "=" calcFunc-eq 160 161 ) + ( "\\neq" calcFunc-neq 160 161 ) + ( "\\ne" calcFunc-neq 160 161 ) + ( "\\lnot" calcFunc-lnot -1 121 ) + ( "\\land" calcFunc-land 110 111 ) + ( "\\lor" calcFunc-lor 100 101 ) + ( "?" (math-read-if) 91 90 ) + ( "!!!" calcFunc-pnot -1 85 ) + ( "&&&" calcFunc-pand 80 81 ) + ( "|||" calcFunc-por 75 76 ) + ( "\\gets" calcFunc-assign 51 50 ) + ( ":=" calcFunc-assign 51 50 ) + ( "::" calcFunc-condition 45 46 ) + ( "\\to" calcFunc-evalto 40 41 ) + ( "\\to" calcFunc-evalto 40 -1 ) + ( "=>" calcFunc-evalto 40 41 ) + ( "=>" calcFunc-evalto 40 -1 )))) (put 'latex 'math-function-table - '( ( \\arccos . calcFunc-arccos ) - ( \\arcsin . calcFunc-arcsin ) - ( \\arctan . calcFunc-arctan ) - ( \\arg . calcFunc-arg ) - ( \\cos . calcFunc-cos ) - ( \\cosh . calcFunc-cosh ) - ( \\det . calcFunc-det ) - ( \\exp . calcFunc-exp ) - ( \\gcd . calcFunc-gcd ) - ( \\ln . calcFunc-ln ) - ( \\log . calcFunc-log10 ) - ( \\max . calcFunc-max ) - ( \\min . calcFunc-min ) - ( \\tan . calcFunc-tan ) - ( \\sin . calcFunc-sin ) - ( \\sinh . calcFunc-sinh ) - ( \\sqrt . calcFunc-sqrt ) - ( \\tanh . calcFunc-tanh ) - ( \\frac . (math-latex-parse-frac /)) - ( \\tfrac . (math-latex-parse-frac /)) - ( \\dfrac . (math-latex-parse-frac /)) - ( \\binom . (math-latex-parse-frac calcFunc-choose)) - ( \\tbinom . (math-latex-parse-frac calcFunc-choose)) - ( \\dbinom . (math-latex-parse-frac calcFunc-choose)) - ( \\phi . calcFunc-totient ) - ( \\mu . calcFunc-moebius ))) + (append + (get 'tex 'math-function-table) + '(( \\frac . (math-latex-parse-frac /)) + ( \\tfrac . (math-latex-parse-frac /)) + ( \\dfrac . (math-latex-parse-frac /)) + ( \\binom . (math-latex-parse-frac calcFunc-choose)) + ( \\tbinom . (math-latex-parse-frac calcFunc-choose)) + ( \\dbinom . (math-latex-parse-frac calcFunc-choose)) + ( \\phi . calcFunc-totient ) + ( \\mu . calcFunc-moebius )))) (put 'latex 'math-special-function-table '((/ . (math-latex-print-frac "\\frac")) (calcFunc-choose . (math-latex-print-frac "\\binom")))) (put 'latex 'math-variable-table - '( ( \\pi . var-pi ) - ( \\infty . var-inf ) - ( \\infty . var-uinf ) - ( \\phi . var-phi ) - ( \\gamma . var-gamma ) - ( \\sum . (math-parse-tex-sum calcFunc-sum) ) - ( \\prod . (math-parse-tex-sum calcFunc-prod) ))) + (get 'tex 'math-variable-table)) (put 'latex 'math-complex-format 'i) -- cgit v1.2.3