forked from mrob95/mathfly-talon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlatex.py
285 lines (264 loc) · 6.92 KB
/
latex.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
from talon import Context, Module, actions
mod = Module()
ctx = Context()
ctx.matches = r"""
title: /\.tex/
and not app: scinoteb.exe
"""
mod.list("tex_document_classes", desc="TeX document classes")
ctx.lists["user.tex_document_classes"] = {
"article": "article",
"beamer": "beamer",
"book": "book",
"letter": "letter",
"proceedings": "proc",
"report": "report",
}
mod.list("tex_packages", desc="TeX packages")
ctx.lists["user.tex_packages"] = {
"AMS math": "amsmath",
"physics": "physics",
# "bib latex" = ["[style=authoryear]", "biblatex"]
"colour": "color",
"geometry": "geometry",
"hyper ref": "hyperref",
"graphic X": "graphicx",
"math tools": "mathtools",
"multi col": "multicol",
"long table": "longtable",
"tabular X": "tabularx",
"X color": "xcolor",
"wrap figure": "wrapfig",
}
mod.list("tex_environments", desc="TeX environments")
ctx.lists["user.tex_environments"] = {
"abstract": "abstract",
"add margin": "addmargin",
"align": "align",
"center": "center",
"columns": "columns",
# "column" = ["column", "{0.5\\textwidth}"]
"column": "column",
"cases": "cases",
"display cases": "dcases",
"definition": "definition",
"description": "description",
"document": "document",
"enumerate": "enumerate",
"equation": "equation",
# "figure" = ["figure", "[h!]"]
"figure": "figure",
"flush left": "flushleft",
"flush right": "flushright",
"frame": "frame",
"itemise": "itemize",
"mini page": "minipage",
# "multi (cols | columns)" = ["multicols", "{2}"]
"multi line": "multline",
"proof": "proof",
"quotation": "quotation",
"quote": "quote",
"split": "split",
# "table" = ["table", "[h!]\n\\centering"]
# "long table" = ["longtable", "{lll}"]
# "tabular" = ["tabular", "{llll}"]
# "tabular X" = ["tabular X", "{l X}"]
"theorem": "theorem",
"title page": "titlepage",
"verbatim": "verbatim",
"verse": "verse",
"wrap figure": "wrapfigure",
}
mod.list("tex_commands", desc="TeX commands")
ctx.lists["user.tex_commands"] = {
"author": "author",
"add bib resource": "addbibresource",
"caption": "caption",
"chapter": "chapter",
"simple citation": "cite",
"frame title": "frametitle",
"footnote": "footnote",
"footnote text": "footnotetext[]",
"graphics path": "graphicspath",
"include graphics": "includegraphics[width=1\\textwidth]",
"label": "label",
"new command": "newcommand{}[]",
"paragraph": "paragraph",
"paren cite": "parencite",
"part": "part",
"reference": "ref",
"renew command": "renewcommand",
"sub paragraph": "subparagraph",
"section": "section",
"sub section": "subsection",
"sub sub section": "subsubsection",
"text cite": "textcite",
"bold": "textbf",
"italics": "textit",
"slanted": "textsl",
"emphasis": "emph",
"title": "title",
"use theme": "usetheme",
# Accents
"accent grave": "`",
"accent acute": "'",
"accent dot": ".",
"accent breve": "u",
"circumflex": "^",
"umlaut": '"',
"tilde": "~",
"macron": "=",
}
mod.list("tex_commands_noarg", desc="TeX commands without arguments")
ctx.lists["user.tex_commands_noarg"] = {
"centering": "centering",
"column": "column{0.5\\textwidth}",
"footnote mark": "footnotemark[]",
"horizontal line": "hline",
"lay tech": "LaTeX~ ",
"line break": "linebreak",
"item": "item",
"make title": "maketitle",
"new page": "newpage",
"no indent": "noindent",
"page break": "pagebreak",
"print bibliography": "printbibliography",
"table of contents": "tableofcontents",
"tech": "TeX~ ",
"text backslash": "textbackslash",
"text height": "textheight",
"text width": "textwidth",
"vertical line": "vline",
}
ctx.lists["user.greek_letters"] = {
# Lowercase
"alpha": "alpha",
"beater": "beta",
"gamma": "gamma",
"delta": "delta",
"epsilon": "varepsilon",
"zita": "zeta",
"eater": "eta",
"theta": "theta",
"iota": "iota",
"kappa": "kappa",
"lambda": "lambda",
"mu": "mu",
"new": "nu",
"zee": "xi",
"pie": "pi",
"row": "rho",
"sigma": "sigma",
"tau": "tau",
"upsilon": "upsilon",
"phi": "phi",
"chi": "chi",
"sigh": "psi",
"omega": "omega",
# Capitals
"big gamma": "Gamma",
"big delta": "Delta",
"big theta": "Theta",
"big lambda": "Lambda",
"big zee": "Xi",
"big pie": "Pi",
"big sigma": "Sigma",
"big upsilon": "Upsilon",
"big phi": "Phi",
"big sigh": "Psi",
"big omega": "Omega",
}
ctx.lists["user.bracket_type"] = {
"nude": "matrix",
"curly": "Bmatrix",
"round": "pmatrix",
"square": "bmatrix",
"pipe": "vmatrix",
"double pipe": "Vmatrix",
}
@mod.action_class
class Actions:
def latex_insert_environment(name: str):
"""Insert a latex environment"""
actions.insert(f"\\begin{{{name}}}")
actions.key("enter:2")
actions.insert(f"\\end{{{name}}}")
actions.key("up")
@ctx.action_class("user")
class Actions:
def maths_greek_letter(letter: str):
actions.insert(f"\\{letter}")
def maths_tex_symbol(symbol: str):
actions.insert(f"\\{symbol}")
def maths_begin_superscript():
actions.user.insert_between("^{", "}")
def maths_begin_subscript():
actions.user.insert_between("_{", "}")
mod.list("tex_templates", desc="TeX templates")
ctx.lists["user.tex_templates"] = {
"header": r'''
\documentclass[12pt, a4paper]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[style=authoryear]{biblatex}
\addbibresource{}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.3}
''',
# ------------------------------------
"beamer": r'''
\documentclass{beamer}
\usetheme{metropolis}
\usepackage{graphicx}
\usepackage[style=authoryear]{biblatex}
\addbibresource{}
\begin{document}
\begin{frame}
\frametitle{}
\end{frame}
\end{document}
''',
# ------------------------------------
"(graphic | figure)": r'''
\begin{figure}[h!]
\centering
\label{}
\includegraphics[width=1\textwidth]{}
\caption{}
\end{figure}
''',
# ------------------------------------
"figure": r'''
\begin{wrapfigure}{l}{0.5\textwidth}
\centering
\label{}
\includegraphics[width=0.4\textwidth]{}
\caption{}
\end{wrapfigure}
''',
# ------------------------------------
"physics": r'''
\documentclass[12pt]{article}
\usepackage{physics}
\title{FCI Questions}
\author{Patryk Kozlowski}
\date{\today} %% Change "\today" by another date manually
\begin{document}
\maketitle
\end{document}
''',
# ------------------------------------
"table": r'''
\begin{table}[h!]
\centering
\label{}
\begin{tabular}{ccccc}
& & & & \\
\hline
& & & & \\
\end{tabular}
\caption{}
\end{table}
'''
}