From 4de7ddc837848a80ff8eae1ac99e518b53b3f0e1 Mon Sep 17 00:00:00 2001 From: "Leo C. Stein" Date: Mon, 13 Oct 2025 22:38:39 -0500 Subject: [PATCH] Add unicode's mathematical alphabets to TeX input method * lisp/leim/quail/latin-ltx.el: Add math "alphabets" that can be matched with simple regexps; a few others are added by hand. There are 13 variants: bf, it, bfit, bb, scr, bfscr, frak, bffrak, sf, bfsf, sfit, bfsfit, and tt. --- lisp/leim/quail/latin-ltx.el | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/lisp/leim/quail/latin-ltx.el b/lisp/leim/quail/latin-ltx.el index c40b395a639..cd7b24fccdc 100644 --- a/lisp/leim/quail/latin-ltx.el +++ b/lisp/leim/quail/latin-ltx.el @@ -66,6 +66,22 @@ system, including many technical ones. Examples: (defun latin-ltx--ascii-p (char) (and (characterp char) (< char 128))) + ;; For mathematical alphabets + (defconst latin-ltx--math-variant-prefix-map + '(("BOLD" . "bf") + ("ITALIC" . "it") + ("BOLD ITALIC" . "bfit") + ("DOUBLE-STRUCK" . "bb") + ("SCRIPT" . "scr") + ("BOLD SCRIPT" . "bfscr") + ("FRAKTUR" . "frak") + ("BOLD FRAKTUR" . "bffrak") + ("SANS-SERIF" . "sf") + ("SANS-SERIF BOLD" . "bfsf") + ("SANS-SERIF ITALIC" . "sfit") + ("SANS-SERIF BOLD ITALIC" . "bfsfit") + ("MONOSPACE" . "tt"))) + (defmacro latin-ltx--define-rules (&rest rules) (load "uni-name" nil t) (let ((newrules ())) @@ -742,6 +758,77 @@ system, including many technical ones. Examples: ("\\wp" ?℘) ("\\wr" ?≀) + ;;;; Mathematical alphabets + ;; Latin letters + ((lambda (name _char) + (let* ((variant (match-string 1 name)) + (prefix (cdr (assoc variant latin-ltx--math-variant-prefix-map))) + (basename (match-string 3 name)) + (name (if (match-end 2) (capitalize basename) (downcase basename)))) + (concat "\\" prefix name))) + "\\`MATHEMATICAL \\(.+\\) \\(?:SMALL\\|CAPITA\\(L\\)\\) \\([[:ascii:]]+\\)\\'") + + ;; Digits + ((lambda (name _char) + (let* ((variant (match-string 1 name)) + (prefix (cdr (assoc variant latin-ltx--math-variant-prefix-map))) + (basename (match-string 2 name))) + (concat "\\" prefix (char-to-string (char-from-name basename))))) + "\\`MATHEMATICAL \\(.+\\) \\(DIGIT [[:ascii:]]+\\)\\'") + + ;; Some Greek variants + ;; NOTE: Check if any of these are reversed from their counterparts, like + ;; the claim above of \phi and \varphi being swapped + ((lambda (name _char) + (let* ((variant (match-string 1 name)) + (prefix (cdr (assoc variant latin-ltx--math-variant-prefix-map))) + (basename (downcase (match-string 2 name)))) + (if prefix ;; This avoids e.g. MATHEMATICAL BOLD CAPITAL SYMBOL + (concat "\\" prefix "var" basename)))) + "\\`MATHEMATICAL \\(.+\\) \\([A-Z]+\\) SYMBOL\\'") + + ((lambda (name _char) + (let* ((variant (match-string 1 name)) + (prefix (cdr (assoc variant latin-ltx--math-variant-prefix-map))) + (basename (if (match-end 2) "partial" "nabla"))) + (concat "\\" prefix basename))) + "\\`MATHEMATICAL \\(.*\\) \\(?:NABLA\\|PARTIAL DIFFERENTIA\\(L\\)\\)\\'") + + ;; Some of the math alphabet characters have other canonical names and must be + ;; added manually + ("\\scrB" ?ℬ) + ("\\scrE" ?ℰ) + ("\\scrF" ?ℱ) + ("\\scrH" ?ℋ) + ("\\scrI" ?ℐ) + ("\\scrL" ?ℒ) + ("\\scrM" ?ℳ) + ("\\scrR" ?ℛ) + ("\\frakC" ?ℭ) + ("\\frakH" ?ℌ) + ("\\frakI" ?ℑ) + ("\\frakR" ?ℜ) + ("\\frakZ" ?ℨ) + ("\\bbC" ?ℂ) + ("\\bbH" ?ℍ) + ("\\bbN" ?ℕ) + ("\\bbP" ?ℙ) + ("\\bbQ" ?ℚ) + ("\\bbR" ?ℝ) + ("\\bbZ" ?ℤ) + ("\\ith" ?ℎ) + ("\\scre" ?ℯ) + ("\\scrg" ?ℊ) + ("\\scro" ?ℴ) + + ("\\bbsum" ?⅀) + ("\\bbSigma" ?⅀) + ("\\bbgamma" ?ℽ) + ("\\bbGamma" ?ℾ) + ("\\bbprod" ?ℿ) + ("\\bbPi" ?ℿ) + ("\\bbpi" ?ℼ) + ("\\Bbb{A}" ?𝔸) ; AMS commands for blackboard bold ("\\Bbb{B}" ?𝔹) ; Also sometimes \mathbb. ("\\Bbb{C}" ?ℂ)