aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Belanger2005-01-31 06:25:17 +0000
committerJay Belanger2005-01-31 06:25:17 +0000
commit2d3ce3f29290628c20bf36db7b87c9a908ac16c9 (patch)
tree0129bb2d3ea7275cf56e2ab65c95427b5723d39e
parent4617278c2591718bea340da2949ca6eae57f57d8 (diff)
downloademacs-2d3ce3f29290628c20bf36db7b87c9a908ac16c9.tar.gz
emacs-2d3ce3f29290628c20bf36db7b87c9a908ac16c9.zip
(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.
-rw-r--r--lisp/calc/calc-lang.el167
1 files changed, 167 insertions, 0 deletions
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 @@
36(defun calc-set-language (lang &optional option no-refresh) 36(defun calc-set-language (lang &optional option no-refresh)
37 (setq math-expr-opers (or (get lang 'math-oper-table) math-standard-opers) 37 (setq math-expr-opers (or (get lang 'math-oper-table) math-standard-opers)
38 math-expr-function-mapping (get lang 'math-function-table) 38 math-expr-function-mapping (get lang 'math-function-table)
39 math-expr-special-function-mapping (get lang 'math-special-function-table)
39 math-expr-variable-mapping (get lang 'math-variable-table) 40 math-expr-variable-mapping (get lang 'math-variable-table)
40 calc-language-input-filter (get lang 'math-input-filter) 41 calc-language-input-filter (get lang 'math-input-filter)
41 calc-language-output-filter (get lang 'math-output-filter) 42 calc-language-output-filter (get lang 'math-output-filter)
@@ -296,6 +297,26 @@
296 "TeX language mode with \\func{\\hbox{var}}") 297 "TeX language mode with \\func{\\hbox{var}}")
297 "TeX language mode")))) 298 "TeX language mode"))))
298 299
300(defun calc-latex-language (n)
301 (interactive "P")
302 (calc-wrapper
303 (and n (setq n (prefix-numeric-value n)))
304 (calc-set-language 'latex n)
305 (cond ((not n)
306 (message "LaTeX language mode"))
307 ((= n 0)
308 (message "LaTeX language mode with multiline matrices"))
309 ((= n 1)
310 (message "LaTeX language mode with \\text{func}(\\text{var})"))
311 ((> n 1)
312 (message
313 "LaTeX language mode with \\text{func}(\\text{var}) and multiline matrices"))
314 ((= n -1)
315 (message "LaTeX language mode with \\func(\\text{var})"))
316 ((< n -1)
317 (message
318 "LaTeX language mode with \\func(\\text{var}) and multiline matrices")))))
319
299(put 'tex 'math-oper-table 320(put 'tex 'math-oper-table
300 '( ( "u+" ident -1 1000 ) 321 '( ( "u+" ident -1 1000 )
301 ( "u-" neg -1 1000 ) 322 ( "u-" neg -1 1000 )
@@ -406,6 +427,152 @@
406 str) 427 str)
407(put 'tex 'math-input-filter 'math-tex-input-filter) 428(put 'tex 'math-input-filter 'math-tex-input-filter)
408 429
430(put 'latex 'math-oper-table
431 '( ( "u+" ident -1 1000 )
432 ( "u-" neg -1 1000 )
433 ( "\\hat" calcFunc-hat -1 950 )
434 ( "\\check" calcFunc-check -1 950 )
435 ( "\\tilde" calcFunc-tilde -1 950 )
436 ( "\\acute" calcFunc-acute -1 950 )
437 ( "\\grave" calcFunc-grave -1 950 )
438 ( "\\dot" calcFunc-dot -1 950 )
439 ( "\\ddot" calcFunc-dotdot -1 950 )
440 ( "\\breve" calcFunc-breve -1 950 )
441 ( "\\bar" calcFunc-bar -1 950 )
442 ( "\\vec" calcFunc-Vec -1 950 )
443 ( "\\underline" calcFunc-under -1 950 )
444 ( "\\Hat" calcFunc-Hat -1 950 )
445 ( "\\Check" calcFunc-Check -1 950 )
446 ( "\\Tilde" calcFunc-Tilde -1 950 )
447 ( "\\Acute" calcFunc-Acute -1 950 )
448 ( "\\Grave" calcFunc-Grave -1 950 )
449 ( "\\Dot" calcFunc-Dot -1 950 )
450 ( "\\Ddot" calcFunc-Dotdot -1 950 )
451 ( "\\Breve" calcFunc-Breve -1 950 )
452 ( "\\Bar" calcFunc-Bar -1 950 )
453 ( "\\Vec" calcFunc-VEC -1 950 )
454 ( "\\dddot" calcFunc-dddot -1 950 )
455 ( "\\ddddot" calcFunc-ddddot -1 950 )
456 ( "u|" calcFunc-abs -1 0 )
457 ( "|" closing 0 -1 )
458 ( "\\lfloor" calcFunc-floor -1 0 )
459 ( "\\rfloor" closing 0 -1 )
460 ( "\\lceil" calcFunc-ceil -1 0 )
461 ( "\\rceil" closing 0 -1 )
462 ( "\\pm" sdev 300 300 )
463 ( "!" calcFunc-fact 210 -1 )
464 ( "^" ^ 201 200 )
465 ( "_" calcFunc-subscr 201 200 )
466 ( "\\times" * 191 190 )
467 ( "*" * 191 190 )
468 ( "2x" * 191 190 )
469 ( "+" + 180 181 )
470 ( "-" - 180 181 )
471 ( "\\over" / 170 171 )
472 ( "/" / 170 171 )
473 ( "\div" / 170 171 )
474 ( "\\choose" calcFunc-choose 170 171 )
475 ( "\\mod" % 170 171 )
476 ( "<" calcFunc-lt 160 161 )
477 ( ">" calcFunc-gt 160 161 )
478 ( "\\leq" calcFunc-leq 160 161 )
479 ( "\\le" calcFunc-leq 160 161 )
480 ( "\\leqq" calcFunc-leq 160 161 )
481 ( "\\leqsland" calcFunc-leq 160 161 )
482 ( "\\geq" calcFunc-geq 160 161 )
483 ( "\\ge" calcFunc-geq 160 161 )
484 ( "\\geqq" calcFunc-geq 160 161 )
485 ( "\\geqslant" calcFunc-geq 160 161 )
486 ( "=" calcFunc-eq 160 161 )
487 ( "\\neq" calcFunc-neq 160 161 )
488 ( "\\ne" calcFunc-neq 160 161 )
489 ( "\\lnot" calcFunc-lnot -1 121 )
490 ( "\\land" calcFunc-land 110 111 )
491 ( "\\lor" calcFunc-lor 100 101 )
492 ( "?" (math-read-if) 91 90 )
493 ( "!!!" calcFunc-pnot -1 85 )
494 ( "&&&" calcFunc-pand 80 81 )
495 ( "|||" calcFunc-por 75 76 )
496 ( "\\gets" calcFunc-assign 51 50 )
497 ( ":=" calcFunc-assign 51 50 )
498 ( "::" calcFunc-condition 45 46 )
499 ( "\\to" calcFunc-evalto 40 41 )
500 ( "\\to" calcFunc-evalto 40 -1 )
501 ( "=>" calcFunc-evalto 40 41 )
502 ( "=>" calcFunc-evalto 40 -1 )))
503
504(put 'latex 'math-function-table
505 '( ( \\arccos . calcFunc-arccos )
506 ( \\arcsin . calcFunc-arcsin )
507 ( \\arctan . calcFunc-arctan )
508 ( \\arg . calcFunc-arg )
509 ( \\cos . calcFunc-cos )
510 ( \\cosh . calcFunc-cosh )
511 ( \\det . calcFunc-det )
512 ( \\exp . calcFunc-exp )
513 ( \\gcd . calcFunc-gcd )
514 ( \\ln . calcFunc-ln )
515 ( \\log . calcFunc-log10 )
516 ( \\max . calcFunc-max )
517 ( \\min . calcFunc-min )
518 ( \\tan . calcFunc-tan )
519 ( \\sin . calcFunc-sin )
520 ( \\sinh . calcFunc-sinh )
521 ( \\sqrt . calcFunc-sqrt )
522 ( \\tanh . calcFunc-tanh )
523 ( \\frac . (math-latex-parse-frac /))
524 ( \\tfrac . (math-latex-parse-frac /))
525 ( \\dfrac . (math-latex-parse-frac /))
526 ( \\binom . (math-latex-parse-frac calcFunc-choose))
527 ( \\tbinom . (math-latex-parse-frac calcFunc-choose))
528 ( \\dbinom . (math-latex-parse-frac calcFunc-choose))
529 ( \\phi . calcFunc-totient )
530 ( \\mu . calcFunc-moebius )))
531
532(put 'latex 'math-special-function-table
533 '((/ . (math-latex-print-frac "\\frac"))
534 (calcFunc-choose . (math-latex-print-frac "\\binom"))))
535
536(put 'latex 'math-variable-table
537 '( ( \\pi . var-pi )
538 ( \\infty . var-inf )
539 ( \\infty . var-uinf )
540 ( \\phi . var-phi )
541 ( \\gamma . var-gamma )
542 ( \\sum . (math-parse-tex-sum calcFunc-sum) )
543 ( \\prod . (math-parse-tex-sum calcFunc-prod) )))
544
545(put 'latex 'math-complex-format 'i)
546
547(defun math-latex-parse-frac (f val)
548 (let (numer denom)
549 (setq args (math-read-expr-list))
550 (math-read-token)
551 (setq margs (math-read-factor))
552 (list (nth 2 f) (car args) margs)))
553
554(defun math-latex-print-frac (a fn)
555 (list 'horiz (nth 1 fn) "{" (math-compose-expr (nth 1 a) -1)
556 "}{"
557 (math-compose-expr (nth 2 a) -1)
558 "}"))
559
560(defun math-latex-input-filter (str) ; allow parsing of 123\,456\,789.
561 (while (string-match "[0-9]\\\\,[0-9]" str)
562 (setq str (concat (substring str 0 (1+ (match-beginning 0)))
563 (substring str (1- (match-end 0))))))
564 (while (string-match "\\\\begin{\\(small\\|[bp]\\)?matrix}" str)
565 (setq str (concat (substring str 0 (match-beginning 0))
566 "\\matrix{"
567 (substring str (match-end 0)))))
568 (while (string-match "\\\\end{\\(small\\|[bp]\\)?matrix}" str)
569 (setq str (concat (substring str 0 (match-beginning 0))
570 "}"
571 (substring str (match-end 0)))))
572
573 str)
574
575(put 'latex 'math-input-filter 'math-latex-input-filter)
409 576
410(defun calc-eqn-language (n) 577(defun calc-eqn-language (n)
411 (interactive "P") 578 (interactive "P")