Created
March 15, 2022 15:32
-
-
Save jart/e0554c9b9672d670e664a0ff5eeca37a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; text2math.el --- keyboard shortcuts for converting to math charsets | |
;; Copyright (C) 2022 Justine Alexandra Roberts Tunney | |
;; License: ISC | |
;; Author: Justine Tunney <jtunney@gmail.com> | |
;; Version: 0.1 | |
;; URL: http://github.com/jart/justinemacs | |
;; | |
;; Permission to use, copy, modify, and/or distribute this software for | |
;; any purpose with or without fee is hereby granted, provided that the | |
;; above copyright notice and this permission notice appear in all copies. | |
;; | |
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL | |
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | |
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | |
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |
;; DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | |
;; PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |
;; TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
;; PERFORMANCE OF THIS SOFTWARE. | |
;;; Commentary: | |
;; | |
;; This is messy and better APIs exist in Emacs for implementing it. | |
;;; Code: | |
(defun jart-text-hook () | |
(dolist (key jart-text-keys) | |
(local-set-key (car key) (cdr key)))) | |
(defun jart-text-to-gothic (start end) | |
"Convert buffer text from START to END to gothic characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--gothic)) | |
(defun jart-text-to-doublestruck (start end) | |
"Convert buffer text from START to END to doublestruck characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--doublestruck)) | |
(defun jart-text-to-fraktur (start end) | |
"Convert buffer text from START to END to fraktur characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--fraktur)) | |
(defun jart-text-to-fraktur-bold (start end) | |
"Convert buffer text from START to END to fraktur-bold characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--fraktur-bold)) | |
(defun jart-text-to-italic (start end) | |
"Convert buffer text from START to END to italic characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--italic)) | |
(defun jart-text-replace (b s) | |
(delete-region (car b) (cdr b)) | |
(goto-char (car b)) | |
(insert s) | |
(goto-char (+ (car b) (length s)))) | |
(defun jart-text-to-math-italic (start end) | |
"Convert buffer text from START to END to italic math characters." | |
(interactive "r") | |
(let* ((b (jart--get-bounds start end)) | |
(s (downcase (buffer-substring-no-properties (car b) (cdr b))))) | |
(cond ((equal s "lambda") (jart-text-replace b "ฮป")) | |
((equal s "list") (jart-text-replace b "โ")) | |
((equal s "lambda") (jart-text-replace b "ฮป")) | |
((equal s "closure") (jart-text-replace b "โ ")) | |
((equal s "macro") (jart-text-replace b "ฯ")) | |
((equal s "defmacro") (jart-text-replace b "ฮจ")) | |
((equal s "syntax") (jart-text-replace b "ฮพ")) | |
((equal s "define") (jart-text-replace b "โ")) | |
((equal s "atom") (jart-text-replace b "ฮฑ")) | |
((equal s "cons") (jart-text-replace b "โถ")) | |
((equal s "cond") (jart-text-replace b "ฮถ")) | |
((equal s "quote") (jart-text-replace b "โฆ")) | |
((equal s "defun") (jart-text-replace b "ฮ")) | |
((equal s "subset") (jart-text-replace b "โ")) | |
((equal s "superset") (jart-text-replace b "โ")) | |
((equal s "reverse") (jart-text-replace b "ะฏ")) | |
((equal s "expand") (jart-text-replace b "ษ")) | |
((equal s "eq") (jart-text-replace b "โก")) | |
((equal s "car") (jart-text-replace b "โ ")) | |
((equal s "cdr") (jart-text-replace b "โ")) | |
((equal s "compose") (jart-text-replace b "โ")) | |
((equal s "true") (jart-text-replace b "โค")) | |
((equal s "nil") (jart-text-replace b "โฅ")) | |
((equal s "and") (jart-text-replace b "โง")) | |
((equal s "or") (jart-text-replace b "โจ")) | |
((equal s "member") (jart-text-replace b "โ")) | |
((equal s "xor") (jart-text-replace b "โป")) | |
((equal s "nand") (jart-text-replace b "โผ")) | |
((equal s "nor") (jart-text-replace b "โฝ")) | |
((equal s "implies") (jart-text-replace b "โถ")) | |
((equal s "union") (jart-text-replace b "โช")) | |
((equal s "intersection") (jart-text-replace b "โฉ")) | |
((equal s "not") (jart-text-replace b "ยฌ")) | |
((equal s "sqrt") (jart-text-replace b "โ")) | |
((equal s "therefore") (jart-text-replace b "โด")) | |
((equal s "unreachable") (jart-text-replace b "โ ")) | |
((equal s "because") (jart-text-replace b "โต")) | |
((equal s "function") (jart-text-replace b "๐")) | |
((equal s "iff") (jart-text-replace b "โบ")) | |
((equal s "if") (jart-text-replace b "โ")) | |
((equal s "order") (jart-text-replace b "โ")) | |
((equal s "asterism") (jart-text-replace b "โ")) | |
((equal s "append") (jart-text-replace b "โ")) | |
((equal s "partial") (jart-text-replace b "โ")) | |
((equal s "integrate") (jart-text-replace b "โซ")) | |
((equal s "cmp") (jart-text-replace b "โท")) | |
((equal s "fork") (jart-text-replace b "โ")) | |
((equal s "ycombinator") (jart-text-replace b "๐")) | |
((equal s "beta") (jart-text-replace b "ฮฒ")) | |
((equal s "gamma") (jart-text-replace b "ฮ")) | |
((equal s "delta") (jart-text-replace b "ฮด")) | |
((equal s "epsilon") (jart-text-replace b "ฮต")) | |
((equal s "zeta") (jart-text-replace b "ฮถ")) | |
((equal s "eta") (jart-text-replace b "ฮท")) | |
((equal s "theta") (jart-text-replace b "ฮธ")) | |
((equal s "iota") (jart-text-replace b "ฮน")) | |
((equal s "kappa") (jart-text-replace b "ฮบ")) | |
((equal s "mu") (jart-text-replace b "ฮผ")) | |
((equal s "nu") (jart-text-replace b "ฮฝ")) | |
((equal s "xi") (jart-text-replace b "ฮพ")) | |
((equal s "rho") (jart-text-replace b "ฯ")) | |
((equal s "pi") (jart-text-replace b "ฯ")) | |
((equal s "sum") (jart-text-replace b "ฮฃ")) | |
((equal s "sigma") (jart-text-replace b "ฯ")) | |
((equal s "rho") (jart-text-replace b "ฯ")) | |
((equal s "tau") (jart-text-replace b "ฯ")) | |
((equal s "phi") (jart-text-replace b "ฯ")) | |
((equal s "psi") (jart-text-replace b "ฯ")) | |
((equal s "chi") (jart-text-replace b "ฯ")) | |
((equal s "omega") (jart-text-replace b "ฯ")) | |
((equal s "cycle") (jart-text-replace b "โณ")) | |
((equal s "bet") (jart-text-replace b "โถ")) | |
((equal s "gimel") (jart-text-replace b "โท")) | |
((equal s "dalet") (jart-text-replace b "โธ")) | |
((equal s "alef") (jart-text-replace b "โต")) | |
((equal s "copy") (jart-text-replace b "ยฉ")) | |
((equal s "registered") (jart-text-replace b "ยฎ")) | |
((equal s "yen") (jart-text-replace b "ยฅ")) | |
((equal s "pound") (jart-text-replace b "ยฃ")) | |
((equal s "cent") (jart-text-replace b "ยข")) | |
((equal s "le") (jart-text-replace b "โค")) | |
((equal s "ge") (jart-text-replace b "โฅ")) | |
((equal s "eval") (jart-text-replace b "โน")) | |
((equal s "expands") (jart-text-replace b "โถ")) | |
(t (jart--text-to-math b jart--math-italic))))) | |
(defun jart-text-to-subscript (start end) | |
"Convert buffer text from START to END to subscript math characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--subscript)) | |
(defun jart-text-to-superscript (start end) | |
"Convert buffer text from START to END to superscript math characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--superscript)) | |
(defun jart-text-to-bold (start end) | |
"Convert buffer text from START to END to bold characters." | |
(interactive "r") | |
(jart--text-to-math (jart--get-bounds start end) jart--bold)) | |
(defconst jart--gothic '((?A ?Z . ?๐) | |
(?a ?z . ?๐))) | |
(defconst jart--doublestruck '( | |
(?A ?A . ?๐ธ) | |
(?B ?B . ?๐น) | |
(?C ?C . ?โ) | |
(?D ?D . ?๐ป) | |
(?E ?E . ?๐ผ) | |
(?F ?F . ?๐ฝ) | |
(?G ?G . ?๐พ) | |
(?H ?H . ?โ) | |
(?I ?I . ?๐) | |
(?J ?J . ?๐) | |
(?K ?K . ?๐) | |
(?L ?L . ?๐) | |
(?M ?M . ?๐) | |
(?N ?N . ?โ) | |
(?O ?O . ?๐) | |
(?P ?P . ?โ) | |
(?Q ?Q . ?โ) | |
(?R ?R . ?โ) | |
(?S ?S . ?๐) | |
(?T ?T . ?๐) | |
(?U ?U . ?๐) | |
(?V ?V . ?๐) | |
(?W ?W . ?๐) | |
(?X ?X . ?๐) | |
(?Y ?Y . ?๐) | |
(?Z ?Z . ?โค) | |
(?0 ?0 . ?๐) | |
(?1 ?1 . ?๐) | |
(?2 ?2 . ?๐) | |
(?3 ?3 . ?๐) | |
(?4 ?4 . ?๐) | |
(?5 ?5 . ?๐) | |
(?6 ?6 . ?๐) | |
(?7 ?7 . ?๐) | |
(?8 ?8 . ?๐ ) | |
(?9 ?9 . ?๐ก) | |
(?a ?a . ?๐) | |
(?b ?b . ?๐) | |
(?c ?c . ?๐) | |
(?d ?d . ?๐) | |
(?e ?e . ?๐) | |
(?f ?f . ?๐) | |
(?g ?g . ?๐) | |
(?h ?h . ?๐) | |
(?i ?i . ?๐) | |
(?j ?j . ?๐) | |
(?k ?k . ?๐) | |
(?l ?l . ?๐) | |
(?m ?m . ?๐) | |
(?n ?n . ?๐) | |
(?o ?o . ?๐ ) | |
(?p ?p . ?๐ก) | |
(?q ?q . ?๐ข) | |
(?r ?r . ?๐ฃ) | |
(?s ?s . ?๐ค) | |
(?t ?t . ?๐ฅ) | |
(?u ?u . ?๐ฆ) | |
(?v ?v . ?๐ง) | |
(?w ?w . ?๐จ) | |
(?x ?x . ?๐ฉ) | |
(?y ?y . ?๐ช) | |
(?z ?z . ?๐ซ) | |
)) | |
;; static const wchar_t A[2][10][26] = { | |
;; {L"ABCDEFGHIJKLMNOPQRSTUVWXYZ", | |
;; L"abcdefghijklmnopqrstuvwxyz", | |
;; L"๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก", | |
;; L"๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป", | |
;; L"๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง", | |
;; L"๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐"}, | |
;; {L"ABCDEFGHIJKLMNOPQRSTUVWXYZ", | |
;; L"abcdefghijklmnopqrstuvwxyz", | |
;; L"๐๐ โญ๐๐๐๐โโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐โจ", | |
;; L"๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก", | |
;; L"๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป", | |
;; L"๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง", | |
;; L"๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐"}, | |
;; }; | |
;; | |
;; static const wchar_t B[2][10][26] = { | |
;; {L"๐๐ โญ๐๐๐๐โโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐โจ", | |
;; L"๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท", | |
;; L"๐๐ โญ๐๐๐๐โโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐โจ", | |
;; L"๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท", | |
;; L"๐๐ โญ๐๐๐๐โโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐โจ", | |
;; L"๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท", | |
;; L"๐๐ โญ๐๐๐๐โโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐โจ", | |
;; L"๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท", | |
;; L"๐๐ โญ๐๐๐๐โโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐โจ", | |
;; L"๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท"}, | |
;; {L"๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐", | |
;; L"๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ", | |
;; L"๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"}, | |
;; }; | |
;; | |
;; int main(int argc, char *argv[]) { | |
;; int a, b, i, j, k; | |
;; for (i = 0; i < ARRAYLEN(A); ++i) { | |
;; for (j = 0; j < ARRAYLEN(A[0]); ++j) { | |
;; for (a = b = k = 0; k < 26; ++k) { | |
;; if (!a) { | |
;; a = A[i][j][k]; | |
;; b = B[i][j][k]; | |
;; } | |
;; if (k == 25 || (A[i][j][k] + 1 != A[i][j][k + 1] || | |
;; B[i][j][k] + 1 != B[i][j][k + 1])) { | |
;; kprintf("(?%lc ?%lc . ?%lc) ;; %05X-%05X โ %05X-%05X\n", a, A[i][j][k], | |
;; b, a, A[i][j][k], b, B[i][j][k]); | |
;; a = 0; | |
;; } | |
;; } | |
;; } | |
;; kprintf("\n"); | |
;; } | |
;; } | |
(defconst jart--fraktur '( ;;C-c C-z | |
(?A ?B . ?๐) ;; 00041-00042 โ 1D504-1D505 | |
(?C ?C . ?โญ) ;; 00043-00043 โ 0212D-0212D | |
(?D ?G . ?๐) ;; 00044-00047 โ 1D507-1D50A | |
(?H ?H . ?โ) ;; 00048-00048 โ 0210C-0210C | |
(?I ?I . ?โ) ;; 00049-00049 โ 02111-02111 | |
(?J ?Q . ?๐) ;; 0004A-00051 โ 1D50D-1D514 | |
(?R ?R . ?โ) ;; 00052-00052 โ 0211C-0211C | |
(?S ?Y . ?๐) ;; 00053-00059 โ 1D516-1D51C | |
(?Z ?Z . ?โจ) ;; 0005A-0005A โ 02128-02128 | |
(?a ?z . ?๐) ;; 00061-0007A โ 1D51E-1D537 | |
(?๐ฌ ?๐ญ . ?๐) ;; 1D56C-1D56D โ 1D504-1D505 | |
(?๐ฎ ?๐ฎ . ?โญ) ;; 1D56E-1D56E โ 0212D-0212D | |
(?๐ฏ ?๐ฒ . ?๐) ;; 1D56F-1D572 โ 1D507-1D50A | |
(?๐ณ ?๐ณ . ?โ) ;; 1D573-1D573 โ 0210C-0210C | |
(?๐ด ?๐ด . ?โ) ;; 1D574-1D574 โ 02111-02111 | |
(?๐ต ?๐ผ . ?๐) ;; 1D575-1D57C โ 1D50D-1D514 | |
(?๐ฝ ?๐ฝ . ?โ) ;; 1D57D-1D57D โ 0211C-0211C | |
(?๐พ ?๐ . ?๐) ;; 1D57E-1D584 โ 1D516-1D51C | |
(?๐ ?๐ . ?โจ) ;; 1D585-1D585 โ 02128-02128 | |
(?๐ ?๐ . ?๐) ;; 1D586-1D59F โ 1D51E-1D537 | |
(?๐ ?๐ . ?๐) ;; 1D608-1D609 โ 1D504-1D505 | |
(?๐ ?๐ . ?โญ) ;; 1D60A-1D60A โ 0212D-0212D | |
(?๐ ?๐ . ?๐) ;; 1D60B-1D60E โ 1D507-1D50A | |
(?๐ ?๐ . ?โ) ;; 1D60F-1D60F โ 0210C-0210C | |
(?๐ ?๐ . ?โ) ;; 1D610-1D610 โ 02111-02111 | |
(?๐ ?๐ . ?๐) ;; 1D611-1D618 โ 1D50D-1D514 | |
(?๐ ?๐ . ?โ) ;; 1D619-1D619 โ 0211C-0211C | |
(?๐ ?๐ . ?๐) ;; 1D61A-1D620 โ 1D516-1D51C | |
(?๐ก ?๐ก . ?โจ) ;; 1D621-1D621 โ 02128-02128 | |
(?๐ข ?๐ป . ?๐) ;; 1D622-1D63B โ 1D51E-1D537 | |
(?๐ด ?๐ต . ?๐) ;; 1D434-1D435 โ 1D504-1D505 | |
(?๐ถ ?๐ถ . ?โญ) ;; 1D436-1D436 โ 0212D-0212D | |
(?๐ท ?๐บ . ?๐) ;; 1D437-1D43A โ 1D507-1D50A | |
(?๐ป ?๐ป . ?โ) ;; 1D43B-1D43B โ 0210C-0210C | |
(?๐ผ ?๐ผ . ?โ) ;; 1D43C-1D43C โ 02111-02111 | |
(?๐ฝ ?๐ . ?๐) ;; 1D43D-1D444 โ 1D50D-1D514 | |
(?๐ ?๐ . ?โ) ;; 1D445-1D445 โ 0211C-0211C | |
(?๐ ?๐ . ?๐) ;; 1D446-1D44C โ 1D516-1D51C | |
(?๐ ?๐ . ?โจ) ;; 1D44D-1D44D โ 02128-02128 | |
(?๐ ?๐ง . ?๐) ;; 1D44E-1D467 โ 1D51E-1D537 | |
(?๐ ?๐ . ?๐) ;; 1D400-1D401 โ 1D504-1D505 | |
(?๐ ?๐ . ?โญ) ;; 1D402-1D402 โ 0212D-0212D | |
(?๐ ?๐ . ?๐) ;; 1D403-1D406 โ 1D507-1D50A | |
(?๐ ?๐ . ?โ) ;; 1D407-1D407 โ 0210C-0210C | |
(?๐ ?๐ . ?โ) ;; 1D408-1D408 โ 02111-02111 | |
(?๐ ?๐ . ?๐) ;; 1D409-1D410 โ 1D50D-1D514 | |
(?๐ ?๐ . ?โ) ;; 1D411-1D411 โ 0211C-0211C | |
(?๐ ?๐ . ?๐) ;; 1D412-1D418 โ 1D516-1D51C | |
(?๐ ?๐ . ?โจ) ;; 1D419-1D419 โ 02128-02128 | |
(?๐ฎ ?๐ . ?๐) ;; 1D5EE-1D607 โ 1D51E-1D537 | |
)) | |
(defconst jart--fraktur-bold '( ;;C-c C-v | |
(?A ?Z . ?๐ฌ) ;; 00041-0005A โ 1D56C-1D585 | |
(?a ?z . ?๐) ;; 00061-0007A โ 1D586-1D59F | |
(?๐ ?๐ . ?๐ฌ) ;; 1D504-1D505 โ 1D56C-1D56D | |
(?โญ ?โญ . ?๐ฎ) ;; 0212D-0212D โ 1D56E-1D56E | |
(?๐ ?๐ . ?๐ฏ) ;; 1D507-1D50A โ 1D56F-1D572 | |
(?โ ?โ . ?๐ณ) ;; 0210C-0210C โ 1D573-1D573 | |
(?โ ?โ . ?๐ด) ;; 02111-02111 โ 1D574-1D574 | |
(?๐ ?๐ . ?๐ต) ;; 1D50D-1D514 โ 1D575-1D57C | |
(?โ ?โ . ?๐ฝ) ;; 0211C-0211C โ 1D57D-1D57D | |
(?๐ ?๐ . ?๐พ) ;; 1D516-1D51C โ 1D57E-1D584 | |
(?โจ ?โจ . ?๐ ) ;; 02128-02128 โ 1D585-1D585 | |
(?๐ ?๐ท . ?๐) ;; 1D51E-1D537 โ 1D586-1D59F | |
(?๐ ?๐ก . ?๐ฌ) ;; 1D608-1D621 โ 1D56C-1D585 | |
(?๐ข ?๐ป . ?๐) ;; 1D622-1D63B โ 1D586-1D59F | |
(?๐ด ?๐ . ?๐ฌ) ;; 1D434-1D44D โ 1D56C-1D585 | |
(?๐ ?๐ง . ?๐) ;; 1D44E-1D467 โ 1D586-1D59F | |
(?๐ ?๐ . ?๐ฌ) ;; 1D400-1D419 โ 1D56C-1D585 | |
(?๐ฎ ?๐ . ?๐) ;; 1D5EE-1D607 โ 1D586-1D59F | |
)) | |
(defconst jart--italic '((?A ?Z . ?๐) | |
(?a ?z . ?๐ข))) | |
(defconst jart--math-italic '((?' ?' . ?โฒ) | |
(?0 ?9 . ?๐ถ) | |
(?A ?Z . ?๐ด) | |
(?a ?z . ?๐))) | |
(defconst jart--bold | |
'((?0 ?9 . ?๐ฌ) (?๐ข ?๐ซ . ?๐ฌ) (?๐ถ ?๐ฟ . ?๐ฌ) (?๐ถ ?๐ฟ . ?๐ฌ) | |
(?A ?Z . ?๐) (?a ?z . ?๐ฎ) (?๐ด ?๐ . ?๐จ) (?๐ ?๐ง . ?๐) | |
(?๐ ?๐ก . ?๐ผ) (?๐ข ?๐ป . ?๐) (?๐ข ?๐ป . ?๐จ) (?๐ผ ?๐ . ?๐))) | |
(defconst jart--subscript | |
'((?0 ?9 . ?โ) (?๐ถ ?๐ฟ . ?โ) (?๐ข ?๐ซ . ?โ) (?๐ ?๐ . ?โ) (?๐ ?๐ก . ?โ) | |
(?. ?. . ?โค) (?+ ?+ . ?โ) (?- ?- . ?โ) (?= ?= . ?โ) (?a ?a . ?โ) | |
(?e ?e . ?โ) (?o ?o . ?โ) (?x ?x . ?โ) (?h ?h . ?โ) (?k ?k . ?โ) | |
(?m ?m . ?โ) (?n ?n . ?โ) (?p ?p . ?โ) (?s ?s . ?โ) (?t ?t . ?โ) | |
(?\( ?\) . ?โ) | |
(?i ?i . ?แตข) | |
(?j ?j . ?โฑผ) | |
(?l ?l . ?โ) | |
(?m ?m . ?โ) | |
(?r ?r . ?แตฃ) | |
(?u ?u . ?แตค) | |
(?v ?v . ?แตฅ) | |
(?x ?x . ?โ))) | |
(defconst jart--superscript | |
'((?0 ?0 . ?โฐ) (?๐ถ ?๐ถ . ?โฐ) (?๐ข ?๐ข . ?โฐ) (?๐ ?๐ . ?โฐ) (?๐ ?๐ . ?โฐ) | |
(?1 ?1 . ?ยน) | |
(?2 ?3 . ?ยฒ) | |
(?4 ?9 . ?โด) (?๐บ ?๐ฟ . ?โด) (?๐ฆ ?๐ซ . ?โด) (?๐ ?๐ . ?โด) (?๐ ?๐ก . ?โด) | |
(?i ?i . ?โฑ) | |
(?a ?a . ?แต) | |
(?b ?b . ?แต) | |
(?c ?c . ?แถ) | |
(?d ?d . ?แต) | |
(?e ?e . ?แต) | |
(?f ?f . ?แถ ) | |
(?g ?g . ?แต) | |
(?h ?h . ?สฐ) | |
(?j ?j . ?สฒ) | |
(?k ?k . ?แต) | |
(?l ?l . ?หก) | |
(?m ?m . ?แต) | |
(?n ?n . ?โฟ) | |
(?o ?o . ?แต) | |
(?p ?p . ?แต) | |
(?r ?r . ?สณ) | |
(?s ?s . ?หข) | |
(?t ?t . ?แต) | |
(?u ?u . ?แต) | |
(?v ?v . ?แต) | |
(?w ?w . ?สท) | |
(?x ?x . ?หฃ) | |
(?y ?y . ?สธ) | |
(?z ?z . ?แถป) | |
(?A ?B . ?แดฌ) | |
(?D ?E . ?แดฐ) | |
(?G ?P . ?แดณ) | |
(?R ?R . ?แดฟ) | |
(?T ?W . ?แต) | |
(?+ ?+ . ?โบ) | |
(?- ?- . ?โป) | |
(?= ?= . ?โง) | |
(?\( ?\) . ?โฝ))) | |
(defun jart--get-bounds (start end) | |
(or (and (use-region-p) | |
(cons start end)) | |
(bounds-of-thing-at-point 'symbol) | |
(bounds-of-thing-at-point 'number) | |
(save-excursion | |
(forward-thing 'symbol) | |
(bounds-of-thing-at-point 'symbol)) | |
(user-error "no region or thing at point"))) | |
(defun jart--text-to-math (bounds ranges) | |
"Convert buffer text from START to END to italic math characters." | |
(let ((n 0) | |
(text (buffer-substring-no-properties | |
(car bounds) (cdr bounds)))) | |
(while (< n (length text)) | |
(let ((c (string-to-char (substring text n (+ n 1))))) | |
(dolist (r ranges) | |
(when (and (>= c (car r)) | |
(<= c (cadr r))) | |
(store-substring | |
text n (char-to-string (+ (- c (car r)) (cddr r))))))) | |
(setq n (+ n 1))) | |
(delete-region (car bounds) (cdr bounds)) | |
(goto-char (car bounds)) | |
(insert text) | |
(goto-char (+ (car bounds) (length text))))) | |
(defconst jart-text-keys | |
(list (cons (kbd "C-c C-f") 'jart-text-to-math-italic) | |
(cons (kbd "C-c f") 'jart-text-to-italic) | |
(cons (kbd "C-c C-z") 'jart-text-to-fraktur) | |
(cons (kbd "C-c C-v") 'jart-text-to-fraktur-bold) | |
(cons (kbd "C-c d") 'jart-text-to-doublestruck) | |
(cons (kbd "C-c C-g") 'jart-text-to-gothic) | |
(cons (kbd "C-c b") 'jart-text-to-bold) | |
(cons (kbd "C-c .") 'jart-text-to-superscript) | |
(cons (kbd "C-c ,") 'jart-text-to-subscript))) | |
(let (i) | |
(dolist (i jart-text-keys) | |
(global-set-key (car i) (cdr i))) | |
(dolist (i (list (cons 'sh-script 'sh-mode-hook) | |
(cons 'text-mode 'text-mode-hook) | |
(cons 'gnuplot-mode 'gnuplot-mode-hook))) | |
(eval-after-load (car i) | |
`(progn | |
(add-hook ',(cdr i) 'jart-text-hook))))) | |
(provide 'text2math) | |
;;; text2math.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment