diff options
| -rw-r--r-- | lisp/calc/calc-ext.el | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el index e2d4711e432..b35ae4f141b 100644 --- a/lisp/calc/calc-ext.el +++ b/lisp/calc/calc-ext.el | |||
| @@ -2886,11 +2886,79 @@ calc-kill calc-kill-region calc-yank)))) | |||
| 2886 | 2886 | ||
| 2887 | (defvar math-expr-data) | 2887 | (defvar math-expr-data) |
| 2888 | 2888 | ||
| 2889 | (defvar math-read-replacement-list | ||
| 2890 | '(;; Misc symbols | ||
| 2891 | ("±" "+/-") ; plus or minus | ||
| 2892 | ("×" "*") ; multiplication sign | ||
| 2893 | ("÷" ":") ; division sign | ||
| 2894 | ("−" "-") ; subtraction sign | ||
| 2895 | ("∕" "/") ; division sign | ||
| 2896 | ("∗" "*") ; asterisk multiplication | ||
| 2897 | ("∞" "inf") ; infinity symbol | ||
| 2898 | ("≤" "<=") | ||
| 2899 | ("≥" ">=") | ||
| 2900 | ("≦" "<=") | ||
| 2901 | ("≧" ">=") | ||
| 2902 | ;; fractions | ||
| 2903 | ("¼" "(1:4)") ; 1/4 | ||
| 2904 | ("½" "(1:2)") ; 1/2 | ||
| 2905 | ("¾" "(3:4)") ; 3/4 | ||
| 2906 | ("⅓" "(1:3)") ; 1/3 | ||
| 2907 | ("⅔" "(2:3)") ; 2/3 | ||
| 2908 | ("⅕" "(1:5)") ; 1/5 | ||
| 2909 | ("⅖" "(2:5)") ; 2/5 | ||
| 2910 | ("⅗" "(3:5)") ; 3/5 | ||
| 2911 | ("⅘" "(4:5)") ; 4/5 | ||
| 2912 | ("⅙" "(1:6)") ; 1/6 | ||
| 2913 | ("⅚" "(5:6)") ; 5/6 | ||
| 2914 | ("⅛" "(1:8)") ; 1/8 | ||
| 2915 | ("⅜" "(3:8)") ; 3/8 | ||
| 2916 | ("⅝" "(5:8)") ; 5/8 | ||
| 2917 | ("⅞" "(7:8)") ; 7/8 | ||
| 2918 | ("⅟" "1:") ; 1/... | ||
| 2919 | ;; superscripts | ||
| 2920 | ("⁰" "0") ; 0 | ||
| 2921 | ("¹" "1") ; 1 | ||
| 2922 | ("²" "2") ; 2 | ||
| 2923 | ("³" "3") ; 3 | ||
| 2924 | ("⁴" "4") ; 4 | ||
| 2925 | ("⁵" "5") ; 5 | ||
| 2926 | ("⁶" "6") ; 6 | ||
| 2927 | ("⁷" "7") ; 7 | ||
| 2928 | ("⁸" "8") ; 8 | ||
| 2929 | ("⁹" "9") ; 9 | ||
| 2930 | ("⁺" "+") ; + | ||
| 2931 | ("⁻" "-") ; - | ||
| 2932 | ("⁽" "(") ; ( | ||
| 2933 | ("⁾" ")") ; ) | ||
| 2934 | ("ⁿ" "n") ; n | ||
| 2935 | ("ⁱ" "i")) ; i | ||
| 2936 | "A list whose elements (old new) indicate replacements to make | ||
| 2937 | in Calc algebraic input.") | ||
| 2938 | |||
| 2939 | (defvar math-read-superscripts | ||
| 2940 | "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni | ||
| 2941 | "A string consisting of the superscripts allowed by Calc.") | ||
| 2942 | |||
| 2943 | (defun math-read-preprocess-string (str) | ||
| 2944 | "Replace some substrings of STR by Calc equivalents." | ||
| 2945 | (setq str | ||
| 2946 | (replace-regexp-in-string (concat "[" math-read-superscripts "]+") | ||
| 2947 | "^(\\&)" str)) | ||
| 2948 | (let ((rep-list math-read-replacement-list)) | ||
| 2949 | (while rep-list | ||
| 2950 | (setq str | ||
| 2951 | (replace-regexp-in-string (nth 0 (car rep-list)) | ||
| 2952 | (nth 1 (car rep-list)) str)) | ||
| 2953 | (setq rep-list (cdr rep-list)))) | ||
| 2954 | str) | ||
| 2955 | |||
| 2889 | (defun math-read-expr (math-exp-str) | 2956 | (defun math-read-expr (math-exp-str) |
| 2890 | (let ((math-exp-pos 0) | 2957 | (let ((math-exp-pos 0) |
| 2891 | (math-exp-old-pos 0) | 2958 | (math-exp-old-pos 0) |
| 2892 | (math-exp-keep-spaces nil) | 2959 | (math-exp-keep-spaces nil) |
| 2893 | math-exp-token math-expr-data) | 2960 | math-exp-token math-expr-data) |
| 2961 | (setq math-exp-str (math-read-preprocess-string math-exp-str)) | ||
| 2894 | (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str)) | 2962 | (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str)) |
| 2895 | (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots" | 2963 | (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots" |
| 2896 | (substring math-exp-str (+ math-exp-token 2))))) | 2964 | (substring math-exp-str (+ math-exp-token 2))))) |