1
Fork 0
replacements/Main.hs
2022-08-16 13:02:41 +02:00

145 lines
No EOL
3.2 KiB
Haskell
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# 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 =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
\<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n\
\<plist version=\"1.0\">\n\
\<array>\n\
\"
footer =
"</array>\n\
\</plist>\n\
\"
dict l r =
"\t<dict>\n\
\\t\t<key>phrase</key>\n\
\\t\t<string>" <> l <> "</string>\n\
\\t\t<key>shortcut</key>\n\
\\t\t<string>" <> r <> "</string>\n\
\\t</dict>\n\
\"
main = do
let allReplacements = (concat [greek, logic, set, others, mathbb]) :: [(Text, Text)]
putStr header
mapM (putStr . uncurry dict) allReplacements
putStr footer