diff options
author | Ivan Tham | 2021-06-15 16:50:42 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-16 12:42:05 +0000 |
commit | a364d6c3837c36225dcd4ec9b15ef2c192feef0b (patch) | |
tree | 5a49571b656f1a68c167933a78690ba4f3918051 | |
parent | d1c8a74771b241ee0824853bd5e8229cb0ab4187 (diff) |
Add latex
-rw-r--r-- | .gitmodules | 5 | ||||
m--------- | helix-syntax/languages/tree-sitter-latex | 0 | ||||
-rw-r--r-- | helix-syntax/src/lib.rs | 1 | ||||
-rw-r--r-- | languages.toml | 9 | ||||
-rw-r--r-- | runtime/queries/latex/folds.scm | 12 | ||||
-rw-r--r-- | runtime/queries/latex/highlights.scm | 410 |
6 files changed, 437 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules index 4cf9e502..87acea60 100644 --- a/.gitmodules +++ b/.gitmodules @@ -89,3 +89,8 @@ [submodule "helix-syntax/languages/tree-sitter-nix"] path = helix-syntax/languages/tree-sitter-nix url = https://github.com/cstrahan/tree-sitter-nix + shallow = true +[submodule "helix-syntax/languages/tree-sitter-latex"] + path = helix-syntax/languages/tree-sitter-latex + url = https://github.com/latex-lsp/tree-sitter-latex + shallow = true diff --git a/helix-syntax/languages/tree-sitter-latex b/helix-syntax/languages/tree-sitter-latex new file mode 160000 +Subproject 7f720661de5316c0f8fee956526d4002fa1086d diff --git a/helix-syntax/src/lib.rs b/helix-syntax/src/lib.rs index a4706d3b..5e3bb3ea 100644 --- a/helix-syntax/src/lib.rs +++ b/helix-syntax/src/lib.rs @@ -80,6 +80,7 @@ mk_langs!( (Java, tree_sitter_java), (Json, tree_sitter_json), (Julia, tree_sitter_julia), + (Latex, tree_sitter_latex), (Nix, tree_sitter_nix), (Php, tree_sitter_php), (Python, tree_sitter_python), diff --git a/languages.toml b/languages.toml index b93bcb8b..9ae7a658 100644 --- a/languages.toml +++ b/languages.toml @@ -156,6 +156,15 @@ roots = [] indent = { tab-width = 2, unit = " " } +[[language]] +name = "latex" +scope = "source.tex" +injection-regex = "tex" +file-types = ["tex"] +roots = [] + +indent = { tab-width = 4, unit = "\t" } + # [[language]] # name = "haskell" # scope = "source.haskell" diff --git a/runtime/queries/latex/folds.scm b/runtime/queries/latex/folds.scm new file mode 100644 index 00000000..fb5c7176 --- /dev/null +++ b/runtime/queries/latex/folds.scm @@ -0,0 +1,12 @@ +[ + (chapter) + (part) + (section) + (subsection) + (subsubsection) + (paragraph) + (subparagraph) + + (environment) + (displayed_equation) +] @fold diff --git a/runtime/queries/latex/highlights.scm b/runtime/queries/latex/highlights.scm new file mode 100644 index 00000000..cd04a62c --- /dev/null +++ b/runtime/queries/latex/highlights.scm @@ -0,0 +1,410 @@ +;; Math +[ + (displayed_equation) + (inline_formula) +] @text.math + +;; This highlights the whole environment like vimtex does +((environment + (begin + name: (word) @_env)) @text.math + (#any-of? @_env + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) + +[ + (generic_command_name) + "\\newcommand" + "\\renewcommand" + "\\DeclareRobustCommand" + "\\DeclareMathOperator" + "\\newglossaryentry" + "\\caption" + "\\label" + "\\newlabel" + "\\color" + "\\colorbox" + "\\textcolor" + "\\pagecolor" + "\\definecolor" + "\\definecolorset" + "\\newtheorem" + "\\declaretheorem" + "\\newacronym" +] @function.macro + +[ + "\\ref" + "\\vref" + "\\Vref" + "\\autoref" + "\\pageref" + "\\cref" + "\\Cref" + "\\cref*" + "\\Cref*" + "\\namecref" + "\\nameCref" + "\\lcnamecref" + "\\namecrefs" + "\\nameCrefs" + "\\lcnamecrefs" + "\\labelcref" + "\\labelcpageref" + "\\crefrange" + "\\crefrange" + "\\Crefrange" + "\\Crefrange" + "\\crefrange*" + "\\crefrange*" + "\\Crefrange*" + "\\Crefrange*" +] @function.macro + +[ + "\\cite" + "\\cite*" + "\\Cite" + "\\nocite" + "\\citet" + "\\citep" + "\\citet*" + "\\citep*" + "\\citeauthor" + "\\citeauthor*" + "\\Citeauthor" + "\\Citeauthor*" + "\\citetitle" + "\\citetitle*" + "\\citeyear" + "\\citeyear*" + "\\citedate" + "\\citedate*" + "\\citeurl" + "\\fullcite" + "\\citeyearpar" + "\\citealt" + "\\citealp" + "\\citetext" + "\\parencite" + "\\parencite*" + "\\Parencite" + "\\footcite" + "\\footfullcite" + "\\footcitetext" + "\\textcite" + "\\Textcite" + "\\smartcite" + "\\Smartcite" + "\\supercite" + "\\autocite" + "\\Autocite" + "\\autocite*" + "\\Autocite*" + "\\volcite" + "\\Volcite" + "\\pvolcite" + "\\Pvolcite" + "\\fvolcite" + "\\ftvolcite" + "\\svolcite" + "\\Svolcite" + "\\tvolcite" + "\\Tvolcite" + "\\avolcite" + "\\Avolcite" + "\\notecite" + "\\notecite" + "\\pnotecite" + "\\Pnotecite" + "\\fnotecite" +] @function.macro + +[ + "\\ref" + "\\vref" + "\\Vref" + "\\autoref" + "\\pageref" + "\\cref" + "\\Cref" + "\\cref*" + "\\Cref*" + "\\namecref" + "\\nameCref" + "\\lcnamecref" + "\\namecrefs" + "\\nameCrefs" + "\\lcnamecrefs" + "\\labelcref" + "\\labelcpageref" +] @function.macro + + +[ + "\\crefrange" + "\\crefrange" + "\\Crefrange" + "\\Crefrange" + "\\crefrange*" + "\\crefrange*" + "\\Crefrange*" + "\\Crefrange*" +] @function.macro + + +[ + "\\gls" + "\\Gls" + "\\GLS" + "\\glspl" + "\\Glspl" + "\\GLSpl" + "\\glsdisp" + "\\glslink" + "\\glstext" + "\\Glstext" + "\\GLStext" + "\\glsfirst" + "\\Glsfirst" + "\\GLSfirst" + "\\glsplural" + "\\Glsplural" + "\\GLSplural" + "\\glsfirstplural" + "\\Glsfirstplural" + "\\GLSfirstplural" + "\\glsname" + "\\Glsname" + "\\GLSname" + "\\glssymbol" + "\\Glssymbol" + "\\glsdesc" + "\\Glsdesc" + "\\GLSdesc" + "\\glsuseri" + "\\Glsuseri" + "\\GLSuseri" + "\\glsuserii" + "\\Glsuserii" + "\\GLSuserii" + "\\glsuseriii" + "\\Glsuseriii" + "\\GLSuseriii" + "\\glsuseriv" + "\\Glsuseriv" + "\\GLSuseriv" + "\\glsuserv" + "\\Glsuserv" + "\\GLSuserv" + "\\glsuservi" + "\\Glsuservi" + "\\GLSuservi" +] @function.macro + + +[ + "\\acrshort" + "\\Acrshort" + "\\ACRshort" + "\\acrshortpl" + "\\Acrshortpl" + "\\ACRshortpl" + "\\acrlong" + "\\Acrlong" + "\\ACRlong" + "\\acrlongpl" + "\\Acrlongpl" + "\\ACRlongpl" + "\\acrfull" + "\\Acrfull" + "\\ACRfull" + "\\acrfullpl" + "\\Acrfullpl" + "\\ACRfullpl" + "\\acs" + "\\Acs" + "\\acsp" + "\\Acsp" + "\\acl" + "\\Acl" + "\\aclp" + "\\Aclp" + "\\acf" + "\\Acf" + "\\acfp" + "\\Acfp" + "\\ac" + "\\Ac" + "\\acp" + "\\glsentrylong" + "\\Glsentrylong" + "\\glsentrylongpl" + "\\Glsentrylongpl" + "\\glsentryshort" + "\\Glsentryshort" + "\\glsentryshortpl" + "\\Glsentryshortpl" + "\\glsentryfullpl" + "\\Glsentryfullpl" +] @function.macro + +(comment) @comment + +(bracket_group) @parameter + +[(math_operator) "="] @operator + +[ + "\\usepackage" + "\\documentclass" + "\\input" + "\\include" + "\\subfile" + "\\subfileinclude" + "\\subfileinclude" + "\\includegraphics" + "\\addbibresource" + "\\bibliography" + "\\includesvg" + "\\includeinkscape" + "\\usepgflibrary" + "\\usetikzlibrary" +] @include + +[ + "\\part" + "\\chapter" + "\\section" + "\\subsection" + "\\subsubsection" + "\\paragraph" + "\\subparagraph" +] @type + +"\\item" @punctuation.special + +((word) @punctuation.delimiter +(#eq? @punctuation.delimiter "&")) + +["$" "\\[" "\\]" "\\(" "\\)"] @punctuation.delimiter + +(label_definition + name: (_) @text.reference) +(label_reference + label: (_) @text.reference) +(equation_label_reference + label: (_) @text.reference) +(label_reference + label: (_) @text.reference) +(label_number + label: (_) @text.reference) + +(citation + key: (word) @text.reference) + +(key_val_pair + key: (_) @parameter + value: (_)) + +["[" "]" "{" "}"] @punctuation.bracket ;"(" ")" is has no special meaning in LaTeX + +(chapter + text: (brace_group) @text.title) + +(part + text: (brace_group) @text.title) + +(section + text: (brace_group) @text.title) + +(subsection + text: (brace_group) @text.title) + +(subsubsection + text: (brace_group) @text.title) + +(paragraph + text: (brace_group) @text.title) + +(subparagraph + text: (brace_group) @text.title) + +((environment + (begin + name: (word) @_frame) + (brace_group + child: (text) @text.title)) + (#eq? @_frame "frame")) + +((generic_command + name:(generic_command_name) @_name + arg: (brace_group + (text) @text.title)) + (#eq? @_name "\\frametitle")) + +;; Formatting + +((generic_command + name:(generic_command_name) @_name + arg: (_) @text.emphasis) + (#eq? @_name "\\emph")) + +((generic_command + name:(generic_command_name) @_name + arg: (_) @text.emphasis) + (#match? @_name "^(\\\\textit|\\\\mathit)$")) + +((generic_command + name:(generic_command_name) @_name + arg: (_) @text.strong) + (#match? @_name "^(\\\\textbf|\\\\mathbf)$")) + +((generic_command + name:(generic_command_name) @_name + . + arg: (_) @text.uri) + (#match? @_name "^(\\\\url|\\\\href)$")) + +(ERROR) @error + +[ + "\\begin" + "\\end" +] @text.environment + +(begin + name: (_) @text.environment.name + (#not-any-of? @text.environment.name + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) + +(end + name: (_) @text.environment.name + (#not-any-of? @text.environment.name + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) |