From 95f24491172ef3f0d32eec2faff3e28898169502 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Tue, 16 Aug 2022 13:02:41 +0200 Subject: [PATCH] First and final commit --- Main.hs | 145 +++++++++++++ README.md | 11 + Text Substitutions.plist | 456 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 612 insertions(+) create mode 100755 Main.hs create mode 100755 README.md create mode 100755 Text Substitutions.plist diff --git a/Main.hs b/Main.hs new file mode 100755 index 0000000..d77ad02 --- /dev/null +++ b/Main.hs @@ -0,0 +1,145 @@ +{-# language OverloadedStrings #-} + +import Data.Text hiding (concat) +import Data.Text.IO +import Prelude hiding (putStr) + +flatten ls = [ (l, r) | (l, rs) <- ls, r <- rs ] +convLatex ls = [ (l, replace "\\" "«" r) | (l, r) <- ls ] + +-- not used, doesn't work well in conjunction with lower +greekUpper = convLatex + [ ("Α", "\\Alpha") + , ("Β", "\\Beta") + , ("Γ", "\\Gamma") + , ("Δ", "\\Delta") + , ("Ε", "\\Epsilon") + , ("Ζ", "\\Zeta") + , ("Η", "\\Eta") + , ("Θ", "\\Theta") + , ("Ι", "\\Iota") + , ("Κ", "\\Kappa") + , ("Λ", "\\Lambda") + , ("Μ", "\\Mu") + , ("Ν", "\\Nu") + , ("Ξ", "\\Xi") + , ("Ο", "\\Omikron") + , ("Π", "\\Pi") + , ("Ρ", "\\Rho") + , ("Σ", "\\Sigma") + , ("Τ", "\\Tau") + , ("Υ", "\\Upsilon") + , ("Φ", "\\Phi") + , ("Χ", "\\Chi") + , ("Ψ", "\\Psi") + , ("Ω", "\\Omega") + ] + +greek = convLatex + [ ("α", "\\alpha") + , ("β", "\\beta") + , ("γ", "\\gamma") + , ("δ", "\\delta") + , ("ε", "\\epsilon") + , ("ζ", "\\zeta") + , ("η", "\\eta") + , ("θ", "\\theta") + , ("ι", "\\iota") + , ("κ", "\\kappa") + , ("λ", "\\lambda") + , ("μ", "\\mu") + , ("ν", "\\nu") + , ("ξ", "\\xi") + , ("ο", "\\omikron") + , ("π", "\\pi") + , ("ρ", "\\rho") + , ("σ", "\\sigma") + , ("τ", "\\tau") + , ("υ", "\\upsilon") + , ("φ", "\\phi") + , ("χ", "\\chi") + , ("ψ", "\\psi") + , ("ω", "\\omega") + ] + +logic = (convLatex . flatten) + [ ("∧", ["\\wedge", "\\and"]) + , ("∨", ["\\vee", "\\vee"]) + , ("¬", ["\\not", "\\neg"]) + , ("⇔", ["\\iff"]) + , ("⇒", ["\\implies"]) + , ("⊤", ["\\top"]) + , ("⊥", ["\\bottom", "\\perp"]) + , ("∃", ["\\exists"]) + , ("∀", ["\\forall"]) + ] + +set = (convLatex . flatten) + [ ("∅", ["\\emptyset"]) + , ("∪", ["\\union", "\\cup"]) + , ("∩", ["\\intersection", "\\cap"]) + , ("≠", ["\\neq"]) + , ("⊂", ["\\subset"]) + , ("⊆", ["\\subseteq"]) + , ("⊊", ["\\subsetneq"]) + , ("∊", ["\\in"]) + , ("∉", ["\\notin"]) + ] + +others = convLatex + [ ("≈", "\\iso") + , ("~", "\\sim") + , ("≤", "\\leq") + , ("≥", "\\geq") + , ("∞", "\\infty") + , ("→", "\\to") + , ("↦", "\\mapsto") + , ("↠", "\\epi") + , ("↪", "\\mono") + , ("∘", "\\circ") + , ("·", "\\cdot") + , ("×", "\\times") + , ("∑", "\\sum") + , ("∏", "\\prod") + , ("∐", "\\coprod") + , ("⊕", "\\oplus") + , ("⊗", "\\otimes") + ] + +mathbb = (convLatex . flatten) + [ ("𝔸", ["\\atoms", "\\AA"]) + , ("ℕ", ["\\naturals", "\\NN"]) + , ("ℚ", ["\\rationals", "\\QQ"]) + , ("ℝ", ["\\reals", "\\RR"]) + , ("ℤ", ["\\integers", "\\ZZ"]) + ] + +allReplacements :: [(Text, Text)] +allReplacements = concat [greek, logic, set, others, mathbb] + +header = + "\n\ + \\n\ + \\n\ + \\n\ + \" + +footer = + "\n\ + \\n\ + \" + +dict l r = + "\t\n\ + \\t\tphrase\n\ + \\t\t" <> l <> "\n\ + \\t\tshortcut\n\ + \\t\t" <> r <> "\n\ + \\t\n\ + \" + +main = do + let allReplacements = (concat [greek, logic, set, others, mathbb]) :: [(Text, Text)] + putStr header + mapM (putStr . uncurry dict) allReplacements + putStr footer \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..2d0a72b --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +Replacements +============ + +For Mac OS. Run the following command: + +``` +runhaskell Main.hs > "Text Substitutions.plist" +``` + +Then drag & drop the file into the keyboard settings. + diff --git a/Text Substitutions.plist b/Text Substitutions.plist new file mode 100755 index 0000000..32a3427 --- /dev/null +++ b/Text Substitutions.plist @@ -0,0 +1,456 @@ + + + + + + phrase + α + shortcut + «alpha + + + phrase + β + shortcut + «beta + + + phrase + γ + shortcut + «gamma + + + phrase + δ + shortcut + «delta + + + phrase + ε + shortcut + «epsilon + + + phrase + ζ + shortcut + «zeta + + + phrase + η + shortcut + «eta + + + phrase + θ + shortcut + «theta + + + phrase + ι + shortcut + «iota + + + phrase + κ + shortcut + «kappa + + + phrase + λ + shortcut + «lambda + + + phrase + μ + shortcut + «mu + + + phrase + ν + shortcut + «nu + + + phrase + ξ + shortcut + «xi + + + phrase + ο + shortcut + «omikron + + + phrase + π + shortcut + «pi + + + phrase + ρ + shortcut + «rho + + + phrase + σ + shortcut + «sigma + + + phrase + τ + shortcut + «tau + + + phrase + υ + shortcut + «upsilon + + + phrase + φ + shortcut + «phi + + + phrase + χ + shortcut + «chi + + + phrase + ψ + shortcut + «psi + + + phrase + ω + shortcut + «omega + + + phrase + + shortcut + «wedge + + + phrase + + shortcut + «and + + + phrase + + shortcut + «vee + + + phrase + + shortcut + «vee + + + phrase + ¬ + shortcut + «not + + + phrase + ¬ + shortcut + «neg + + + phrase + + shortcut + «iff + + + phrase + + shortcut + «implies + + + phrase + + shortcut + «top + + + phrase + + shortcut + «bottom + + + phrase + + shortcut + «perp + + + phrase + + shortcut + «exists + + + phrase + + shortcut + «forall + + + phrase + + shortcut + «emptyset + + + phrase + + shortcut + «union + + + phrase + + shortcut + «cup + + + phrase + + shortcut + «intersection + + + phrase + + shortcut + «cap + + + phrase + + shortcut + «neq + + + phrase + + shortcut + «subset + + + phrase + + shortcut + «subseteq + + + phrase + + shortcut + «subsetneq + + + phrase + + shortcut + «in + + + phrase + + shortcut + «notin + + + phrase + + shortcut + «iso + + + phrase + ~ + shortcut + «sim + + + phrase + + shortcut + «leq + + + phrase + + shortcut + «geq + + + phrase + + shortcut + «infty + + + phrase + + shortcut + «to + + + phrase + + shortcut + «mapsto + + + phrase + + shortcut + «epi + + + phrase + + shortcut + «mono + + + phrase + + shortcut + «circ + + + phrase + · + shortcut + «cdot + + + phrase + × + shortcut + «times + + + phrase + + shortcut + «sum + + + phrase + + shortcut + «prod + + + phrase + + shortcut + «coprod + + + phrase + + shortcut + «oplus + + + phrase + + shortcut + «otimes + + + phrase + 𝔸 + shortcut + «atoms + + + phrase + 𝔸 + shortcut + «AA + + + phrase + + shortcut + «naturals + + + phrase + + shortcut + «NN + + + phrase + + shortcut + «rationals + + + phrase + + shortcut + «QQ + + + phrase + + shortcut + «reals + + + phrase + + shortcut + «RR + + + phrase + + shortcut + «integers + + + phrase + + shortcut + «ZZ + + +