on master help sign in
Add latex
commita364d6c3837c36225dcd4ec9b15ef2c192feef0b authorIvan Tham <pickfire@riseup.net> dateWed 16 Jun 2021, 00:50 (5 years ago) parentd1c8a74
6 files changed+438
.gitmodules+5 helix-syntax/languages/tree-sitter-latex+1 helix-syntax/src/lib.rs+1 languages.toml+9 runtime/queries/latex/folds.scm+12 runtime/queries/latex/highlights.scm+410
.gitmodules+5
@@ -89,3 +89,8 @@
8989[submodule "helix-syntax/languages/tree-sitter-nix"]
9090 path = helix-syntax/languages/tree-sitter-nix
9191 url = https://github.com/cstrahan/tree-sitter-nix
92+ shallow = true
93+[submodule "helix-syntax/languages/tree-sitter-latex"]
94+ path = helix-syntax/languages/tree-sitter-latex
95+ url = https://github.com/latex-lsp/tree-sitter-latex
96+ shallow = true
helix-syntax/languages/tree-sitter-latexnew file+1

Submodule changed.

helix-syntax/src/lib.rs+1
@@ -80,6 +80,7 @@ mk_langs!(
8080 (Java, tree_sitter_java),
8181 (Json, tree_sitter_json),
8282 (Julia, tree_sitter_julia),
83+ (Latex, tree_sitter_latex),
8384 (Nix, tree_sitter_nix),
8485 (Php, tree_sitter_php),
8586 (Python, tree_sitter_python),
languages.toml+9
@@ -156,6 +156,15 @@ roots = []
156156
157157indent = { tab-width = 2, unit = " " }
158158
159+[[language]]
160+name = "latex"
161+scope = "source.tex"
162+injection-regex = "tex"
163+file-types = ["tex"]
164+roots = []
165+
166+indent = { tab-width = 4, unit = "\t" }
167+
159168# [[language]]
160169# name = "haskell"
161170# scope = "source.haskell"
runtime/queries/latex/folds.scmnew file+12
@@ -0,0 +1,12 @@
1+[
2+ (chapter)
3+ (part)
4+ (section)
5+ (subsection)
6+ (subsubsection)
7+ (paragraph)
8+ (subparagraph)
9+
10+ (environment)
11+ (displayed_equation)
12+] @fold
runtime/queries/latex/highlights.scmnew file+410
@@ -0,0 +1,410 @@
1+;; Math
2+[
3+ (displayed_equation)
4+ (inline_formula)
5+] @text.math
6+
7+;; This highlights the whole environment like vimtex does
8+((environment
9+ (begin
10+ name: (word) @_env)) @text.math
11+ (#any-of? @_env
12+ "displaymath" "displaymath*"
13+ "equation" "equation*"
14+ "multline" "multline*"
15+ "eqnarray" "eqnarray*"
16+ "align" "align*"
17+ "array" "array*"
18+ "split" "split*"
19+ "alignat" "alignat*"
20+ "gather" "gather*"
21+ "flalign" "flalign*"))
22+
23+[
24+ (generic_command_name)
25+ "\\newcommand"
26+ "\\renewcommand"
27+ "\\DeclareRobustCommand"
28+ "\\DeclareMathOperator"
29+ "\\newglossaryentry"
30+ "\\caption"
31+ "\\label"
32+ "\\newlabel"
33+ "\\color"
34+ "\\colorbox"
35+ "\\textcolor"
36+ "\\pagecolor"
37+ "\\definecolor"
38+ "\\definecolorset"
39+ "\\newtheorem"
40+ "\\declaretheorem"
41+ "\\newacronym"
42+] @function.macro
43+
44+[
45+ "\\ref"
46+ "\\vref"
47+ "\\Vref"
48+ "\\autoref"
49+ "\\pageref"
50+ "\\cref"
51+ "\\Cref"
52+ "\\cref*"
53+ "\\Cref*"
54+ "\\namecref"
55+ "\\nameCref"
56+ "\\lcnamecref"
57+ "\\namecrefs"
58+ "\\nameCrefs"
59+ "\\lcnamecrefs"
60+ "\\labelcref"
61+ "\\labelcpageref"
62+ "\\crefrange"
63+ "\\crefrange"
64+ "\\Crefrange"
65+ "\\Crefrange"
66+ "\\crefrange*"
67+ "\\crefrange*"
68+ "\\Crefrange*"
69+ "\\Crefrange*"
70+] @function.macro
71+
72+[
73+ "\\cite"
74+ "\\cite*"
75+ "\\Cite"
76+ "\\nocite"
77+ "\\citet"
78+ "\\citep"
79+ "\\citet*"
80+ "\\citep*"
81+ "\\citeauthor"
82+ "\\citeauthor*"
83+ "\\Citeauthor"
84+ "\\Citeauthor*"
85+ "\\citetitle"
86+ "\\citetitle*"
87+ "\\citeyear"
88+ "\\citeyear*"
89+ "\\citedate"
90+ "\\citedate*"
91+ "\\citeurl"
92+ "\\fullcite"
93+ "\\citeyearpar"
94+ "\\citealt"
95+ "\\citealp"
96+ "\\citetext"
97+ "\\parencite"
98+ "\\parencite*"
99+ "\\Parencite"
100+ "\\footcite"
101+ "\\footfullcite"
102+ "\\footcitetext"
103+ "\\textcite"
104+ "\\Textcite"
105+ "\\smartcite"
106+ "\\Smartcite"
107+ "\\supercite"
108+ "\\autocite"
109+ "\\Autocite"
110+ "\\autocite*"
111+ "\\Autocite*"
112+ "\\volcite"
113+ "\\Volcite"
114+ "\\pvolcite"
115+ "\\Pvolcite"
116+ "\\fvolcite"
117+ "\\ftvolcite"
118+ "\\svolcite"
119+ "\\Svolcite"
120+ "\\tvolcite"
121+ "\\Tvolcite"
122+ "\\avolcite"
123+ "\\Avolcite"
124+ "\\notecite"
125+ "\\notecite"
126+ "\\pnotecite"
127+ "\\Pnotecite"
128+ "\\fnotecite"
129+] @function.macro
130+
131+[
132+ "\\ref"
133+ "\\vref"
134+ "\\Vref"
135+ "\\autoref"
136+ "\\pageref"
137+ "\\cref"
138+ "\\Cref"
139+ "\\cref*"
140+ "\\Cref*"
141+ "\\namecref"
142+ "\\nameCref"
143+ "\\lcnamecref"
144+ "\\namecrefs"
145+ "\\nameCrefs"
146+ "\\lcnamecrefs"
147+ "\\labelcref"
148+ "\\labelcpageref"
149+] @function.macro
150+
151+
152+[
153+ "\\crefrange"
154+ "\\crefrange"
155+ "\\Crefrange"
156+ "\\Crefrange"
157+ "\\crefrange*"
158+ "\\crefrange*"
159+ "\\Crefrange*"
160+ "\\Crefrange*"
161+] @function.macro
162+
163+
164+[
165+ "\\gls"
166+ "\\Gls"
167+ "\\GLS"
168+ "\\glspl"
169+ "\\Glspl"
170+ "\\GLSpl"
171+ "\\glsdisp"
172+ "\\glslink"
173+ "\\glstext"
174+ "\\Glstext"
175+ "\\GLStext"
176+ "\\glsfirst"
177+ "\\Glsfirst"
178+ "\\GLSfirst"
179+ "\\glsplural"
180+ "\\Glsplural"
181+ "\\GLSplural"
182+ "\\glsfirstplural"
183+ "\\Glsfirstplural"
184+ "\\GLSfirstplural"
185+ "\\glsname"
186+ "\\Glsname"
187+ "\\GLSname"
188+ "\\glssymbol"
189+ "\\Glssymbol"
190+ "\\glsdesc"
191+ "\\Glsdesc"
192+ "\\GLSdesc"
193+ "\\glsuseri"
194+ "\\Glsuseri"
195+ "\\GLSuseri"
196+ "\\glsuserii"
197+ "\\Glsuserii"
198+ "\\GLSuserii"
199+ "\\glsuseriii"
200+ "\\Glsuseriii"
201+ "\\GLSuseriii"
202+ "\\glsuseriv"
203+ "\\Glsuseriv"
204+ "\\GLSuseriv"
205+ "\\glsuserv"
206+ "\\Glsuserv"
207+ "\\GLSuserv"
208+ "\\glsuservi"
209+ "\\Glsuservi"
210+ "\\GLSuservi"
211+] @function.macro
212+
213+
214+[
215+ "\\acrshort"
216+ "\\Acrshort"
217+ "\\ACRshort"
218+ "\\acrshortpl"
219+ "\\Acrshortpl"
220+ "\\ACRshortpl"
221+ "\\acrlong"
222+ "\\Acrlong"
223+ "\\ACRlong"
224+ "\\acrlongpl"
225+ "\\Acrlongpl"
226+ "\\ACRlongpl"
227+ "\\acrfull"
228+ "\\Acrfull"
229+ "\\ACRfull"
230+ "\\acrfullpl"
231+ "\\Acrfullpl"
232+ "\\ACRfullpl"
233+ "\\acs"
234+ "\\Acs"
235+ "\\acsp"
236+ "\\Acsp"
237+ "\\acl"
238+ "\\Acl"
239+ "\\aclp"
240+ "\\Aclp"
241+ "\\acf"
242+ "\\Acf"
243+ "\\acfp"
244+ "\\Acfp"
245+ "\\ac"
246+ "\\Ac"
247+ "\\acp"
248+ "\\glsentrylong"
249+ "\\Glsentrylong"
250+ "\\glsentrylongpl"
251+ "\\Glsentrylongpl"
252+ "\\glsentryshort"
253+ "\\Glsentryshort"
254+ "\\glsentryshortpl"
255+ "\\Glsentryshortpl"
256+ "\\glsentryfullpl"
257+ "\\Glsentryfullpl"
258+] @function.macro
259+
260+(comment) @comment
261+
262+(bracket_group) @parameter
263+
264+[(math_operator) "="] @operator
265+
266+[
267+ "\\usepackage"
268+ "\\documentclass"
269+ "\\input"
270+ "\\include"
271+ "\\subfile"
272+ "\\subfileinclude"
273+ "\\subfileinclude"
274+ "\\includegraphics"
275+ "\\addbibresource"
276+ "\\bibliography"
277+ "\\includesvg"
278+ "\\includeinkscape"
279+ "\\usepgflibrary"
280+ "\\usetikzlibrary"
281+] @include
282+
283+[
284+ "\\part"
285+ "\\chapter"
286+ "\\section"
287+ "\\subsection"
288+ "\\subsubsection"
289+ "\\paragraph"
290+ "\\subparagraph"
291+] @type
292+
293+"\\item" @punctuation.special
294+
295+((word) @punctuation.delimiter
296+(#eq? @punctuation.delimiter "&"))
297+
298+["$" "\\[" "\\]" "\\(" "\\)"] @punctuation.delimiter
299+
300+(label_definition
301+ name: (_) @text.reference)
302+(label_reference
303+ label: (_) @text.reference)
304+(equation_label_reference
305+ label: (_) @text.reference)
306+(label_reference
307+ label: (_) @text.reference)
308+(label_number
309+ label: (_) @text.reference)
310+
311+(citation
312+ key: (word) @text.reference)
313+
314+(key_val_pair
315+ key: (_) @parameter
316+ value: (_))
317+
318+["[" "]" "{" "}"] @punctuation.bracket ;"(" ")" is has no special meaning in LaTeX
319+
320+(chapter
321+ text: (brace_group) @text.title)
322+
323+(part
324+ text: (brace_group) @text.title)
325+
326+(section
327+ text: (brace_group) @text.title)
328+
329+(subsection
330+ text: (brace_group) @text.title)
331+
332+(subsubsection
333+ text: (brace_group) @text.title)
334+
335+(paragraph
336+ text: (brace_group) @text.title)
337+
338+(subparagraph
339+ text: (brace_group) @text.title)
340+
341+((environment
342+ (begin
343+ name: (word) @_frame)
344+ (brace_group
345+ child: (text) @text.title))
346+ (#eq? @_frame "frame"))
347+
348+((generic_command
349+ name:(generic_command_name) @_name
350+ arg: (brace_group
351+ (text) @text.title))
352+ (#eq? @_name "\\frametitle"))
353+
354+;; Formatting
355+
356+((generic_command
357+ name:(generic_command_name) @_name
358+ arg: (_) @text.emphasis)
359+ (#eq? @_name "\\emph"))
360+
361+((generic_command
362+ name:(generic_command_name) @_name
363+ arg: (_) @text.emphasis)
364+ (#match? @_name "^(\\\\textit|\\\\mathit)$"))
365+
366+((generic_command
367+ name:(generic_command_name) @_name
368+ arg: (_) @text.strong)
369+ (#match? @_name "^(\\\\textbf|\\\\mathbf)$"))
370+
371+((generic_command
372+ name:(generic_command_name) @_name
373+ .
374+ arg: (_) @text.uri)
375+ (#match? @_name "^(\\\\url|\\\\href)$"))
376+
377+(ERROR) @error
378+
379+[
380+ "\\begin"
381+ "\\end"
382+] @text.environment
383+
384+(begin
385+ name: (_) @text.environment.name
386+ (#not-any-of? @text.environment.name
387+ "displaymath" "displaymath*"
388+ "equation" "equation*"
389+ "multline" "multline*"
390+ "eqnarray" "eqnarray*"
391+ "align" "align*"
392+ "array" "array*"
393+ "split" "split*"
394+ "alignat" "alignat*"
395+ "gather" "gather*"
396+ "flalign" "flalign*"))
397+
398+(end
399+ name: (_) @text.environment.name
400+ (#not-any-of? @text.environment.name
401+ "displaymath" "displaymath*"
402+ "equation" "equation*"
403+ "multline" "multline*"
404+ "eqnarray" "eqnarray*"
405+ "align" "align*"
406+ "array" "array*"
407+ "split" "split*"
408+ "alignat" "alignat*"
409+ "gather" "gather*"
410+ "flalign" "flalign*"))