Advertisement
WolfieMario

MathTyping.ahk

Sep 4th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Math/Greek Typing Script by Gerrard Lukacs
  2.  
  3. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  4. #Warn  ; Recommended for catching common errors.
  5. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  6.  
  7. global alphabeticalGreek := false
  8. global latinToGreek := {a:"α", b:"β", c:"χ", d:"δ", e:"ε", f:"φ"
  9.                       , g:"γ", h:"η", i:"ι", k:"κ", l:"λ", m:"μ"
  10.                       , n:"ν", o:"ο", p:"π", q:"θ", r:"ρ", s:"σ"
  11.                       , t:"τ", u:"υ", w:"ω", x:"ξ", y:"ψ", z:"ζ"}
  12.  
  13. initializeHotkeys()
  14. Menu Tray, Add    ; Blank makes a separator
  15. Menu Tray, Add, Alphabetical Greek, TrayGreek
  16. if (alphabeticalGreek)
  17.     Menu Tray, Check, Alphabetical Greek
  18. Return
  19.  
  20. initializeHotkeys()
  21. {
  22.     letter := Asc("a")
  23.     endLetter := Asc("z")
  24.    
  25.     while letter <= endLetter
  26.     {
  27.         Hotkey % "!" . Chr(letter), LowerGreekHotkey
  28.         Hotkey % "+!" . Chr(letter), UpperGreekHotkey
  29.         letter++
  30.     }
  31. }
  32.  
  33. lowerGreek(latin)
  34. {
  35.     static a := Asc("a")
  36.     static alpha := Asc("α")
  37.     static finalSigma := Asc("ς")
  38.    
  39.     if (alphabeticalGreek)
  40.     {
  41.         if (latin >= "y")
  42.             return ""
  43.        
  44.         greek := Asc(latin) - a + alpha
  45.         if (greek >= finalSigma)
  46.             greek++
  47.         return Chr(greek)
  48.     }
  49.     else
  50.     {
  51.         return latinToGreek[latin]
  52.     }
  53. }
  54.  
  55. upperGreek(latin)
  56. {
  57.     static upperDist := Asc("α") - Asc("Α") ; Uppercase Alpha
  58.     ; Note: final sigma has no uppercase form, but Unicode leaves
  59.     ; a blank slot so all the numbers line up nicely.
  60.    
  61.     greek := lowerGreek(latin)
  62.     return Chr(Asc(greek) - upperDist)
  63. }
  64.  
  65. TrayGreek:
  66.    alphabeticalGreek := !alphabeticalGreek
  67.     Menu Tray, ToggleCheck, Alphabetical Greek
  68.     Return
  69.  
  70. LowerGreekHotkey:
  71.    Send % lowerGreek(SubStr(A_ThisHotkey, 2))
  72.     Return
  73.  
  74. UpperGreekHotkey:
  75.    Send % upperGreek(SubStr(A_ThisHotkey, 3))
  76.     Return
  77.  
  78. ; By default, Alt with a Latin letter produces its corresponding Greek
  79. ; letter, e.g. αβχδεφγ (there are no Greek letters for j or v. h is η,
  80. ; q is θ, c is χ, x is ξ, u is υ, y is ψ, and w is ω). If "Alphabetical
  81. ; Greek" is selected from the tray menu, letters are transliterated
  82. ; alphabetically, e.g. αβγδεζη (there are no letters for y and z).
  83. ; Alt with a capital letter works similarly: ΑΒΧΔΕΦΓ / ΑΒΓΔΕΖΗ.
  84.  
  85. ^!s:: Send ς  ; Final Sigma            Ctrl Alt s
  86.  
  87. ^!a:: Send ∀  ; For All                Ctrl Alt a
  88. ^!e:: Send ∃  ; There Exists           Ctrl Alt e
  89. ^!t:: Send ∴  ; Therefore              Ctrl Alt t
  90. ^!b:: Send ∵  ; Because                Ctrl Alt b
  91. ^!d:: Send ∆  ; Delta/change           Ctrl Alt d
  92. ^!+d::Send ∇  ; Del Operator           Ctrl Alt D
  93. ^!+p::Send ∏  ; Product                Ctrl Alt P
  94. ^!+s::Send ∑  ; Summation              Ctrl Alt S
  95. ^!r:: Send √  ; Square Root            Ctrl Alt r
  96. ^!i:: Send ∫  ; Integral               Ctrl Alt i
  97. !8::  Send ∞  ; Infinity                    Alt 8
  98. !0::  Send Ø  ; Empty Set*                  Alt 0
  99.               ; *This is actually Capital O with Stroke, because the
  100.               ; actual Empty Set symbol doesn't render in Notepad++.
  101.  
  102. !+,:: Send ≤  ; Less Than or Equal To       Alt <
  103. !+.:: Send ≥  ; Greater Than or Equal To    Alt >
  104. !=::  Send ≠  ; Not Equal                   Alt =
  105. !+=:: Send ±  ; Plus or Minus               Alt +
  106. !+8:: Send ×  ; Multiplication              Alt *
  107. !/::  Send ÷  ; Division                    Alt /
  108. !.::  Send ∙  ; Bullet Operator             Alt .
  109. !-::  Send ‾  ; Overline                    Alt -
  110.  
  111. !3::  Send ∈  ; Element of                  Alt 3
  112. ^!3:: Send ∋  ; Contains as Member     Ctrl Alt 3
  113. !+9:: Send ⊂  ; Subset                      Alt (
  114. !+0:: Send ⊃  ; Superset                    Alt )
  115. ^!+9::Send ⊆  ; Subset or Equal To     Ctrl Alt (
  116. ^!+0::Send ⊇  ; Superset or Equal To   Ctrl Alt )
  117. ^!u:: Send ∪  ; Union                  Ctrl Alt u
  118. ^!+u::Send ∩  ; Intersection           Ctrl Alt U
  119. ^!v:: Send ∨  ; Disjunction            Ctrl Alt v
  120. !+6:: Send ∧  ; Conjunction                 Alt ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement