forked from mrob95/mathfly-talon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
maths.py
71 lines (61 loc) · 1.85 KB
/
maths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from talon import Context, Module, actions
from typing import NamedTuple, Optional
fractions = {
"half": "2",
"halve": "2",
"third": "3",
"quarter": "4",
"fourth": "4",
"fifth": "5",
"sixth": "6",
"seventh": "7",
"eighth": "8",
"ninth": "9",
"tenth": "10",
}
mod = Module()
ctx = Context()
mod.tag("maths")
mod.list("bracket_type", "Matrix bracket types, eg parenthesized, brackets, etc.")
mod.list("matrix_type", "Matrix types, eg full, diagonal, etc.")
ctx.lists["user.matrix_type"] = {
"identity": "identity",
"scaler": "scalar",
"diagonal": "diagonal",
"full": "full",
}
mod.list("maths_fractions", "Fractions")
ctx.lists["user.maths_fractions"] = {
**fractions,
**{f"{k}s": v for k, v in fractions.items()},
}
@mod.action_class
class Actions:
def maths_greek_letter(letter: str):
"""Insert a greek letter (one of those in the greek_letters list)"""
actions.insert("\\" + str(letter))
def maths_tex_symbol(symbol: str):
"""Insert a TeX symbol (one of those in the tex_symbols list)"""
actions.insert("\\" + str(symbol))
def maths_begin_subscript():
"""Begin subscript"""
actions.key("_ { } left")
def maths_end_subscript():
"""End subscript"""
actions.key("right")
def maths_subscript(label: str):
"""Subscript"""
actions.user.maths_begin_subscript()
actions.insert(label)
actions.user.maths_end_subscript()
def maths_begin_superscript():
"""Begin superscript"""
actions.key("^ { } left")
def maths_end_superscript():
"""End superscript"""
actions.key("right")
def maths_superscript(exponent: str):
"""Superscript"""
actions.user.maths_begin_superscript()
actions.insert(exponent)
actions.user.maths_end_superscript()