Mercurial > emacs
changeset 59811:9e28f5bc25bb
(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.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Mon, 31 Jan 2005 06:25:17 +0000 |
parents | 3192518bb184 |
children | fb44bc67721e |
files | lisp/calc/calc-lang.el |
diffstat | 1 files changed, 167 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/calc/calc-lang.el Mon Jan 31 06:23:04 2005 +0000 +++ b/lisp/calc/calc-lang.el Mon Jan 31 06:25:17 2005 +0000 @@ -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")